diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-12-10 18:40:33 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-12-10 18:40:33 +0100 |
| commit | d754425bfaaaedc15faa98e3391af50682c82e31 (patch) | |
| tree | 8fe3990e31cf47d4c75cad40a49a38ced29b67d8 /src | |
| parent | 46e3e639f8efe35d2a878a5b1674235cead05abf (diff) | |
| download | nissy-d754425bfaaaedc15faa98e3391af50682c82e31.tar.gz nissy-d754425bfaaaedc15faa98e3391af50682c82e31.zip | |
Added batch mode
Diffstat (limited to 'src')
| -rw-r--r-- | src/shell.c | 26 | ||||
| -rw-r--r-- | src/shell.h | 2 |
2 files changed, 18 insertions, 10 deletions
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) | |||
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | void | 57 | void |
| 58 | launch() | 58 | launch(bool prompt) |
| 59 | { | 59 | { |
| 60 | int i, shell_argc; | 60 | int i, shell_argc; |
| 61 | char line[MAXLINELEN], **shell_argv; | 61 | char line[MAXLINELEN], **shell_argv; |
| @@ -64,12 +64,15 @@ launch() | |||
| 64 | for (i = 0; i < MAXNTOKENS; i++) | 64 | for (i = 0; i < MAXNTOKENS; i++) |
| 65 | shell_argv[i] = malloc((MAXTOKENLEN+1) * sizeof(char)); | 65 | shell_argv[i] = malloc((MAXTOKENLEN+1) * sizeof(char)); |
| 66 | 66 | ||
| 67 | fprintf(stderr, "Welcome to Nissy "VERSION".\n" | 67 | if (prompt) { |
| 68 | "Type \"commands\" for a list of commands.\n" | 68 | fprintf(stderr, "Welcome to Nissy "VERSION".\n" |
| 69 | ); | 69 | "Type \"commands\" for a list of commands.\n"); |
| 70 | } | ||
| 70 | 71 | ||
| 71 | while (true) { | 72 | while (true) { |
| 72 | fprintf(stdout, "nissy-# "); | 73 | if (prompt) { |
| 74 | fprintf(stdout, "nissy-# "); | ||
| 75 | } | ||
| 73 | if (fgets(line, MAXLINELEN, stdin) == NULL) | 76 | if (fgets(line, MAXLINELEN, stdin) == NULL) |
| 74 | break; | 77 | break; |
| 75 | shell_argc = parseline(line, shell_argv); | 78 | shell_argc = parseline(line, shell_argv); |
| @@ -85,10 +88,15 @@ launch() | |||
| 85 | int | 88 | int |
| 86 | main(int argc, char *argv[]) | 89 | main(int argc, char *argv[]) |
| 87 | { | 90 | { |
| 88 | if (argc > 1) | 91 | if (argc > 1) { |
| 89 | exec_args(argc-1, &argv[1]); | 92 | if (!strcmp(argv[1], "-b")) { |
| 90 | else | 93 | launch(false); |
| 91 | launch(); | 94 | } else { |
| 95 | exec_args(argc-1, &argv[1]); | ||
| 96 | } | ||
| 97 | } else { | ||
| 98 | launch(true); | ||
| 99 | } | ||
| 92 | 100 | ||
| 93 | return 0; | 101 | return 0; |
| 94 | } | 102 | } |
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 @@ | |||
| 8 | #define MAXNTOKENS 255 | 8 | #define MAXNTOKENS 255 |
| 9 | 9 | ||
| 10 | void exec_args(int c, char **v); | 10 | void exec_args(int c, char **v); |
| 11 | void launch(); | 11 | void launch(bool prompt); |
| 12 | 12 | ||
| 13 | #endif | 13 | #endif |
