From 4232bd5a9b3f4152fa7983e721b7807c2eabe8a3 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sun, 27 Mar 2022 22:41:26 -0400 Subject: clean up singleton() --- menudriver.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/menudriver.c b/menudriver.c index 9b2b07b..1ea810f 100644 --- a/menudriver.c +++ b/menudriver.c @@ -194,7 +194,9 @@ void menudrive(char *dir) if (chdir(next) == -1 || stat("contents", &st)) { bad = 1, chdir(hold); } else { - strcpy(last, next), pushlast(), next[0] = '\0'; + strcpy(last, next); + pushlast(); + next[0] = '\0'; } } else if (S_ISREG(st.st_mode)) { @@ -303,30 +305,26 @@ void menudrive(char *dir) void singleton(char *fil) { struct stat st; - if (stat(fil, &st) == 0 && S_ISREG(st.st_mode)) { /* regular file */ - clrscr(); + if (!(stat(fil, &st) == 0 && S_ISREG(st.st_mode))) { + fprintf(stderr, "menudriver: cannot access \"%s\"\n", fil), exit(1); + return; + } + clrscr(); + + snprintf(cmd, sizeof(cmd), "%s %s", viewer, fil); #ifndef UWIN - if (st.st_mode & S_IXUSR) { /* executable (by owner) */ - snprintf(cmd, sizeof(cmd), "./%s", fil); - system(cmd); - fastback = 0; - } else + if (st.st_mode & S_IXUSR) { /* executable (by owner) */ + snprintf(cmd, sizeof(cmd), "./%s", fil); + fastback = 0; + } #endif - { - snprintf(cmd, sizeof(cmd), "%s %s", viewer, fil); - system(cmd); - } - - if (!fastback) { - wait_for_return(); - } - exit(0); - - } else { - fprintf(stderr, "menudriver: cannot access \"%s\"\n", fil), exit(1); + if (!fastback) { + wait_for_return(); } + + exit(0); } void callshell(char v[]) -- cgit v1.2.1