OSDN Git Service

[Refactor] #37353 やはりgotoは悪い文明!! 粉砕する!! / After all goto is a bad civillization!...
authorHourier <hourier@users.sourceforge.jp>
Fri, 14 Feb 2020 14:28:18 +0000 (23:28 +0900)
committerHourier <hourier@users.sourceforge.jp>
Fri, 14 Feb 2020 14:29:13 +0000 (23:29 +0900)
src/main-x11.c
src/main.c
src/object-flavor.c
src/readdib.c
src/report.c
src/util.c

index 442544a..d596bc0 100644 (file)
@@ -1900,27 +1900,25 @@ static errr CheckEvent(bool wait)
        int i;
 
 #ifdef USE_XIM
- redo_checkevent:
+       do
+       {
 #endif
 
-       /* Do not wait unless requested */
-       if (!wait && !XPending(Metadpy->dpy)) return (1);
+               /* Do not wait unless requested */
+               if (!wait && !XPending(Metadpy->dpy)) return (1);
 
-       /*
-        * Hack - redraw the selection, if needed.
-        * This doesn't actually check that one of its squares was drawn to,
-        * only that this may have happened.
-        */
-       if (s_ptr->select && !s_ptr->drawn) mark_selection();
+               /*
+                * Hack - redraw the selection, if needed.
+                * This doesn't actually check that one of its squares was drawn to,
+                * only that this may have happened.
+                */
+               if (s_ptr->select && !s_ptr->drawn) mark_selection();
 
-       /* Load the Event */
-       XNextEvent(Metadpy->dpy, xev);
+               /* Load the Event */
+               XNextEvent(Metadpy->dpy, xev);
 
 #ifdef USE_XIM
-       if (XFilterEvent(xev, xev->xany.window)
-       {
-               goto redo_checkevent;
-       }
+       } while (XFilterEvent(xev, xev->xany.window)
 #endif
 
        /* Notice new keymaps */
index cb64707..2aa0737 100644 (file)
@@ -32,7 +32,6 @@
 
 #if !defined(WINDOWS)
 
-
 /*
  * A hook for "quit()".
  *
@@ -238,6 +237,49 @@ static void change_path(concptr info)
        }
 }
 
+static void display_usage(void)
+{
+       /* Dump usage information */
+       puts("Usage: angband [options] [-- subopts]");
+       puts("  -n       Start a new character");
+       puts("  -f       Request fiddle mode");
+       puts("  -w       Request wizard mode");
+       puts("  -b       Request BGM mode");
+       puts("  -v       Request sound mode");
+       puts("  -g       Request graphics mode");
+       puts("  -o       Request original keyset");
+       puts("  -r       Request rogue-like keyset");
+       puts("  -M       Request monochrome mode");
+       puts("  -s<num>  Show <num> high scores");
+       puts("  -u<who>  Use your <who> savefile");
+       puts("  -m<sys>  Force 'main-<sys>.c' usage");
+       puts("  -d<def>  Define a 'lib' dir sub-path");
+       puts("");
+
+#ifdef USE_X11
+       puts("  -mx11    To use X11");
+       puts("  --       Sub options");
+       puts("  -- -d    Set display name");
+       puts("  -- -o    Request old 8x8 tile graphics");
+       puts("  -- -a    Request Adam Bolt 16x16 tile graphics");
+       puts("  -- -b    Request Bigtile graphics mode");
+       puts("  -- -s    Turn off smoothscaling graphics");
+       puts("  -- -n#   Number of terms to use");
+       puts("");
+#endif /* USE_X11 */
+
+#ifdef USE_GCU
+       puts("  -mgcu    To use GCU (GNU Curses)");
+#endif /* USE_GCU */
+
+#ifdef USE_CAP
+       puts("  -mcap    To use CAP (\"Termcap\" calls)");
+#endif /* USE_CAP */
+
+       /* Actually abort the process */
+       quit(NULL);
+}
+
 
 /*
  * Simple "main" function for multiple platforms.
@@ -319,9 +361,14 @@ int main(int argc, char *argv[])
        for (i = 1; args && (i < argc); i++)
        {
                /* Require proper options */
-               if (argv[i][0] != '-') goto usage;
+               if (argv[i][0] != '-')
+               {
+                       display_usage();
+                       continue;
+               }
 
                /* Analyze option */
+               bool is_usage_needed = FALSE;
                switch (argv[i][1])
                {
                        case 'N':
@@ -330,35 +377,30 @@ int main(int argc, char *argv[])
                                new_game = TRUE;
                                break;
                        }
-
                        case 'F':
                        case 'f':
                        {
                                arg_fiddle = TRUE;
                                break;
                        }
-
                        case 'W':
                        case 'w':
                        {
                                arg_wizard = TRUE;
                                break;
                        }
-
                        case 'B':
                        case 'b':
                        {
                                arg_music = TRUE;
                                break;
                        }
-
                        case 'V':
                        case 'v':
                        {
                                arg_sound = TRUE;
                                break;
                        }
-
                        case 'G':
                        case 'g':
                        {
@@ -366,21 +408,18 @@ int main(int argc, char *argv[])
                                arg_graphics = GRAPHICS_ORIGINAL;
                                break;
                        }
-
                        case 'R':
                        case 'r':
                        {
                                arg_force_roguelike = TRUE;
                                break;
                        }
-
                        case 'O':
                        case 'o':
                        {
                                arg_force_original = TRUE;
                                break;
                        }
-
                        case 'S':
                        case 's':
                        {
@@ -388,40 +427,50 @@ int main(int argc, char *argv[])
                                if (show_score <= 0) show_score = 10;
                                break;
                        }
-
                        case 'u':
                        case 'U':
                        {
-                               if (!argv[i][2]) goto usage;
+                               if (!argv[i][2])
+                               {
+                                       is_usage_needed = TRUE;
+                                       break;
+                               }
+
                                strcpy(p_ptr->name, &argv[i][2]);
                                break;
                        }
-
                        case 'm':
                        {
-                               if (!argv[i][2]) goto usage;
+                               if (!argv[i][2])
+                               {
+                                       is_usage_needed = TRUE;
+                                       break;
+                               }
+
                                mstr = &argv[i][2];
                                break;
                        }
-
                        case 'M':
                        {
                                arg_monochrome = TRUE;
                                break;
                        }
-
                        case 'd':
                        case 'D':
                        {
                                change_path(&argv[i][2]);
                                break;
                        }
-
 #ifdef CHUUKEI
                        case 'p':
                        case 'P':
                        {
-                               if (!argv[i][2]) goto usage;
+                               if (!argv[i][2])
+                               {
+                                       is_usage_needed = TRUE;
+                                       break;
+                               }
+
                                chuukei_server = TRUE;
                                if (connect_chuukei_server(&argv[i][2]) < 0) chuukei_server = FALSE;
                                break;
@@ -430,20 +479,28 @@ int main(int argc, char *argv[])
                        case 'c':
                        case 'C':
                        {
-                               if (!argv[i][2]) goto usage;
+                               if (!argv[i][2])
+                               {
+                                       is_usage_needed = TRUE;
+                                       break;
+                               }
+
                                chuukei_client = TRUE;
                                connect_chuukei_server(&argv[i][2]);
                                break;
                        }
 #endif
-
                        case 'x':
                        {
-                               if (!argv[i][2]) goto usage;
+                               if (!argv[i][2])
+                               {
+                                       is_usage_needed = TRUE;
+                                       break;
+                               }
+
                                prepare_browse_movie(&argv[i][2]);
                                break;
-                       }                       
-
+                       }
                        case '-':
                        {
                                argv[i] = argv[0];
@@ -452,51 +509,16 @@ int main(int argc, char *argv[])
                                args = FALSE;
                                break;
                        }
-
                        default:
-                       usage:
                        {
-                               /* Dump usage information */
-                               puts("Usage: angband [options] [-- subopts]");
-                               puts("  -n       Start a new character");
-                               puts("  -f       Request fiddle mode");
-                               puts("  -w       Request wizard mode");
-                               puts("  -b       Request BGM mode");
-                               puts("  -v       Request sound mode");
-                               puts("  -g       Request graphics mode");
-                               puts("  -o       Request original keyset");
-                               puts("  -r       Request rogue-like keyset");
-                               puts("  -M       Request monochrome mode");
-                               puts("  -s<num>  Show <num> high scores");
-                               puts("  -u<who>  Use your <who> savefile");
-                               puts("  -m<sys>  Force 'main-<sys>.c' usage");
-                               puts("  -d<def>  Define a 'lib' dir sub-path");
-                               puts("");
-
-#ifdef USE_X11
-                               puts("  -mx11    To use X11");
-                               puts("  --       Sub options");
-                               puts("  -- -d    Set display name");
-                               puts("  -- -o    Request old 8x8 tile graphics");
-                               puts("  -- -a    Request Adam Bolt 16x16 tile graphics");
-                               puts("  -- -b    Request Bigtile graphics mode");
-                               puts("  -- -s    Turn off smoothscaling graphics");
-                               puts("  -- -n#   Number of terms to use");
-                               puts("");
-#endif /* USE_X11 */
-
-#ifdef USE_GCU
-                               puts("  -mgcu    To use GCU (GNU Curses)");
-#endif /* USE_GCU */
-
-#ifdef USE_CAP
-                               puts("  -mcap    To use CAP (\"Termcap\" calls)");
-#endif /* USE_CAP */
-
-                               /* Actually abort the process */
-                               quit(NULL);
+                               is_usage_needed = TRUE;
+                               break;
                        }
                }
