Fix more compiler warnings
authorErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 11 Jun 2016 03:16:03 +0000 (13:16 +1000)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 11 Jun 2016 03:16:03 +0000 (13:16 +1000)
src/common/unused.h [new file with mode: 0644]
src/curses/ux_text.c
src/dumb/dumb_init.c
src/dumb/dumb_input.c
src/dumb/dumb_output.c

diff --git a/src/common/unused.h b/src/common/unused.h
new file mode 100644 (file)
index 0000000..7498161
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+** Insired by code from Martin Pool.
+*/
+
+#ifndef COMMON_UNUSED_H
+#define COMMON_UNUSED_H
+
+#ifdef UNUSED
+#elif defined (__GNUC__)
+#      define UNUSED(x) UNUSED_ ## x __attribute__ ((unused))
+#elif defined (__LCLINT__)
+#      define UNUSED(x) /*@unused@*/ x
+#else
+#      define UNUSED(x) x
+#endif
+
+#ifdef __GNUC__
+#      define WARN_UNUSED      __attribute__ ((warn_unused_result))
+#else
+#      define WARN_UNUSED
+#endif
+
+#endif
index 2aa8cfad90696ff03895c04fba897ecbfe21f789..57d3b7512073f83c2f4e85df44003c97ff25717d 100644 (file)
@@ -206,7 +206,7 @@ void os_set_font (int new_font)
  */
 void os_display_char (zchar c)
 {
-    if (c >= ZC_LATIN1_MIN && c <= ZC_LATIN1_MAX) {
+    if (c >= ZC_LATIN1_MIN) {
         if (u_setup.plain_ascii) {
 
          char *ptr = latin1_to_ascii + 3 * (c - ZC_LATIN1_MIN);
@@ -274,7 +274,7 @@ void os_display_string (const zchar *s)
  */
 int os_char_width (zchar c)
 {
-    if (c >= ZC_LATIN1_MIN && c <= ZC_LATIN1_MAX && u_setup.plain_ascii) {
+    if (c >= ZC_LATIN1_MIN && u_setup.plain_ascii) {
 
         int width = 0;
         const char *ptr = latin1_to_ascii + 3 * (c - ZC_LATIN1_MIN);
index 58c262f5d08e487cec0c6b36b40657394faf3eaf..961613a77e6f8b1638b2e79847bff94ebfec5d43 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "dumb_frotz.h"
+#include "../common/unused.h"
 
 f_setup_t f_setup;
 
@@ -158,7 +159,7 @@ int os_random_seed (void)
     else return user_random_seed;
 }
 
-void os_restart_game (int stage) {}
+void os_restart_game (int UNUSED (stage)) {}
 
 void os_fatal (const char *s, ...)
 {
index 7238ba3710ac02d6378ac5dc2ac4ddf99edf2a85..701ec71be7f4417188a34394c78c5ca22903b7ef 100644 (file)
@@ -5,6 +5,8 @@
  */
 
 #include "dumb_frotz.h"
+#include "../common/unused.h"
+
 f_setup_t f_setup;
 
 static char runtime_usage[] =
@@ -248,7 +250,7 @@ static bool dumb_read_line(char *s, char *prompt, bool show_cursor,
       if (type != INPUT_LINE_CONTINUED)
        fprintf(stderr, "DUMB-FROTZ: No input to discard\n");
       else {
-       dumb_discard_old_input(strlen(continued_line_chars));
+       dumb_discard_old_input(strlen((char*) continued_line_chars));
        continued_line_chars[0] = '\0';
        type = INPUT_LINE;
       }
@@ -263,7 +265,7 @@ static bool dumb_read_line(char *s, char *prompt, bool show_cursor,
          for (i = 0; (i < h_screen_rows - 2) && *next_page; i++)
            next_page = strchr(next_page, '\n') + 1;
          /* next_page - current_page is width */
-         printf("%.*s", next_page - current_page, current_page);
+         printf("%.*s", (int) (next_page - current_page), current_page);
          current_page = next_page;
          if (!*current_page)
            break;
@@ -329,7 +331,7 @@ zchar os_read_key (int timeout, bool show_cursor)
   return c;
 }
 
-zchar os_read_line (int max, zchar *buf, int timeout, int width, int continued)
+zchar os_read_line (int UNUSED (max), zchar *buf, int timeout, int UNUSED(width), int continued)
 {
   char *p;
   int terminator;
@@ -370,7 +372,7 @@ zchar os_read_line (int max, zchar *buf, int timeout, int width, int continued)
   dumb_display_user_input(read_line_buffer);
 
   /* copy to the buffer and save the rest for next time.  */
-  strcat(buf, read_line_buffer);
+  strcat((char*) buf, read_line_buffer);
   p = read_line_buffer + strlen(read_line_buffer) + 1;
   memmove(read_line_buffer, p, strlen(p) + 1);
 
index 310cc08bb1f3cc812544175723a9736e989ba366..31ec7273d6561a4385d2bcb6c411b8f4fed5d3e9 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "dumb_frotz.h"
+#include "../common/unused.h"
 
 f_setup_t f_setup;
 
@@ -74,7 +75,7 @@ static char *dumb_changes_row(int r)
 
 int os_char_width (zchar z)
 {
-    if (plain_ascii && z >= ZC_LATIN1_MIN && z <= ZC_LATIN1_MAX) {
+    if (plain_ascii && z >= ZC_LATIN1_MIN) {
        char *p = latin1_to_ascii + 4 * (z - ZC_LATIN1_MIN);
        return strchr(p, ' ') - p;
     }
@@ -164,7 +165,7 @@ void dumb_discard_old_input(int num_chars)
 
 void os_display_char (zchar c)
 {
-    if (c >= ZC_LATIN1_MIN && c <= ZC_LATIN1_MAX) {
+    if (c >= ZC_LATIN1_MIN) {
        if (plain_ascii) {
            char *ptr = latin1_to_ascii + 4 * (c - ZC_LATIN1_MIN);
            do
@@ -199,7 +200,7 @@ void os_display_string (const zchar *s)
     }
 }
 
-void os_erase_area (int top, int left, int bottom, int right, int win)
+void os_erase_area (int top, int left, int bottom, int right, int UNUSED (win))
 {
     int row, col;
     top--; left--; bottom--; right--;
@@ -238,8 +239,8 @@ int os_font_data(int font, int *height, int *width)
     return 0;
 }
 
-void os_set_colour (int x, int y) {}
-void os_set_font (int x) {}
+void os_set_colour (int UNUSED (x), int UNUSED (y)) {}
+void os_set_font (int UNUSED (x)) {}
 
 /* Print a cell to stdout.  */
 static void show_cell(cell cel)
@@ -432,10 +433,10 @@ void os_beep (int volume)
 /* To make the common code happy */
 
 void os_init_sound(void) {}
-void os_prepare_sample (int a) {}
-void os_finish_with_sample (int a) {}
-void os_start_sample (int a, int b, int c, zword d) {}
-void os_stop_sample (int a) {}
+void os_prepare_sample (int UNUSED (a)) {}
+void os_finish_with_sample (int UNUSED (a)) {}
+void os_start_sample (int UNUSED (a), int UNUSED (b), int UNUSED (c), zword UNUSED (d)) {}
+void os_stop_sample (int UNUSED (a)) {}
 
 
 /* if val is '0' or '1', set *var accordingly, else toggle it.  */