mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
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.
This commit is contained in:
40
devel.but
40
devel.but
@ -2854,7 +2854,7 @@ when finished with by passing it to the game's own
|
||||
|
||||
\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 @@ status bar is also not included in this size.)
|
||||
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 @@ call to this function. Some back ends require that \cw{midend_size()}
|
||||
|
||||
\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 @@ Calling this function is very likely to result in calls back to the
|
||||
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 @@ of the corresponding \cw{struct preset_menu_entry} returned by
|
||||
|
||||
\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 @@ The returned string, if it is non-\cw{NULL}, is dynamically allocated.
|
||||
|
||||
\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,18 +3324,18 @@ status code.)
|
||||
|
||||
\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.
|
||||
|
||||
\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 @@ output string.
|
||||
\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 @@ as output by \cw{midend_serialise()}.
|
||||
|
||||
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 @@ place.
|
||||
\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
|
||||
|
2
emcc.c
2
emcc.c
@ -829,7 +829,7 @@ struct savefile_read_ctx {
|
||||
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)
|
||||
|
2
gtk.c
2
gtk.c
@ -2240,7 +2240,7 @@ static void savefile_write(void *wctx, const void *buf, int len)
|
||||
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;
|
||||
|
32
midend.c
32
midend.c
@ -122,7 +122,7 @@ struct deserialise_data {
|
||||
* 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 @@ static void midend_size_new_drawstate(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)
|
||||
{
|
||||
int min, max;
|
||||
int rx, ry;
|
||||
@ -545,12 +545,12 @@ void midend_new_game(midend *me)
|
||||
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 @@ struct newgame_undo_deserialise_read_ctx {
|
||||
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 @@ void midend_restart_game(midend *me)
|
||||
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 @@ static int midend_really_process_key(midend *me, int x, int y, int button)
|
||||
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 @@ static int midend_really_process_key(midend *me, int x, int y, int button)
|
||||
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 @@ int midend_which_preset(midend *me)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int midend_wants_statusbar(midend *me)
|
||||
bool midend_wants_statusbar(midend *me)
|
||||
{
|
||||
return me->ourgame->wants_statusbar;
|
||||
}
|
||||
@ -1779,7 +1779,7 @@ const char *midend_set_config(midend *me, int which, config_item *cfg)
|
||||
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 @@ void midend_serialise(midend *me,
|
||||
* 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 @@ static const char *midend_deserialise_internal(
|
||||
}
|
||||
|
||||
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 @@ const char *midend_deserialise(
|
||||
* 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 @@ const char *identify_game(char **name,
|
||||
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;
|
||||
|
||||
|
2
osx.m
2
osx.m
@ -158,7 +158,7 @@ static void savefile_write(void *wctx, const void *buf, int len)
|
||||
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;
|
||||
|
21
puzzles.h
21
puzzles.h
@ -164,8 +164,7 @@ struct config_item {
|
||||
int selected;
|
||||
} choices;
|
||||
struct {
|
||||
/* just TRUE or FALSE */
|
||||
int bval;
|
||||
bool bval;
|
||||
} boolean;
|
||||
} u;
|
||||
};
|
||||
@ -314,12 +313,12 @@ void midend_free(midend *me);
|
||||
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,19 +327,19 @@ void midend_freeze_timer(midend *me, float tprop);
|
||||
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);
|
||||
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 midend_serialise(midend *me,
|
||||
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);
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user