summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--menudriver.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/menudriver.c b/menudriver.c
index 17e2272..af47f54 100644
--- a/menudriver.c
+++ b/menudriver.c
@@ -11,13 +11,13 @@
#include <errno.h>
#include <limits.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
-#include <unistd.h>
#include <sys/wait.h>
-#include <string.h>
-#include <signal.h>
+#include <unistd.h>
#ifndef PATH_MAX
#ifdef _XOPEN_PATH_MAX
@@ -46,8 +46,7 @@ void poplast(void);
void settings(const char *, const char *, int);
int subdir(void);
-char next[40] = "", cmd[80], last[40] = ".";
-int val;
+char next[40] = "", last[40] = ".";
static void wait_for_return(void)
{
@@ -58,12 +57,12 @@ static void wait_for_return(void)
}
}
-static void view_menu(const char *command, const char *filename)
+static void view_menu(const char *viewer, const char *filename)
{
- if (command) {
- char buf[PATH_MAX];
- snprintf(buf, sizeof(buf), "%s %s", command, filename);
- system(buf);
+ if (viewer) {
+ char cmd[PATH_MAX];
+ snprintf(cmd, sizeof(cmd), "%s %s", viewer, filename);
+ system(cmd);
return;
}
@@ -99,7 +98,7 @@ 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;
+ //fastback = 0;
} else {
snprintf(cmd, sizeof(cmd), "%s %s", viewer, filename);
}
@@ -116,10 +115,13 @@ int main(int argc, char *argv[])
char *viewer = getenv("VIEWER");
char *fb = getenv("RETURNTOMENU");
char *menuviewer = getenv("MENUVIEWER");
+ char *dir = ".";
if (argc > 2) {
fprintf(stderr, "menudriver: wrong number of args\n");
exit(1);
+ } else if (argc == 2) {
+ dir = argv[1];
}
if (!viewer) {
@@ -130,13 +132,14 @@ int main(int argc, char *argv[])
fastback = !(*fb == 'N' || *fb == 'n');
}
- menudrive(menuviewer, viewer, argc == 1 ? "." : argv[1]);
+ menudrive(menuviewer, viewer, dir);
}
/* checks if last is a number (and if so leaves value in val) */
int lastval(void)
{
/* special case, have just entered subdir */
+ int val;
if (strcmp(last, ".") == 0 && subdir()) {
poplast();
@@ -216,11 +219,11 @@ void menudrive(const char *menuviewer, const char *viewer, char *dir)
}
if (strcmp(next, "+") == 0 && lastval()) {
- (void)sprintf(next, "%d", val + 1);
+ (void)sprintf(next, "%d", atoi(last) + 1);
}
if (strcmp(next, "-") == 0 && lastval()) {
- (void)sprintf(next, "%d", val - 1);
+ (void)sprintf(next, "%d", atoi(last) - 1);
}
if (stat(next, &st) == 0) {
@@ -232,7 +235,8 @@ void menudrive(const char *menuviewer, const char *viewer, char *dir)
if (S_ISDIR(st.st_mode)) { /* directory */
char hold[PATH_MAX];
if (!getcwd(hold, sizeof(hold))) {
- fprintf(stderr, "panic: cwd too long\n"), exit(1);
+ fprintf(stderr, "panic: cwd too long\n");
+ exit(1);
}
if (chdir(next) == -1 || stat("contents", &st)) {
@@ -408,7 +412,6 @@ void pushlast(void)
return;
}
- /* suppressed 'cos interferes with special case in lastval() */
strcpy(lastp, last);
lastp += n + 1;
strcpy(last, ".");