aboutsummaryrefslogtreecommitdiff
path: root/src/shell.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-14 16:23:19 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-14 16:23:19 +0100
commit936794a863822878caa29bd7847cd5248796932f (patch)
tree000ae21d5c78590249a61955c4df9437aff7883b /src/shell.c
parent07288010d8d98eeb04e531ca9be8a1d3cf68e0a0 (diff)
downloadnissy-936794a863822878caa29bd7847cd5248796932f.tar.gz
nissy-936794a863822878caa29bd7847cd5248796932f.zip
Better output in batch mode
Diffstat (limited to '')
-rw-r--r--src/shell.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/shell.c b/src/shell.c
index f6f88d9..5fb18bc 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -55,7 +55,7 @@ exec_args(int c, char **v)
55} 55}
56 56
57void 57void
58launch(bool prompt) 58launch(bool batchmode)
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,18 +64,27 @@ launch(bool prompt)
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 if (prompt) { 67 if (!batchmode) {
68 fprintf(stderr, "Welcome to Nissy "VERSION".\n" 68 fprintf(stderr, "Welcome to Nissy "VERSION".\n"
69 "Type \"commands\" for a list of commands.\n"); 69 "Type \"commands\" for a list of commands.\n");
70 } 70 }
71 71
72 while (true) { 72 while (true) {
73 if (prompt) { 73 if (!batchmode) {
74 fprintf(stdout, "nissy-# "); 74 fprintf(stdout, "nissy-# ");
75 } 75 }
76
76 if (fgets(line, MAXLINELEN, stdin) == NULL) 77 if (fgets(line, MAXLINELEN, stdin) == NULL)
77 break; 78 break;
79
80 if (batchmode) {
81 printf(">>>\n"
82 ">>> Executing command: %s"
83 ">>>\n", line);
84 }
85
78 shell_argc = parseline(line, shell_argv); 86 shell_argc = parseline(line, shell_argv);
87
79 if (shell_argc > 0) 88 if (shell_argc > 0)
80 exec_args(shell_argc, shell_argv); 89 exec_args(shell_argc, shell_argv);
81 } 90 }
@@ -90,12 +99,12 @@ main(int argc, char *argv[])
90{ 99{
91 if (argc > 1) { 100 if (argc > 1) {
92 if (!strcmp(argv[1], "-b")) { 101 if (!strcmp(argv[1], "-b")) {
93 launch(false); 102 launch(true);
94 } else { 103 } else {
95 exec_args(argc-1, &argv[1]); 104 exec_args(argc-1, &argv[1]);
96 } 105 }
97 } else { 106 } else {
98 launch(true); 107 launch(false);
99 } 108 }
100 109
101 return 0; 110 return 0;

Generated with cgit - Back to sebastiano.tronto.net