ref: cd6cadbecf245b2916350939343db14e2978f782
parent: a76d269cf222ba81e717c7e9046db391f19036eb
author: Simon Tatham <anakin@pobox.com>
date: Tue Nov 13 16:37:09 EST 2018
Adopt C99 bool in the midend API. This changes parameters of midend_size and midend_print_puzzle, the return types of midend_process_key, midend_wants_statusbar, midend_can_format_as_text_now and midend_can_{undo,redo}, the 'bval' field in struct config_item, and finally the return type of the function pointer passed to midend_deserialise and identify_game. The last of those changes requires a corresponding fix in clients of midend_deserialise and identify_game, so in this commit I've also updated all the in-tree front ends to match. I expect downstream front ends will need to do the same when they merge this change.
--- a/devel.but
+++ b/devel.but
@@ -2854,7 +2854,7 @@
\H{midend-size} \cw{midend_size()}
-\c void midend_size(midend *me, int *x, int *y, int user_size);
+\c void midend_size(midend *me, int *x, int *y, bool user_size);
Tells the mid-end to figure out its window size.
@@ -2872,7 +2872,7 @@
Use \c{user_size} to indicate whether \c{*x} and \c{*y} are a
requested size, or just a maximum size.
-If \c{user_size} is set to \cw{TRUE}, the mid-end will treat the
+If \c{user_size} is set to \cw{true}, the mid-end will treat the
input size as a request, and will pick a tile size which
approximates it \e{as closely as possible}, going over the game's
preferred tile size if necessary to achieve this. The mid-end will
@@ -2995,7 +2995,7 @@
\H{midend-process-key} \cw{midend_process_key()}
-\c int midend_process_key(midend *me, int x, int y, int button);
+\c bool midend_process_key(midend *me, int x, int y, int button);
The front end calls this function to report a mouse or keyboard
event. The parameters \c{x}, \c{y} and \c{button} are almost
@@ -3028,10 +3028,10 @@
front end's drawing API and/or \cw{activate_timer()}
(\k{frontend-activate-timer}).
-The return value from \cw{midend_process_key()} is non-zero, unless
-the effect of the keypress was to request termination of the
-program. A front end should shut down the puzzle in response to a
-zero return.
+The return value from \cw{midend_process_key()} is \cw{true} unless
+the effect of the keypress was to request termination of the program.
+A front end should shut down the puzzle in response to a \cw{false}
+return.
\H{midend-request-keys} \cw{midend_request_keys()}
@@ -3147,9 +3147,9 @@
\H{midend-wants-statusbar} \cw{midend_wants_statusbar()}
-\c int midend_wants_statusbar(midend *me);
+\c bool midend_wants_statusbar(midend *me);
-This function returns \cw{TRUE} if the puzzle has a use for a
+This function returns \cw{true} if the puzzle has a use for a
textual status line (to display score, completion status, currently
active tiles, time, or anything else).
@@ -3267,12 +3267,12 @@
\H{midend-can-format-as-text-now} \cw{midend_can_format_as_text_now()}
-\c int midend_can_format_as_text_now(midend *me);
+\c bool midend_can_format_as_text_now(midend *me);
-Returns \cw{TRUE} if the game code is capable of formatting puzzles
+Returns \cw{true} if the game code is capable of formatting puzzles
of the currently selected game type as ASCII.
-If this returns \cw{FALSE}, then \cw{midend_text_format()}
+If this returns \cw{false}, then \cw{midend_text_format()}
(\k{midend-text-format}) will return \cw{NULL}.
\H{midend-text-format} \cw{midend_text_format()}
@@ -3324,9 +3324,9 @@
\H{midend-can-undo} \cw{midend_can_undo()}
-\c int midend_can_undo(midend *me);
+\c bool midend_can_undo(midend *me);
-Returns \cw{TRUE} if the midend is currently in a state where the undo
+Returns \cw{true} if the midend is currently in a state where the undo
operation is meaningful (i.e. at least one position exists on the undo
chain before the present one). Front ends may wish to use this to
visually activate and deactivate an undo button.
@@ -3333,9 +3333,9 @@
\H{midend-can-redo} \cw{midend_can_redo()}
-\c int midend_can_redo(midend *me);
+\c bool midend_can_redo(midend *me);
-Returns \cw{TRUE} if the midend is currently in a state where the redo
+Returns \cw{true} if the midend is currently in a state where the redo
operation is meaningful (i.e. at least one position exists on the redo
chain after the present one). Front ends may wish to use this to
visually activate and deactivate a redo button.
@@ -3367,7 +3367,7 @@
\H{midend-deserialise} \cw{midend_deserialise()}
\c const char *midend_deserialise(midend *me,
-\c int (*read)(void *ctx, void *buf, int len), void *rctx);
+\c bool (*read)(void *ctx, void *buf, int len), void *rctx);
This function is the counterpart to \cw{midend_serialise()}. It
calls the supplied \cw{read} function repeatedly to read a quantity
@@ -3376,8 +3376,8 @@
The \cw{read} function is called with the first parameter (\c{ctx})
equal to \c{rctx}, and should attempt to read \c{len} bytes of data
-into the buffer pointed to by \c{buf}. It should return \cw{FALSE}
-on failure or \cw{TRUE} on success. It should not report success
+into the buffer pointed to by \c{buf}. It should return \cw{false}
+on failure or \cw{true} on success. It should not report success
unless it has filled the entire buffer; on platforms which might be
reading from a pipe or other blocking data source, \c{read} is
responsible for looping until the whole buffer has been filled.
@@ -3405,7 +3405,7 @@
\H{identify-game} \cw{identify_game()}
\c const char *identify_game(char **name,
-\c int (*read)(void *ctx, void *buf, int len), void *rctx);
+\c bool (*read)(void *ctx, void *buf, int len), void *rctx);
This function examines a serialised midend stream, of the same kind
used by \cw{midend_serialise()} and \cw{midend_deserialise()}, and
--- a/emcc.c
+++ b/emcc.c
@@ -829,7 +829,7 @@
int len_remaining;
};
-static int savefile_read(void *vctx, void *buf, int len)
+static bool savefile_read(void *vctx, void *buf, int len)
{
struct savefile_read_ctx *ctx = (struct savefile_read_ctx *)vctx;
if (ctx->len_remaining < len)
--- a/gtk.c
+++ b/gtk.c
@@ -2240,7 +2240,7 @@
ctx->error = errno;
}
-static int savefile_read(void *wctx, void *buf, int len)
+static bool savefile_read(void *wctx, void *buf, int len)
{
FILE *fp = (FILE *)wctx;
int ret;
--- a/midend.c
+++ b/midend.c
@@ -122,7 +122,7 @@
* Forward reference.
*/
static const char *midend_deserialise_internal(
- midend *me, int (*read)(void *ctx, void *buf, int len), void *rctx,
+ midend *me, bool (*read)(void *ctx, void *buf, int len), void *rctx,
const char *(*check)(void *ctx, midend *, const struct deserialise_data *),
void *cctx);
@@ -297,7 +297,7 @@
}
}
-void midend_size(midend *me, int *x, int *y, int user_size)
+void midend_size(midend *me, int *x, int *y, bool user_size)
{
int min, max;
int rx, ry;
@@ -545,12 +545,12 @@
me->newgame_can_store_undo = TRUE;
}
-int midend_can_undo(midend *me)
+bool midend_can_undo(midend *me)
{
return (me->statepos > 1 || me->newgame_undo.len);
}
-int midend_can_redo(midend *me)
+bool midend_can_redo(midend *me)
{
return (me->statepos < me->nstates || me->newgame_redo.len);
}
@@ -560,7 +560,7 @@
int len, pos;
};
-static int newgame_undo_deserialise_read(void *ctx, void *buf, int len)
+static bool newgame_undo_deserialise_read(void *ctx, void *buf, int len)
{
struct newgame_undo_deserialise_read_ctx *const rctx = ctx;
@@ -852,11 +852,11 @@
midend_set_timer(me);
}
-static int midend_really_process_key(midend *me, int x, int y, int button)
+static bool midend_really_process_key(midend *me, int x, int y, int button)
{
game_state *oldstate =
me->ourgame->dup_game(me->states[me->statepos - 1].state);
- int type = MOVE, gottype = FALSE, ret = 1;
+ int type = MOVE, gottype = FALSE, ret = TRUE;
float anim_time;
game_state *s;
char *movestr = NULL;
@@ -893,7 +893,7 @@
goto done;
} else if (button == 'q' || button == 'Q' || button == '\x11' ||
button == UI_QUIT) {
- ret = 0;
+ ret = false;
goto done;
} else
goto done;
@@ -967,9 +967,9 @@
return ret;
}
-int midend_process_key(midend *me, int x, int y, int button)
+bool midend_process_key(midend *me, int x, int y, int button)
{
- int ret = 1;
+ bool ret = true;
/*
* Harmonise mouse drag and release messages.
@@ -1445,7 +1445,7 @@
return ret;
}
-int midend_wants_statusbar(midend *me)
+bool midend_wants_statusbar(midend *me)
{
return me->ourgame->wants_statusbar;
}
@@ -1779,7 +1779,7 @@
return NULL;
}
-int midend_can_format_as_text_now(midend *me)
+bool midend_can_format_as_text_now(midend *me)
{
if (me->ourgame->can_format_as_text_ever)
return me->ourgame->can_format_as_text_now(me->params);
@@ -2060,7 +2060,7 @@
* success, or an error message.
*/
static const char *midend_deserialise_internal(
- midend *me, int (*read)(void *ctx, void *buf, int len), void *rctx,
+ midend *me, bool (*read)(void *ctx, void *buf, int len), void *rctx,
const char *(*check)(void *ctx, midend *, const struct deserialise_data *),
void *cctx)
{
@@ -2428,7 +2428,7 @@
}
const char *midend_deserialise(
- midend *me, int (*read)(void *ctx, void *buf, int len), void *rctx)
+ midend *me, bool (*read)(void *ctx, void *buf, int len), void *rctx)
{
return midend_deserialise_internal(me, read, rctx, NULL, NULL);
}
@@ -2441,7 +2441,7 @@
* failure.
*/
const char *identify_game(char **name,
- int (*read)(void *ctx, void *buf, int len),
+ bool (*read)(void *ctx, void *buf, int len),
void *rctx)
{
int nstates = 0, statepos = -1, gotstates = 0;
@@ -2539,7 +2539,7 @@
return ret;
}
-const char *midend_print_puzzle(midend *me, document *doc, int with_soln)
+const char *midend_print_puzzle(midend *me, document *doc, bool with_soln)
{
game_state *soln = NULL;
--- a/osx.m
+++ b/osx.m
@@ -158,7 +158,7 @@
fwrite(buf, 1, len, fp);
}
-static int savefile_read(void *wctx, void *buf, int len)
+static bool savefile_read(void *wctx, void *buf, int len)
{
FILE *fp = (FILE *)wctx;
int ret;
--- a/puzzles.h
+++ b/puzzles.h
@@ -164,8 +164,7 @@
int selected;
} choices;
struct {
- /* just TRUE or FALSE */
- int bval;
+ bool bval;
} boolean;
} u;
};
@@ -314,12 +313,12 @@
const game *midend_which_game(midend *me);
void midend_set_params(midend *me, game_params *params);
game_params *midend_get_params(midend *me);
-void midend_size(midend *me, int *x, int *y, int user_size);
+void midend_size(midend *me, int *x, int *y, bool user_size);
void midend_reset_tilesize(midend *me);
void midend_new_game(midend *me);
void midend_restart_game(midend *me);
void midend_stop_anim(midend *me);
-int midend_process_key(midend *me, int x, int y, int button);
+bool midend_process_key(midend *me, int x, int y, int button);
key_label *midend_request_keys(midend *me, int *nkeys);
void midend_force_redraw(midend *me);
void midend_redraw(midend *me);
@@ -328,7 +327,7 @@
void midend_timer(midend *me, float tplus);
struct preset_menu *midend_get_presets(midend *me, int *id_limit);
int midend_which_preset(midend *me);
-int midend_wants_statusbar(midend *me);
+bool midend_wants_statusbar(midend *me);
enum { CFG_SETTINGS, CFG_SEED, CFG_DESC, CFG_FRONTEND_SPECIFIC };
config_item *midend_get_config(midend *me, int which, char **wintitle);
const char *midend_set_config(midend *me, int which, config_item *cfg);
@@ -335,12 +334,12 @@
const char *midend_game_id(midend *me, const char *id);
char *midend_get_game_id(midend *me);
char *midend_get_random_seed(midend *me);
-int midend_can_format_as_text_now(midend *me);
+bool midend_can_format_as_text_now(midend *me);
char *midend_text_format(midend *me);
const char *midend_solve(midend *me);
int midend_status(midend *me);
-int midend_can_undo(midend *me);
-int midend_can_redo(midend *me);
+bool midend_can_undo(midend *me);
+bool midend_can_redo(midend *me);
void midend_supersede_game_desc(midend *me, const char *desc,
const char *privdesc);
char *midend_rewrite_statusbar(midend *me, const char *text);
@@ -348,14 +347,14 @@
void (*write)(void *ctx, const void *buf, int len),
void *wctx);
const char *midend_deserialise(midend *me,
- int (*read)(void *ctx, void *buf, int len),
+ bool (*read)(void *ctx, void *buf, int len),
void *rctx);
const char *identify_game(char **name,
- int (*read)(void *ctx, void *buf, int len),
+ bool (*read)(void *ctx, void *buf, int len),
void *rctx);
void midend_request_id_changes(midend *me, void (*notify)(void *), void *ctx);
/* Printing functions supplied by the mid-end */
-const char *midend_print_puzzle(midend *me, document *doc, int with_soln);
+const char *midend_print_puzzle(midend *me, document *doc, bool with_soln);
int midend_tilesize(midend *me);
/*
--- a/windows.c
+++ b/windows.c
@@ -1557,7 +1557,7 @@
fwrite(buf, 1, len, fp);
}
-static int savefile_read(void *wctx, void *buf, int len)
+static bool savefile_read(void *wctx, void *buf, int len)
{
FILE *fp = (FILE *)wctx;
int ret;