OSDN Git Service

GCU: remove assumed window width of 80 columns in wipe hook
[hengbandforosx/hengbandosx.git] / src / main-gcu.cpp
index e0c4106..3d60796 100644 (file)
 #include "locale/japanese.h"
 #include "main/sound-definitions-table.h"
 #include "main/sound-of-music.h"
-#include "system/angband.h"
 #include "system/angband-version.h"
+#include "system/angband.h"
 #include "system/player-type-definition.h"
 #include "term/gameterm.h"
 #include "term/term-color-types.h"
@@ -578,8 +578,9 @@ static bool check_file(concptr s)
 {
     FILE *fff;
     fff = fopen(s, "r");
-    if (!fff)
+    if (!fff) {
         return false;
+    }
 
     fclose(fff);
     return true;
@@ -591,8 +592,9 @@ static bool check_file(concptr s)
 static bool init_sound(void)
 {
     /* Initialize once */
-    if (can_use_sound)
+    if (can_use_sound) {
         return can_use_sound;
+    }
 
     int i;
     char wav[128];
@@ -607,8 +609,9 @@ static bool init_sound(void)
         path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_SOUND, wav);
 
         /* Save the sound filename, if it exists */
-        if (check_file(buf))
+        if (check_file(buf)) {
             sound_file[i] = string_make(buf);
+        }
     }
 
     /* Sound available */
@@ -624,8 +627,9 @@ static void game_term_init_gcu(term_type *t)
     term_data *td = (term_data *)(t->data);
 
     /* Count init's, handle first */
-    if (active++ != 0)
+    if (active++ != 0) {
         return;
+    }
 
     /* Erase the screen */
     (void)wclear(td->win);
@@ -651,8 +655,9 @@ static void game_term_nuke_gcu(term_type *t)
     delwin(td->win);
 
     /* Count nuke's, handle last */
-    if (--active != 0)
+    if (--active != 0) {
         return;
+    }
 
     /* Hack -- make sure the cursor is visible */
     term_xtra(TERM_XTRA_SHAPE, 1);
@@ -684,8 +689,9 @@ static void game_term_nuke_gcu(term_type *t)
 static void term_string_push(char *buf)
 {
     int i, l = strlen(buf);
-    for (i = l; i >= 0; i--)
+    for (i = l; i >= 0; i--) {
         term_key_push(buf[i]);
+    }
 }
 
 #ifdef USE_GETCH
@@ -709,10 +715,12 @@ static errr game_term_xtra_gcu_event(int v)
         i = getch();
 
         /* Broken input is special */
-        if (i == ERR)
+        if (i == ERR) {
             exit_game_panic(p_ptr);
-        if (i == EOF)
+        }
+        if (i == EOF) {
             exit_game_panic(p_ptr);
+        }
 
         *bp++ = (char)i;
 
@@ -720,11 +728,13 @@ static errr game_term_xtra_gcu_event(int v)
         nodelay(stdscr, true);
 
         while ((i = getch()) != EOF) {
-            if (i == ERR)
+            if (i == ERR) {
                 exit_game_panic(p_ptr);
+            }
             *bp++ = (char)i;
-            if (bp == &buf[255])
+            if (bp == &buf[255]) {
                 break;
+            }
         }
 
         /* Wait for it next time */
@@ -753,10 +763,12 @@ static errr game_term_xtra_gcu_event(int v)
         nodelay(stdscr, false);
 
         /* None ready */
-        if (i == ERR)
+        if (i == ERR) {
             return 1;
-        if (i == EOF)
+        }
+        if (i == EOF) {
             return 1;
+        }
 
         /* Enqueue the keypress */
         term_key_push(i);
@@ -785,15 +797,17 @@ static errr game_term_xtra_gcu_event(int v)
         i = read(0, bp++, 1);
 
         /* Hack -- Handle bizarre "errors" */
-        if ((i <= 0) && (errno != EINTR))
+        if ((i <= 0) && (errno != EINTR)) {
             exit_game_panic(p_ptr);
+        }
 
         /* Get the current flags for stdin */
         k = fcntl(0, F_GETFL, 0);
 
         /* Oops */
-        if (k < 0)
+        if (k < 0) {
             return 1;
+        }
 
         /* Tell stdin not to block */
         if (fcntl(0, F_SETFL, k | O_NDELAY) >= 0) {
@@ -802,8 +816,9 @@ static errr game_term_xtra_gcu_event(int v)
             }
 
             /* Replace the flags for stdin */
-            if (fcntl(0, F_SETFL, k))
+            if (fcntl(0, F_SETFL, k)) {
                 return 1;
+            }
         }
 
         bp[0] = '\0';
@@ -823,23 +838,27 @@ static errr game_term_xtra_gcu_event(int v)
         k = fcntl(0, F_GETFL, 0);
 
         /* Oops */
-        if (k < 0)
+        if (k < 0) {
             return 1;
+        }
 
         /* Tell stdin not to block */
