diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-03-28 10:46:56 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-03-28 10:46:56 -0400 |
commit | 9ab73dbe16237b6b2b1e8e214c10d879b843c726 (patch) | |
tree | 3733818ab47e3172a69469f3fe97510ed1c59bd9 /menudriver.c | |
parent | 6a32ada5270c5a948f939b7f14be17c3fba646f0 (diff) |
make next and last local variables
Diffstat (limited to 'menudriver.c')
-rw-r--r-- | menudriver.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/menudriver.c b/menudriver.c index af47f54..10e1c26 100644 --- a/menudriver.c +++ b/menudriver.c @@ -41,13 +41,11 @@ int fastback = 0; void callshell(char[]); void clrscr(void); void menudrive(const char *, const char *, char *); -void pushlast(void); -void poplast(void); +void pushlast(char *); +void poplast(char *); void settings(const char *, const char *, int); int subdir(void); -char next[40] = "", last[40] = "."; - static void wait_for_return(void) { printf("[Hit return to continue]"); @@ -98,7 +96,6 @@ static void view_file(const char *viewer, const char *filename) if (st.st_mode & S_IXUSR) { #endif snprintf(cmd, sizeof(cmd), "./%s", filename); - //fastback = 0; } else { snprintf(cmd, sizeof(cmd), "%s %s", viewer, filename); } @@ -136,19 +133,19 @@ int main(int argc, char *argv[]) } /* checks if last is a number (and if so leaves value in val) */ -int lastval(void) +int lastval(char *last) { /* special case, have just entered subdir */ int val; if (strcmp(last, ".") == 0 && subdir()) { - poplast(); + poplast(last); if (sscanf(last, "%d", &val) == 1) { chdir(".."); return (1); } - pushlast(); + pushlast(last); return 0; } @@ -157,6 +154,8 @@ int lastval(void) void menudrive(const char *menuviewer, const char *viewer, char *dir) { + char next[40] = "", last[40] = "."; + char *np; int c; int bad = 0; @@ -210,7 +209,7 @@ void menudrive(const char *menuviewer, const char *viewer, char *dir) if (next[0] == '\0') { chdir(".."); - poplast(); + poplast(last); continue; } @@ -218,11 +217,11 @@ void menudrive(const char *menuviewer, const char *viewer, char *dir) strcpy(next, last); /* repeat last option */ } - if (strcmp(next, "+") == 0 && lastval()) { + if (strcmp(next, "+") == 0 && lastval(last)) { (void)sprintf(next, "%d", atoi(last) + 1); } - if (strcmp(next, "-") == 0 && lastval()) { + if (strcmp(next, "-") == 0 && lastval(last)) { (void)sprintf(next, "%d", atoi(last) - 1); } @@ -244,7 +243,7 @@ void menudrive(const char *menuviewer, const char *viewer, char *dir) chdir(hold); } else { strcpy(last, next); - pushlast(); + pushlast(last); next[0] = '\0'; } @@ -394,7 +393,7 @@ int subdir(void) return (lastp > lastvec + 1); } -void pushlast(void) +void pushlast(char *last) { int n = strlen(last); if (last[0] == '.') { @@ -402,7 +401,7 @@ void pushlast(void) if (last[1] == '\0') { return; } else if (last[1] == '.' && last[2] == '\0') { - poplast(); + poplast(last); return; } } @@ -417,7 +416,7 @@ void pushlast(void) strcpy(last, "."); } -void poplast(void) +void poplast(char *last) { strcpy(lastp, last); /* just in case we come back immediately */ lastp--; |