From d754425bfaaaedc15faa98e3391af50682c82e31 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 10 Dec 2021 18:40:33 +0100 Subject: Added batch mode --- src/shell.c | 26 +++++++++++++++++--------- src/shell.h | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/shell.c b/src/shell.c index 8bc2e0b..f6f88d9 100644 --- a/src/shell.c +++ b/src/shell.c @@ -55,7 +55,7 @@ exec_args(int c, char **v) } void -launch() +launch(bool prompt) { int i, shell_argc; char line[MAXLINELEN], **shell_argv; @@ -64,12 +64,15 @@ launch() for (i = 0; i < MAXNTOKENS; i++) shell_argv[i] = malloc((MAXTOKENLEN+1) * sizeof(char)); - fprintf(stderr, "Welcome to Nissy "VERSION".\n" - "Type \"commands\" for a list of commands.\n" - ); + if (prompt) { + fprintf(stderr, "Welcome to Nissy "VERSION".\n" + "Type \"commands\" for a list of commands.\n"); + } while (true) { - fprintf(stdout, "nissy-# "); + if (prompt) { + fprintf(stdout, "nissy-# "); + } if (fgets(line, MAXLINELEN, stdin) == NULL) break; shell_argc = parseline(line, shell_argv); @@ -85,10 +88,15 @@ launch() int main(int argc, char *argv[]) { - if (argc > 1) - exec_args(argc-1, &argv[1]); - else - launch(); + if (argc > 1) { + if (!strcmp(argv[1], "-b")) { + launch(false); + } else { + exec_args(argc-1, &argv[1]); + } + } else { + launch(true); + } return 0; } diff --git a/src/shell.h b/src/shell.h index a72d136..bb85ba2 100644 --- a/src/shell.h +++ b/src/shell.h @@ -8,6 +8,6 @@ #define MAXNTOKENS 255 void exec_args(int c, char **v); -void launch(); +void launch(bool prompt); #endif -- cgit v1.3