nissy

Where is nissy?
git clone https://git.tronto.net/nissy
Download | Log | Files | Refs | README

commit 97c9dba402d6d4097cbdc4c44c00222c53122033
parent ac458f4de9a1d5fa203bed7b57de05ea65451788
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 13 Feb 2022 12:12:42 +0100

Fixed bug in reading scrambles with unmatched parentheses

Diffstat:
MTODO.md | 3+++
Mnissy | 0
Dnissy-2.0.tar.gz | 0
Msrc/alg.c | 13+++++++++++--
Msrc/commands.c | 13+------------
5 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -4,6 +4,9 @@ This is a list of things that I would like to add or change at some point. It's more of a personal reminder than anything else. ## For version 2.1 +### Bugs +* when reading scramble, unmatched ( does not produce any error, unmatched ) +produces TWO errors but it goes on anyway ### Scrambles * Better two-phase solver, make sure to not have cancelling moves (possibly use cleanup function) diff --git a/nissy b/nissy Binary files differ. diff --git a/nissy-2.0.tar.gz b/nissy-2.0.tar.gz Binary files differ. diff --git a/src/alg.c b/src/alg.c @@ -268,27 +268,31 @@ move_string(Move m) Alg * new_alg(char *str) { - Alg *alg = malloc(sizeof(Alg)); + Alg *alg; int i; - bool niss = false, move_read; + bool niss, move_read; Move j, m; + alg = malloc(sizeof(Alg)); alg->move = malloc(30 * sizeof(Move)); alg->inv = malloc(30 * sizeof(bool)); alg->allocated = 30; alg->len = 0; + niss = false; for (i = 0; str[i]; i++) { if (str[i] == ' ' || str[i] == '\t' || str[i] == '\n') continue; if (str[i] == '(' && niss) { fprintf(stderr, "Error reading moves: nested ( )\n"); + alg->len = 0; return alg; } if (str[i] == ')' && !niss) { fprintf(stderr, "Error reading moves: unmatched )\n"); + alg->len = 0; return alg; } @@ -353,6 +357,11 @@ new_alg(char *str) } } + if (niss) { + fprintf(stderr, "Error reading moves: unmatched (\n"); + alg->len = 0; + } + return alg; } diff --git a/src/commands.c b/src/commands.c @@ -519,25 +519,14 @@ read_scramble(int c, char **v, CommandArgs *args) int i, k, n; unsigned int j; char *algstr; - Alg *aux; if (c < 1) { fprintf(stderr, "Error: no scramble given?\n"); return false; } - n = 0; - for(i = 0; i < c; i++) { - aux = new_alg(v[i]); - if (aux->len == 0) { - fprintf(stderr, "Error: %s or its argument" - "unrecognized\n", v[i]); - free(aux); - return false; - } - free(aux); + for(n = 0, i = 0; i < c; i++) n += strlen(v[i]); - } algstr = malloc((n + 1) * sizeof(char)); k = 0;