OSDN Git Service

[Refactor] #37353 report.cの整形 / Reshaped report.c
authorHourier <hourier@users.sourceforge.jp>
Sun, 5 Jan 2020 05:55:50 +0000 (14:55 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sun, 5 Jan 2020 05:55:50 +0000 (14:55 +0900)
src/report.c

index 7f82d90..10fbb07 100644 (file)
@@ -86,20 +86,22 @@ typedef struct {
 static BUF* buf_new(void)
 {
        BUF *p;
-
-       if ((p = malloc(sizeof(BUF))) == NULL)
-               return NULL;
+       p = malloc(sizeof(BUF));
+       if (!p) return NULL;
 
        p->size = 0;
        p->max_size = BUFSIZE;
-       if ((p->data = malloc(BUFSIZE)) == NULL)
+       p->data = malloc(BUFSIZE);
+       if (!p->data)
        {
                free(p);
                return NULL;
        }
+
        return p;
 }
 
+
 /*!
  * @brief 転送用バッファの解放
  * @param b 解放するバッファの参照ポインタ
@@ -110,6 +112,7 @@ static void buf_delete(BUF *b)
        free(b);
 }
 
+
 /*!
  * @brief 転送用バッファにデータを追加する
  * @param buf 追加先バッファの参照ポインタ
@@ -137,6 +140,7 @@ static int buf_append(BUF *buf, concptr data, size_t size)
        return buf->size;
 }
 
+
 /*!
  * @brief 転送用バッファにフォーマット指定した文字列データを追加する
  * @param buf 追加先バッファの参照ポインタ
@@ -238,6 +242,7 @@ static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
 }
 #endif
 
+
 /*!
  * @brief HTTPによるダンプ内容伝送
  * @param sd ソケットID
@@ -278,6 +283,7 @@ static bool http_post(int sd, concptr url, BUF *buf)
        return strncmp(response_buf, HTTP_RESPONSE_CODE_OK, strlen(HTTP_RESPONSE_CODE_OK)) == 0;
 }
 
+
 /*!
  * @brief キャラクタダンプを作って BUFに保存
  * @param creature_ptr プレーヤーへの参照ポインタ
@@ -321,19 +327,13 @@ static errr make_dump(player_type *creature_ptr, BUF* dumpbuf)
        return (0);
 }
 
+
 /*!
  * @brief スクリーンダンプを作成する/ Make screen dump to buffer
  * @return 作成したスクリーンダンプの参照ポインタ
  */
 concptr make_screen_dump(player_type *creature_ptr)
 {
-       BUF *screen_buf;
-       int y, x, i;
-       concptr ret;
-
-       TERM_COLOR a = 0, old_a = 0;
-       SYMBOL_CODE c = ' ';
-
        static concptr html_head[] = {
                "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
                "<pre>",
@@ -345,16 +345,15 @@ concptr make_screen_dump(player_type *creature_ptr)
                0,
        };
 
-       bool old_use_graphics = use_graphics;
-
        int wid, hgt;
-
        Term_get_size(&wid, &hgt);
 
        /* Alloc buffer */
+       BUF *screen_buf;
        screen_buf = buf_new();
        if (screen_buf == NULL) return (NULL);
 
+       bool old_use_graphics = use_graphics;
        if (old_use_graphics)
        {
                /* Clear -more- prompt first */
@@ -367,18 +366,20 @@ concptr make_screen_dump(player_type *creature_ptr)
                handle_stuff();
        }
 
-       for (i = 0; html_head[i]; i++)
+       for (int i = 0; html_head[i]; i++)
                buf_sprintf(screen_buf, html_head[i]);
 
        /* Dump the screen */
-       for (y = 0; y < hgt; y++)
+       for (int y = 0; y < hgt; y++)
        {
                /* Start the row */
                if (y != 0)
                        buf_sprintf(screen_buf, "\n");
 
                /* Dump each row */
-               for (x = 0; x < wid - 1; x++)
+               TERM_COLOR a = 0, old_a = 0;
+               SYMBOL_CODE c = ' ';
+               for (int x = 0; x < wid - 1; x++)
                {
                        int rv, gv, bv;
                        concptr cc = NULL;
@@ -407,18 +408,21 @@ concptr make_screen_dump(player_type *creature_ptr)
                                            ((y == 0 && x == 0) ? "" : "</font>"), rv, gv, bv);
                                old_a = a;
                        }
+
                        if (cc)
                                buf_sprintf(screen_buf, "%s", cc);
                        else
                                buf_sprintf(screen_buf, "%c", c);
                }
        }
+
        buf_sprintf(screen_buf, "</font>");
 
-       for (i = 0; html_foot[i]; i++)
+       for (int i = 0; html_foot[i]; i++)
                buf_sprintf(screen_buf, html_foot[i]);
 
        /* Screen dump size is too big ? */
+       concptr ret;
        if (screen_buf->size + 1> SCREEN_BUF_MAX_SIZE)
        {
                ret = NULL;
@@ -446,7 +450,9 @@ concptr make_screen_dump(player_type *creature_ptr)
        return ret;
 }
 
+
 /*!
+ * todo メッセージは言語選択の関数マクロで何とかならんか?
  * @brief スコア転送処理のメインルーチン
  * @param creature_ptr プレーヤーへの参照ポインタ
  * @return エラーコード
@@ -465,11 +471,9 @@ errr report_score(player_type *creature_ptr)
 #endif
 
        BUF *score;
-       int sd;
-       char seikakutmp[128];
-
        score = buf_new();
 
+       char seikakutmp[128];
 #ifdef JP
        sprintf(seikakutmp, "%s%s", ap_ptr->title, (ap_ptr->no ? "の" : ""));
 #else
@@ -531,7 +535,8 @@ errr report_score(player_type *creature_ptr)
 
        Term_clear();
 
-       while (1)
+       int sd;
+       while (TRUE)
        {
                char buff[160];
 #ifdef JP