xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 0d14a06969d8e2c9e5af3a860c96aa850bf2242c

Add files for :pushd and :popd commands
Author: xaizek
Author date (UTC): 2011-05-22 09:49
Committer name: xaizek
Committer date (UTC): 2011-05-22 09:49
Parent(s): 0d40464e8d4499fcf47faa49d3554495ab67f64f
Signing key:
Tree: 021f14c11249c86a237f1d3d2ebe9f2c6ff752b0
File Lines added Lines deleted
src/dir_stack.c 87 0
src/dir_stack.h 5 4
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
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master