aboutsummaryrefslogtreecommitdiff
path: root/src/shell.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-27 12:43:14 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-27 12:43:14 +0100
commit2332679ad64e3e0318ca812421190156edec9186 (patch)
tree35a0d1fee1f9e57c973640c599d1e2896e44fd45 /src/shell.c
parent8cec37cb3e490b06639f2e05df8b947a9333d5d2 (diff)
downloadnissy-2332679ad64e3e0318ca812421190156edec9186.tar.gz
nissy-2332679ad64e3e0318ca812421190156edec9186.zip
Added option -i to accept scramble(s) from stdin, very useful for batch mode
Diffstat (limited to '')
-rw-r--r--src/shell.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/shell.c b/src/shell.c
index 5fb18bc..2cb3719 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -32,8 +32,10 @@ void
32exec_args(int c, char **v) 32exec_args(int c, char **v)
33{ 33{
34 int i; 34 int i;
35 char line[MAXLINELEN];
35 Command *cmd = NULL; 36 Command *cmd = NULL;
36 CommandArgs *args; 37 CommandArgs *args;
38 Alg *scramble;
37 39
38 for (i = 0; i < NCOMMANDS; i++) 40 for (i = 0; i < NCOMMANDS; i++)
39 if (commands[i] != NULL && !strcmp(v[0], commands[i]->name)) 41 if (commands[i] != NULL && !strcmp(v[0], commands[i]->name))
@@ -50,7 +52,27 @@ exec_args(int c, char **v)
50 return; 52 return;
51 } 53 }
52 54
53 cmd->exec(args); 55 if (args->scrstdin) {
56 while (true) {
57 if (fgets(line, MAXLINELEN, stdin) == NULL) {
58 clearerr(stdin);
59 break;
60 }
61
62 scramble = new_alg(line);
63
64 printf(">>> Line: %s", line);
65
66 if (scramble != NULL && scramble->len > 0) {
67 args->scramble = scramble;
68 cmd->exec(args);
69 free_alg(scramble);
70 args->scramble = NULL;
71 }
72 }
73 } else {
74 cmd->exec(args);
75 }
54 free_args(args); 76 free_args(args);
55} 77}
56 78

Generated with cgit - Back to sebastiano.tronto.net