summaryrefslogtreecommitdiff
path: root/menudriver.c
diff options
context:
space:
mode:
Diffstat (limited to 'menudriver.c')
-rw-r--r--menudriver.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/menudriver.c b/menudriver.c
index 7d517ef..989a06a 100644
--- a/menudriver.c
+++ b/menudriver.c
@@ -9,6 +9,7 @@
* Revised to C11 standard and made 64bit compatible, January 2020 *
*------------------------------------------------------------------------*/
+#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@@ -55,6 +56,14 @@ int val, ok = 0;
#include <string.h>
#define index(s,c) strchr(s,c)
+static void wait_for_return(void) {
+ printf("[Hit return to continue]");
+ fflush(stdout);
+ while (getchar() != '\n') {
+ /* keep reading until new-line */
+ }
+}
+
int main(int argc, char *argv[])
{
char *v = getenv("VIEWER");
@@ -203,8 +212,7 @@ void menudrive(char *dir)
strcat(cmd, next);
system(cmd);
if (fastback) {
- printf("[Hit return to continue]");
- while (getchar() != '\n') ;
+ wait_for_return();
}
} else {
@@ -249,11 +257,7 @@ void menudrive(char *dir)
} else if (strcmp(next, "???") == 0) {
/* ask to see menudriver settings */
settings();
- printf("[Hit return to continue]");
- while (getchar() != '\n') {
- /* keep reading until new-line */
- }
-
+ wait_for_return();
next[0] = '\0';
} else if (strcmp(next, "q") == 0 || strcmp(next, "/q") == 0) {
@@ -279,8 +283,7 @@ void menudrive(char *dir)
callshell(syscm); /* `system' always gets /bin/sh */
}
- printf("[Hit return to continue]");
- while (getchar() != '\n') ;
+ wait_for_return();
next[0] = '\0';
} else {
@@ -322,8 +325,7 @@ void singleton(char *fil)
}
if (!fastback) {
- printf("[Hit return to continue]");
- while (getchar() != '\n') ;
+ wait_for_return();
}
exit(0);
@@ -336,7 +338,6 @@ void singleton(char *fil)
void callshell(char v[])
{
static char *shell = NULL;
- int pid;
if (!shell) {
shell = getenv("SHELL");
@@ -346,16 +347,19 @@ void callshell(char v[])
}
void (*oldsig)(int) = signal(SIGINT, SIG_IGN);
- if ((pid = fork())) { /* parent */
- if (pid == -1) {
- perror("UNIX error - cannot create process");
- }
+ switch (fork()) {
+ case -1:
+ perror("UNIX error - cannot create process");
+ return;
+ case 0:
+ execl(shell, shell, "-c", v, (char *)0);
+ fprintf(stderr, "%s\n", strerror(errno));
+ exit(1);
+
+ default:
wait(0);
(void)signal(SIGINT, oldsig);
-
- } else {
- execl(shell, shell, "-c", v, (char *)0);
}
}
@@ -434,3 +438,4 @@ void clrscr(void)
{
system("tput clear");
}
+