From a35405ca35914b7573d63d5ea377da8ee984011b Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 18 Feb 2023 18:12:49 +0000 Subject: [PATCH] Make emcc.c clean under -Wmissing-prototypes etc Also -Wstrict-prototypes and -Wmissing-variable-declarations. Functions that are called from JavaScript now have a separate declaration at the top of the file with a comment reminding one to update emcclib.js if they're changed. --- emcc.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/emcc.c b/emcc.c index 7f63e53..d634b7c 100644 --- a/emcc.c +++ b/emcc.c @@ -59,8 +59,8 @@ extern void js_get_date_64(unsigned *p); extern void js_update_permalinks(const char *desc, const char *seed); extern void js_enable_undo_redo(bool undo, bool redo); extern void js_update_key_labels(const char *lsk, const char *csk); -extern void js_activate_timer(); -extern void js_deactivate_timer(); +extern void js_activate_timer(void); +extern void js_deactivate_timer(void); extern void js_canvas_start_draw(void); extern void js_canvas_draw_update(int x, int y, int w, int h); extern void js_canvas_end_draw(void); @@ -88,7 +88,7 @@ extern void js_canvas_remove_statusbar(void); extern void js_canvas_set_statusbar(const char *text); extern bool js_canvas_get_preferred_size(int *wp, int *hp); extern void js_canvas_set_size(int w, int h); -extern double js_get_device_pixel_ratio(); +extern double js_get_device_pixel_ratio(void); extern void js_dialog_init(const char *title); extern void js_dialog_string(int i, const char *title, const char *initvalue); @@ -99,6 +99,26 @@ extern void js_dialog_launch(void); extern void js_dialog_cleanup(void); extern void js_focus_canvas(void); +/* + * These functions are called from JavaScript, so their prototypes + * need to be kept in sync with emccpre.js. + */ +bool mouseup(int x, int y, int button); +bool mousedown(int x, int y, int button); +bool mousemove(int x, int y, int buttons); +bool key(int keycode, const char *key, const char *chr, int location, + bool shift, bool ctrl); +void timer_callback(double tplus); +void command(int n); +char *get_save_file(void); +void free_save_file(char *buffer); +void load_game(const char *buffer, int len); +void dlg_return_sval(int index, const char *val); +void dlg_return_ival(int index, int val); +void resize_puzzle(int w, int h); +void restore_puzzle_size(int w, int h); +void rescale_puzzle(void); + /* * Call JS to get the date, and use that to initialise our random * number generator to invent the first game seed. @@ -129,6 +149,7 @@ void fatal(const char *fmt, ...) js_error_box(buf); } +#ifdef DEBUGGING void debug_printf(const char *fmt, ...) { char buf[512]; @@ -138,12 +159,13 @@ void debug_printf(const char *fmt, ...) va_end(ap); js_debug(buf); } +#endif /* * Helper function that makes it easy to test strings that might be * NULL. */ -int strnullcmp(const char *a, const char *b) +static int strnullcmp(const char *a, const char *b) { if (a == NULL || b == NULL) return a != NULL ? +1 : b != NULL ? -1 : 0; @@ -153,18 +175,18 @@ int strnullcmp(const char *a, const char *b) /* * HTMLish names for the colours allocated by the puzzle. */ -char **colour_strings; -int ncolours; +static char **colour_strings; +static int ncolours; /* * The global midend object. */ -midend *me; +static midend *me; /* ---------------------------------------------------------------------- * Timing functions. */ -bool timer_active = false; +static bool timer_active = false; void deactivate_timer(frontend *fe) { js_deactivate_timer(); @@ -193,7 +215,7 @@ static int canvas_w, canvas_h; * Called when we resize as a result of changing puzzle settings * or device pixel ratio. */ -static void resize() +static void resize(void) { int w, h; bool user; @@ -206,7 +228,7 @@ static void resize() } /* Called from JS when the device pixel ratio changes */ -void rescale_puzzle() +void rescale_puzzle(void) { resize(); midend_force_redraw(me); @@ -591,7 +613,7 @@ static char *js_text_fallback(void *handle, const char *const *strings, return dupstr(strings[0]); /* Emscripten has no trouble with UTF-8 */ } -const struct drawing_api js_drawing = { +static const struct drawing_api js_drawing = { js_draw_text, js_draw_rect, js_draw_line, @@ -618,9 +640,9 @@ const struct drawing_api js_drawing = { */ static game_params **presets; static int npresets; -bool have_presets_dropdown; +static bool have_presets_dropdown; -void populate_js_preset_menu(int menuid, struct preset_menu *menu) +static void populate_js_preset_menu(int menuid, struct preset_menu *menu) { int i; for (i = 0; i < menu->n_entries; i++) { @@ -635,7 +657,7 @@ void populate_js_preset_menu(int menuid, struct preset_menu *menu) } } -void select_appropriate_preset(void) +static void select_appropriate_preset(void) { if (have_presets_dropdown) { int preset = midend_which_preset(me);