• R/O
  • HTTP
  • SSH
  • HTTPS

hengband: Commit

変愚蛮怒のメインリポジトリです


Commit MetaInfo

Revisão4201e72c7a4745b7fa16a70e2fd68ac78ade76d8 (tree)
Hora2020-02-14 23:29:13
AutorHourier <hourier@user...>
CommiterHourier

Mensagem de Log

[Refactor] #37353 やはりgotoは悪い文明!! 粉砕する!! / After all goto is a bad civillization!! CRUSH'EM!!

Mudança Sumário

Diff

--- a/src/main-x11.c
+++ b/src/main-x11.c
@@ -1900,27 +1900,25 @@ static errr CheckEvent(bool wait)
19001900 int i;
19011901
19021902 #ifdef USE_XIM
1903- redo_checkevent:
1903+ do
1904+ {
19041905 #endif
19051906
1906- /* Do not wait unless requested */
1907- if (!wait && !XPending(Metadpy->dpy)) return (1);
1907+ /* Do not wait unless requested */
1908+ if (!wait && !XPending(Metadpy->dpy)) return (1);
19081909
1909- /*
1910- * Hack - redraw the selection, if needed.
1911- * This doesn't actually check that one of its squares was drawn to,
1912- * only that this may have happened.
1913- */
1914- if (s_ptr->select && !s_ptr->drawn) mark_selection();
1910+ /*
1911+ * Hack - redraw the selection, if needed.
1912+ * This doesn't actually check that one of its squares was drawn to,
1913+ * only that this may have happened.
1914+ */
1915+ if (s_ptr->select && !s_ptr->drawn) mark_selection();
19151916
1916- /* Load the Event */
1917- XNextEvent(Metadpy->dpy, xev);
1917+ /* Load the Event */
1918+ XNextEvent(Metadpy->dpy, xev);
19181919
19191920 #ifdef USE_XIM
1920- if (XFilterEvent(xev, xev->xany.window)
1921- {
1922- goto redo_checkevent;
1923- }
1921+ } while (XFilterEvent(xev, xev->xany.window)
19241922 #endif
19251923
19261924 /* Notice new keymaps */
--- a/src/main.c
+++ b/src/main.c
@@ -32,7 +32,6 @@
3232
3333 #if !defined(WINDOWS)
3434
35-
3635 /*
3736 * A hook for "quit()".
3837 *
@@ -238,6 +237,49 @@ static void change_path(concptr info)
238237 }
239238 }
240239
240+static void display_usage(void)
241+{
242+ /* Dump usage information */
243+ puts("Usage: angband [options] [-- subopts]");
244+ puts(" -n Start a new character");
245+ puts(" -f Request fiddle mode");
246+ puts(" -w Request wizard mode");
247+ puts(" -b Request BGM mode");
248+ puts(" -v Request sound mode");
249+ puts(" -g Request graphics mode");
250+ puts(" -o Request original keyset");
251+ puts(" -r Request rogue-like keyset");
252+ puts(" -M Request monochrome mode");
253+ puts(" -s<num> Show <num> high scores");
254+ puts(" -u<who> Use your <who> savefile");
255+ puts(" -m<sys> Force 'main-<sys>.c' usage");
256+ puts(" -d<def> Define a 'lib' dir sub-path");
257+ puts("");
258+
259+#ifdef USE_X11
260+ puts(" -mx11 To use X11");
261+ puts(" -- Sub options");
262+ puts(" -- -d Set display name");
263+ puts(" -- -o Request old 8x8 tile graphics");
264+ puts(" -- -a Request Adam Bolt 16x16 tile graphics");
265+ puts(" -- -b Request Bigtile graphics mode");
266+ puts(" -- -s Turn off smoothscaling graphics");
267+ puts(" -- -n# Number of terms to use");
268+ puts("");
269+#endif /* USE_X11 */
270+
271+#ifdef USE_GCU
272+ puts(" -mgcu To use GCU (GNU Curses)");
273+#endif /* USE_GCU */
274+
275+#ifdef USE_CAP
276+ puts(" -mcap To use CAP (\"Termcap\" calls)");
277+#endif /* USE_CAP */
278+
279+ /* Actually abort the process */
280+ quit(NULL);
281+}
282+
241283
242284 /*
243285 * Simple "main" function for multiple platforms.
@@ -319,9 +361,14 @@ int main(int argc, char *argv[])
319361 for (i = 1; args && (i < argc); i++)
320362 {
321363 /* Require proper options */
322- if (argv[i][0] != '-') goto usage;
364+ if (argv[i][0] != '-')
365+ {
366+ display_usage();
367+ continue;
368+ }
323369
324370 /* Analyze option */
371+ bool is_usage_needed = FALSE;
325372 switch (argv[i][1])
326373 {
327374 case 'N':
@@ -330,35 +377,30 @@ int main(int argc, char *argv[])
330377 new_game = TRUE;
331378 break;
332379 }
333-
334380 case 'F':
335381 case 'f':
336382 {
337383 arg_fiddle = TRUE;
338384 break;
339385 }
340-
341386 case 'W':
342387 case 'w':
343388 {
344389 arg_wizard = TRUE;
345390 break;
346391 }
347-
348392 case 'B':
349393 case 'b':
350394 {
351395 arg_music = TRUE;
352396 break;
353397 }
354-
355398 case 'V':
356399 case 'v':
357400 {
358401 arg_sound = TRUE;
359402 break;
360403 }
361-
362404 case 'G':
363405 case 'g':
364406 {
@@ -366,21 +408,18 @@ int main(int argc, char *argv[])
366408 arg_graphics = GRAPHICS_ORIGINAL;
367409 break;
368410 }
369-
370411 case 'R':
371412 case 'r':
372413 {
373414 arg_force_roguelike = TRUE;
374415 break;
375416 }
376-
377417 case 'O':
378418 case 'o':
379419 {
380420 arg_force_original = TRUE;
381421 break;
382422 }
383-
384423 case 'S':
385424 case 's':
386425 {
@@ -388,40 +427,50 @@ int main(int argc, char *argv[])
388427 if (show_score <= 0) show_score = 10;
389428 break;
390429 }
391-
392430 case 'u':
393431 case 'U':
394432 {
395- if (!argv[i][2]) goto usage;
433+ if (!argv[i][2])
434+ {
435+ is_usage_needed = TRUE;
436+ break;
437+ }
438+
396439 strcpy(p_ptr->name, &argv[i][2]);
397440 break;
398441 }
399-
400442 case 'm':
401443 {
402- if (!argv[i][2]) goto usage;
444+ if (!argv[i][2])
445+ {
446+ is_usage_needed = TRUE;
447+ break;
448+ }
449+
403450 mstr = &argv[i][2];
404451 break;
405452 }
406-
407453 case 'M':
408454 {
409455 arg_monochrome = TRUE;
410456 break;
411457 }
412-
413458 case 'd':
414459 case 'D':
415460 {
416461 change_path(&argv[i][2]);
417462 break;
418463 }
419-
420464 #ifdef CHUUKEI
421465 case 'p':
422466 case 'P':
423467 {
424- if (!argv[i][2]) goto usage;
468+ if (!argv[i][2])
469+ {
470+ is_usage_needed = TRUE;
471+ break;
472+ }
473+
425474 chuukei_server = TRUE;
426475 if (connect_chuukei_server(&argv[i][2]) < 0) chuukei_server = FALSE;
427476 break;
@@ -430,20 +479,28 @@ int main(int argc, char *argv[])
430479 case 'c':
431480 case 'C':
432481 {
433- if (!argv[i][2]) goto usage;
482+ if (!argv[i][2])
483+ {
484+ is_usage_needed = TRUE;
485+ break;
486+ }
487+
434488 chuukei_client = TRUE;
435489 connect_chuukei_server(&argv[i][2]);
436490 break;
437491 }
438492 #endif
439-
440493 case 'x':
441494 {
442- if (!argv[i][2]) goto usage;
495+ if (!argv[i][2])
496+ {
497+ is_usage_needed = TRUE;
498+ break;
499+ }
500+
443501 prepare_browse_movie(&argv[i][2]);
444502 break;
445- }
446-
503+ }
447504 case '-':
448505 {
449506 argv[i] = argv[0];
@@ -452,51 +509,16 @@ int main(int argc, char *argv[])
452509 args = FALSE;
453510 break;
454511 }
455-
456512 default:
457- usage:
458513 {
459- /* Dump usage information */
460- puts("Usage: angband [options] [-- subopts]");
461- puts(" -n Start a new character");
462- puts(" -f Request fiddle mode");
463- puts(" -w Request wizard mode");
464- puts(" -b Request BGM mode");
465- puts(" -v Request sound mode");
466- puts(" -g Request graphics mode");
467- puts(" -o Request original keyset");
468- puts(" -r Request rogue-like keyset");
469- puts(" -M Request monochrome mode");
470- puts(" -s<num> Show <num> high scores");
471- puts(" -u<who> Use your <who> savefile");
472- puts(" -m<sys> Force 'main-<sys>.c' usage");
473- puts(" -d<def> Define a 'lib' dir sub-path");
474- puts("");
475-
476-#ifdef USE_X11
477- puts(" -mx11 To use X11");
478- puts(" -- Sub options");
479- puts(" -- -d Set display name");
480- puts(" -- -o Request old 8x8 tile graphics");
481- puts(" -- -a Request Adam Bolt 16x16 tile graphics");
482- puts(" -- -b Request Bigtile graphics mode");
483- puts(" -- -s Turn off smoothscaling graphics");
484- puts(" -- -n# Number of terms to use");
485- puts("");
486-#endif /* USE_X11 */
487-
488-#ifdef USE_GCU
489- puts(" -mgcu To use GCU (GNU Curses)");
490-#endif /* USE_GCU */
491-
492-#ifdef USE_CAP
493- puts(" -mcap To use CAP (\"Termcap\" calls)");
494-#endif /* USE_CAP */
495-
496- /* Actually abort the process */
497- quit(NULL);
514+ is_usage_needed = TRUE;
515+ break;
498516 }
499517 }
518+
519+ if (!is_usage_needed) continue;
520+
521+ display_usage();
500522 }
501523
502524 /* Hack -- Forget standard args */
@@ -597,6 +619,3 @@ int main(int argc, char *argv[])
597619 }
598620
599621 #endif
600-
601-
602-
--- a/src/object-flavor.c
+++ b/src/object-flavor.c
@@ -2249,7 +2249,11 @@ void object_desc(player_type *player_ptr, char *buf, object_type *o_ptr, BIT_FLA
22492249
22502250
22512251 /* No more details wanted */
2252- if (mode & OD_NAME_ONLY) goto object_desc_done;
2252+ if (mode & OD_NAME_ONLY)
2253+ {
2254+ my_strcpy(buf, tmp_val, MAX_NLEN);
2255+ return;
2256+ }
22532257
22542258 /* Hack -- Chests must be described in detail */
22552259 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
25872591
25882592
25892593 /* No more details wanted */
2590- if (mode & OD_NAME_AND_ENCHANT) goto object_desc_done;
2591-
2594+ if (mode & OD_NAME_AND_ENCHANT)
2595+ {
2596+ my_strcpy(buf, tmp_val, MAX_NLEN);
2597+ return;
2598+ }
25922599
25932600 if (known) /* Known item only */
25942601 {
@@ -2716,7 +2723,11 @@ void object_desc(player_type *player_ptr, char *buf, object_type *o_ptr, BIT_FLA
27162723 }
27172724
27182725 /* No more details wanted */
2719- if (mode & OD_OMIT_INSCRIPTION) goto object_desc_done;
2726+ if (mode & OD_OMIT_INSCRIPTION)
2727+ {
2728+ my_strcpy(buf, tmp_val, MAX_NLEN);
2729+ return;
2730+ }
27202731
27212732 /* Prepare real inscriptions in a buffer */
27222733 tmp_val2[0] = '\0';
@@ -2832,7 +2843,6 @@ void object_desc(player_type *player_ptr, char *buf, object_type *o_ptr, BIT_FLA
28322843 t = object_desc_chr(t, c2);
28332844 }
28342845
2835-object_desc_done:
28362846 my_strcpy(buf, tmp_val, MAX_NLEN);
28372847 }
28382848
--- a/src/readdib.c
+++ b/src/readdib.c
@@ -56,6 +56,8 @@
5656 */
5757 #define MAXREAD 32768
5858
59+void global_free(DIBINIT *pInfo, INT_PTR *fh, BOOL unlock_needed);
60+
5961 /*!
6062 * @brief 32KBのデータ読み取りを繰り返すことで、64KB以上のデータを一度に読み取るサブルーチン
6163 * 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,
217219 */
218220 BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
219221 {
220- unsigned fh;
221222 LPBITMAPINFOHEADER lpbi;
222223 OFSTRUCT of;
223224 BITMAPFILEHEADER bf;
@@ -229,7 +230,7 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
229230 BOOL bCoreHead = FALSE;
230231
231232 /* Open the file and get a handle to it's BITMAPINFO */
232- fh = OpenFile(lpFileName, &of, OF_READ);
233+ INT_PTR fh = OpenFile(lpFileName, &of, OF_READ);
233234 if (fh == -1)
234235 {
235236 wsprintf(str, "Can't open file '%s'", (LPSTR)lpFileName);
@@ -245,16 +246,14 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
245246
246247 lpbi = (LPBITMAPINFOHEADER)GlobalLock(pInfo->hDIB);
247248
248- /* read the BITMAPFILEHEADER */
249- if (sizeof (bf) != _lread(fh, (LPSTR)&bf, sizeof(bf)))
250- goto ErrExit;
251-
252- /* 'BM' */
253- if (bf.bfType != 0x4d42)
254- goto ErrExit;
255-
256- if (sizeof(BITMAPCOREHEADER) != _lread(fh, (LPSTR)lpbi, sizeof(BITMAPCOREHEADER)))
257- goto ErrExit;
249+ BOOL is_read_error = sizeof(bf) != _lread(fh, (LPSTR)&bf, sizeof(bf));
250+ is_read_error |= bf.bfType != 0x4d42;
251+ is_read_error |= sizeof(BITMAPCOREHEADER) != _lread(fh, (LPSTR)lpbi, sizeof(BITMAPCOREHEADER));
252+ if (is_read_error)
253+ {
254+ global_free(pInfo, &fh, TRUE);
255+ return result;
256+ }
258257
259258 if (lpbi->biSize == sizeof(BITMAPCOREHEADER))
260259 {
@@ -270,7 +269,10 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
270269 /* get to the start of the header and read INFOHEADER */
271270 _llseek(fh, sizeof(BITMAPFILEHEADER), SEEK_SET);
272271 if (sizeof(BITMAPINFOHEADER) != _lread(fh, (LPSTR)lpbi, sizeof(BITMAPINFOHEADER)))
273- goto ErrExit;
272+ {
273+ global_free(pInfo, &fh, TRUE);
274+ return result;
275+ }
274276 }
275277
276278 nNumColors = (WORD)lpbi->biClrUsed;
@@ -305,7 +307,10 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
305307
306308 /* can't resize buffer for loading */
307309 if (!pInfo->hDIB)
308- goto ErrExit2;
310+ {
311+ global_free(pInfo, &fh, FALSE);
312+ return result;
313+ }
309314
310315 lpbi = (LPBITMAPINFOHEADER)GlobalLock(pInfo->hDIB);
311316
@@ -351,7 +356,8 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
351356 &((HBITMAP)pInfo->hBitmap)))
352357 {
353358 ReleaseDC(hWnd,hDC);
354- goto ErrExit2;
359+ global_free(pInfo, &fh, FALSE);
360+ return result;
355361 }
356362 else
357363 {
@@ -361,13 +367,22 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo)
361367 }
362368 else
363369 {
364-ErrExit:
365370 GlobalUnlock(pInfo->hDIB);
366-ErrExit2:
367371 GlobalFree(pInfo->hDIB);
368372 }
369373
370374 _lclose(fh);
371- return(result);
375+ return result;
372376 }
373377
378+
379+void global_free(DIBINIT *pInfo, INT_PTR *fh, BOOL unlock_needed)
380+{
381+ if (unlock_needed)
382+ {
383+ GlobalUnlock(pInfo->hDIB);
384+ }
385+
386+ GlobalFree(pInfo->hDIB);
387+ _lclose(*fh);
388+}
--- a/src/report.c
+++ b/src/report.c
@@ -391,11 +391,10 @@ concptr make_screen_dump(player_type *creature_ptr)
391391 * todo メッセージは言語選択の関数マクロで何とかならんか?
392392 * @brief スコア転送処理のメインルーチン
393393 * @param creature_ptr プレーヤーへの参照ポインタ
394- * @return エラーコード
394+ * @return 正常終了の時0、異常があったら1
395395 */
396396 errr report_score(player_type *creature_ptr)
397397 {
398- errr err = 0;
399398 #ifdef WINDOWS
400399 WSADATA wsaData;
401400 WORD wVersionRequested = (WORD)((1) | (1 << 8));
@@ -447,7 +446,10 @@ errr report_score(player_type *creature_ptr)
447446 if (WSAStartup(wVersionRequested, &wsaData))
448447 {
449448 msg_print("Report: WSAStartup failed.");
450- goto report_end;
449+#ifdef WINDOWS
450+ WSACleanup();
451+#endif
452+ return 1;
451453 }
452454 #endif
453455
@@ -486,8 +488,10 @@ errr report_score(player_type *creature_ptr)
486488 if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
487489 #endif
488490 {
489- err = 1;
490- goto report_end;
491+#ifdef WINDOWS
492+ WSACleanup();
493+#endif
494+ return 1;
491495 }
492496
493497 continue;
@@ -516,8 +520,10 @@ errr report_score(player_type *creature_ptr)
516520 if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
517521 #endif
518522 {
519- err = 1;
520- goto report_end;
523+#ifdef WINDOWS
524+ WSACleanup();
525+#endif
526+ return 1;
521527 }
522528
523529 continue;
@@ -527,12 +533,10 @@ errr report_score(player_type *creature_ptr)
527533 break;
528534 }
529535
530-report_end:
531536 #ifdef WINDOWS
532537 WSACleanup();
533538 #endif
534539
535- return err;
540+ return 0;
536541 }
537-
538542 #endif /* WORLD_SCORE */
--- a/src/util.c
+++ b/src/util.c
@@ -1979,8 +1979,11 @@ void message_add(concptr str)
19791979 if (message__last == MESSAGE_MAX) message__last = 0;
19801980
19811981 message__ptr[x] = message__ptr[i];
1982-
1983- goto end_of_message_add;
1982+ if (splitted2 != NULL)
1983+ {
1984+ message_add(splitted2);
1985+ return;
1986+ }
19841987 }
19851988
19861989 if (message__head + n + 1 >= MESSAGE_BUF)
@@ -2032,9 +2035,10 @@ void message_add(concptr str)
20322035 message__buf[message__head + i] = '\0';
20332036 message__head += n + 1;
20342037
2035-end_of_message_add:
20362038 if (splitted2 != NULL)
2039+ {
20372040 message_add(splitted2);
2041+ }
20382042 }
20392043
20402044
Show on old repository browser