additions of missing 'static' and explicit 'void' in parameter lists,
plus one or two other things like explicitly casting chars in variadic
argument lists to int and using DBL_MAX if HUGE_VAL isn't available.
git-svn-id: svn://svn.tartarus.org/sgt/puzzles@9166
cda61777-01e9-0310-a592-
d414129be87e
#include <assert.h>
#include <ctype.h>
#include <math.h>
#include <assert.h>
#include <ctype.h>
#include <math.h>
#include "puzzles.h"
#include "tree234.h"
#include "puzzles.h"
#include "tree234.h"
/* Used by the other grid generators. Create a brand new grid with nothing
* initialised (all lists are NULL) */
/* Used by the other grid generators. Create a brand new grid with nothing
* initialised (all lists are NULL) */
-static grid *grid_empty()
+static grid *grid_empty(void)
{
grid *g = snew(grid);
g->faces = NULL;
{
grid *g = snew(grid);
g->faces = NULL;
static void grid_try_svg(grid *g, int which)
{
char *svg = getenv("PUZZLES_SVG_GRID");
static void grid_try_svg(grid *g, int which)
{
char *svg = getenv("PUZZLES_SVG_GRID");
double mindist = HUGE_VAL;
double mindist = HUGE_VAL;
+#else
+#ifdef DBL_MAX
+ double mindist = DBL_MAX;
+#else
+#error No way to get maximum floating-point number.
+#endif
+#endif
#define SQUARE_TILESIZE 20
#define SQUARE_TILESIZE 20
-void grid_size_square(int width, int height,
+static void grid_size_square(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int a = SQUARE_TILESIZE;
int *tilesize, int *xextent, int *yextent)
{
int a = SQUARE_TILESIZE;
-grid *grid_new_square(int width, int height, char *desc)
+static grid *grid_new_square(int width, int height, char *desc)
{
int x, y;
/* Side length */
{
int x, y;
/* Side length */
#define HONEY_A 15
#define HONEY_B 26
#define HONEY_A 15
#define HONEY_B 26
-void grid_size_honeycomb(int width, int height,
+static void grid_size_honeycomb(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int a = HONEY_A;
int *tilesize, int *xextent, int *yextent)
{
int a = HONEY_A;
*yextent = (2 * b * (height-1)) + 3*b;
}
*yextent = (2 * b * (height-1)) + 3*b;
}
-grid *grid_new_honeycomb(int width, int height, char *desc)
+static grid *grid_new_honeycomb(int width, int height, char *desc)
{
int x, y;
int a = HONEY_A;
{
int x, y;
int a = HONEY_A;
#define TRIANGLE_VEC_X 15
#define TRIANGLE_VEC_Y 26
#define TRIANGLE_VEC_X 15
#define TRIANGLE_VEC_Y 26
-void grid_size_triangular(int width, int height,
+static void grid_size_triangular(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int vec_x = TRIANGLE_VEC_X;
int *tilesize, int *xextent, int *yextent)
{
int vec_x = TRIANGLE_VEC_X;
/* Doesn't use the previous method of generation, it pre-dates it!
* A triangular grid is just about simple enough to do by "brute force" */
/* Doesn't use the previous method of generation, it pre-dates it!
* A triangular grid is just about simple enough to do by "brute force" */
-grid *grid_new_triangular(int width, int height, char *desc)
+static grid *grid_new_triangular(int width, int height, char *desc)
#define SNUBSQUARE_A 15
#define SNUBSQUARE_B 26
#define SNUBSQUARE_A 15
#define SNUBSQUARE_B 26
-void grid_size_snubsquare(int width, int height,
+static void grid_size_snubsquare(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int a = SNUBSQUARE_A;
int *tilesize, int *xextent, int *yextent)
{
int a = SNUBSQUARE_A;
*yextent = (a+b) * (height-1) + a + b;
}
*yextent = (a+b) * (height-1) + a + b;
}
-grid *grid_new_snubsquare(int width, int height, char *desc)
+static grid *grid_new_snubsquare(int width, int height, char *desc)
{
int x, y;
int a = SNUBSQUARE_A;
{
int x, y;
int a = SNUBSQUARE_A;
#define CAIRO_A 14
#define CAIRO_B 31
#define CAIRO_A 14
#define CAIRO_B 31
-void grid_size_cairo(int width, int height,
+static void grid_size_cairo(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int b = CAIRO_B; /* a unused in determining grid size. */
int *tilesize, int *xextent, int *yextent)
{
int b = CAIRO_B; /* a unused in determining grid size. */
*yextent = 2*b*(height-1) + 2*b;
}
*yextent = 2*b*(height-1) + 2*b;
}
-grid *grid_new_cairo(int width, int height, char *desc)
+static grid *grid_new_cairo(int width, int height, char *desc)
{
int x, y;
int a = CAIRO_A;
{
int x, y;
int a = CAIRO_A;
#define GREATHEX_A 15
#define GREATHEX_B 26
#define GREATHEX_A 15
#define GREATHEX_B 26
-void grid_size_greathexagonal(int width, int height,
+static void grid_size_greathexagonal(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int a = GREATHEX_A;
int *tilesize, int *xextent, int *yextent)
{
int a = GREATHEX_A;
*yextent = (2*a + 2*b) * (height-1) + 3*b + a;
}
*yextent = (2*a + 2*b) * (height-1) + 3*b + a;
}
-grid *grid_new_greathexagonal(int width, int height, char *desc)
+static grid *grid_new_greathexagonal(int width, int height, char *desc)
{
int x, y;
int a = GREATHEX_A;
{
int x, y;
int a = GREATHEX_A;
#define OCTAGONAL_A 29
#define OCTAGONAL_B 41
#define OCTAGONAL_A 29
#define OCTAGONAL_B 41
-void grid_size_octagonal(int width, int height,
+static void grid_size_octagonal(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int a = OCTAGONAL_A;
int *tilesize, int *xextent, int *yextent)
{
int a = OCTAGONAL_A;
*yextent = (2*a + b) * height;
}
*yextent = (2*a + b) * height;
}
-grid *grid_new_octagonal(int width, int height, char *desc)
+static grid *grid_new_octagonal(int width, int height, char *desc)
{
int x, y;
int a = OCTAGONAL_A;
{
int x, y;
int a = OCTAGONAL_A;
#define KITE_A 15
#define KITE_B 26
#define KITE_A 15
#define KITE_B 26
-void grid_size_kites(int width, int height,
+static void grid_size_kites(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int a = KITE_A;
int *tilesize, int *xextent, int *yextent)
{
int a = KITE_A;
*yextent = 6*a * (height-1) + 8*a;
}
*yextent = 6*a * (height-1) + 8*a;
}
-grid *grid_new_kites(int width, int height, char *desc)
+static grid *grid_new_kites(int width, int height, char *desc)
{
int x, y;
int a = KITE_A;
{
int x, y;
int a = KITE_A;
#define FLORET_PX 75
#define FLORET_PY -26
#define FLORET_PX 75
#define FLORET_PY -26
-void grid_size_floret(int width, int height,
+static void grid_size_floret(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int px = FLORET_PX, py = FLORET_PY; /* |( 75, -26)| = 79.43 */
int *tilesize, int *xextent, int *yextent)
{
int px = FLORET_PX, py = FLORET_PY; /* |( 75, -26)| = 79.43 */
*yextent = (5*qy-4*py) * (height-1) + 4*qy + 2*ry;
}
*yextent = (5*qy-4*py) * (height-1) + 4*qy + 2*ry;
}
-grid *grid_new_floret(int width, int height, char *desc)
+static grid *grid_new_floret(int width, int height, char *desc)
{
int x, y;
/* Vectors for sides; weird numbers needed to keep puzzle aligned with window
{
int x, y;
/* Vectors for sides; weird numbers needed to keep puzzle aligned with window
#define DODEC_A 15
#define DODEC_B 26
#define DODEC_A 15
#define DODEC_B 26
-void grid_size_dodecagonal(int width, int height,
+static void grid_size_dodecagonal(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int a = DODEC_A;
int *tilesize, int *xextent, int *yextent)
{
int a = DODEC_A;
*yextent = (3*a + 2*b) * (height-1) + 2*(2*a + b);
}
*yextent = (3*a + 2*b) * (height-1) + 2*(2*a + b);
}
-grid *grid_new_dodecagonal(int width, int height, char *desc)
+static grid *grid_new_dodecagonal(int width, int height, char *desc)
{
int x, y;
int a = DODEC_A;
{
int x, y;
int a = DODEC_A;
-void grid_size_greatdodecagonal(int width, int height,
+static void grid_size_greatdodecagonal(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int a = DODEC_A;
int *tilesize, int *xextent, int *yextent)
{
int a = DODEC_A;
*yextent = (3*a + 3*b) * (height-1) + 2*(2*a + b);
}
*yextent = (3*a + 3*b) * (height-1) + 2*(2*a + b);
}
-grid *grid_new_greatdodecagonal(int width, int height, char *desc)
+static grid *grid_new_greatdodecagonal(int width, int height, char *desc)
{
int x, y;
/* Vector for side of triangle - ratio is close to sqrt(3) */
{
int x, y;
/* Vector for side of triangle - ratio is close to sqrt(3) */
tree234 *points;
} setface_ctx;
tree234 *points;
} setface_ctx;
+static double round_int_nearest_away(double r)
{
return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
}
{
return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
}
-int set_faces(penrose_state *state, vector *vs, int n, int depth)
+static int set_faces(penrose_state *state, vector *vs, int n, int depth)
{
setface_ctx *sf_ctx = (setface_ctx *)state->ctx;
int i;
{
setface_ctx *sf_ctx = (setface_ctx *)state->ctx;
int i;
for (i = 0; i < n; i++) {
double tx = v_x(vs, i), ty = v_y(vs, i);
for (i = 0; i < n; i++) {
double tx = v_x(vs, i), ty = v_y(vs, i);
- xs[i] = (int)round( tx*cosa + ty*sina);
- ys[i] = (int)round(-tx*sina + ty*cosa);
+ xs[i] = (int)round_int_nearest_away( tx*cosa + ty*sina);
+ ys[i] = (int)round_int_nearest_away(-tx*sina + ty*cosa);
if (xs[i] < sf_ctx->xmin || xs[i] > sf_ctx->xmax) return 0;
if (ys[i] < sf_ctx->ymin || ys[i] > sf_ctx->ymax) return 0;
if (xs[i] < sf_ctx->xmin || xs[i] > sf_ctx->xmax) return 0;
if (ys[i] < sf_ctx->ymin || ys[i] > sf_ctx->ymax) return 0;
#define PENROSE_TILESIZE 100
#define PENROSE_TILESIZE 100
-void grid_size_penrose(int width, int height,
+static void grid_size_penrose(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int l = PENROSE_TILESIZE;
int *tilesize, int *xextent, int *yextent)
{
int l = PENROSE_TILESIZE;
-void grid_size_penrose_p2_kite(int width, int height,
+static void grid_size_penrose_p2_kite(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
grid_size_penrose(width, height, tilesize, xextent, yextent);
}
int *tilesize, int *xextent, int *yextent)
{
grid_size_penrose(width, height, tilesize, xextent, yextent);
}
-void grid_size_penrose_p3_thick(int width, int height,
+static void grid_size_penrose_p3_thick(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
grid_size_penrose(width, height, tilesize, xextent, yextent);
}
int *tilesize, int *xextent, int *yextent)
{
grid_size_penrose(width, height, tilesize, xextent, yextent);
}
-grid *grid_new_penrose_p2_kite(int width, int height, char *desc)
+static grid *grid_new_penrose_p2_kite(int width, int height, char *desc)
{
return grid_new_penrose(width, height, PENROSE_P2, desc);
}
{
return grid_new_penrose(width, height, PENROSE_P2, desc);
}
-grid *grid_new_penrose_p3_thick(int width, int height, char *desc)
+static grid *grid_new_penrose_p3_thick(int width, int height, char *desc)
{
return grid_new_penrose(width, height, PENROSE_P3, desc);
}
{
return grid_new_penrose(width, height, PENROSE_P3, desc);
}
SOLVERLIST(SOLVER_FN_DECL)
static int (*(solver_fns[]))(solver_state *) = { SOLVERLIST(SOLVER_FN) };
static int const solver_diffs[] = { SOLVERLIST(SOLVER_DIFF) };
SOLVERLIST(SOLVER_FN_DECL)
static int (*(solver_fns[]))(solver_state *) = { SOLVERLIST(SOLVER_FN) };
static int const solver_diffs[] = { SOLVERLIST(SOLVER_DIFF) };
-const int NUM_SOLVERS = sizeof(solver_diffs)/sizeof(*solver_diffs);
+static const int NUM_SOLVERS = sizeof(solver_diffs)/sizeof(*solver_diffs);
struct game_params {
int w, h;
struct game_params {
int w, h;
if (grid_desc) {
retval = snewn(strlen(grid_desc) + 1 + strlen(game_desc) + 1, char);
if (grid_desc) {
retval = snewn(strlen(grid_desc) + 1 + strlen(game_desc) + 1, char);
- sprintf(retval, "%s%c%s", grid_desc, GRID_DESC_SEP, game_desc);
+ sprintf(retval, "%s%c%s", grid_desc, (int)GRID_DESC_SEP, game_desc);
sfree(grid_desc);
sfree(game_desc);
} else {
sfree(grid_desc);
sfree(game_desc);
} else {
struct vector { int a, b, c, d; };
struct vector { int a, b, c, d; };
-static vector v_origin()
+static vector v_origin(void)
{
vector v;
v.a = v.b = v.c = v.d = 0;
{
vector v;
v.a = v.b = v.c = v.d = 0;
* draw an isoceles triangle centred on the X axis. */
#ifdef TEST_VECTORS
* draw an isoceles triangle centred on the X axis. */
#ifdef TEST_VECTORS
+static vector v_unit(void)
-vector xform_coord(vector vo, int shrink, vector vtrans, int ang)
+static vector xform_coord(vector vo, int shrink, vector vtrans, int ang)
{
if (shrink < 0)
vo = v_shrinkphi(vo);
{
if (shrink < 0)
vo = v_shrinkphi(vo);
{
fprintf(stderr, "Usage: penrose-test [--recursion] P2|P3 SIZE DEPTH\n");
exit(1);
{
fprintf(stderr, "Usage: penrose-test [--recursion] P2|P3 SIZE DEPTH\n");
exit(1);
#define setmember(obj, field) ( (obj) . field = field )
#define setmember(obj, field) ( (obj) . field = field )
-char *nfmtstr(int n, char *fmt, ...) {
+static char *nfmtstr(int n, char *fmt, ...) {
va_list va;
char *ret = snewn(n+1, char);
va_start(va, fmt);
va_list va;
char *ret = snewn(n+1, char);
va_start(va, fmt);
};
#define DEFAULT_PRESET 0
};
#define DEFAULT_PRESET 0
-static struct game_params presets[] = {{9, 6}, {12, 8}, {13, 9}, {16, 11}};
+static struct game_params range_presets[] = {{9, 6}, {12, 8}, {13, 9}, {16, 11}};
/* rationale: I want all four combinations of {odd/even, odd/even}, as
* they play out differently with respect to two-way symmetry. I also
* want them to be generated relatively fast yet still be large enough
/* rationale: I want all four combinations of {odd/even, odd/even}, as
* they play out differently with respect to two-way symmetry. I also
* want them to be generated relatively fast yet still be large enough
static game_params *default_params(void)
{
game_params *ret = snew(game_params);
static game_params *default_params(void)
{
game_params *ret = snew(game_params);
- *ret = presets[DEFAULT_PRESET]; /* structure copy */
+ *ret = range_presets[DEFAULT_PRESET]; /* structure copy */
static int game_fetch_preset(int i, char **name, game_params **params)
{
static int game_fetch_preset(int i, char **name, game_params **params)
{
- if (i < 0 || i >= lenof(presets)) return FALSE;
- *name = nfmtstr(40, "%d x %d", presets[i].w, presets[i].h);
- *params = dup_params(&presets[i]);
+ if (i < 0 || i >= lenof(range_presets)) return FALSE;
+
+ ret = default_params();
+ *ret = range_presets[i]; /* struct copy */
+ *params = ret;
+
+ *name = nfmtstr(40, "%d x %d", range_presets[i].w, range_presets[i].h);
+static reasoning *const reasonings[] = {
+ solver_reasoning_not_too_big,
+ solver_reasoning_adjacency,
+ solver_reasoning_connectedness,
+ solver_reasoning_recursion
+};
+
static move *do_solve(game_state *state,
int nclues,
const square *clues,
move *move_buffer,
int difficulty)
{
static move *do_solve(game_state *state,
int nclues,
const square *clues,
move *move_buffer,
int difficulty)
{
- reasoning *reasonings[] = {
- solver_reasoning_not_too_big,
- solver_reasoning_adjacency,
- solver_reasoning_connectedness,
- solver_reasoning_recursion
- };
-
struct move *buf = move_buffer, *oldbuf;
int i;
struct move *buf = move_buffer, *oldbuf;
int i;
if (state->prev[si] == -1 && state->next[si] == -1)
return "";
sprintf(buf, "%c%d,%d",
if (state->prev[si] == -1 && state->next[si] == -1)
return "";
sprintf(buf, "%c%d,%d",
- ui->drag_is_from ? 'C' : 'X', ui->sx, ui->sy);
+ (int)(ui->drag_is_from ? 'C' : 'X'), ui->sx, ui->sy);
if (state->prev[si] == -1 && state->next[si] == -1)
return "";
sprintf(buf, "%c%d,%d",
if (state->prev[si] == -1 && state->next[si] == -1)
return "";
sprintf(buf, "%c%d,%d",
- (button == 'x') ? 'C' : 'X', ui->cx, ui->cy);
+ (int)((button == 'x') ? 'C' : 'X'), ui->cx, ui->cy);