shithub: puzzles

Download patch

ref: a35405ca35914b7573d63d5ea377da8ee984011b
parent: 85cf484e7a1abd57339edd4f18ccbe85cc7c9918
author: Ben Harris <[email protected]>
date: Sat Feb 18 13:12:49 EST 2023

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.

--- a/emcc.c
+++ b/emcc.c
@@ -59,8 +59,8 @@
 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_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);
@@ -100,6 +100,26 @@
 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 @@
     js_error_box(buf);
 }
 
+#ifdef DEBUGGING
 void debug_printf(const char *fmt, ...)
 {
     char buf[512];
@@ -138,12 +159,13 @@
     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 @@
 /*
  * 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 @@
  * 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 @@
 }
 
 /* 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 @@
     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 @@
  */
 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 select_appropriate_preset(void)
+static void select_appropriate_preset(void)
 {
     if (have_presets_dropdown) {
         int preset = midend_which_preset(me);