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 --- doc/nissy.1 | 27 ++++++++++++++++++--------- nissy | Bin 169544 -> 169544 bytes nissy-2.0beta5.tar.gz | Bin 55883 -> 56623 bytes src/shell.c | 26 +++++++++++++++++--------- src/shell.h | 2 +- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/doc/nissy.1 b/doc/nissy.1 index 992745d..0e2e5cb 100644 --- a/doc/nissy.1 +++ b/doc/nissy.1 @@ -6,25 +6,34 @@ .Nd a Rubik's cube solver and FMC assistant . .Sh SYNOPSIS -.Nm +.Nm Op Fl b .Nm .Ar command .Op options... . -When run without any argument an interactive shell is launched, otherwise -the provided -.Ar command -is executed and nissy terminates. -The commands that can be run in the interactive shell are the same that can -be run non-interactively and are provided below. -. .Sh DESCRIPTION .Nm is a Rubik's Cube solver. Its optimal solver function uses Kociemba's one-step algorithm (huge optimal solver), and its performance is comparable to that -of Kociemba's implementation in Cube Explorer. +of Kociemba's implementation in Cube Explorer when using a single CPU +thread, and much faster when using multiple threads. nissy can also solve different substeps of the Thistlethwaite's algorithm and more. +.Pp +When run without any argument an interactive shell is launched, otherwise +the provided +.Ar command +is executed and nissy terminates. If the option +.Fl b +is given, every argument after it is ignored and the shell is launched without +any prompt or welcome message. This can be used to run nissy in batch mode, +for example writing a list of commands in a +.Ar file +(one per line) and running +.Ar nissy -b < file +.Pp +The commands that can be run in the interactive shell are the same that can +be run non-interactively and are provided below. . .Sh COMMANDS The available diff --git a/nissy b/nissy index 58bb540..4c759f5 100755 Binary files a/nissy and b/nissy differ diff --git a/nissy-2.0beta5.tar.gz b/nissy-2.0beta5.tar.gz index 1fa13b3..78bb536 100644 Binary files a/nissy-2.0beta5.tar.gz and b/nissy-2.0beta5.tar.gz differ 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