Make Return and Escape work reliably in GTK dialog boxes.
[sgt/puzzles] / cube.c
diff --git a/cube.c b/cube.c
index c867471..ccc8689 100644 (file)
--- a/cube.c
+++ b/cube.c
@@ -285,8 +285,8 @@ static void enum_grid_squares(game_params *params,
     if (solid->order == 4) {
         int x, y;
 
-        for (x = 0; x < params->d1; x++)
-            for (y = 0; y < params->d2; y++) {
+       for (y = 0; y < params->d2; y++)
+           for (x = 0; x < params->d1; x++) {
                 struct grid_square sq;
 
                 sq.x = (float)x;
@@ -560,7 +560,7 @@ static void classify_grid_square_callback(void *ctx, struct grid_square *sq)
        data->squareindex++;
 }
 
-char *new_game_seed(game_params *params)
+char *new_game_seed(game_params *params, random_state *rs)
 {
     struct grid_data data;
     int i, j, k, m, area, facesperclass;
@@ -605,7 +605,7 @@ char *new_game_seed(game_params *params)
 
     for (i = 0; i < data.nclasses; i++) {
        for (j = 0; j < facesperclass; j++) {
-            int n = rand_upto(data.nsquares[i]);
+            int n = random_upto(rs, data.nsquares[i]);
 
            assert(!flags[data.gridptrs[i][n]]);
            flags[data.gridptrs[i][n]] = TRUE;
@@ -653,7 +653,7 @@ char *new_game_seed(game_params *params)
     /*
      * Choose a non-blue square for the polyhedron.
      */
-    sprintf(p, ":%d", data.gridptrs[0][rand_upto(m)]);
+    sprintf(p, ":%d", data.gridptrs[0][random_upto(rs, m)]);
 
     sfree(data.gridptrs[0]);
     sfree(flags);
@@ -809,6 +809,34 @@ static struct solid *transform_poly(const struct solid *solid, int flip,
     return ret;
 }
 
+char *validate_seed(game_params *params, char *seed)
+{
+    int area = grid_area(params->d1, params->d2, solids[params->solid]->order);
+    int i, j;
+
+    i = (area + 3) / 4;
+    for (j = 0; j < i; j++) {
+       int c = seed[j];
+       if (c >= '0' && c <= '9') continue;
+       if (c >= 'A' && c <= 'F') continue;
+       if (c >= 'a' && c <= 'f') continue;
+       return "Not enough hex digits at start of string";
+       /* NB if seed[j]=='\0' that will also be caught here, so we're safe */
+    }
+
+    if (seed[i] != ':')
+       return "Expected ':' after hex digits";
+
+    i++;
+    do {
+       if (seed[i] < '0' || seed[i] > '9')
+           return "Expected decimal integer after ':'";
+       i++;
+    } while (seed[i]);
+
+    return NULL;
+}
+
 game_state *new_game(game_params *params, char *seed)
 {
     game_state *state = snew(game_state);