From bfb7b1ab9d2c85a256c42c006060ffe7c2652638 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 12 Mar 2025 16:40:07 +0100 Subject: Revert API change --- src/nissy.c | 4 +--- src/nissy.h | 4 ---- src/solvers/coord/common.h | 17 +++++++++++++++++ src/solvers/coord/gendata.h | 2 +- src/solvers/coord/solve.h | 16 +++++++--------- 5 files changed, 26 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/nissy.c b/src/nissy.c index ed1d3f4..eb483a0 100644 --- a/src/nissy.c +++ b/src/nissy.c @@ -503,7 +503,6 @@ long long nissy_solve( const char cube[static NISSY_SIZE_B32], const char *solver, - const char *options, unsigned nissflag, unsigned minmoves, unsigned maxmoves, @@ -569,11 +568,10 @@ nissy_solve( parse_ret = parse_h48_solver(solver, &h, &k); if (parse_ret != NISSY_OK) return parse_ret; -/* TODO give warning if options is not NULL or empty? */ return solve_h48(c, minmoves, maxmoves, maxsols, opt, t, data_size, data, sols_size, sols, stats); } else if (!strncmp(solver, "coord_", 6)) { - return solve_coord_dispatch(c, solver + 6, options, nissflag, + return solve_coord_dispatch(c, solver + 6, nissflag, minmoves, maxmoves, maxsols, opt, t, data_size, data, sols_size, sols); } else { diff --git a/src/nissy.h b/src/nissy.h index 9c26292..6c5a3e6 100644 --- a/src/nissy.h +++ b/src/nissy.h @@ -257,9 +257,6 @@ Solve the given cube using the given solver and options. Parameters: cube - The cube to solver, in B32 format. solver - The name of the solver. - options - Extra options for the solver. Some solver require additional - parameters, some do not. For example, a coordinate solver - may require an "axis" (UD, FB, RL) as a parameter. nissflag - The flags for NISS (linear, inverse, mixed, or combinations). minmoves - The minimum number of moves for a solution. maxmoves - The maximum number of moves for a solution. @@ -293,7 +290,6 @@ long long nissy_solve( const char cube[static NISSY_SIZE_B32], const char *solver, - const char *options, unsigned nissflag, unsigned minmoves, unsigned maxmoves, diff --git a/src/solvers/coord/common.h b/src/solvers/coord/common.h index d827665..f21a903 100644 --- a/src/solvers/coord/common.h +++ b/src/solvers/coord/common.h @@ -6,6 +6,7 @@ coord_t *all_coordinates[] = { STATIC void append_coord_name(const coord_t *, char *); STATIC coord_t *parse_coord(const char *, int); STATIC uint8_t parse_axis(const char *, int); +STATIC void parse_coord_and_axis(const char *, int, coord_t **, uint8_t *); STATIC void append_coord_name(const coord_t *coord, char *str) @@ -44,3 +45,19 @@ parse_axis(const char *axis, int n) return UINT8_ERROR; } + +STATIC void +parse_coord_and_axis(const char *str, int n, coord_t **coord, uint8_t *axis) +{ + int i; + + for (i = 0; i < n; i++) + if (str[i] == '_') + break; + + if (coord != NULL) + *coord = parse_coord(str, i); + + if (axis != NULL) + *axis = i == n ? UINT8_ERROR : parse_axis(str+i+1, n-i-1); +} diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h index d366466..9512b93 100644 --- a/src/solvers/coord/gendata.h +++ b/src/solvers/coord/gendata.h @@ -9,7 +9,7 @@ gendata_coord_dispatch(const char *coordstr, void *buf) { coord_t *coord; - coord = parse_coord(coordstr, strlen(coordstr)); + parse_coord_and_axis(coordstr, strlen(coordstr), &coord, NULL); if (coord == NULL) { LOG("Could not parse coordinate '%s'\n", coord); diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index 190ac1f..75c6a4e 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h @@ -20,9 +20,8 @@ typedef struct { STATIC int64_t solve_coord(cube_t, coord_t *, uint8_t, uint8_t, uint8_t, uint8_t, uint64_t, int, int, uint64_t, const void *, uint64_t, char *); -STATIC int64_t solve_coord_dispatch(cube_t, const char *, const char *, - uint8_t, uint8_t, uint8_t, uint64_t, int, int, uint64_t, const void *, - uint64_t, char *); +STATIC int64_t solve_coord_dispatch(cube_t, const char *, uint8_t, uint8_t, + uint8_t, uint64_t, int, int, uint64_t, const void *, uint64_t, char *); STATIC bool solve_coord_appendchar(char *, uint64_t, uint64_t *, char); STATIC int64_t solve_coord_appendsolution(dfsarg_solve_coord_t *); STATIC int64_t solve_coord_dfs(dfsarg_solve_coord_t *); @@ -123,8 +122,7 @@ solve_coord_dfs(dfsarg_solve_coord_t *arg) STATIC int64_t solve_coord_dispatch( cube_t cube, - const char *coordstr, - const char *options, + const char *coord_and_axis, uint8_t nissflag, uint8_t minmoves, uint8_t maxmoves, @@ -140,16 +138,16 @@ solve_coord_dispatch( coord_t *coord; uint8_t axis; - coord = parse_coord(coordstr, strlen(coordstr)); - axis = parse_axis(options, strlen(options)); + parse_coord_and_axis( + coord_and_axis, strlen(coord_and_axis), &coord, &axis); if (coord == NULL) { - LOG("Could not parse coordinate '%s'\n", coordstr); + LOG("Could not parse coordinate from '%s'\n", coord_and_axis); return NISSY_ERROR_INVALID_SOLVER; } if (axis == UINT8_ERROR) { - LOG("Could not parse axis from options '%s'\n", options); + LOG("Could not parse axis from '%s'\n", coord_and_axis); return NISSY_ERROR_INVALID_SOLVER; } -- cgit v1.3