File src/dir_stack.c added (mode: 100644) (index 000000000..a7546a506) |
|
1 |
|
#include <stdlib.h> |
|
2 |
|
#include <string.h> |
|
3 |
|
|
|
4 |
|
#include "filelist.h" |
|
5 |
|
#include "ui.h" |
|
6 |
|
|
|
7 |
|
#include "dir_stack.h" |
|
8 |
|
|
|
9 |
|
struct stack_entry { |
|
10 |
|
char* lpane_dir; |
|
11 |
|
char* lpane_file; |
|
12 |
|
char* rpane_dir; |
|
13 |
|
char* rpane_file; |
|
14 |
|
}; |
|
15 |
|
|
|
16 |
|
static struct stack_entry * stack; |
|
17 |
|
static unsigned int stack_size; |
|
18 |
|
static unsigned int stack_top; |
|
19 |
|
|
|
20 |
|
static void free_entry(const struct stack_entry * entry); |
|
21 |
|
|
|
22 |
|
/* |
|
23 |
|
* Returns 0 on success and -1 when not enough memory |
|
24 |
|
*/ |
|
25 |
|
int |
|
26 |
|
pushd(void) |
|
27 |
|
{ |
|
28 |
|
if(stack_top == stack_size) |
|
29 |
|
{ |
|
30 |
|
struct stack_entry* s = realloc(stack, (stack_size + 1)*sizeof(*stack)); |
|
31 |
|
if(s == NULL) |
|
32 |
|
return -1; |
|
33 |
|
|
|
34 |
|
stack = s; |
|
35 |
|
stack_size++; |
|
36 |
|
} |
|
37 |
|
|
|
38 |
|
stack[stack_top].lpane_dir = strdup(lwin.curr_dir); |
|
39 |
|
stack[stack_top].lpane_file = strdup(lwin.dir_entry[lwin.list_pos].name); |
|
40 |
|
stack[stack_top].rpane_dir = strdup(rwin.curr_dir); |
|
41 |
|
stack[stack_top].rpane_file = strdup(rwin.dir_entry[rwin.list_pos].name); |
|
42 |
|
|
|
43 |
|
if(stack[stack_top].lpane_dir == NULL || stack[stack_top].lpane_file == NULL |
|
44 |
|
|| stack[stack_top].rpane_dir == NULL |
|
45 |
|
|| stack[stack_top].rpane_file == NULL) |
|
46 |
|
{ |
|
47 |
|
free_entry(&stack[stack_top]); |
|
48 |
|
return -1; |
|
49 |
|
} |
|
50 |
|
|
|
51 |
|
stack_top++; |
|
52 |
|
|
|
53 |
|
return 0; |
|
54 |
|
} |
|
55 |
|
|
|
56 |
|
/* |
|
57 |
|
* Returns 0 on success and -1 on underflow |
|
58 |
|
*/ |
|
59 |
|
int |
|
60 |
|
popd(void) |
|
61 |
|
{ |
|
62 |
|
if(stack_top == 0) |
|
63 |
|
return -1; |
|
64 |
|
|
|
65 |
|
stack_top -= 1; |
|
66 |
|
|
|
67 |
|
change_directory(&lwin, stack[stack_top].lpane_dir); |
|
68 |
|
load_dir_list(&lwin, 0); |
|
69 |
|
|
|
70 |
|
change_directory(&rwin, stack[stack_top].rpane_dir); |
|
71 |
|
load_dir_list(&rwin, 0); |
|
72 |
|
|
|
73 |
|
moveto_list_pos(curr_view, curr_view->list_pos); |
|
74 |
|
|
|
75 |
|
return 0; |
|
76 |
|
} |
|
77 |
|
|
|
78 |
|
static void |
|
79 |
|
free_entry(const struct stack_entry * entry) |
|
80 |
|
{ |
|
81 |
|
free(entry->lpane_dir); |
|
82 |
|
free(entry->lpane_file); |
|
83 |
|
free(entry->rpane_dir); |
|
84 |
|
free(entry->rpane_file); |
|
85 |
|
} |
|
86 |
|
|
|
87 |
|
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab : */ |
File src/dir_stack.h copied from file src/signals.h (similarity 87%) (mode: 100644) (index c8fc48b13..dc162729b) |
1 |
1 |
/* vifm |
/* vifm |
2 |
|
* Copyright (C) 2001 Ken Steen. |
|
|
2 |
|
* Copyright (C) 2011 xaizek. |
3 |
3 |
* |
* |
4 |
4 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
5 |
5 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
|
16 |
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
17 |
17 |
*/ |
*/ |
18 |
18 |
|
|
19 |
|
#ifndef __SIGNALS_H__ |
|
20 |
|
#define __SIGNALS_H__ |
|
|
19 |
|
#ifndef __DIR_STACK_H__ |
|
20 |
|
#define __DIR_STACK_H__ |
21 |
21 |
|
|
22 |
|
void setup_signals(void); |
|
|
22 |
|
int pushd(void); |
|
23 |
|
int popd(void); |
23 |
24 |
|
|
24 |
25 |
#endif |
#endif |
25 |
26 |
|
|