aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/nissy.18
-rwxr-xr-xnissybin0 -> 322576 bytes
-rw-r--r--src/commands.c25
-rw-r--r--src/cubetypes.h2
-rw-r--r--src/shell.c24
-rw-r--r--src/shell.h2
6 files changed, 44 insertions, 17 deletions
diff --git a/doc/nissy.1 b/doc/nissy.1
index c725c0a..2d2836c 100644
--- a/doc/nissy.1
+++ b/doc/nissy.1
@@ -192,6 +192,13 @@ Display version information.
192. 192.
193.El 193.El
194. 194.
195.Sh SCRAMBLES
196All the commands above that accept a scramble also accept a
197.Fl Nm i
198option with no arguments.
199If this option is given, multiple scrambles are read from standard
200input (one per line) until and EOF is found, at which point stdin is cleared.
201.
195.Sh ENVIRONMENT 202.Sh ENVIRONMENT
196Data is stored in the folder pointed to by 203Data is stored in the folder pointed to by
197.Nm $NISSYDATA. 204.Nm $NISSYDATA.
@@ -203,7 +210,6 @@ is used instead. If none of this environment variables is defined
203(e.g. in a non-UNIX system), the current folder is used. 210(e.g. in a non-UNIX system), the current folder is used.
204. 211.
205.Sh EXAMPLES 212.Sh EXAMPLES
206.
207The command: 213The command:
208.Dl nissy solve -v \(dqR\(aqU\(aqFD2L2FR2U2R2BD2LB2D\(aqB2L\(aqR\(aqBD2BU2LU2R\(aqU\(aqF\(dq 214.Dl nissy solve -v \(dqR\(aqU\(aqFD2L2FR2U2R2BD2LB2D\(aqB2L\(aqR\(aqBD2BU2LU2R\(aqU\(aqF\(dq
209. 215.
diff --git a/nissy b/nissy
new file mode 100755
index 0000000..3c9c278
--- /dev/null
+++ b/nissy
Binary files differ
diff --git a/src/commands.c b/src/commands.c
index fc63e7c..9ecc9c7 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -4,7 +4,6 @@
4 4
5CommandArgs * gen_parse_args(int c, char **v); 5CommandArgs * gen_parse_args(int c, char **v);
6CommandArgs * help_parse_args(int c, char **v); 6CommandArgs * help_parse_args(int c, char **v);
7CommandArgs * print_parse_args(int c, char **v);
8CommandArgs * parse_only_scramble(int c, char **v); 7CommandArgs * parse_only_scramble(int c, char **v);
9CommandArgs * parse_no_arg(int c, char **v); 8CommandArgs * parse_no_arg(int c, char **v);
10CommandArgs * solve_parse_args(int c, char **v); 9CommandArgs * solve_parse_args(int c, char **v);
@@ -92,7 +91,7 @@ print_cmd = {
92 .name = "print", 91 .name = "print",
93 .usage = "print SCRAMBLE", 92 .usage = "print SCRAMBLE",
94 .description = "Print written description of the cube", 93 .description = "Print written description of the cube",
95 .parse_args = print_parse_args, 94 .parse_args = parse_only_scramble,
96 .exec = print_exec, 95 .exec = print_exec,
97}; 96};
98 97
@@ -235,6 +234,8 @@ solve_parse_args(int c, char **v)
235 infinitesols = true; 234 infinitesols = true;
236 } else if (!strcmp(v[i], "-N")) { 235 } else if (!strcmp(v[i], "-N")) {
237 a->opts->can_niss = true; 236 a->opts->can_niss = true;
237 } else if (!strcmp(v[i], "-i")) {
238 a->scrstdin = true;
238 } else if (!strcmp(v[i], "-v")) { 239 } else if (!strcmp(v[i], "-v")) {
239 a->opts->verbose = true; 240 a->opts->verbose = true;
240 } else if (!strcmp(v[i], "-a")) { 241 } else if (!strcmp(v[i], "-a")) {
@@ -251,7 +252,7 @@ solve_parse_args(int c, char **v)
251 if (infinitesols && !fixedmsols) 252 if (infinitesols && !fixedmsols)
252 a->opts->max_solutions = 1000000; /* 1M = +infty */ 253 a->opts->max_solutions = 1000000; /* 1M = +infty */
253 254
254 a->success = read_scramble(c-i, &v[i], a); 255 a->success = (a->scrstdin && i == c) || read_scramble(c-i, &v[i], a);
255 return a; 256 return a;
256} 257}
257 258
@@ -338,7 +339,12 @@ parse_only_scramble(int c, char **v)
338{ 339{
339 CommandArgs *a = new_args(); 340 CommandArgs *a = new_args();
340 341
341 a->success = read_scramble(c, v, a); 342 if (!strcmp(v[0], "-i")) {
343 a->scrstdin = true;
344 a->success = c == 1;
345 } else {
346 a->success = read_scramble(c, v, a);
347 }
342 348
343 return a; 349 return a;
344} 350}
@@ -353,16 +359,6 @@ parse_no_arg(int c, char **v)
353 return a; 359 return a;
354} 360}
355 361
356CommandArgs *
357print_parse_args(int c, char **v)
358{
359 CommandArgs *a = new_args();
360
361 a->success = read_scramble(c, v, a);
362
363 return a;
364}
365
366/* Exec functions implementation *********************************************/ 362/* Exec functions implementation *********************************************/
367 363
368static void 364static void
@@ -611,6 +607,7 @@ new_args()
611 CommandArgs *args = malloc(sizeof(CommandArgs)); 607 CommandArgs *args = malloc(sizeof(CommandArgs));
612 608
613 args->success = false; 609 args->success = false;
610 args->scrstdin = false;
614 args->scramble = NULL; /* initialized in read_scramble */ 611 args->scramble = NULL; /* initialized in read_scramble */
615 args->opts = malloc(sizeof(SolveOptions)); 612 args->opts = malloc(sizeof(SolveOptions));
616 613
diff --git a/src/cubetypes.h b/src/cubetypes.h
index 20e028b..8ba1341 100644
--- a/src/cubetypes.h
+++ b/src/cubetypes.h
@@ -158,6 +158,8 @@ commandargs
158 Command * command; /* For help */ 158 Command * command; /* For help */
159 int n; 159 int n;
160 int scrt; 160 int scrt;
161 bool scrstdin;
162 bool header;
161}; 163};
162 164
163struct 165struct
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
diff --git a/src/shell.h b/src/shell.h
index bb85ba2..80f86ba 100644
--- a/src/shell.h
+++ b/src/shell.h
@@ -8,6 +8,6 @@
8#define MAXNTOKENS 255 8#define MAXNTOKENS 255
9 9
10void exec_args(int c, char **v); 10void exec_args(int c, char **v);
11void launch(bool prompt); 11void launch(bool batchmode);
12 12
13#endif 13#endif

Generated with cgit - Back to sebastiano.tronto.net