OSDN Git Service

upgrade to 3.6.1
[jnethack/source.git] / win / win32 / mhsplash.c
index 19e4b3b..d1bceaa 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 mhsplash.c      $NHDT-Date: 1432512813 2015/05/25 00:13:33 $  $NHDT-Branch: master $:$NHDT-Revision: 1.25 $ */
+/* NetHack 3.6 mhsplash.c      $NHDT-Date: 1449751714 2015/12/10 12:48:34 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.27 $ */
 /* Copyright (C) 2001 by Alex Kompel    */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -36,13 +36,9 @@ mswin_display_splash_window(BOOL show_ver)
     RECT controlrt;
     HWND hWnd;
     int buttop;
-    int strsize = 0;
-    int bufsize = BUFSZ;
-    char *buf = malloc(bufsize);
+    strbuf_t strbuf;
 
-    if (buf == NULL)
-        panic("out of memory");
-    buf[0] = '\0';
+    strbuf_init(&strbuf);
 
     hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH),
                         GetNHApp()->hMainWnd, NHSplashWndProc);
@@ -87,60 +83,27 @@ mswin_display_splash_window(BOOL show_ver)
                clientrt.right - 2 * SPLASH_OFFSET_X, controlrt.bottom, TRUE);
 
     /* Fill the text control */
-    Sprintf(buf, "%s\r\n%s\r\n%s\r\n%s\r\n\r\n", COPYRIGHT_BANNER_A,
+    strbuf_reserve(&strbuf, BUFSIZ);
+    Sprintf(strbuf.str, "%s\n%s\n%s\n%s\n\n", COPYRIGHT_BANNER_A,
             COPYRIGHT_BANNER_B, COPYRIGHT_BANNER_C, COPYRIGHT_BANNER_D);
-    strsize = strlen(buf);
 
     if (show_ver) {
         /* Show complete version information */
         dlb *f;
-
-#if 0 /*W360-1*/
-        getversionstring(buf + strsize);
-        strcat(buf, "\r\n\r\n");
-#else
         char verbuf[BUFSZ];
         int verstrsize = 0;
-
         getversionstring(verbuf);
-        verstrsize = strlen(verbuf);
-        if (verstrsize + strlen("\r\n\r\n") + 1  <  BUFSZ - 1)
-            strcat(verbuf, "\r\n\r\n");
-        verstrsize = strlen(verbuf);
-
-        if (strsize + verstrsize + 1 > bufsize) {
-            bufsize += BUFSZ;
-            buf = realloc(buf, bufsize);
-            if (buf == NULL)
-                panic("out of memory");
-        }
-        strcat(buf, verbuf);
-#endif
-        strsize = strlen(buf);
-
+        strbuf_append(&strbuf, verbuf);
+        strbuf_append(&strbuf, "\n\n");
+            
         /* Add compile options */
         f = dlb_fopen(OPTIONS_USED, RDTMODE);
         if (f) {
             char line[LLEN + 1];
 
-            while (dlb_fgets(line, LLEN, f)) {
-                size_t len;
-                len = strlen(line);
-                if (len > 0 && line[len - 1] == '\n') {
-                    line[len - 1] = '\r';
-                    line[len] = '\n';
-                    line[len + 1] = '\0';
-                    len++;
-                }
-                if (strsize + (int) len + 1 > bufsize) {
-                    bufsize += BUFSZ;
-                    buf = realloc(buf, bufsize);
-                    if (buf == NULL)
-                        panic("out of memory");
-                }
-                strcat(buf, line);
-                strsize += len;
-            }
+            while (dlb_fgets(line, LLEN, f))
+                strbuf_append(&strbuf, line);
             (void) dlb_fclose(f);
         }
     } else {
@@ -153,32 +116,18 @@ mswin_display_splash_window(BOOL show_ver)
             if (nf != NULL) {
                 char line[LLEN + 1];
 
-                while (fgets(line, LLEN, nf)) {
-                    size_t len;
-                    len = strlen(line);
-                    if (len > 0 && line[len - 1] == '\n') {
-                        line[len - 1] = '\r';
-                        line[len] = '\n';
-                        line[len + 1] = '\0';
-                        len++;
-                    }
-                    if (strsize + (int) len + 1 > bufsize) {
-                        bufsize += BUFSZ;
-                        buf = realloc(buf, bufsize);
-                        if (buf == NULL)
-                            panic("out of memory");
-                    }
-                    strcat(buf, line);
-                    strsize += len;
-                }
+                while (fgets(line, LLEN, nf))
+                    strbuf_append(&strbuf, line);
                 (void) fclose(nf);
             } else {
-                strcat(buf, "No news.");
+                strbuf_append(&strbuf, "No news.");
             }
         }
     }
-    SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), buf);
-    free(buf);
+
+    strbuf_nl_to_crlf(&strbuf);
+    SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), strbuf.str);
+    strbuf_empty(&strbuf);
     ShowWindow(hWnd, SW_SHOW);
 
     while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) {