変愚蛮怒のメインリポジトリです
Revisión | ad322d83c7f53abd684a261086e81c175fdf5726 (tree) |
---|---|
Tiempo | 2020-03-01 17:57:38 |
Autor | Hourier <hourier@user...> |
Commiter | Hourier |
[Refactor] #39962 Separated tokenizer.c/h from files.c
@@ -191,6 +191,7 @@ | ||
191 | 191 | <ClCompile Include="..\..\src\horror-descriptions.c" /> |
192 | 192 | <ClCompile Include="..\..\src\init.c" /> |
193 | 193 | <ClCompile Include="..\..\src\io\gf-descriptions.c" /> |
194 | + <ClCompile Include="..\..\src\io\tokenizer.c" /> | |
194 | 195 | <ClCompile Include="..\..\src\monster-dist-offsets.c" /> |
195 | 196 | <ClCompile Include="..\..\src\monster-process.c" /> |
196 | 197 | <ClCompile Include="..\..\src\monster-status.c" /> |
@@ -332,6 +333,7 @@ | ||
332 | 333 | <ClInclude Include="..\..\src\english.h" /> |
333 | 334 | <ClInclude Include="..\..\src\horror-descriptions.h" /> |
334 | 335 | <ClInclude Include="..\..\src\io\gf-descriptions.h" /> |
336 | + <ClInclude Include="..\..\src\io\tokenizer.h" /> | |
335 | 337 | <ClInclude Include="..\..\src\monster-dist-offsets.h" /> |
336 | 338 | <ClInclude Include="..\..\src\object-flavor.h" /> |
337 | 339 | <ClInclude Include="..\..\src\player-inventory.h" /> |
@@ -451,6 +451,9 @@ | ||
451 | 451 | <ClCompile Include="..\..\src\view\display-player-middle.c"> |
452 | 452 | <Filter>view</Filter> |
453 | 453 | </ClCompile> |
454 | + <ClCompile Include="..\..\src\io\tokenizer.c"> | |
455 | + <Filter>io</Filter> | |
456 | + </ClCompile> | |
454 | 457 | </ItemGroup> |
455 | 458 | <ItemGroup> |
456 | 459 | <ClInclude Include="..\..\src\gamevalue.h" /> |
@@ -884,6 +887,9 @@ | ||
884 | 887 | <ClInclude Include="..\..\src\view\display-player-middle.h"> |
885 | 888 | <Filter>view</Filter> |
886 | 889 | </ClInclude> |
890 | + <ClInclude Include="..\..\src\io\tokenizer.h"> | |
891 | + <Filter>io</Filter> | |
892 | + </ClInclude> | |
887 | 893 | </ItemGroup> |
888 | 894 | <ItemGroup> |
889 | 895 | <None Include="..\..\src\wall.bmp" /> |
@@ -27,6 +27,7 @@ hengband_SOURCES = \ | ||
27 | 27 | player/temporary-resistances.c player/temporary-resistances.h \ |
28 | 28 | \ |
29 | 29 | io/gf-descriptions.c io/gf-descriptions.h \ |
30 | + io/tokenizer.c io/tokenizer.h \ | |
30 | 31 | signal-handlers.c signal-handlers.h uid-checker.c uid-checker.h \ |
31 | 32 | character-dump.c character-dump.h core.c core.h files.c files.h \ |
32 | 33 | \ |
@@ -35,6 +35,7 @@ | ||
35 | 35 | #include "util.h" |
36 | 36 | #include "core.h" |
37 | 37 | |
38 | +#include "io/tokenizer.h" | |
38 | 39 | #include "files.h" |
39 | 40 | #include "dungeon-file.h" |
40 | 41 | #include "rooms-vault.h" |
@@ -32,6 +32,7 @@ | ||
32 | 32 | #include "autopick.h" |
33 | 33 | #include "save.h" |
34 | 34 | #include "io/gf-descriptions.h" |
35 | +#include "io/tokenizer.h" | |
35 | 36 | |
36 | 37 | #define PREF_TYPE_NORMAL 0 |
37 | 38 | #define PREF_TYPE_AUTOPICK 1 |
@@ -59,60 +60,6 @@ char savefile[1024]; | ||
59 | 60 | char savefile_base[40]; |
60 | 61 | |
61 | 62 | /*! |
62 | - * @brief 各種データテキストをトークン単位に分解する / Extract the first few "tokens" from a buffer | |
63 | - * @param buf データテキストの参照ポインタ | |
64 | - * @param num トークンの数 | |
65 | - * @param tokens トークンを保管する文字列参照ポインタ配列 | |
66 | - * @param mode オプション | |
67 | - * @return 解釈した文字列数 | |
68 | - * @details | |
69 | - * <pre> | |
70 | - * This function uses "colon" and "slash" as the delimeter characters. | |
71 | - * We never extract more than "num" tokens. The "last" token may include | |
72 | - * "delimeter" characters, allowing the buffer to include a "string" token. | |
73 | - * We save pointers to the tokens in "tokens", and return the number found. | |
74 | - * Hack -- Attempt to handle the 'c' character formalism | |
75 | - * Hack -- An empty buffer, or a final delimeter, yields an "empty" token. | |
76 | - * Hack -- We will always extract at least one token | |
77 | - * </pre> | |
78 | - */ | |
79 | -s16b tokenize(char *buf, s16b num, char **tokens, BIT_FLAGS mode) | |
80 | -{ | |
81 | - s16b i = 0; | |
82 | - char *s = buf; | |
83 | - while (i < num - 1) | |
84 | - { | |
85 | - char *t; | |
86 | - for (t = s; *t; t++) | |
87 | - { | |
88 | - if ((*t == ':') || (*t == '/')) break; | |
89 | - | |
90 | - if ((mode & TOKENIZE_CHECKQUOTE) && (*t == '\'')) | |
91 | - { | |
92 | - t++; | |
93 | - if (*t == '\\') t++; | |
94 | - if (!*t) break; | |
95 | - | |
96 | - t++; | |
97 | - if (*t != '\'') *t = '\''; | |
98 | - } | |
99 | - | |
100 | - if (*t == '\\') t++; | |
101 | - } | |
102 | - | |
103 | - if (!*t) break; | |
104 | - | |
105 | - *t++ = '\0'; | |
106 | - tokens[i++] = s; | |
107 | - s = t; | |
108 | - } | |
109 | - | |
110 | - tokens[i++] = s; | |
111 | - return i; | |
112 | -} | |
113 | - | |
114 | - | |
115 | -/*! | |
116 | 63 | * @brief 設定ファイルの各行から各種テキスト情報を取得する / |
117 | 64 | * Parse a sub-file of the "extra info" (format shown below) |
118 | 65 | * @param creature_ptr プレーヤーへの参照ポインタ |
@@ -1,7 +1,5 @@ | ||
1 | 1 | #pragma once |
2 | 2 | |
3 | -#define TOKENIZE_CHECKQUOTE 0x01 /* Special handling of single quotes */ | |
4 | - | |
5 | 3 | extern char savefile[1024]; |
6 | 4 | extern char savefile_base[40]; |
7 | 5 |
@@ -0,0 +1,54 @@ | ||
1 | +#include "io/tokenizer.h" | |
2 | + | |
3 | +/*! | |
4 | + * @brief 各種データテキストをトークン単位に分解する / Extract the first few "tokens" from a buffer | |
5 | + * @param buf データテキストの参照ポインタ | |
6 | + * @param num トークンの数 | |
7 | + * @param tokens トークンを保管する文字列参照ポインタ配列 | |
8 | + * @param mode オプション | |
9 | + * @return 解釈した文字列数 | |
10 | + * @details | |
11 | + * <pre> | |
12 | + * This function uses "colon" and "slash" as the delimeter characters. | |
13 | + * We never extract more than "num" tokens. The "last" token may include | |
14 | + * "delimeter" characters, allowing the buffer to include a "string" token. | |
15 | + * We save pointers to the tokens in "tokens", and return the number found. | |
16 | + * Hack -- Attempt to handle the 'c' character formalism | |
17 | + * Hack -- An empty buffer, or a final delimeter, yields an "empty" token. | |
18 | + * Hack -- We will always extract at least one token | |
19 | + * </pre> | |
20 | + */ | |
21 | +s16b tokenize(char *buf, s16b num, char **tokens, BIT_FLAGS mode) | |
22 | +{ | |
23 | + s16b i = 0; | |
24 | + char *s = buf; | |
25 | + while (i < num - 1) | |
26 | + { | |
27 | + char *t; | |
28 | + for (t = s; *t; t++) | |
29 | + { | |
30 | + if ((*t == ':') || (*t == '/')) break; | |
31 | + | |
32 | + if ((mode & TOKENIZE_CHECKQUOTE) && (*t == '\'')) | |
33 | + { | |
34 | + t++; | |
35 | + if (*t == '\\') t++; | |
36 | + if (!*t) break; | |
37 | + | |
38 | + t++; | |
39 | + if (*t != '\'') *t = '\''; | |
40 | + } | |
41 | + | |
42 | + if (*t == '\\') t++; | |
43 | + } | |
44 | + | |
45 | + if (!*t) break; | |
46 | + | |
47 | + *t++ = '\0'; | |
48 | + tokens[i++] = s; | |
49 | + s = t; | |
50 | + } | |
51 | + | |
52 | + tokens[i++] = s; | |
53 | + return i; | |
54 | +} |
@@ -0,0 +1,7 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | +#include "angband.h" | |
4 | + | |
5 | +#define TOKENIZE_CHECKQUOTE 0x01 /* Special handling of single quotes */ | |
6 | + | |
7 | +s16b tokenize(char *buf, s16b num, char **tokens, BIT_FLAGS mode); |
@@ -1,6 +1,7 @@ | ||
1 | 1 | #include "angband.h" |
2 | 2 | #include "util.h" |
3 | 3 | |
4 | +#include "io/tokenizer.h" | |
4 | 5 | #include "files.h" |
5 | 6 | #include "object-flavor.h" |
6 | 7 | #include "artifact.h" |
@@ -26,6 +26,7 @@ | ||
26 | 26 | #include "monster-status.h" |
27 | 27 | #include "quest.h" |
28 | 28 | #include "dungeon-file.h" |
29 | +#include "io/tokenizer.h" | |
29 | 30 | #include "files.h" |
30 | 31 | #include "feature.h" |
31 | 32 | #include "floor-town.h" |