-        if (fcntl(0, F_SETFL, k | O_NDELAY) < 0)
+        if (fcntl(0, F_SETFL, k | O_NDELAY) < 0) {
             return 1;
+        }
 
         /* Read one byte, if possible */
         i = read(0, buf, 1);
 
         /* Replace the flags for stdin */
-        if (fcntl(0, F_SETFL, k))
+        if (fcntl(0, F_SETFL, k)) {
             return 1;
+        }
 
         /* Ignore "invalid" keys */
-        if ((i != 1) || (!buf[0]))
+        if ((i != 1) || (!buf[0])) {
             return 1;
+        }
 
         /* Enqueue the keypress */
         term_key_push(buf[0]);
@@ -859,16 +878,19 @@ static errr game_term_xtra_gcu_sound(int v)
     char buf[1024];
 
     /* Sound disabled */
-    if (!use_sound)
+    if (!use_sound) {
         return 1;
+    }
 
     /* Illegal sound */
-    if ((v < 0) || (v >= SOUND_MAX))
+    if ((v < 0) || (v >= SOUND_MAX)) {
         return 1;
+    }
 
     /* Unknown sound */
-    if (!sound_file[v])
+    if (!sound_file[v]) {
         return 1;
+    }
 
     sprintf(buf, "./gcusound.sh %s\n", sound_file[v]);
 
@@ -890,10 +912,12 @@ static int create_color(int i, int scale)
     int rgb = 16 + scale * scale * r + scale * g + b;
     /* In the case of white and black we need to use the ANSI colors */
     if (r == g && g == b) {
-        if (b == 0)
+        if (b == 0) {
             rgb = 0;
-        if (b == scale)
+        }
+        if (b == scale) {
             rgb = 15;
+        }
     }
     return rgb;
 }
@@ -983,8 +1007,9 @@ static errr game_term_xtra_gcu(int n, int v)
 
     /* Flush events */
     case TERM_XTRA_FLUSH:
-        while (!game_term_xtra_gcu_event(false))
+        while (!game_term_xtra_gcu_event(false)) {
             ;
+        }
         return 0;
 
     /* Delay */
@@ -1028,14 +1053,15 @@ static errr game_term_wipe_gcu(int x, int y, int n)
     wmove(td->win, y, x);
 
     /* Clear to end of line */
-    if (x + n >= 80) {
+    if (x + n >= td->t.wid) {
         wclrtoeol(td->win);
     }
 
     /* Clear some characters */
     else {
-        while (n-- > 0)
+        while (n-- > 0) {
             waddch(td->win, ' ');
+        }
     }
 
     /* Success */
@@ -1093,8 +1119,9 @@ static errr game_term_text_gcu(int x, int y, int n, byte a, concptr s)
 
 #ifdef A_COLOR
     /* Set the color */
-    if (can_use_color)
+    if (can_use_color) {
         wattrset(td->win, colortable[a & 0x0F]);
+    }
 #endif
 
 #ifdef JP
@@ -1121,8 +1148,9 @@ static errr term_data_init_gcu(term_data *td, int rows, int cols, int y, int x)
     term_type *t = &td->t;
 
     /* Make sure the window has a positive size */
-    if (rows <= 0 || cols <= 0)
+    if (rows <= 0 || cols <= 0) {
         return 0;
+    }
 
     /* Create a window */
     td->win = newwin(rows, cols, y, x);
@@ -1181,23 +1209,26 @@ static int _parse_size_list(const char *arg, int sizes[], int max)
 
     for (;;) {
         if (!*stop || !isdigit(*stop)) {
-            if (i >= max)
+            if (i >= max) {
                 break;
-            if (*start == '*')
+            }
+            if (*start == '*') {
                 sizes[i] = 255;
-            else {
+            else {
                 /* rely on atoi("23,34,*") -> 23
                    otherwise, copy [start, stop) into a new buffer first.*/
                 sizes[i] = atoi(start);
             }
             i++;
-            if (!*stop || *stop != ',')
+            if (!*stop || *stop != ',') {
                 break;
+            }
 
             stop++;
             start = stop;
-        } else
+        } else {
             stop++;
+        }
     }
     return i;
 }
@@ -1251,8 +1282,9 @@ errr init_gcu(int argc, char *argv[])
     }
 
     /* Initialize for others systems */
-    if (initscr() == (WINDOW *)ERR)
+    if (initscr() == (WINDOW *)ERR) {
         return -1;
+    }
 
     /* Activate hooks */
     quit_aux = hook_quit;
@@ -1260,8 +1292,9 @@ errr init_gcu(int argc, char *argv[])
 
     /* Hack -- Require large screen, or Quit with message */
     i = ((LINES < 24) || (COLS < 80));
-    if (i)
+    if (i) {
         quit_fmt("%s needs an 80x24 'curses' screen", std::string(VARIANT_NAME).c_str());
+    }
 
 #ifdef A_COLOR
 
@@ -1414,8 +1447,9 @@ errr init_gcu(int argc, char *argv[])
             }
 
             /* Skip non-existant windows */