+
+               if (!is_usage_needed) continue;
+
+               display_usage();
        }
 
        /* Hack -- Forget standard args */
@@ -597,6 +619,3 @@ int main(int argc, char *argv[])
 }
 
 #endif
-
-
-
index b39471e..ca614cd 100644 (file)
@@ -2249,7 +2249,11 @@ void object_desc(player_type *player_ptr, char *buf, object_type *o_ptr, BIT_FLA
 
 
        /* No more details wanted */
-       if (mode & OD_NAME_ONLY) goto object_desc_done;
+       if (mode & OD_NAME_ONLY)
+       {
+               my_strcpy(buf, tmp_val, MAX_NLEN);
+               return;
+       }
 
        /* Hack -- Chests must be described in detail */
        if (o_ptr->tval == TV_CHEST)
@@ -2587,8 +2591,11 @@ void object_desc(player_type *player_ptr, char *buf, object_type *o_ptr, BIT_FLA
 
 
        /* No more details wanted */
-       if (mode & OD_NAME_AND_ENCHANT) goto object_desc_done;
-
+       if (mode & OD_NAME_AND_ENCHANT)
+       {
+               my_strcpy(buf, tmp_val, MAX_NLEN);
+               return;
+       }
 
        if (known) /* Known item only */
        {
@@ -2716,7 +2723,11 @@ void object_desc(player_type *player_ptr, char *buf, object_type *o_ptr, BIT_FLA
        }
 
        /* No more details wanted */
-       if (mode & OD_OMIT_INSCRIPTION) goto object_desc_done;
+       if (mode & OD_OMIT_INSCRIPTION)
+       {
+               my_strcpy(buf, tmp_val, MAX_NLEN);
+               return;
+       }
 
        /* Prepare real inscriptions in a buffer */
        tmp_val2[0] = '\0';
@@ -2832,7 +2843,6 @@ void object_desc(player_type *player_ptr, char *buf, object_type *o_ptr, BIT_FLA
                t = object_desc_chr(t, c2);
        }
 
-object_desc_done:
        my_strcpy(buf, tmp_val, MAX_NLEN);
 }
 
index e220b06..1039246 100644 (file)
@@ -56,6 +56,8 @@
  */
 #define MAXREAD  32768
 
+void global_free(DIBINIT *pInfo, INT_PTR *fh, BOOL unlock_needed);
+
 /*!
  * @brief 32KBのデータ読み取りを繰り返すことで、64KB以上のデータを一度に読み取るサブルーチン
  * Private routine to read more than 64K at a time Reads data in steps of 32k till all the data has been read.
@@ -217,7 +219,6 @@ static BOOL NEAR PASCAL MakeBitmapAndPalette(HDC hDC, HANDLE hDIB,
  */
 BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
 {
-       unsigned fh;
        LPBITMAPINFOHEADER lpbi;
        OFSTRUCT of;
        BITMAPFILEHEADER bf;
@@ -229,7 +230,7 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
        BOOL bCoreHead = FALSE;
 
        /* Open the file and get a handle to it's BITMAPINFO */
-       fh = OpenFile(lpFileName, &of, OF_READ);
+       INT_PTR fh = OpenFile(lpFileName, &of, OF_READ);
        if (fh == -1)
        {
                wsprintf(str, "Can't open file '%s'", (LPSTR)lpFileName);
@@ -245,16 +246,14 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
 
        lpbi = (LPBITMAPINFOHEADER)GlobalLock(pInfo->hDIB);
 
-       /* read the BITMAPFILEHEADER */
-       if (sizeof (bf) != _lread(fh, (LPSTR)&bf, sizeof(bf)))
-               goto ErrExit;
-
-       /* 'BM' */
-       if (bf.bfType != 0x4d42)
-               goto ErrExit;
-
-       if (sizeof(BITMAPCOREHEADER) != _lread(fh, (LPSTR)lpbi, sizeof(BITMAPCOREHEADER)))
-               goto ErrExit;
+       BOOL is_read_error = sizeof(bf) != _lread(fh, (LPSTR)&bf, sizeof(bf));
+       is_read_error |= bf.bfType != 0x4d42;
+       is_read_error |= sizeof(BITMAPCOREHEADER) != _lread(fh, (LPSTR)lpbi, sizeof(BITMAPCOREHEADER));
+       if (is_read_error)
+       {
+               global_free(pInfo, &fh, TRUE);
+               return result;
+       }
 
        if (lpbi->biSize == sizeof(BITMAPCOREHEADER))
        {
@@ -270,7 +269,10 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
                /* get to the start of the header and read INFOHEADER */
                _llseek(fh, sizeof(BITMAPFILEHEADER), SEEK_SET);
                if (sizeof(BITMAPINFOHEADER) != _lread(fh, (LPSTR)lpbi, sizeof(BITMAPINFOHEADER)))
-                       goto ErrExit;
+               {
+                       global_free(pInfo, &fh, TRUE);
+                       return result;
+               }
        }
 
        nNumColors = (WORD)lpbi->biClrUsed;
@@ -305,7 +307,10 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
 
        /* can't resize buffer for loading */
        if (!pInfo->hDIB)
-               goto ErrExit2;
+       {
+               global_free(pInfo, &fh, FALSE);
+               return result;
+       }
 
        lpbi = (LPBITMAPINFOHEADER)GlobalLock(pInfo->hDIB);
 
@@ -351,7 +356,8 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
                                          &((HBITMAP)pInfo->hBitmap)))
                {
                        ReleaseDC(hWnd,hDC);
-                       goto ErrExit2;
+                       global_free(pInfo, &fh, FALSE);
+                       return result;
                }
                else
                {
@@ -361,13 +367,22 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
        }
        else
        {
-ErrExit:
                GlobalUnlock(pInfo->hDIB);
-ErrExit2:
                GlobalFree(pInfo->hDIB);
        }
 
        _lclose(fh);
-       return(result);
+       return result;
 }
 
+
+void global_free(DIBINIT *pInfo, INT_PTR *fh, BOOL unlock_needed)
+{
+       if (unlock_needed)
+       {
+               GlobalUnlock(pInfo->hDIB);
+       }
+
+       GlobalFree(pInfo->hDIB);
+       _lclose(*fh);
+}
index 10d13ae..c2324d3 100644 (file)
@@ -391,11 +391,10 @@ concptr make_screen_dump(player_type *creature_ptr)
  * todo メッセージは言語選択の関数マクロで何とかならんか?
  * @brief スコア転送処理のメインルーチン
  * @param creature_ptr プレーヤーへの参照ポインタ
- * @return エラーコード
+ * @return 正常終了の時0、異常があったら1
  */
 errr report_score(player_type *creature_ptr)
 {
-       errr err = 0;
 #ifdef WINDOWS
        WSADATA wsaData;
        WORD wVersionRequested = (WORD)((1) | (1 << 8));
@@ -447,7 +446,10 @@ errr report_score(player_type *creature_ptr)
        if (WSAStartup(wVersionRequested, &wsaData))
        {
                msg_print("Report: WSAStartup failed.");
-               goto report_end;
+#ifdef WINDOWS
+               WSACleanup();
+#endif
+               return 1;
        }
 #endif
 
@@ -486,8 +488,10 @@ errr report_score(player_type *creature_ptr)
                        if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
 #endif
                        {
-                               err = 1;
-                               goto report_end;
+#ifdef WINDOWS
+                               WSACleanup();
+#endif
+                               return 1;
                        }
 
                        continue;
@@ -516,8 +520,10 @@ errr report_score(player_type *creature_ptr)
                        if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
 #endif
                        {
-                               err = 1;
-                               goto report_end;
+#ifdef WINDOWS
+                               WSACleanup();
+#endif
+                               return 1;
                        }
 
                        continue;
@@ -527,12 +533,10 @@ errr report_score(player_type *creature_ptr)
                break;
        }
 
-report_end:
 #ifdef WINDOWS
        WSACleanup();
 #endif
 
-       return err;
+       return 0;
 }
-
 #endif /* WORLD_SCORE */
index 2c5cc80..19b3456 100644 (file)
@@ -1979,8 +1979,11 @@ void message_add(concptr str)
                if (message__last == MESSAGE_MAX) message__last = 0;
 
                message__ptr[x] = message__ptr[i];
-
-               goto end_of_message_add;
+               if (splitted2 != NULL)
+               {
+                       message_add(splitted2);
+                       return;
+               }
        }
 
        if (message__head + n + 1 >= MESSAGE_BUF)
@@ -2032,9 +2035,10 @@ void message_add(concptr str)
        message__buf[message__head + i] = '\0';
        message__head += n + 1;
 
-end_of_message_add:
        if (splitted2 != NULL)
+       {
                message_add(splitted2);
+       }
 }