author | tron |
Tue, 25 Oct 2005 18:29:32 +0000 | |
changeset 2554 | cd74b7099965 |
parent 2482 | dffcca243dbc |
child 2566 | da24c0f2d2d8 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
1721
64d59b181596
(svn r2225) -Fix: split the endian-detection to target/host. Now cross-compiling
truelight
parents:
1376
diff
changeset
|
3 |
#define STRGEN |
64d59b181596
(svn r2225) -Fix: split the endian-detection to target/host. Now cross-compiling
truelight
parents:
1376
diff
changeset
|
4 |
|
0 | 5 |
#include "../stdafx.h" |
6 |
#include <stdio.h> |
|
7 |
#include <string.h> |
|
8 |
#include <stdlib.h> |
|
9 |
#include <stdarg.h> |
|
10 |
||
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2459
diff
changeset
|
11 |
#if (!defined(WIN32) && !defined(WIN64)) || defined(__CYGWIN__) |
0 | 12 |
#include <unistd.h> |
13 |
#endif |
|
14 |
||
181
0b95567f2d0f
(svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents:
0
diff
changeset
|
15 |
#ifdef __MORPHOS__ |
0b95567f2d0f
(svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents:
0
diff
changeset
|
16 |
#ifdef stderr |
0b95567f2d0f
(svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents:
0
diff
changeset
|
17 |
#undef stderr |
0b95567f2d0f
(svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents:
0
diff
changeset
|
18 |
#endif |
0b95567f2d0f
(svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents:
0
diff
changeset
|
19 |
#define stderr stdout |
0b95567f2d0f
(svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents:
0
diff
changeset
|
20 |
#endif // __MORPHOS__ |
0b95567f2d0f
(svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents:
0
diff
changeset
|
21 |
|
0 | 22 |
/* Compiles a list of strings into a compiled string list */ |
23 |
||
24 |
typedef void (*ParseCmdProc)(char *buf, int value); |
|
25 |
||
26 |
typedef struct { |
|
27 |
uint32 ident; |
|
28 |
uint32 version; // 32-bits of auto generated version info which is basically a hash of strings.h |
|
29 |
char name[32]; // the international name of this language |
|
30 |
char own_name[32]; // the localized name of this language |
|
1376
425781645fba
(svn r1880) [Codechange] Added isocodes to langfiles and support code to strgen (Lauri Nurmi)
miham
parents:
1097
diff
changeset
|
31 |
char isocode[16]; // the ISO code for the language (not country code) |
0 | 32 |
uint16 offsets[32]; // the offsets |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
33 |
byte plural_form; // plural form index |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
34 |
byte pad[3]; // pad header to be a multiple of 4 |
0 | 35 |
} LanguagePackHeader; |
36 |
||
37 |
typedef struct CmdStruct { |
|
38 |
const char *cmd; |
|
39 |
ParseCmdProc proc; |
|
40 |
long value; |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
41 |
int8 consumes; |
2087 | 42 |
byte flags; |
0 | 43 |
} CmdStruct; |
44 |
||
2087 | 45 |
enum { |
46 |
C_DONTCOUNT = 1, |
|
47 |
C_CASE = 2, |
|
48 |
}; |
|
49 |
||
50 |
||
51 |
typedef struct Case { |
|
52 |
int caseidx; |
|
53 |
char *string; |
|
54 |
struct Case *next; |
|
55 |
} Case; |
|
56 |
||
2459
4b65354b7586
(svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents:
2418
diff
changeset
|
57 |
static const char* _file = "(unknown file)"; |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
58 |
static int _cur_line; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
59 |
static int _errors, _warnings; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
60 |
|
2087 | 61 |
typedef struct LangString { |
62 |
char *name; // Name of the string |
|
63 |
char *english; // English text |
|
64 |
char *translated; // Translated text |
|
65 |
uint16 hash_next; // next hash entry |
|
66 |
uint16 index; |
|
67 |
Case *english_case; // cases for english |
|
68 |
Case *translated_case; // cases for foreign |
|
69 |
} LangString; |
|
70 |
||
71 |
static LangString *_strings[65536]; |
|
72 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
73 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
74 |
#define HASH_SIZE 32767 |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
75 |
static uint16 _hash_head[HASH_SIZE]; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
76 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
77 |
static byte _put_buf[4096]; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
78 |
static int _put_pos; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
79 |
static int _next_string_id; |
0 | 80 |
|
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
81 |
static uint32 _hash; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
82 |
static char _lang_name[32], _lang_ownname[32], _lang_isocode[16]; |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
83 |
static byte _lang_pluralform; |
2087 | 84 |
#define MAX_NUM_GENDER 8 |
85 |
static char _genders[MAX_NUM_GENDER][8]; |
|
86 |
static int _numgenders; |
|
0 | 87 |
|
2087 | 88 |
// contains the name of all cases. |
89 |
#define MAX_NUM_CASES 50 |
|
90 |
static char _cases[MAX_NUM_CASES][16]; |
|
91 |
static int _numcases; |
|
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
92 |
|
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
93 |
// for each plural value, this is the number of plural forms. |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
94 |
static const byte _plural_form_counts[] = { 2,1,2,3,3,3,3,3,4 }; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
95 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
96 |
static const char *_cur_ident; |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
97 |
|
2087 | 98 |
typedef struct CmdPair { |
99 |
const CmdStruct *a; |
|
100 |
char *v; |
|
101 |
} CmdPair; |
|
102 |
||
103 |
typedef struct ParsedCommandStruct { |
|
104 |
int np; |
|
105 |
CmdPair pairs[32]; |
|
106 |
const CmdStruct *cmd[32]; // ordered by param # |
|
107 |
} ParsedCommandStruct; |
|
108 |
||
109 |
// Used when generating some advanced commands. |
|
110 |
static ParsedCommandStruct _cur_pcs; |
|
111 |
static int _cur_argidx; |
|
112 |
||
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
113 |
static uint HashStr(const char *s) |
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
114 |
{ |
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
115 |
uint hash = 0; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
116 |
for(; *s; s++) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
117 |
hash = ((hash << 3) | (hash >> 29)) ^ *s; |
0 | 118 |
return hash % HASH_SIZE; |
119 |
} |
|
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
120 |
|
2087 | 121 |
static void HashAdd(const char *s, LangString *ls) |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
122 |
{ |
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
123 |
uint hash = HashStr(s); |
2087 | 124 |
ls->hash_next = _hash_head[hash]; |
125 |
_hash_head[hash] = ls->index + 1; |
|
0 | 126 |
} |
127 |
||
2087 | 128 |
static LangString *HashFind(const char *s) |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
129 |
{ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
130 |
int idx = _hash_head[HashStr(s)]; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
131 |
while (--idx >= 0) { |
2087 | 132 |
LangString *ls = _strings[idx]; |
133 |
if (!strcmp(ls->name, s)) return ls; |
|
134 |
idx = ls->hash_next; |
|
0 | 135 |
} |
2087 | 136 |
return NULL; |
0 | 137 |
} |
138 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
139 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
140 |
static void CDECL Warning(const char *s, ...) |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
141 |
{ |
0 | 142 |
char buf[1024]; |
143 |
va_list va; |
|
144 |
va_start(va, s); |
|
145 |
vsprintf(buf, s, va); |
|
146 |
va_end(va); |
|
2459
4b65354b7586
(svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents:
2418
diff
changeset
|
147 |
fprintf(stderr, "%s:%d: Warning: %s\n", _file, _cur_line, buf); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
148 |
_warnings++; |
0 | 149 |
} |
150 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
151 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
152 |
static void CDECL Error(const char *s, ...) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
153 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
154 |
char buf[1024]; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
155 |
va_list va; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
156 |
va_start(va, s); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
157 |
vsprintf(buf, s, va); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
158 |
va_end(va); |
2459
4b65354b7586
(svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents:
2418
diff
changeset
|
159 |
fprintf(stderr, "%s:%d: Error: %s\n", _file, _cur_line, buf); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
160 |
_errors++; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
161 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
162 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
163 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
164 |
static void NORETURN CDECL Fatal(const char *s, ...) |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
165 |
{ |
0 | 166 |
char buf[1024]; |
167 |
va_list va; |
|
168 |
va_start(va, s); |
|
169 |
vsprintf(buf, s, va); |
|
170 |
va_end(va); |
|
2459
4b65354b7586
(svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents:
2418
diff
changeset
|
171 |
fprintf(stderr, "%s:%d: FATAL: %s\n", _file, _cur_line, buf); |
0 | 172 |
exit(1); |
173 |
} |
|
174 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
175 |
|
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
176 |
static void ttd_strlcpy(char *dst, const char *src, size_t len) |
0 | 177 |
{ |
178 |
assert(len > 0); |
|
179 |
while (--len && *src) |
|
180 |
*dst++=*src++; |
|
181 |
*dst = 0; |
|
182 |
} |
|
183 |
||
184 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
185 |
static void PutByte(byte c) |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
186 |
{ |
0 | 187 |
if (_put_pos == lengthof(_put_buf)) |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
188 |
Fatal("Put buffer too small"); |
0 | 189 |
_put_buf[_put_pos++] = c; |
190 |
} |
|
191 |
||
192 |
||
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
193 |
static void EmitSingleByte(char *buf, int value) |
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
194 |
{ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
195 |
if (*buf != '\0') |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
196 |
Warning("Ignoring trailing letters in command"); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
197 |
PutByte((byte)value); |
0 | 198 |
} |
199 |
||
200 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
201 |
static void EmitEscapedByte(char *buf, int value) |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
202 |
{ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
203 |
if (*buf != '\0') |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
204 |
Warning("Ignoring trailing letters in command"); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
205 |
PutByte((byte)0x85); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
206 |
PutByte((byte)value); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
207 |
} |
0 | 208 |
|
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
209 |
static void EmitSetX(char *buf, int value) |
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
210 |
{ |
0 | 211 |
char *err; |
212 |
int x = strtol(buf, &err, 0); |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
213 |
if (*err != 0) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
214 |
Fatal("SetX param invalid"); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
215 |
PutByte(1); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
216 |
PutByte((byte)x); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
217 |
} |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
218 |
|
0 | 219 |
|
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
220 |
static void EmitSetXY(char *buf, int value) |
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
221 |
{ |
0 | 222 |
char *err; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
223 |
int x,y; |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
224 |
|
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
225 |
x = strtol(buf, &err, 0); |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
226 |
if (*err != ' ') Fatal("SetXY param invalid"); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
227 |
y = strtol(err+1, &err, 0); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
228 |
if (*err != 0) Fatal("SetXY param invalid"); |
0 | 229 |
|
2087 | 230 |
PutByte(2); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
231 |
PutByte((byte)x); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
232 |
PutByte((byte)y); |
0 | 233 |
} |
234 |
||
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
235 |
// The plural specifier looks like |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
236 |
// {NUM} {PLURAL -1 passenger passengers} then it picks either passenger/passengers depending on the count in NUM |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
237 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
238 |
// This is encoded like |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
239 |
// CommandByte <ARG#> <NUM> {Length of each string} {each string} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
240 |
|
2087 | 241 |
bool ParseRelNum(char **buf, int *value) |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
242 |
{ |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
243 |
char *s = *buf, *end; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
244 |
bool rel = false; |
2087 | 245 |
int v; |
246 |
||
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
247 |
while (*s == ' ' || *s == '\t') s++; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
248 |
if (*s == '+') { rel = true; s++; } |
2087 | 249 |
v = strtol(s, &end, 0); |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
250 |
if (end == s) return false; |
2087 | 251 |
if (rel || (v < 0)) |
252 |
*value += v; |
|
253 |
else |
|
254 |
*value = v; |
|
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
255 |
*buf = end; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
256 |
return true; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
257 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
258 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
259 |
// Parse out the next word, or NULL |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
260 |
char *ParseWord(char **buf) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
261 |
{ |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
262 |
char *s = *buf, *r; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
263 |
while (*s == ' ' || *s == '\t') s++; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
264 |
if (*s == 0) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
265 |
return NULL; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
266 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
267 |
if (*s == '"') { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
268 |
r = ++s; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
269 |
// parse until next " or NUL |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
270 |
for(;;) { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
271 |
if (*s == 0) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
272 |
break; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
273 |
if (*s == '"') { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
274 |
*s++ = 0; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
275 |
break; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
276 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
277 |
s++; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
278 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
279 |
} else { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
280 |
// proceed until whitespace or NUL |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
281 |
r = s; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
282 |
for(;;) { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
283 |
if (*s == 0) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
284 |
break; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
285 |
if (*s == ' ' || *s == '\t') { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
286 |
*s++ = 0; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
287 |
break; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
288 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
289 |
s++; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
290 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
291 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
292 |
*buf = s; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
293 |
return r; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
294 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
295 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
296 |
// Forward declaration |
2087 | 297 |
static int TranslateArgumentIdx(int arg); |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
298 |
|
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
299 |
static void EmitWordList(char **words, int nw) |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
300 |
{ |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
301 |
int i,j; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
302 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
303 |
PutByte(nw); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
304 |
for(i=0; i<nw; i++) |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
305 |
PutByte(strlen(words[i])); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
306 |
for(i=0; i<nw; i++) { |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
307 |
for(j=0; words[i][j]; j++) |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
308 |
PutByte(words[i][j]); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
309 |
} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
310 |
} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
311 |
|
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
312 |
static void EmitPlural(char *buf, int value) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
313 |
{ |
2087 | 314 |
int argidx = _cur_argidx; |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
315 |
char *words[5]; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
316 |
int nw = 0; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
317 |
|
2087 | 318 |
// Parse out the number, if one exists. Otherwise default to prev arg. |
319 |
if (!ParseRelNum(&buf, &argidx)) |
|
320 |
argidx--; |
|
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
321 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
322 |
// Parse each string |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
323 |
for(nw=0; nw<5; nw++) { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
324 |
words[nw] = ParseWord(&buf); |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
325 |
if (!words[nw]) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
326 |
break; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
327 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
328 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
329 |
if (nw == 0) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
330 |
Fatal("No plural words"); |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
331 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
332 |
if (_plural_form_counts[_lang_pluralform] != nw) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
333 |
Fatal("%s: Invalid number of plural forms. Expecting %d, found %d.", _cur_ident, |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
334 |
_plural_form_counts[_lang_pluralform], nw); |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
335 |
|
2410
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2407
diff
changeset
|
336 |
PutByte(0x8D); |
2087 | 337 |
PutByte(TranslateArgumentIdx(argidx)); |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
338 |
EmitWordList(words, nw); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
339 |
} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
340 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
341 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
342 |
static void EmitGender(char *buf, int value) |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
343 |
{ |
2087 | 344 |
int argidx = _cur_argidx; |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
345 |
char *words[8]; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
346 |
int nw; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
347 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
348 |
if (buf[0] == '=') { |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
349 |
buf++; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
350 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
351 |
// This is a {G=DER} command |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
352 |
for(nw=0; ;nw++) { |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
353 |
if (nw >= 8) |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
354 |
Fatal("G argument '%s' invalid", buf); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
355 |
if (!strcmp(buf, _genders[nw])) |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
356 |
break; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
357 |
} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
358 |
// now nw contains the gender index |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
359 |
PutByte(0x87); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
360 |
PutByte(nw); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
361 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
362 |
} else { |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
363 |
// This is a {G 0 foo bar two} command. |
2087 | 364 |
// If no relative number exists, default to +0 |
365 |
if (!ParseRelNum(&buf, &argidx)) {} |
|
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
366 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
367 |
for(nw=0; nw<8; nw++) { |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
368 |
words[nw] = ParseWord(&buf); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
369 |
if (!words[nw]) |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
370 |
break; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
371 |
} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
372 |
if (nw != _numgenders) Fatal("Bad # of arguments for gender command"); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
373 |
PutByte(0x85); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
374 |
PutByte(13); |
2087 | 375 |
PutByte(TranslateArgumentIdx(argidx)); |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
376 |
EmitWordList(words, nw); |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
377 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
378 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
379 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
380 |
|
0 | 381 |
static const CmdStruct _cmd_structs[] = { |
382 |
// Update position |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
383 |
{"SETX", EmitSetX, 1, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
384 |
{"SETXY", EmitSetXY, 2, 0}, |
0 | 385 |
|
386 |
// Font size |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
387 |
{"TINYFONT", EmitSingleByte, 8, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
388 |
{"BIGFONT", EmitSingleByte, 9, 0}, |
0 | 389 |
|
390 |
// New line |
|
2087 | 391 |
{"", EmitSingleByte, 10, 0, C_DONTCOUNT}, |
0 | 392 |
|
2411 | 393 |
{"{", EmitSingleByte, '{', 0, C_DONTCOUNT}, |
394 |
||
0 | 395 |
// Colors |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
396 |
{"BLUE", EmitSingleByte, 15, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
397 |
{"SILVER", EmitSingleByte, 16, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
398 |
{"GOLD", EmitSingleByte, 17, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
399 |
{"RED", EmitSingleByte, 18, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
400 |
{"PURPLE", EmitSingleByte, 19, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
401 |
{"LTBROWN", EmitSingleByte, 20, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
402 |
{"ORANGE", EmitSingleByte, 21, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
403 |
{"GREEN", EmitSingleByte, 22, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
404 |
{"YELLOW", EmitSingleByte, 23, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
405 |
{"DKGREEN", EmitSingleByte, 24, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
406 |
{"CREAM", EmitSingleByte, 25, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
407 |
{"BROWN", EmitSingleByte, 26, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
408 |
{"WHITE", EmitSingleByte, 27, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
409 |
{"LTBLUE", EmitSingleByte, 28, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
410 |
{"GRAY", EmitSingleByte, 29, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
411 |
{"DKBLUE", EmitSingleByte, 30, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
412 |
{"BLACK", EmitSingleByte, 31, 0}, |
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
181
diff
changeset
|
413 |
|
236
da0ae9d977e0
(svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents:
222
diff
changeset
|
414 |
// 0x85 |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
415 |
{"CURRCOMPACT", EmitEscapedByte, 0, 1}, // compact currency (32 bits) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
416 |
{"REV", EmitEscapedByte, 2, 0}, // openttd revision string |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
417 |
{"SHORTCARGO", EmitEscapedByte, 3, 2}, // short cargo description, only ### tons, or ### litres |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
418 |
{"CURRCOMPACT64", EmitEscapedByte, 4, 2}, // compact currency 64 bits |
0 | 419 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
420 |
{"COMPANY", EmitEscapedByte, 5, 1}, // company string. This is actually a {STRING1} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
421 |
// The first string includes the second string. |
0 | 422 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
423 |
{"PLAYERNAME", EmitEscapedByte, 5, 1}, // playername string. This is actually a {STRING1} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
424 |
// The first string includes the second string. |
0 | 425 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
426 |
{"VEHICLE", EmitEscapedByte, 5, 1}, // playername string. This is actually a {STRING1} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
427 |
// The first string includes the second string. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
428 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
429 |
|
2087 | 430 |
{"STRING1", EmitEscapedByte, 5, 1, C_CASE}, // included string that consumes ONE argument |
431 |
{"STRING2", EmitEscapedByte, 6, 2, C_CASE}, // included string that consumes TWO arguments |
|
432 |
{"STRING3", EmitEscapedByte, 7, 3, C_CASE}, // included string that consumes THREE arguments |
|
433 |
{"STRING4", EmitEscapedByte, 8, 4, C_CASE}, // included string that consumes FOUR arguments |
|
434 |
{"STRING5", EmitEscapedByte, 9, 5, C_CASE}, // included string that consumes FIVE arguments |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
435 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
436 |
{"STATIONFEATURES", EmitEscapedByte, 10, 1}, // station features string, icons of the features |
2069
929b43e70be9
(svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents:
2063
diff
changeset
|
437 |
{"INDUSTRY", EmitEscapedByte, 11, 1}, // industry, takes an industry # |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
438 |
{"VOLUME", EmitEscapedByte, 12, 1}, |
2087 | 439 |
{"DATE_TINY", EmitEscapedByte, 14, 1}, |
440 |
{"CARGO", EmitEscapedByte, 15, 2}, |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
441 |
|
2087 | 442 |
{"P", EmitPlural, 0, 0, C_DONTCOUNT}, // plural specifier |
443 |
{"G", EmitGender, 0, 0, C_DONTCOUNT}, // gender specifier |
|
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
444 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
445 |
{"DATE_LONG", EmitSingleByte, 0x82, 1}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
446 |
{"DATE_SHORT", EmitSingleByte, 0x83, 1}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
447 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
448 |
{"VELOCITY", EmitSingleByte, 0x84, 1}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
449 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
450 |
{"SKIP", EmitSingleByte, 0x86, 1}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
451 |
|
2087 | 452 |
{"STRING", EmitSingleByte, 0x88, 1, C_CASE}, |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
453 |
|
2410
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2407
diff
changeset
|
454 |
// Numbers |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2407
diff
changeset
|
455 |
{"COMMA", EmitSingleByte, 0x8B, 1}, // Number with comma |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2407
diff
changeset
|
456 |
{"NUM", EmitSingleByte, 0x8E, 1}, // Signed number |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2407
diff
changeset
|
457 |
|
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2407
diff
changeset
|
458 |
{"CURRENCY", EmitSingleByte, 0x8F, 1}, |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2407
diff
changeset
|
459 |
|
2087 | 460 |
{"WAYPOINT", EmitSingleByte, 0x99, 1}, // waypoint name |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
461 |
{"STATION", EmitSingleByte, 0x9A, 1}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
462 |
{"TOWN", EmitSingleByte, 0x9B, 1}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
463 |
{"CURRENCY64", EmitSingleByte, 0x9C, 2}, |
2087 | 464 |
// 0x9D is used for the pseudo command SETCASE |
465 |
// 0x9E is used for case switching |
|
466 |
||
0 | 467 |
// 0x9E=158 is the LAST special character we may use. |
468 |
||
2407 | 469 |
{"UPARROW", EmitSingleByte, 0x80, 0}, |
470 |
||
471 |
{"NBSP", EmitSingleByte, 0xA0, 0, C_DONTCOUNT}, |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
472 |
{"POUNDSIGN", EmitSingleByte, 0xA3, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
473 |
{"YENSIGN", EmitSingleByte, 0xA5, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
474 |
{"COPYRIGHT", EmitSingleByte, 0xA9, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
475 |
{"DOWNARROW", EmitSingleByte, 0xAA, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
476 |
{"CHECKMARK", EmitSingleByte, 0xAC, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
477 |
{"CROSS", EmitSingleByte, 0xAD, 0}, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
478 |
{"RIGHTARROW", EmitSingleByte, 0xAF, 0}, |
0 | 479 |
|
2353 | 480 |
{"TRAIN", EmitSingleByte, 0x94, 0}, |
481 |
{"LORRY", EmitSingleByte, 0x95, 0}, |
|
482 |
{"BUS", EmitSingleByte, 0x96, 0}, |
|
483 |
{"PLANE", EmitSingleByte, 0x97, 0}, |
|
484 |
{"SHIP", EmitSingleByte, 0x98, 0}, |
|
520
a78a6d47585d
(svn r847) Add the station type icons to strgen: {TRAIN}, {LORRY}, {BUS}, {PLANE} and {SHIP}
tron
parents:
451
diff
changeset
|
485 |
|
2353 | 486 |
{"SMALLUPARROW", EmitSingleByte, 0x90, 0}, |
487 |
{"SMALLDOWNARROW", EmitSingleByte, 0x91, 0}, |
|
0 | 488 |
}; |
489 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
490 |
|
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
491 |
static const CmdStruct *FindCmd(const char *s, int len) |
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
492 |
{ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
493 |
int i; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
494 |
const CmdStruct *cs = _cmd_structs; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
495 |
for(i=0; i != lengthof(_cmd_structs); i++, cs++) { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
496 |
if (!strncmp(cs->cmd, s, len) && cs->cmd[len] == '\0') |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
497 |
return cs; |
0 | 498 |
} |
499 |
return NULL; |
|
500 |
} |
|
501 |
||
2087 | 502 |
static int ResolveCaseName(const char *str, int len) |
503 |
{ |
|
504 |
int i; |
|
505 |
for(i=0; i<MAX_NUM_CASES; i++) |
|
506 |
if (!memcmp(_cases[i], str, len) && _cases[i][len] == 0) |
|
507 |
return i + 1; |
|
508 |
Fatal("Invalid case-name '%s'", str); |
|
509 |
} |
|
510 |
||
0 | 511 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
512 |
// returns NULL on eof |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
513 |
// else returns command struct |
2087 | 514 |
static const CmdStruct *ParseCommandString(const char **str, char *param, int *argno, int *casei) |
0 | 515 |
{ |
2087 | 516 |
const char *s = *str, *start; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
517 |
const CmdStruct *cmd; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
518 |
int plen = 0; |
2060
b414856d85af
(svn r2569) Get rid of some dubious casts and thus warnings on 64bit machines
tron
parents:
2059
diff
changeset
|
519 |
byte c; |
0 | 520 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
521 |
*argno = -1; |
2087 | 522 |
*casei = -1; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
523 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
524 |
// Scan to the next command, exit if there's no next command. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
525 |
for(; *s != '{'; s++) { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
526 |
if (*s == '\0') |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
527 |
return NULL; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
528 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
529 |
s++; // Skip past the { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
530 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
531 |
if (*s >= '0' && *s <= '9') { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
532 |
char *end; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
533 |
*argno = strtoul(s, &end, 0); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
534 |
if (*end != ':') { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
535 |
Fatal("missing arg #"); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
536 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
537 |
s = end + 1; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
538 |
} |
0 | 539 |
|
540 |
// parse command name |
|
541 |
start = s; |
|
2087 | 542 |
do { |
0 | 543 |
c = *s++; |
2087 | 544 |
} while (c != '}' && c != ' ' && c != '=' && c != '.' && c != 0); |
0 | 545 |
|
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
546 |
cmd = FindCmd(start, s - start - 1); |
0 | 547 |
if (cmd == NULL) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
548 |
Error("Undefined command '%.*s'", s - start - 1, start); |
0 | 549 |
return NULL; |
550 |
} |
|
551 |
||
2087 | 552 |
if (c == '.') { |
553 |
const char *casep = s; |
|
554 |
||
555 |
if (!(cmd->flags & C_CASE)) |
|
556 |
Fatal("Command '%s' can't have a case", cmd->cmd); |
|
557 |
||
558 |
do c = *s++; while (c != '}' && c != ' ' && c != '\0'); |
|
559 |
*casei = ResolveCaseName(casep, s-casep-1); |
|
560 |
} |
|
561 |
||
562 |
if (c == '\0') { |
|
563 |
Error("Missing } from command '%s'", start); |
|
564 |
return NULL; |
|
565 |
} |
|
566 |
||
567 |
||
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
568 |
if (c != '}') { |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
569 |
if (c == '=') s--; |
0 | 570 |
// copy params |
571 |
start = s; |
|
572 |
for(;;) { |
|
573 |
c = *s++; |
|
574 |
if (c == '}') break; |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
575 |
if (c == '\0') { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
576 |
Error("Missing } from command '%s'", start); |
0 | 577 |
return NULL; |
578 |
} |
|
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
579 |
if ( s - start == 250) |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
580 |
Fatal("param command too long"); |
0 | 581 |
*param++ = c; |
582 |
} |
|
583 |
} |
|
584 |
*param = 0; |
|
585 |
||
586 |
*str = s; |
|
587 |
||
588 |
return cmd; |
|
589 |
} |
|
590 |
||
591 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
592 |
static void HandlePragma(char *str) |
0 | 593 |
{ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
594 |
if (!memcmp(str, "id ", 3)) { |
0 | 595 |
_next_string_id = strtoul(str + 3, NULL, 0); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
596 |
} else if (!memcmp(str, "name ", 5)) { |
0 | 597 |
ttd_strlcpy(_lang_name, str + 5, sizeof(_lang_name)); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
598 |
} else if (!memcmp(str, "ownname ", 8)) { |
0 | 599 |
ttd_strlcpy(_lang_ownname, str + 8, sizeof(_lang_ownname)); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
600 |
} else if (!memcmp(str, "isocode ", 8)) { |
1376
425781645fba
(svn r1880) [Codechange] Added isocodes to langfiles and support code to strgen (Lauri Nurmi)
miham
parents:
1097
diff
changeset
|
601 |
ttd_strlcpy(_lang_isocode, str + 8, sizeof(_lang_isocode)); |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
602 |
} else if (!memcmp(str, "plural ", 7)) { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
603 |
_lang_pluralform = atoi(str + 7); |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
604 |
if (_lang_pluralform >= lengthof(_plural_form_counts)) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
605 |
Fatal("Invalid pluralform %d", _lang_pluralform); |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
606 |
} else if (!memcmp(str, "gender ", 7)) { |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
607 |
char *buf = str + 7, *s; |
2087 | 608 |
for(;;) { |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
609 |
s = ParseWord(&buf); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
610 |
if (!s) break; |
2087 | 611 |
if (_numgenders >= MAX_NUM_GENDER) Fatal("Too many genders, max %d", MAX_NUM_GENDER); |
612 |
ttd_strlcpy(_genders[_numgenders], s, sizeof(_genders[_numgenders])); |
|
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
613 |
_numgenders++; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
614 |
} |
2087 | 615 |
} else if (!memcmp(str, "case ", 5)) { |
616 |
char *buf = str + 5, *s; |
|
617 |
for(;;) { |
|
618 |
s = ParseWord(&buf); |
|
619 |
if (!s) break; |
|
620 |
if (_numcases >= MAX_NUM_CASES) Fatal("Too many cases, max %d", MAX_NUM_CASES); |
|
621 |
ttd_strlcpy(_cases[_numcases], s, sizeof(_cases[_numcases])); |
|
622 |
_numcases++; |
|
623 |
} |
|
0 | 624 |
} else { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
625 |
Fatal("unknown pragma '%s'", str); |
0 | 626 |
} |
627 |
} |
|
628 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
629 |
static void ExtractCommandString(ParsedCommandStruct *p, char *s, bool warnings) |
0 | 630 |
{ |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
631 |
const CmdStruct *ar; |
0 | 632 |
char param[100]; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
633 |
int argno; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
634 |
int argidx = 0; |
2087 | 635 |
int casei; |
0 | 636 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
637 |
memset(p, 0, sizeof(*p)); |
0 | 638 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
639 |
for(;;) { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
640 |
// read until next command from a. |
2107
607a900aefa3
(svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents:
2087
diff
changeset
|
641 |
ar = ParseCommandString((const char **)&s, param, &argno, &casei); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
642 |
if (ar == NULL) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
643 |
break; |
0 | 644 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
645 |
// Sanity checking |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
646 |
if (argno != -1 && !ar->consumes) Fatal("Non consumer param can't have a paramindex"); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
647 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
648 |
if (ar->consumes) { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
649 |
if (argno != -1) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
650 |
argidx = argno; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
651 |
if (argidx < 0 || argidx >= lengthof(p->cmd)) Fatal("invalid param idx %d", argidx); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
652 |
if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) Fatal("duplicate param idx %d", argidx); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
653 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
654 |
p->cmd[argidx++] = ar; |
2087 | 655 |
} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
656 |
if (p->np >= lengthof(p->pairs)) Fatal("too many commands in string, max %d", lengthof(p->pairs)); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
657 |
p->pairs[p->np].a = ar; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
658 |
p->pairs[p->np].v = param[0]?strdup(param):""; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
659 |
p->np++; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
660 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
661 |
} |
0 | 662 |
} |
663 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
664 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
665 |
static const CmdStruct *TranslateCmdForCompare(const CmdStruct *a) |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
666 |
{ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
667 |
if (!a) return NULL; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
668 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
669 |
if (!strcmp(a->cmd, "STRING1") || |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
670 |
!strcmp(a->cmd, "STRING2") || |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
671 |
!strcmp(a->cmd, "STRING3") || |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
672 |
!strcmp(a->cmd, "STRING4") || |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
673 |
!strcmp(a->cmd, "STRING5")) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
674 |
return FindCmd("STRING", 6); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
675 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
676 |
if (!strcmp(a->cmd, "SKIP")) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
677 |
return NULL; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
678 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
679 |
return a; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
680 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
681 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
682 |
|
2069
929b43e70be9
(svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents:
2063
diff
changeset
|
683 |
static bool CheckCommandsMatch(char *a, char *b, const char *name) |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
684 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
685 |
ParsedCommandStruct templ; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
686 |
ParsedCommandStruct lang; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
687 |
int i,j; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
688 |
bool result = true; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
689 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
690 |
ExtractCommandString(&templ, b, true); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
691 |
ExtractCommandString(&lang, a, true); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
692 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
693 |
// For each string in templ, see if we find it in lang |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
694 |
if (templ.np != lang.np) { |
2069
929b43e70be9
(svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents:
2063
diff
changeset
|
695 |
Warning("%s: template string and language string have a different # of commands", name); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
696 |
result = false; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
697 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
698 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
699 |
for(i = 0; i < templ.np; i++) { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
700 |
// see if we find it in lang, and zero it out |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
701 |
bool found = false; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
702 |
for(j = 0; j < lang.np; j++) { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
703 |
if (templ.pairs[i].a == lang.pairs[j].a && |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
704 |
!strcmp(templ.pairs[i].v, lang.pairs[j].v)) { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
705 |
// it was found in both. zero it out from lang so we don't find it again |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
706 |
lang.pairs[j].a = NULL; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
707 |
found = true; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
708 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
709 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
710 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
711 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
712 |
if (!found) { |
2069
929b43e70be9
(svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents:
2063
diff
changeset
|
713 |
Warning("%s: command '%s' exists in template file but not in language file", name, templ.pairs[i].a->cmd); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
714 |
result = false; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
715 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
716 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
717 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
718 |
// if we reach here, all non consumer commands match up. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
719 |
// Check if the non consumer commands match up also. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
720 |
for(i = 0; i < lengthof(templ.cmd); i++) { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
721 |
if (TranslateCmdForCompare(templ.cmd[i]) != TranslateCmdForCompare(lang.cmd[i])) { |
2069
929b43e70be9
(svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents:
2063
diff
changeset
|
722 |
Warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i, |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
723 |
!lang.cmd[i] ? "<empty>" : lang.cmd[i]->cmd, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
724 |
!templ.cmd[i] ? "<empty>" : templ.cmd[i]->cmd); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
725 |
result = false; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
726 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
727 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
728 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
729 |
return result; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
730 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
731 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
732 |
static void HandleString(char *str, bool master) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
733 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
734 |
char *s,*t; |
2087 | 735 |
LangString *ent; |
736 |
char *casep; |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
181
diff
changeset
|
737 |
|
0 | 738 |
if (*str == '#') { |
739 |
if (str[1] == '#' && str[2] != '#') |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
740 |
HandlePragma(str + 2); |
0 | 741 |
return; |
742 |
} |
|
743 |
||
744 |
// Ignore comments & blank lines |
|
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
745 |
if (*str == ';' || *str == ' ' || *str == '\0') |
0 | 746 |
return; |
747 |
||
748 |
s = strchr(str, ':'); |
|
749 |
if (s == NULL) { |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
750 |
Error("Line has no ':' delimiter"); |
0 | 751 |
return; |
752 |
} |
|
753 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
754 |
// Trim spaces. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
755 |
// After this str points to the command name, and s points to the command contents |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
756 |
for(t = s; t > str && (t[-1]==' ' || t[-1]=='\t'); t--); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
757 |
*t = 0; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
758 |
s++; |
0 | 759 |
|
2087 | 760 |
// Check if the string has a case.. |
761 |
// The syntax for cases is IDENTNAME.case |
|
762 |
casep = strchr(str, '.'); |
|
763 |
if (casep) *casep++ = 0; |
|
764 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
765 |
// Check if this string already exists.. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
766 |
ent = HashFind(str); |
0 | 767 |
|
768 |
if (master) { |
|
2087 | 769 |
if (ent != NULL && !casep) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
770 |
Error("String name '%s' is used multiple times", str); |
0 | 771 |
return; |
772 |
} |
|
773 |
||
2087 | 774 |
if (ent == NULL && casep) { |
775 |
Error("Base string name '%s' doesn't exist yet. Define it before defining a case.", str); |
|
0 | 776 |
return; |
777 |
} |
|
778 |
||
2087 | 779 |
if (ent == NULL) { |
780 |
if (_strings[_next_string_id]) { |
|
781 |
Error("String ID 0x%X for '%s' already in use by '%s'", ent, str, _strings[_next_string_id]->name); |
|
782 |
return; |
|
783 |
} |
|
784 |
||
785 |
// Allocate a new LangString |
|
786 |
ent = calloc(sizeof(LangString), 1); |
|
787 |
_strings[_next_string_id] = ent; |
|
788 |
ent->index = _next_string_id++; |
|
789 |
ent->name = strdup(str); |
|
790 |
||
791 |
HashAdd(str, ent); |
|
792 |
} |
|
793 |
||
794 |
if (casep) { |
|
795 |
Case *c = malloc(sizeof(Case)); |
|
796 |
c->caseidx = ResolveCaseName(casep, strlen(casep)); |
|
797 |
c->string = strdup(s); |
|
798 |
c->next = ent->english_case; |
|
799 |
ent->english_case = c; |
|
800 |
} else { |
|
801 |
ent->english = strdup(s); |
|
802 |
} |
|
803 |
||
0 | 804 |
} else { |
2087 | 805 |
if (ent == NULL) { |
2069
929b43e70be9
(svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents:
2063
diff
changeset
|
806 |
Warning("String name '%s' does not exist in master file", str); |
0 | 807 |
return; |
808 |
} |
|
809 |
||
2087 | 810 |
if (ent->translated && !casep) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
811 |
Error("String name '%s' is used multiple times", str); |
0 | 812 |
return; |
813 |
} |
|
814 |
||
2087 | 815 |
if (s[0] == ':' && s[1] == '\0' && casep == NULL) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
816 |
// Special syntax :: means we should just inherit the master string |
2087 | 817 |
ent->translated = strdup(ent->english); |
0 | 818 |
} else { |
2087 | 819 |
// make sure that the commands match |
820 |
if (!CheckCommandsMatch(s, ent->english, str)) |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
821 |
return; |
2087 | 822 |
|
823 |
if (casep) { |
|
824 |
Case *c = malloc(sizeof(Case)); |
|
825 |
c->caseidx = ResolveCaseName(casep, strlen(casep)); |
|
826 |
c->string = strdup(s); |
|
827 |
c->next = ent->translated_case; |
|
828 |
ent->translated_case = c; |
|
829 |
} else { |
|
830 |
ent->translated = strdup(s); |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
831 |
} |
0 | 832 |
} |
833 |
} |
|
834 |
} |
|
835 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
836 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
837 |
static void rstrip(char *buf) |
0 | 838 |
{ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
839 |
int i = strlen(buf); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
840 |
while (i>0 && (buf[i-1]=='\r' || buf[i-1]=='\n' || buf[i-1] == ' ')) i--; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
841 |
buf[i] = 0; |
0 | 842 |
} |
843 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
844 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
845 |
static void ParseFile(const char *file, bool english) |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
846 |
{ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
847 |
FILE *in; |
0 | 848 |
char buf[2048]; |
849 |
||
2459
4b65354b7586
(svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents:
2418
diff
changeset
|
850 |
_file = file; |
4b65354b7586
(svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents:
2418
diff
changeset
|
851 |
|
2087 | 852 |
// For each new file we parse, reset the genders. |
853 |
_numgenders = 0; |
|
854 |
// TODO:!! We can't reset the cases. In case the translated strings |
|
855 |
// derive some strings from english.... |
|
856 |
||
857 |
||
0 | 858 |
in = fopen(file, "r"); |
2459
4b65354b7586
(svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents:
2418
diff
changeset
|
859 |
if (in == NULL) Fatal("Cannot open file"); |
0 | 860 |
_cur_line = 1; |
861 |
while (fgets(buf, sizeof(buf),in) != NULL) { |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
862 |
rstrip(buf); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
863 |
HandleString(buf, english); |
0 | 864 |
_cur_line++; |
865 |
} |
|
866 |
fclose(in); |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
867 |
} |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
868 |
|
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
869 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
870 |
static uint32 MyHashStr(uint32 hash, const char *s) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
871 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
872 |
for(; *s; s++) { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
873 |
hash = ((hash << 3) | (hash >> 29)) ^ *s; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
874 |
if (hash & 1) hash = (hash>>1) ^ 0xDEADBEEF; else hash >>= 1; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
875 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
876 |
return hash; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
877 |
} |
0 | 878 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
879 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
880 |
// make a hash of the file to get a unique "version number" |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
881 |
static void MakeHashOfStrings() |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
882 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
883 |
uint32 hash = 0; |
2087 | 884 |
LangString *ls; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
885 |
char *s; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
886 |
const CmdStruct *cs; |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
887 |
char buf[256]; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
888 |
int i; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
889 |
int argno; |
2087 | 890 |
int casei; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
891 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
892 |
for(i = 0; i != 65536; i++) { |
2087 | 893 |
if ((ls=_strings[i]) != NULL) { |
894 |
s = ls->name; |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
895 |
hash ^= i * 0x717239; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
896 |
if (hash & 1) hash = (hash>>1) ^ 0xDEADBEEF; else hash >>= 1; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
897 |
hash = MyHashStr(hash, s + 1); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
898 |
|
2087 | 899 |
s = ls->english; |
2107
607a900aefa3
(svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents:
2087
diff
changeset
|
900 |
while ((cs = ParseCommandString((const char **)&s, buf, &argno, &casei)) != NULL) { |
2087 | 901 |
if (cs->flags & C_DONTCOUNT) |
902 |
continue; |
|
903 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
904 |
hash ^= (cs - _cmd_structs) * 0x1234567; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
905 |
if (hash & 1) hash = (hash>>1) ^ 0xF00BAA4; else hash >>= 1; |
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
181
diff
changeset
|
906 |
} |
0 | 907 |
} |
908 |
} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
909 |
_hash = hash; |
0 | 910 |
} |
911 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
912 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
913 |
static int CountInUse(int grp) |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
914 |
{ |
0 | 915 |
int i; |
916 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
917 |
for(i = 0x800; --i >= 0;) { |
2087 | 918 |
if (_strings[(grp<<11)+i] != NULL) |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
919 |
break; |
0 | 920 |
} |
921 |
return i + 1; |
|
922 |
} |
|
923 |
||
924 |
||
925 |
||
926 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
927 |
bool CompareFiles(const char *n1, const char *n2) |
0 | 928 |
{ |
929 |
FILE *f1, *f2; |
|
930 |
char b1[4096]; |
|
931 |
char b2[4096]; |
|
932 |
size_t l1, l2; |
|
933 |
||
934 |
f2 = fopen(n2, "rb"); |
|
935 |
if (f2 == NULL) return false; |
|
936 |
||
937 |
f1 = fopen(n1, "rb"); |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
938 |
if (f1 == NULL) Fatal("can't open %s", n1); |
0 | 939 |
|
940 |
do { |
|
941 |
l1 = fread(b1, 1, sizeof(b1), f1); |
|
942 |
l2 = fread(b2, 1, sizeof(b2), f2); |
|
943 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
944 |
if (l1 != l2 || memcmp(b1, b2, l1)) { |
0 | 945 |
fclose(f2); |
946 |
fclose(f1); |
|
947 |
return false; |
|
948 |
} |
|
949 |
} while (l1); |
|
950 |
||
951 |
fclose(f2); |
|
952 |
fclose(f1); |
|
953 |
return true; |
|
954 |
} |
|
955 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
956 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
957 |
static void WriteStringsH(const char *filename) |
0 | 958 |
{ |
959 |
FILE *out; |
|
960 |
int i; |
|
961 |
int next = -1; |
|
962 |
int lastgrp; |
|
963 |
||
964 |
out = fopen("tmp.xxx", "w"); |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
965 |
if (out == NULL) { Fatal("can't open tmp.xxx"); } |
0 | 966 |
|
967 |
fprintf(out, "enum {"); |
|
968 |
||
969 |
lastgrp = 0; |
|
970 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
971 |
for(i = 0; i != 65536; i++) { |
2087 | 972 |
if (_strings[i]) { |
0 | 973 |
if (lastgrp != (i >> 11)) { |
974 |
lastgrp = (i >> 11); |
|
975 |
fprintf(out, "};\n\nenum {"); |
|
976 |
} |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
181
diff
changeset
|
977 |
|
2087 | 978 |
fprintf(out, next == i ? "%s,\n" : "\n%s = 0x%X,\n", _strings[i]->name, i); |
0 | 979 |
next = i + 1; |
980 |
} |
|
981 |
} |
|
982 |
||
983 |
fprintf(out, "};\n"); |
|
984 |
||
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
181
diff
changeset
|
985 |
fprintf(out, |
0 | 986 |
"\nenum {\n" |
181
0b95567f2d0f
(svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents:
0
diff
changeset
|
987 |
"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n" |
0 | 988 |
"\tLANGUAGE_PACK_VERSION = 0x%X,\n" |
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
989 |
"};\n", (uint)_hash); |
0 | 990 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
991 |
|
0 | 992 |
fclose(out); |
993 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
994 |
if (CompareFiles("tmp.xxx", filename)) { |
0 | 995 |
// files are equal. tmp.xxx is not needed |
996 |
unlink("tmp.xxx"); |
|
997 |
} else { |
|
998 |
// else rename tmp.xxx into filename |
|
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2459
diff
changeset
|
999 |
#if defined(WIN32) || defined(WIN64) |
0 | 1000 |
unlink(filename); |
1001 |
#endif |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1002 |
if (rename("tmp.xxx", filename) == -1) Fatal("rename() failed"); |
0 | 1003 |
} |
1004 |
} |
|
1005 |
||
2087 | 1006 |
static int TranslateArgumentIdx(int argidx) |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1007 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1008 |
int i, sum; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1009 |
|
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1010 |
if (argidx < 0 || argidx >= lengthof(_cur_pcs.cmd)) |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1011 |
Fatal("invalid argidx %d", argidx); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1012 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1013 |
for(i = sum = 0; i < argidx; i++) { |
2374
74afdc193f78
(svn r2900) Fix a bug, which incremented the counter of a loop twice and therefore calculated wrong argument indices
tron
parents:
2353
diff
changeset
|
1014 |
const CmdStruct *cs = _cur_pcs.cmd[i]; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1015 |
sum += cs ? cs->consumes : 1; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1016 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1017 |
|
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1018 |
return sum; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1019 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1020 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1021 |
static void PutArgidxCommand(void) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1022 |
{ |
2410
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2407
diff
changeset
|
1023 |
PutByte(0x8C); |
2087 | 1024 |
PutByte(TranslateArgumentIdx(_cur_argidx)); |
1025 |
} |
|
1026 |
||
1027 |
||
1028 |
static void PutCommandString(const char *str) |
|
1029 |
{ |
|
1030 |
const CmdStruct *cs; |
|
1031 |
char param[256]; |
|
1032 |
int argno; |
|
1033 |
int casei; |
|
1034 |
||
1035 |
_cur_argidx = 0; |
|
1036 |
||
1037 |
while (*str != '\0') { |
|
1038 |
// Process characters as they are until we encounter a { |
|
1039 |
if (*str != '{') { |
|
1040 |
PutByte(*str++); |
|
1041 |
continue; |
|
1042 |
} |
|
1043 |
cs = ParseCommandString(&str, param, &argno, &casei); |
|
1044 |
if (cs == NULL) break; |
|
1045 |
||
1046 |
if (casei != -1) { |
|
1047 |
PutByte(0x9D); // {SETCASE} |
|
1048 |
PutByte(casei); |
|
1049 |
} |
|
1050 |
||
1051 |
// For params that consume values, we need to handle the argindex properly |
|
1052 |
if (cs->consumes) { |
|
1053 |
// Check if we need to output a move-param command |
|
1054 |
if (argno!=-1 && argno != _cur_argidx) { |
|
1055 |
_cur_argidx = argno; |
|
1056 |
PutArgidxCommand(); |
|
1057 |
} |
|
1058 |
||
1059 |
// Output the one from the master string... it's always accurate. |
|
1060 |
cs = _cur_pcs.cmd[_cur_argidx++]; |
|
1061 |
if (!cs) |
|
1062 |
Fatal("%s: No argument exists at posision %d", _cur_ident, _cur_argidx-1); |
|
1063 |
} |
|
1064 |
||
1065 |
cs->proc(param, cs->value); |
|
1066 |
} |
|
1067 |
} |
|
1068 |
||
1069 |
static void WriteLength(FILE *f, uint length) |
|
1070 |
{ |
|
1071 |
if (length < 0xC0) { |
|
1072 |
fputc(length, f); |
|
1073 |
} else if (length < 0x4000) { |
|
1074 |
fputc((length >> 8) | 0xC0, f); |
|
1075 |
fputc(length & 0xFF, f); |
|
1076 |
} else { |
|
1077 |
Fatal("string too long"); |
|
1078 |
} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1079 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1080 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1081 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1082 |
static void WriteLangfile(const char *filename, int show_todo) |
0 | 1083 |
{ |
1084 |
FILE *f; |
|
1085 |
int in_use[32]; |
|
1086 |
LanguagePackHeader hdr; |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1087 |
int i,j; |
0 | 1088 |
|
1089 |
f = fopen(filename, "wb"); |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1090 |
if (f == NULL) Fatal("can't open %s", filename); |
0 | 1091 |
|
1092 |
memset(&hdr, 0, sizeof(hdr)); |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1093 |
for(i = 0; i != 32; i++) { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1094 |
int n = CountInUse(i); |
0 | 1095 |
in_use[i] = n; |
1096 |
hdr.offsets[i] = TO_LE16(n); |
|
1097 |
} |
|
1098 |
||
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
181
diff
changeset
|
1099 |
// see line 655: fprintf(..."\tLANGUAGE_PACK_IDENT = 0x474E414C,...) |
181
0b95567f2d0f
(svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents:
0
diff
changeset
|
1100 |
hdr.ident = TO_LE32(0x474E414C); // Big Endian value for 'LANG' |
0 | 1101 |
hdr.version = TO_LE32(_hash); |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1102 |
hdr.plural_form = _lang_pluralform; |
0 | 1103 |
strcpy(hdr.name, _lang_name); |
1104 |
strcpy(hdr.own_name, _lang_ownname); |
|
1376
425781645fba
(svn r1880) [Codechange] Added isocodes to langfiles and support code to strgen (Lauri Nurmi)
miham
parents:
1097
diff
changeset
|
1105 |
strcpy(hdr.isocode, _lang_isocode); |
0 | 1106 |
|
1107 |
fwrite(&hdr, sizeof(hdr), 1, f); |
|
1108 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1109 |
for(i = 0; i != 32; i++) { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1110 |
for(j = 0; j != in_use[i]; j++) { |
2087 | 1111 |
LangString *ls = _strings[(i<<11)+j]; |
1112 |
||
1113 |
Case *casep; |
|
1114 |
char *cmdp; |
|
0 | 1115 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1116 |
// For undefined strings, just set that it's an empty string |
2087 | 1117 |
if (ls == NULL) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1118 |
WriteLength(f, 0); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1119 |
continue; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1120 |
} |
0 | 1121 |
|
2087 | 1122 |
_cur_ident = ls->name; |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1123 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1124 |
// Produce a message if a string doesn't have a translation. |
2087 | 1125 |
if (show_todo && ls->translated == NULL) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1126 |
if (show_todo == 2) { |
2087 | 1127 |
Warning("'%s' is untranslated", ls->name); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1128 |
} else { |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1129 |
const char *s = "<TODO> "; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1130 |
while(*s) PutByte(*s++); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1131 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1132 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1133 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1134 |
// Extract the strings and stuff from the english command string |
2087 | 1135 |
ExtractCommandString(&_cur_pcs, ls->english, false); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1136 |
|
2087 | 1137 |
if (ls->translated_case || ls->translated) { |
1138 |
casep = ls->translated_case; |
|
1139 |
cmdp = ls->translated; |
|
1140 |
} else { |
|
1141 |
casep = ls->english_case; |
|
1142 |
cmdp = ls->english; |
|
1143 |
} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1144 |
|
2087 | 1145 |
if (casep) { |
1146 |
Case *c; |
|
1147 |
int num; |
|
1148 |
// Need to output a case-switch. |
|
1149 |
// It has this format |
|
1150 |
// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT> |
|
1151 |
// Each LEN is printed using 2 bytes in big endian order. |
|
1152 |
PutByte(0x9E); |
|
1153 |
// Count the number of cases |
|
1154 |
for(num=0,c=casep; c; c=c->next) num++; |
|
1155 |
PutByte(num); |
|
1156 |
||
1157 |
// Write each case |
|
1158 |
for(c=casep; c; c=c->next) { |
|
1159 |
int pos; |
|
1160 |
PutByte(c->caseidx); |
|
1161 |
// Make some space for the 16-bit length |
|
1162 |
pos = _put_pos; |
|
1163 |
PutByte(0); |
|
1164 |
PutByte(0); |
|
1165 |
// Write string |
|
1166 |
PutCommandString(c->string); |
|
1167 |
PutByte(0); // terminate with a zero |
|
1168 |
// Fill in the length |
|
1169 |
_put_buf[pos] = (_put_pos - (pos + 2)) >> 8; |
|
1170 |
_put_buf[pos+1] = (_put_pos - (pos + 2)) & 0xFF; |
|
0 | 1171 |
} |
2087 | 1172 |
} |
0 | 1173 |
|
2087 | 1174 |
if (cmdp) |
1175 |
PutCommandString(cmdp); |
|
0 | 1176 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1177 |
WriteLength(f, _put_pos); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1178 |
fwrite(_put_buf, 1, _put_pos, f); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1179 |
_put_pos = 0; |
0 | 1180 |
} |
1181 |
} |
|
1182 |
||
1183 |
fputc(0, f); |
|
1184 |
||
1185 |
fclose(f); |
|
1186 |
} |
|
1187 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1188 |
|
250
733e18ca6e93
(svn r251) -Project ready for 0.3.4 release. Updated installer, readme and fileinformation
darkvater
parents:
236
diff
changeset
|
1189 |
int CDECL main(int argc, char* argv[]) |
0 | 1190 |
{ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1191 |
char *r; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1192 |
char buf[256]; |
0 | 1193 |
int show_todo = 0; |
1194 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1195 |
if (argc > 1 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))) { |
2418
8599776539b1
(svn r2944) Add Revision keyword to the file for --version/-v
Darkvater
parents:
2411
diff
changeset
|
1196 |
puts("$Revision$"); |
0 | 1197 |
return 0; |
1198 |
} |
|
1199 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1200 |
if (argc > 1 && !strcmp(argv[1], "-t")) { |
0 | 1201 |
show_todo = 1; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1202 |
argc--, argv++; |
0 | 1203 |
} |
1204 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1205 |
if (argc > 1 && !strcmp(argv[1], "-w")) { |
0 | 1206 |
show_todo = 2; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1207 |
argc--, argv++; |
0 | 1208 |
} |
1209 |
||
1210 |
||
1211 |
if (argc == 1) { |
|
1212 |
// parse master file |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1213 |
ParseFile("lang/english.txt", true); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1214 |
MakeHashOfStrings(); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1215 |
if (_errors) return 1; |
0 | 1216 |
|
1217 |
// write english.lng and strings.h |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
181
diff
changeset
|
1218 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1219 |
WriteLangfile("lang/english.lng", 0); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1220 |
WriteStringsH("table/strings.h"); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1221 |
|
2059
35037679fcfb
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
1222 |
} else if (argc == 2) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1223 |
ParseFile("lang/english.txt", true); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1224 |
MakeHashOfStrings(); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1225 |
ParseFile(argv[1], false); |
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
181
diff
changeset
|
1226 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1227 |
if (_errors) return 1; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1228 |
|
0 | 1229 |
strcpy(buf, argv[1]); |
1230 |
r = strrchr(buf, '.'); |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1231 |
if (!r || strcmp(r, ".txt")) r = strchr(buf, 0); |
0 | 1232 |
strcpy(r, ".lng"); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1233 |
WriteLangfile(buf, show_todo); |
0 | 1234 |
} else { |
1235 |
fprintf(stderr, "invalid arguments\n"); |
|
1236 |
} |
|
1237 |
||
1238 |
return 0; |
|
1239 |
} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1240 |