-            if (rows <= 0 || cols <= 0)
+            if (rows <= 0 || cols <= 0) {
                 continue;
+            }
 
             /* Create a term */
             term_data_init_gcu(&data[next_win], rows, cols, y, x);
@@ -1458,8 +1492,9 @@ errr init_gcu(int argc, char *argv[])
         for (i = 1; i < argc; i++) {
             if (streq(argv[i], "-spacer")) {
                 i++;
-                if (i >= argc)
+                if (i >= argc) {
                     quit("Missing size specifier for -spacer");
+                }
                 sscanf(argv[i], "%dx%d", &spacer_cx, &spacer_cy);
             } else if (streq(argv[i], "-right") || streq(argv[i], "-left")) {
                 const char *arg, *tmp;
@@ -1467,13 +1502,15 @@ errr init_gcu(int argc, char *argv[])
                 int cx, cys[MAX_TERM_DATA] = { 0 }, ct, j, x, y;
 
                 i++;
-                if (i >= argc)
+                if (i >= argc) {
                     quit(format("Missing size specifier for -%s", left ? "left" : "right"));
+                }
 
                 arg = argv[i];
                 tmp = strchr(arg, 'x');
-                if (!tmp)
+                if (!tmp) {
                     quit(format("Expected something like -%s 60x27,* for two %s hand terminals of 60 columns, the first 27 lines and the second whatever is left.", left ? "left" : "right", left ? "left" : "right"));
+                }
                 cx = atoi(arg);
                 remaining.cx -= cx;
                 if (left) {
@@ -1485,17 +1522,20 @@ errr init_gcu(int argc, char *argv[])
                     y = remaining.y;
                 }
                 remaining.cx -= spacer_cx;
-                if (left)
+                if (left) {
                     remaining.x += spacer_cx;
+                }
 
                 tmp++;
                 ct = _parse_size_list(tmp, cys, MAX_TERM_DATA);
                 for (j = 0; j < ct; j++) {
                     int cy = cys[j];
-                    if (y + cy > remaining.y + remaining.cy)
+                    if (y + cy > remaining.y + remaining.cy) {
                         cy = remaining.y + remaining.cy - y;
-                    if (next_term >= MAX_TERM_DATA)
+                    }
+                    if (next_term >= MAX_TERM_DATA) {
                         quit(format("Too many terminals. Only %d are allowed.", MAX_TERM_DATA));
+                    }
                     if (cy <= 0) {
                         quit(format("Out of bounds in -%s: %d is too large (%d rows max for this strip)",
                             left ? "left" : "right", cys[j], remaining.cy));
@@ -1510,13 +1550,15 @@ errr init_gcu(int argc, char *argv[])
                 int cy, cxs[MAX_TERM_DATA] = { 0 }, ct, j, x, y;
 
                 i++;
-                if (i >= argc)
+                if (i >= argc) {
                     quit(format("Missing size specifier for -%s", top ? "top" : "bottom"));
+                }
 
                 arg = argv[i];
                 tmp = strchr(arg, 'x');
-                if (!tmp)
+                if (!tmp) {
                     quit(format("Expected something like -%s *x7 for a single %s terminal of 7 lines using as many columns as are available.", top ? "top" : "bottom", top ? "top" : "bottom"));
+                }
                 tmp++;
                 cy = atoi(tmp);
                 ct = _parse_size_list(arg, cxs, MAX_TERM_DATA);
@@ -1531,16 +1573,19 @@ errr init_gcu(int argc, char *argv[])
                     y = remaining.y + remaining.cy;
                 }
                 remaining.cy -= spacer_cy;
-                if (top)
+                if (top) {
                     remaining.y += spacer_cy;
+                }
 
                 tmp++;
                 for (j = 0; j < ct; j++) {
                     int cx = cxs[j];
-                    if (x + cx > remaining.x + remaining.cx)
+                    if (x + cx > remaining.x + remaining.cx) {
                         cx = remaining.x + remaining.cx - x;
-                    if (next_term >= MAX_TERM_DATA)
+                    }
+                    if (next_term >= MAX_TERM_DATA) {
                         quit(format("Too many terminals. Only %d are allowed.", MAX_TERM_DATA));
+                    }
                     if (cx <= 0) {
                         quit(format("Out of bounds in -%s: %d is too large (%d cols max for this strip)",
                             top ? "top" : "bottom", cxs[j], remaining.cx));
@@ -1553,8 +1598,9 @@ errr init_gcu(int argc, char *argv[])
         }
 
         /* Map Terminal */
-        if (remaining.cx < MIN_TERM0_COLS || remaining.cy < MIN_TERM0_LINES)
+        if (remaining.cx < MIN_TERM0_COLS || remaining.cy < MIN_TERM0_LINES) {
             quit_fmt("Failed: %s needs an %dx%d map screen, not %dx%d", std::string(VARIANT_NAME).c_str(), MIN_TERM0_COLS, MIN_TERM0_LINES, remaining.cx, remaining.cy);
+        }
         data[0].r = remaining;
         term_data_init(&data[0]);
         angband_term[0] = game_term;