author | KUDr |
Sat, 13 Jan 2007 18:55:54 +0000 | |
changeset 5651 | 79496e6d8a56 |
parent 5609 | dc6a58930ba4 |
child 5725 | 0ec667093bc1 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "../stdafx.h" |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
4 |
#include "../macros.h" |
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
5 |
#include "../string.h" |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
6 |
#include "../table/control_codes.h" |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
7 |
#include "../helpers.hpp" |
0 | 8 |
#include <stdio.h> |
9 |
#include <string.h> |
|
10 |
#include <stdlib.h> |
|
11 |
#include <stdarg.h> |
|
12 |
||
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2459
diff
changeset
|
13 |
#if (!defined(WIN32) && !defined(WIN64)) || defined(__CYGWIN__) |
0 | 14 |
#include <unistd.h> |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
15 |
#include <sys/types.h> |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
16 |
#include <sys/stat.h> |
0 | 17 |
#endif |
18 |
||
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
19 |
#if defined WIN32 || defined __WATCOMC__ |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
20 |
#include <direct.h> |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
21 |
#endif /* WIN32 || __WATCOMC__ */ |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
22 |
|
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
|
23 |
#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
|
24 |
#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
|
25 |
#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
|
26 |
#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
|
27 |
#define stderr stdout |
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
28 |
#endif /* __MORPHOS__ */ |
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
|
29 |
|
3395 | 30 |
#ifdef __WATCOMC__ |
31 |
uint _map_log_x; // an unpleasant hack required because Watcom is insisting on |
|
32 |
uint _map_size_x; // these variables being valid references in map.h |
|
33 |
uint _map_size_y; |
|
34 |
uint _map_tile_mask; |
|
35 |
uint _map_size; |
|
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
36 |
#endif /* __WATCOMC__ */ |
3395 | 37 |
|
0 | 38 |
/* Compiles a list of strings into a compiled string list */ |
39 |
||
40 |
typedef void (*ParseCmdProc)(char *buf, int value); |
|
41 |
||
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
42 |
typedef struct LanguagePackHeader { |
0 | 43 |
uint32 ident; |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
44 |
uint32 version; // 32-bits of auto generated version info which is basically a hash of strings.h |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
45 |
char name[32]; // the international name of this language |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4379
diff
changeset
|
46 |
char own_name[32]; // the localized name of this language |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
47 |
char isocode[16]; // the ISO code for the language (not country code) |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
48 |
uint16 offsets[32]; // the offsets |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
49 |
byte plural_form; // plural form index |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
50 |
byte pad[3]; // pad header to be a multiple of 4 |
0 | 51 |
} LanguagePackHeader; |
52 |
||
53 |
typedef struct CmdStruct { |
|
54 |
const char *cmd; |
|
55 |
ParseCmdProc proc; |
|
56 |
long value; |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
57 |
int8 consumes; |
2087 | 58 |
byte flags; |
0 | 59 |
} CmdStruct; |
60 |
||
2087 | 61 |
enum { |
62 |
C_DONTCOUNT = 1, |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
63 |
C_CASE = 2, |
2087 | 64 |
}; |
65 |
||
66 |
||
67 |
typedef struct Case { |
|
68 |
int caseidx; |
|
69 |
char *string; |
|
70 |
struct Case *next; |
|
71 |
} Case; |
|
72 |
||
2586
1c0f0b67a70d
(svn r3123) eh, don't press enter after typing text, previous patch wasn't finished. Now strgen really behaves correctly. Thanks again glx
Darkvater
parents:
2585
diff
changeset
|
73 |
static bool _masterlang; |
2585
fa2f94aa9de2
(svn r3122) - Fix (regression): recent change to strgen which 'fixed' all strings with wrong plural forms. Thanks for glx for pointing this out (after I changed his original patch which was correct..whohoo braindeadness; here I come)
Darkvater
parents:
2566
diff
changeset
|
74 |
static bool _translated; |
2459
a2f63b331830
(svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents:
2418
diff
changeset
|
75 |
static const char* _file = "(unknown file)"; |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
76 |
static int _cur_line; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
77 |
static int _errors, _warnings; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
78 |
|
2087 | 79 |
typedef struct LangString { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
80 |
char *name; // Name of the string |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
81 |
char *english; // English text |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
82 |
char *translated; // Translated text |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
83 |
uint16 hash_next; // next hash entry |
2087 | 84 |
uint16 index; |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
85 |
int line; // line of string in source-file |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
86 |
Case *english_case; // cases for english |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
87 |
Case *translated_case; // cases for foreign |
2087 | 88 |
} LangString; |
89 |
||
90 |
static LangString *_strings[65536]; |
|
91 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
92 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
93 |
#define HASH_SIZE 32767 |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
94 |
static uint16 _hash_head[HASH_SIZE]; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
95 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
96 |
static byte _put_buf[4096]; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
97 |
static int _put_pos; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
98 |
static int _next_string_id; |
0 | 99 |
|
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
100 |
static uint32 _hash; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
101 |
static char _lang_name[32], _lang_ownname[32], _lang_isocode[16]; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
102 |
static byte _lang_pluralform; |
2087 | 103 |
#define MAX_NUM_GENDER 8 |
104 |
static char _genders[MAX_NUM_GENDER][8]; |
|
105 |
static int _numgenders; |
|
0 | 106 |
|
2087 | 107 |
// contains the name of all cases. |
108 |
#define MAX_NUM_CASES 50 |
|
109 |
static char _cases[MAX_NUM_CASES][16]; |
|
110 |
static int _numcases; |
|
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
111 |
|
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
112 |
// for each plural value, this is the number of plural forms. |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
113 |
static const byte _plural_form_counts[] = { 2, 1, 2, 3, 3, 3, 3, 3, 4 }; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
114 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
115 |
static const char *_cur_ident; |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
116 |
|
2087 | 117 |
typedef struct CmdPair { |
118 |
const CmdStruct *a; |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
119 |
const char *v; |
2087 | 120 |
} CmdPair; |
121 |
||
122 |
typedef struct ParsedCommandStruct { |
|
123 |
int np; |
|
124 |
CmdPair pairs[32]; |
|
125 |
const CmdStruct *cmd[32]; // ordered by param # |
|
126 |
} ParsedCommandStruct; |
|
127 |
||
128 |
// Used when generating some advanced commands. |
|
129 |
static ParsedCommandStruct _cur_pcs; |
|
130 |
static int _cur_argidx; |
|
131 |
||
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
132 |
static uint HashStr(const char *s) |
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
133 |
{ |
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
134 |
uint hash = 0; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
135 |
for (; *s != '\0'; s++) hash = ROL(hash, 3) ^ *s; |
0 | 136 |
return hash % HASH_SIZE; |
137 |
} |
|
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
138 |
|
2087 | 139 |
static void HashAdd(const char *s, LangString *ls) |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
140 |
{ |
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
141 |
uint hash = HashStr(s); |
2087 | 142 |
ls->hash_next = _hash_head[hash]; |
143 |
_hash_head[hash] = ls->index + 1; |
|
0 | 144 |
} |
145 |
||
2087 | 146 |
static LangString *HashFind(const char *s) |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
147 |
{ |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
148 |
int idx = _hash_head[HashStr(s)]; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
149 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
150 |
while (--idx >= 0) { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
151 |
LangString* ls = _strings[idx]; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
152 |
|
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
153 |
if (strcmp(ls->name, s) == 0) return ls; |
2087 | 154 |
idx = ls->hash_next; |
0 | 155 |
} |
2087 | 156 |
return NULL; |
0 | 157 |
} |
158 |
||
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3718
diff
changeset
|
159 |
#ifdef _MSC_VER |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3718
diff
changeset
|
160 |
# define LINE_NUM_FMT "(%d)" |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3718
diff
changeset
|
161 |
#else |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3718
diff
changeset
|
162 |
# define LINE_NUM_FMT ":%d" |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3718
diff
changeset
|
163 |
#endif |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
164 |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
165 |
static void CDECL warning(const char *s, ...) |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
166 |
{ |
0 | 167 |
char buf[1024]; |
168 |
va_list va; |
|
169 |
va_start(va, s); |
|
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
170 |
vsnprintf(buf, lengthof(buf), s, va); |
0 | 171 |
va_end(va); |
4447
486395ec1e06
(svn r6225) -Codechange: change the warning/error format of strgen to show up
Darkvater
parents:
4434
diff
changeset
|
172 |
fprintf(stderr, "%s" LINE_NUM_FMT ": warning: %s\n", _file, _cur_line, buf); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
173 |
_warnings++; |
0 | 174 |
} |
175 |
||
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
176 |
void CDECL error(const char *s, ...) |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
177 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
178 |
char buf[1024]; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
179 |
va_list va; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
180 |
va_start(va, s); |
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
181 |
vsnprintf(buf, lengthof(buf), s, va); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
182 |
va_end(va); |
4447
486395ec1e06
(svn r6225) -Codechange: change the warning/error format of strgen to show up
Darkvater
parents:
4434
diff
changeset
|
183 |
fprintf(stderr, "%s" LINE_NUM_FMT ": error: %s\n", _file, _cur_line, buf); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
184 |
_errors++; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
185 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
186 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
187 |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
188 |
static void NORETURN CDECL fatal(const char *s, ...) |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
189 |
{ |
0 | 190 |
char buf[1024]; |
191 |
va_list va; |
|
192 |
va_start(va, s); |
|
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
193 |
vsnprintf(buf, lengthof(buf), s, va); |
0 | 194 |
va_end(va); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3718
diff
changeset
|
195 |
fprintf(stderr, "%s" LINE_NUM_FMT ": FATAL: %s\n", _file, _cur_line, buf); |
0 | 196 |
exit(1); |
197 |
} |
|
198 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
199 |
static void PutByte(byte c) |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
200 |
{ |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
201 |
if (_put_pos == lengthof(_put_buf)) fatal("Put buffer too small"); |
0 | 202 |
_put_buf[_put_pos++] = c; |
203 |
} |
|
204 |
||
205 |
||
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
206 |
static void PutUtf8(uint32 value) |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
207 |
{ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
208 |
if (value < 0x80) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
209 |
PutByte(value); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
210 |
} else if (value < 0x800) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
211 |
PutByte(0xC0 + GB(value, 6, 5)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
212 |
PutByte(0x80 + GB(value, 0, 6)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
213 |
} else if (value < 0x10000) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
214 |
PutByte(0xE0 + GB(value, 12, 4)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
215 |
PutByte(0x80 + GB(value, 6, 6)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
216 |
PutByte(0x80 + GB(value, 0, 6)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
217 |
} else if (value < 0x110000) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
218 |
PutByte(0xF0 + GB(value, 18, 3)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
219 |
PutByte(0x80 + GB(value, 12, 6)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
220 |
PutByte(0x80 + GB(value, 6, 6)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
221 |
PutByte(0x80 + GB(value, 0, 6)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
222 |
} else { |
5360
d87dfdb62e5a
(svn r7540) -Codechange: Print a summary of the number of errors/warnings of a language when strgen is run with the -w flag.
Darkvater
parents:
5111
diff
changeset
|
223 |
warning("Invalid unicode value U+0x%X", value); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
224 |
} |
0 | 225 |
} |
226 |
||
227 |
||
5111
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
228 |
size_t Utf8Validate(const char *s) |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
229 |
{ |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
230 |
uint32 c; |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
231 |
|
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
232 |
if (!HASBIT(s[0], 7)) { |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
233 |
/* 1 byte */ |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
234 |
return 1; |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
235 |
} else if (GB(s[0], 5, 3) == 6 && IsUtf8Part(s[1])) { |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
236 |
/* 2 bytes */ |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
237 |
c = GB(s[0], 0, 5) << 6 | GB(s[1], 0, 6); |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
238 |
if (c >= 0x80) return 2; |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
239 |
} else if (GB(s[0], 4, 4) == 14 && IsUtf8Part(s[1]) && IsUtf8Part(s[2])) { |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
240 |
/* 3 bytes */ |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
241 |
c = GB(s[0], 0, 4) << 12 | GB(s[1], 0, 6) << 6 | GB(s[2], 0, 6); |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
242 |
if (c >= 0x800) return 3; |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
243 |
} else if (GB(s[0], 3, 5) == 30 && IsUtf8Part(s[1]) && IsUtf8Part(s[2]) && IsUtf8Part(s[3])) { |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
244 |
/* 4 bytes */ |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
245 |
c = GB(s[0], 0, 3) << 18 | GB(s[1], 0, 6) << 12 | GB(s[2], 0, 6) << 6 | GB(s[3], 0, 6); |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
246 |
if (c >= 0x10000 && c <= 0x10FFFF) return 4; |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
247 |
} |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
248 |
|
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
249 |
return 0; |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
250 |
} |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
251 |
|
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
252 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
253 |
static void EmitSingleChar(char *buf, int value) |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
254 |
{ |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
255 |
if (*buf != '\0') warning("Ignoring trailing letters in command"); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
256 |
PutUtf8(value); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
257 |
} |
0 | 258 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
259 |
|
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
260 |
static void EmitSetX(char *buf, int value) |
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
261 |
{ |
0 | 262 |
char *err; |
263 |
int x = strtol(buf, &err, 0); |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
264 |
if (*err != 0) fatal("SetX param invalid"); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
265 |
PutUtf8(SCC_SETX); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
266 |
PutByte((byte)x); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
267 |
} |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
268 |
|
0 | 269 |
|
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
270 |
static void EmitSetXY(char *buf, int value) |
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
271 |
{ |
0 | 272 |
char *err; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
273 |
int x; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
274 |
int y; |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
275 |
|
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
276 |
x = strtol(buf, &err, 0); |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
277 |
if (*err != ' ') fatal("SetXY param invalid"); |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
278 |
y = strtol(err + 1, &err, 0); |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
279 |
if (*err != 0) fatal("SetXY param invalid"); |
0 | 280 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
281 |
PutUtf8(SCC_SETXY); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
282 |
PutByte((byte)x); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
283 |
PutByte((byte)y); |
0 | 284 |
} |
285 |
||
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
286 |
// The plural specifier looks like |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
287 |
// {NUM} {PLURAL -1 passenger passengers} then it picks either passenger/passengers depending on the count in NUM |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
288 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
289 |
// This is encoded like |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
290 |
// CommandByte <ARG#> <NUM> {Length of each string} {each string} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
291 |
|
2087 | 292 |
bool ParseRelNum(char **buf, int *value) |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
293 |
{ |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
294 |
const char* s = *buf; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
295 |
char* end; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
296 |
bool rel = false; |
2087 | 297 |
int v; |
298 |
||
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
299 |
while (*s == ' ' || *s == '\t') s++; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
300 |
if (*s == '+') { |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
301 |
rel = true; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
302 |
s++; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
303 |
} |
2087 | 304 |
v = strtol(s, &end, 0); |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
305 |
if (end == s) return false; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
306 |
if (rel || v < 0) { |
2087 | 307 |
*value += v; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
308 |
} else { |
2087 | 309 |
*value = v; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
310 |
} |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
311 |
*buf = end; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
312 |
return true; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
313 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
314 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
315 |
// Parse out the next word, or NULL |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
316 |
char *ParseWord(char **buf) |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
317 |
{ |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
318 |
char *s = *buf, *r; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
319 |
|
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
320 |
while (*s == ' ' || *s == '\t') s++; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
321 |
if (*s == '\0') return NULL; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
322 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
323 |
if (*s == '"') { |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
324 |
r = ++s; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
325 |
// parse until next " or NUL |
2952 | 326 |
for (;;) { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
327 |
if (*s == '\0') break; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
328 |
if (*s == '"') { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
329 |
*s++ = '\0'; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
330 |
break; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
331 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
332 |
s++; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
333 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
334 |
} else { |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
335 |
// proceed until whitespace or NUL |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
336 |
r = s; |
2952 | 337 |
for (;;) { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
338 |
if (*s == '\0') break; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
339 |
if (*s == ' ' || *s == '\t') { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
340 |
*s++ = '\0'; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
341 |
break; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
342 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
343 |
s++; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
344 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
345 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
346 |
*buf = s; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
347 |
return r; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
348 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
349 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
350 |
// Forward declaration |
2087 | 351 |
static int TranslateArgumentIdx(int arg); |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
352 |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
353 |
static void EmitWordList(const char* const* words, uint nw) |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
354 |
{ |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
355 |
uint i; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
356 |
uint j; |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
357 |
|
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
358 |
PutByte(nw); |
2952 | 359 |
for (i = 0; i < nw; i++) PutByte(strlen(words[i])); |
360 |
for (i = 0; i < nw; i++) { |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
361 |
for (j = 0; words[i][j] != '\0'; j++) PutByte(words[i][j]); |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
362 |
} |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
363 |
} |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
364 |
|
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
365 |
static void EmitPlural(char *buf, int value) |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
366 |
{ |
2087 | 367 |
int argidx = _cur_argidx; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
368 |
const char* words[5]; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
369 |
int nw = 0; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
370 |
|
2087 | 371 |
// Parse out the number, if one exists. Otherwise default to prev arg. |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
372 |
if (!ParseRelNum(&buf, &argidx)) argidx--; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
373 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
374 |
// Parse each string |
2566
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
375 |
for (nw = 0; nw < 5; nw++) { |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
376 |
words[nw] = ParseWord(&buf); |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
377 |
if (words[nw] == NULL) break; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
378 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
379 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
380 |
if (nw == 0) |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
381 |
fatal("%s: No plural words", _cur_ident); |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
382 |
|
2765
8fa792b6e525
(svn r3310) Fix a couple of warnings: Initialise all struct members, disambiguate cascaded if/else, remove an unused variable, use (void) for empty parameter lists
tron
parents:
2586
diff
changeset
|
383 |
if (_plural_form_counts[_lang_pluralform] != nw) { |
2585
fa2f94aa9de2
(svn r3122) - Fix (regression): recent change to strgen which 'fixed' all strings with wrong plural forms. Thanks for glx for pointing this out (after I changed his original patch which was correct..whohoo braindeadness; here I come)
Darkvater
parents:
2566
diff
changeset
|
384 |
if (_translated) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
385 |
fatal("%s: Invalid number of plural forms. Expecting %d, found %d.", _cur_ident, |
2566
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
386 |
_plural_form_counts[_lang_pluralform], nw); |
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
387 |
} else { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
388 |
warning("'%s' is untranslated. Tweaking english string to allow compilation for plural forms", _cur_ident); |
2566
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
389 |
if (nw > _plural_form_counts[_lang_pluralform]) { |
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
390 |
nw = _plural_form_counts[_lang_pluralform]; |
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
391 |
} else { |
2952 | 392 |
for (; nw < _plural_form_counts[_lang_pluralform]; nw++) { |
2566
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
393 |
words[nw] = words[nw - 1]; |
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
394 |
} |
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
395 |
} |
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
396 |
} |
2765
8fa792b6e525
(svn r3310) Fix a couple of warnings: Initialise all struct members, disambiguate cascaded if/else, remove an unused variable, use (void) for empty parameter lists
tron
parents:
2586
diff
changeset
|
397 |
} |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
398 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
399 |
PutUtf8(SCC_PLURAL_LIST); |
2087 | 400 |
PutByte(TranslateArgumentIdx(argidx)); |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
401 |
EmitWordList(words, nw); |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
402 |
} |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
403 |
|
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
404 |
|
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
405 |
static void EmitGender(char *buf, int value) |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
406 |
{ |
2087 | 407 |
int argidx = _cur_argidx; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
408 |
uint nw; |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
409 |
|
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
410 |
if (buf[0] == '=') { |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
411 |
buf++; |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
412 |
|
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
413 |
// This is a {G=DER} command |
2952 | 414 |
for (nw = 0; ; nw++) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
415 |
if (nw >= 8) fatal("G argument '%s' invalid", buf); |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
416 |
if (strcmp(buf, _genders[nw]) == 0) break; |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
417 |
} |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
418 |
// now nw contains the gender index |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
419 |
PutUtf8(SCC_GENDER_INDEX); |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
420 |
PutByte(nw); |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
421 |
} else { |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
422 |
const char* words[8]; |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
423 |
|
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
424 |
// This is a {G 0 foo bar two} command. |
2087 | 425 |
// If no relative number exists, default to +0 |
426 |
if (!ParseRelNum(&buf, &argidx)) {} |
|
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
427 |
|
2952 | 428 |
for (nw = 0; nw < 8; nw++) { |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
429 |
words[nw] = ParseWord(&buf); |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
430 |
if (words[nw] == NULL) break; |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
431 |
} |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
432 |
if (nw != _numgenders) fatal("Bad # of arguments for gender command"); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
433 |
PutUtf8(SCC_GENDER_LIST); |
2087 | 434 |
PutByte(TranslateArgumentIdx(argidx)); |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
435 |
EmitWordList(words, nw); |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
436 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
437 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
438 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
439 |
|
0 | 440 |
static const CmdStruct _cmd_structs[] = { |
441 |
// Update position |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
442 |
{"SETX", EmitSetX, SCC_SETX, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
443 |
{"SETXY", EmitSetXY, SCC_SETXY, 0, 0}, |
0 | 444 |
|
445 |
// Font size |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
446 |
{"TINYFONT", EmitSingleChar, SCC_TINYFONT, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
447 |
{"BIGFONT", EmitSingleChar, SCC_BIGFONT, 0, 0}, |
0 | 448 |
|
449 |
// Colors |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
450 |
{"BLUE", EmitSingleChar, SCC_BLUE, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
451 |
{"SILVER", EmitSingleChar, SCC_SILVER, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
452 |
{"GOLD", EmitSingleChar, SCC_GOLD, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
453 |
{"RED", EmitSingleChar, SCC_RED, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
454 |
{"PURPLE", EmitSingleChar, SCC_PURPLE, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
455 |
{"LTBROWN", EmitSingleChar, SCC_LTBROWN, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
456 |
{"ORANGE", EmitSingleChar, SCC_ORANGE, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
457 |
{"GREEN", EmitSingleChar, SCC_GREEN, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
458 |
{"YELLOW", EmitSingleChar, SCC_YELLOW, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
459 |
{"DKGREEN", EmitSingleChar, SCC_DKGREEN, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
460 |
{"CREAM", EmitSingleChar, SCC_CREAM, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
461 |
{"BROWN", EmitSingleChar, SCC_BROWN, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
462 |
{"WHITE", EmitSingleChar, SCC_WHITE, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
463 |
{"LTBLUE", EmitSingleChar, SCC_LTBLUE, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
464 |
{"GRAY", EmitSingleChar, SCC_GRAY, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
465 |
{"DKBLUE", EmitSingleChar, SCC_DKBLUE, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
466 |
{"BLACK", EmitSingleChar, SCC_BLACK, 0, 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
|
467 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
468 |
{"CURRCOMPACT", EmitSingleChar, SCC_CURRENCY_COMPACT, 1, 0}, // compact currency (32 bits) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
469 |
{"REV", EmitSingleChar, SCC_REVISION, 0, 0}, // openttd revision string |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
470 |
{"SHORTCARGO", EmitSingleChar, SCC_CARGO_SHORT, 2, 0}, // short cargo description, only ### tons, or ### litres |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
471 |
{"CURRCOMPACT64", EmitSingleChar, SCC_CURRENCY_COMPACT_64, 2, 0}, // compact currency 64 bits |
0 | 472 |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
473 |
// These are special versions of {STRING1} |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
474 |
// The first string includes the second string. |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
475 |
{"COMPANY", EmitSingleChar, SCC_STRING1, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
476 |
{"PLAYERNAME", EmitSingleChar, SCC_STRING1, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
477 |
{"VEHICLE", EmitSingleChar, SCC_STRING1, 1, 0}, |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
478 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
479 |
{"STRING1", EmitSingleChar, SCC_STRING1, 1, C_CASE}, // included string that consumes ONE argument |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
480 |
{"STRING2", EmitSingleChar, SCC_STRING2, 2, C_CASE}, // included string that consumes TWO arguments |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
481 |
{"STRING3", EmitSingleChar, SCC_STRING3, 3, C_CASE}, // included string that consumes THREE arguments |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
482 |
{"STRING4", EmitSingleChar, SCC_STRING4, 4, C_CASE}, // included string that consumes FOUR arguments |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
483 |
{"STRING5", EmitSingleChar, SCC_STRING5, 5, C_CASE}, // included string that consumes FIVE arguments |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
484 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
485 |
{"STATIONFEATURES", EmitSingleChar, SCC_STATION_FEATURES, 1, 0}, // station features string, icons of the features |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
486 |
{"INDUSTRY", EmitSingleChar, SCC_INDUSTRY_NAME, 1, 0}, // industry, takes an industry # |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
487 |
{"CARGO", EmitSingleChar, SCC_CARGO, 2, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
488 |
{"POWER", EmitSingleChar, SCC_POWER, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
489 |
{"VOLUME", EmitSingleChar, SCC_VOLUME, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
490 |
{"VOLUME_S", EmitSingleChar, SCC_VOLUME_SHORT, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
491 |
{"WEIGHT", EmitSingleChar, SCC_WEIGHT, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
492 |
{"WEIGHT_S", EmitSingleChar, SCC_WEIGHT_SHORT, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
493 |
{"FORCE", EmitSingleChar, SCC_FORCE, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
494 |
{"VELOCITY", EmitSingleChar, SCC_VELOCITY, 1, 0}, |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
495 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4379
diff
changeset
|
496 |
{"P", EmitPlural, 0, 0, C_DONTCOUNT}, // plural specifier |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4379
diff
changeset
|
497 |
{"G", EmitGender, 0, 0, C_DONTCOUNT}, // gender specifier |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
498 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
499 |
{"DATE_TINY", EmitSingleChar, SCC_DATE_TINY, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
500 |
{"DATE_SHORT", EmitSingleChar, SCC_DATE_SHORT, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
501 |
{"DATE_LONG", EmitSingleChar, SCC_DATE_LONG, 1, 0}, |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
502 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
503 |
{"SKIP", EmitSingleChar, SCC_SKIP, 1, 0}, |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
504 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
505 |
{"STRING", EmitSingleChar, SCC_STRING, 1, C_CASE}, |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
506 |
|
2410
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2407
diff
changeset
|
507 |
// Numbers |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
508 |
{"COMMA", EmitSingleChar, SCC_COMMA, 1, 0}, // Number with comma |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
509 |
{"NUM", EmitSingleChar, SCC_NUM, 1, 0}, // Signed number |
2410
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2407
diff
changeset
|
510 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
511 |
{"CURRENCY", EmitSingleChar, SCC_CURRENCY, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
512 |
{"CURRENCY64", EmitSingleChar, SCC_CURRENCY_64, 2, 0}, |
2410
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2407
diff
changeset
|
513 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
514 |
{"WAYPOINT", EmitSingleChar, SCC_WAYPOINT_NAME, 1, 0}, // waypoint name |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
515 |
{"STATION", EmitSingleChar, SCC_STATION_NAME, 1, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
516 |
{"TOWN", EmitSingleChar, SCC_TOWN_NAME, 1, 0}, |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
517 |
|
2087 | 518 |
// 0x9D is used for the pseudo command SETCASE |
519 |
// 0x9E is used for case switching |
|
520 |
||
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
521 |
{"", EmitSingleChar, '\n', 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
522 |
{"{", EmitSingleChar, '{', 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
523 |
{"UPARROW", EmitSingleChar, SCC_UPARROW, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
524 |
{"SMALLUPARROW", EmitSingleChar, SCC_SMALLUPARROW, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
525 |
{"SMALLDOWNARROW", EmitSingleChar, SCC_SMALLDOWNARROW, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
526 |
{"TRAIN", EmitSingleChar, SCC_TRAIN, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
527 |
{"LORRY", EmitSingleChar, SCC_LORRY, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
528 |
{"BUS", EmitSingleChar, SCC_BUS, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
529 |
{"PLANE", EmitSingleChar, SCC_PLANE, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
530 |
{"SHIP", EmitSingleChar, SCC_SHIP, 0, 0}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
531 |
{"NBSP", EmitSingleChar, 0xA0, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
532 |
{"CENT", EmitSingleChar, 0xA2, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
533 |
{"POUNDSIGN", EmitSingleChar, 0xA3, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
534 |
{"EURO", EmitSingleChar, 0x20AC, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
535 |
{"YENSIGN", EmitSingleChar, 0xA5, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
536 |
{"COPYRIGHT", EmitSingleChar, 0xA9, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
537 |
{"DOWNARROW", EmitSingleChar, SCC_DOWNARROW, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
538 |
{"CHECKMARK", EmitSingleChar, SCC_CHECKMARK, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
539 |
{"CROSS", EmitSingleChar, SCC_CROSS, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
540 |
{"REGISTERED", EmitSingleChar, 0xAE, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
541 |
{"RIGHTARROW", EmitSingleChar, SCC_RIGHTARROW, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
542 |
{"SMALLLEFTARROW", EmitSingleChar, SCC_LESSTHAN, 0, C_DONTCOUNT}, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
543 |
{"SMALLRIGHTARROW",EmitSingleChar, SCC_GREATERTHAN, 0, C_DONTCOUNT}, |
0 | 544 |
}; |
545 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
546 |
|
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
547 |
static const CmdStruct *FindCmd(const char *s, int len) |
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
548 |
{ |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
549 |
const CmdStruct* cs; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
550 |
|
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
551 |
for (cs = _cmd_structs; cs != endof(_cmd_structs); cs++) { |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
552 |
if (strncmp(cs->cmd, s, len) == 0 && cs->cmd[len] == '\0') return cs; |
0 | 553 |
} |
554 |
return NULL; |
|
555 |
} |
|
556 |
||
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
557 |
static uint ResolveCaseName(const char *str, uint len) |
2087 | 558 |
{ |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
559 |
uint i; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
560 |
|
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
561 |
for (i = 0; i < MAX_NUM_CASES; i++) { |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
562 |
if (memcmp(_cases[i], str, len) == 0 && _cases[i][len] == 0) return i + 1; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
563 |
} |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
564 |
fatal("Invalid case-name '%s'", str); |
2087 | 565 |
} |
566 |
||
0 | 567 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
568 |
// returns NULL on eof |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
569 |
// else returns command struct |
2087 | 570 |
static const CmdStruct *ParseCommandString(const char **str, char *param, int *argno, int *casei) |
0 | 571 |
{ |
2087 | 572 |
const char *s = *str, *start; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
573 |
const CmdStruct *cmd; |
2060
9f3855e81f4b
(svn r2569) Get rid of some dubious casts and thus warnings on 64bit machines
tron
parents:
2059
diff
changeset
|
574 |
byte c; |
0 | 575 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
576 |
*argno = -1; |
2087 | 577 |
*casei = -1; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
578 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
579 |
// Scan to the next command, exit if there's no next command. |
2952 | 580 |
for (; *s != '{'; s++) { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
581 |
if (*s == '\0') return NULL; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
582 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
583 |
s++; // Skip past the { |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
584 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
585 |
if (*s >= '0' && *s <= '9') { |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
586 |
char *end; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
587 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
588 |
*argno = strtoul(s, &end, 0); |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
589 |
if (*end != ':') fatal("missing arg #"); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
590 |
s = end + 1; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
591 |
} |
0 | 592 |
|
593 |
// parse command name |
|
594 |
start = s; |
|
2087 | 595 |
do { |
0 | 596 |
c = *s++; |
2087 | 597 |
} while (c != '}' && c != ' ' && c != '=' && c != '.' && c != 0); |
0 | 598 |
|
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
599 |
cmd = FindCmd(start, s - start - 1); |
0 | 600 |
if (cmd == NULL) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
601 |
error("Undefined command '%.*s'", s - start - 1, start); |
0 | 602 |
return NULL; |
603 |
} |
|
604 |
||
2087 | 605 |
if (c == '.') { |
606 |
const char *casep = s; |
|
607 |
||
608 |
if (!(cmd->flags & C_CASE)) |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
609 |
fatal("Command '%s' can't have a case", cmd->cmd); |
2087 | 610 |
|
611 |
do c = *s++; while (c != '}' && c != ' ' && c != '\0'); |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
612 |
*casei = ResolveCaseName(casep, s - casep - 1); |
2087 | 613 |
} |
614 |
||
615 |
if (c == '\0') { |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
616 |
error("Missing } from command '%s'", start); |
2087 | 617 |
return NULL; |
618 |
} |
|
619 |
||
620 |
||
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
621 |
if (c != '}') { |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
622 |
if (c == '=') s--; |
0 | 623 |
// copy params |
624 |
start = s; |
|
2952 | 625 |
for (;;) { |
0 | 626 |
c = *s++; |
627 |
if (c == '}') break; |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
628 |
if (c == '\0') { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
629 |
error("Missing } from command '%s'", start); |
0 | 630 |
return NULL; |
631 |
} |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
632 |
if (s - start == 250) fatal("param command too long"); |
0 | 633 |
*param++ = c; |
634 |
} |
|
635 |
} |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
636 |
*param = '\0'; |
0 | 637 |
|
638 |
*str = s; |
|
639 |
||
640 |
return cmd; |
|
641 |
} |
|
642 |
||
643 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
644 |
static void HandlePragma(char *str) |
0 | 645 |
{ |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
646 |
if (!memcmp(str, "id ", 3)) { |
0 | 647 |
_next_string_id = strtoul(str + 3, NULL, 0); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
648 |
} else if (!memcmp(str, "name ", 5)) { |
0 | 649 |
ttd_strlcpy(_lang_name, str + 5, sizeof(_lang_name)); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
650 |
} else if (!memcmp(str, "ownname ", 8)) { |
0 | 651 |
ttd_strlcpy(_lang_ownname, str + 8, sizeof(_lang_ownname)); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
652 |
} else if (!memcmp(str, "isocode ", 8)) { |
1376
d4e1dd8eb7e5
(svn r1880) [Codechange] Added isocodes to langfiles and support code to strgen (Lauri Nurmi)
miham
parents:
1097
diff
changeset
|
653 |
ttd_strlcpy(_lang_isocode, str + 8, sizeof(_lang_isocode)); |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
654 |
} else if (!memcmp(str, "plural ", 7)) { |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
655 |
_lang_pluralform = atoi(str + 7); |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
656 |
if (_lang_pluralform >= lengthof(_plural_form_counts)) |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
657 |
fatal("Invalid pluralform %d", _lang_pluralform); |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
658 |
} else if (!memcmp(str, "gender ", 7)) { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
659 |
char* buf = str + 7; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
660 |
|
2952 | 661 |
for (;;) { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
662 |
const char* s = ParseWord(&buf); |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
663 |
|
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
664 |
if (s == NULL) break; |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
665 |
if (_numgenders >= MAX_NUM_GENDER) fatal("Too many genders, max %d", MAX_NUM_GENDER); |
2087 | 666 |
ttd_strlcpy(_genders[_numgenders], s, sizeof(_genders[_numgenders])); |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
667 |
_numgenders++; |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
668 |
} |
2087 | 669 |
} else if (!memcmp(str, "case ", 5)) { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
670 |
char* buf = str + 5; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
671 |
|
2952 | 672 |
for (;;) { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
673 |
const char* s = ParseWord(&buf); |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
674 |
|
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
675 |
if (s == NULL) break; |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
676 |
if (_numcases >= MAX_NUM_CASES) fatal("Too many cases, max %d", MAX_NUM_CASES); |
2087 | 677 |
ttd_strlcpy(_cases[_numcases], s, sizeof(_cases[_numcases])); |
678 |
_numcases++; |
|
679 |
} |
|
0 | 680 |
} else { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
681 |
fatal("unknown pragma '%s'", str); |
0 | 682 |
} |
683 |
} |
|
684 |
||
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
685 |
static void ExtractCommandString(ParsedCommandStruct* p, const char* s, bool warnings) |
0 | 686 |
{ |
687 |
char param[100]; |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
688 |
int argno; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
689 |
int argidx = 0; |
2087 | 690 |
int casei; |
0 | 691 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
692 |
memset(p, 0, sizeof(*p)); |
0 | 693 |
|
2952 | 694 |
for (;;) { |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
695 |
// read until next command from a. |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
696 |
const CmdStruct* ar = ParseCommandString(&s, param, &argno, &casei); |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
697 |
|
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
698 |
if (ar == NULL) break; |
0 | 699 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
700 |
// Sanity checking |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
701 |
if (argno != -1 && ar->consumes == 0) fatal("Non consumer param can't have a paramindex"); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
702 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
703 |
if (ar->consumes) { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
704 |
if (argno != -1) argidx = argno; |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
705 |
if (argidx < 0 || argidx >= lengthof(p->cmd)) fatal("invalid param idx %d", argidx); |
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
706 |
if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) fatal("duplicate param idx %d", argidx); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
707 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
708 |
p->cmd[argidx++] = ar; |
2087 | 709 |
} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
710 |
if (p->np >= lengthof(p->pairs)) fatal("too many commands in string, max %d", lengthof(p->pairs)); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
711 |
p->pairs[p->np].a = ar; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
712 |
p->pairs[p->np].v = param[0] != '\0' ? strdup(param) : ""; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
713 |
p->np++; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
714 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
715 |
} |
0 | 716 |
} |
717 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
718 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
719 |
static const CmdStruct *TranslateCmdForCompare(const CmdStruct *a) |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
720 |
{ |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
721 |
if (a == NULL) return NULL; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
722 |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
723 |
if (strcmp(a->cmd, "STRING1") == 0 || |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
724 |
strcmp(a->cmd, "STRING2") == 0 || |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
725 |
strcmp(a->cmd, "STRING3") == 0 || |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
726 |
strcmp(a->cmd, "STRING4") == 0 || |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
727 |
strcmp(a->cmd, "STRING5") == 0) { |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
728 |
return FindCmd("STRING", 6); |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
729 |
} |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
730 |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
731 |
if (strcmp(a->cmd, "SKIP") == 0) return NULL; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
732 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
733 |
return a; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
734 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
735 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
736 |
|
2069
30294fb11fc1
(svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents:
2063
diff
changeset
|
737 |
static bool CheckCommandsMatch(char *a, char *b, const char *name) |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
738 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
739 |
ParsedCommandStruct templ; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
740 |
ParsedCommandStruct lang; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
741 |
int i,j; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
742 |
bool result = true; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
743 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
744 |
ExtractCommandString(&templ, b, true); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
745 |
ExtractCommandString(&lang, a, true); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
746 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
747 |
// For each string in templ, see if we find it in lang |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
748 |
if (templ.np != lang.np) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
749 |
warning("%s: template string and language string have a different # of commands", name); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
750 |
result = false; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
751 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
752 |
|
2952 | 753 |
for (i = 0; i < templ.np; i++) { |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
754 |
// see if we find it in lang, and zero it out |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
755 |
bool found = false; |
2952 | 756 |
for (j = 0; j < lang.np; j++) { |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
757 |
if (templ.pairs[i].a == lang.pairs[j].a && |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
758 |
strcmp(templ.pairs[i].v, lang.pairs[j].v) == 0) { |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
759 |
// it was found in both. zero it out from lang so we don't find it again |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
760 |
lang.pairs[j].a = NULL; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
761 |
found = true; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
762 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
763 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
764 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
765 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
766 |
if (!found) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
767 |
warning("%s: command '%s' exists in template file but not in language file", name, templ.pairs[i].a->cmd); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
768 |
result = false; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
769 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
770 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
771 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
772 |
// if we reach here, all non consumer commands match up. |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
773 |
// Check if the non consumer commands match up also. |
2952 | 774 |
for (i = 0; i < lengthof(templ.cmd); i++) { |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
775 |
if (TranslateCmdForCompare(templ.cmd[i]) != TranslateCmdForCompare(lang.cmd[i])) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
776 |
warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i, |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
777 |
lang.cmd[i] == NULL ? "<empty>" : lang.cmd[i]->cmd, |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
778 |
templ.cmd[i] == NULL ? "<empty>" : templ.cmd[i]->cmd); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
779 |
result = false; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
780 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
781 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
782 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
783 |
return result; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
784 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
785 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
786 |
static void HandleString(char *str, bool master) |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
787 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
788 |
char *s,*t; |
2087 | 789 |
LangString *ent; |
790 |
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
|
791 |
|
0 | 792 |
if (*str == '#') { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
793 |
if (str[1] == '#' && str[2] != '#') HandlePragma(str + 2); |
0 | 794 |
return; |
795 |
} |
|
796 |
||
797 |
// Ignore comments & blank lines |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
798 |
if (*str == ';' || *str == ' ' || *str == '\0') return; |
0 | 799 |
|
800 |
s = strchr(str, ':'); |
|
801 |
if (s == NULL) { |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
802 |
error("Line has no ':' delimiter"); |
0 | 803 |
return; |
804 |
} |
|
805 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
806 |
// Trim spaces. |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
807 |
// After this str points to the command name, and s points to the command contents |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
808 |
for (t = s; t > str && (t[-1] == ' ' || t[-1] == '\t'); t--); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
809 |
*t = 0; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
810 |
s++; |
0 | 811 |
|
5111
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
812 |
/* Check string is valid UTF-8 */ |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
813 |
{ |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
814 |
const char *tmp; |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
815 |
for (tmp = s; *tmp != '\0';) { |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
816 |
size_t len = Utf8Validate(tmp); |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
817 |
if (len == 0) fatal("Invalid UTF-8 sequence in '%s'", s); |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
818 |
tmp += len; |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
819 |
} |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
820 |
} |
ee7472776a4d
(svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents:
5108
diff
changeset
|
821 |
|
2087 | 822 |
// Check if the string has a case.. |
823 |
// The syntax for cases is IDENTNAME.case |
|
824 |
casep = strchr(str, '.'); |
|
825 |
if (casep) *casep++ = 0; |
|
826 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
827 |
// Check if this string already exists.. |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
828 |
ent = HashFind(str); |
0 | 829 |
|
830 |
if (master) { |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
831 |
if (ent != NULL && casep == NULL) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
832 |
error("String name '%s' is used multiple times", str); |
0 | 833 |
return; |
834 |
} |
|
835 |
||
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
836 |
if (ent == NULL && casep != NULL) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
837 |
error("Base string name '%s' doesn't exist yet. Define it before defining a case.", str); |
0 | 838 |
return; |
839 |
} |
|
840 |
||
2087 | 841 |
if (ent == NULL) { |
842 |
if (_strings[_next_string_id]) { |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
843 |
error("String ID 0x%X for '%s' already in use by '%s'", ent, str, _strings[_next_string_id]->name); |
2087 | 844 |
return; |
845 |
} |
|
846 |
||
847 |
// Allocate a new LangString |
|
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
848 |
ent = CallocT<LangString>(1); |
2087 | 849 |
_strings[_next_string_id] = ent; |
850 |
ent->index = _next_string_id++; |
|
851 |
ent->name = strdup(str); |
|
2566
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
852 |
ent->line = _cur_line; |
2087 | 853 |
|
854 |
HashAdd(str, ent); |
|
855 |
} |
|
856 |
||
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
857 |
if (casep != NULL) { |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
858 |
Case* c = MallocT<Case>(1); |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
859 |
|
2087 | 860 |
c->caseidx = ResolveCaseName(casep, strlen(casep)); |
861 |
c->string = strdup(s); |
|
862 |
c->next = ent->english_case; |
|
863 |
ent->english_case = c; |
|
864 |
} else { |
|
865 |
ent->english = strdup(s); |
|
866 |
} |
|
867 |
||
0 | 868 |
} else { |
2087 | 869 |
if (ent == NULL) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
870 |
warning("String name '%s' does not exist in master file", str); |
0 | 871 |
return; |
872 |
} |
|
873 |
||
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
874 |
if (ent->translated && casep == NULL) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
875 |
error("String name '%s' is used multiple times", str); |
0 | 876 |
return; |
877 |
} |
|
878 |
||
2087 | 879 |
if (s[0] == ':' && s[1] == '\0' && casep == NULL) { |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
880 |
// Special syntax :: means we should just inherit the master string |
2087 | 881 |
ent->translated = strdup(ent->english); |
0 | 882 |
} else { |
2087 | 883 |
// make sure that the commands match |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
884 |
if (!CheckCommandsMatch(s, ent->english, str)) return; |
2087 | 885 |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
886 |
if (casep != NULL) { |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
887 |
Case* c = MallocT<Case>(1); |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
888 |
|
2087 | 889 |
c->caseidx = ResolveCaseName(casep, strlen(casep)); |
890 |
c->string = strdup(s); |
|
891 |
c->next = ent->translated_case; |
|
892 |
ent->translated_case = c; |
|
893 |
} else { |
|
894 |
ent->translated = strdup(s); |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
895 |
} |
0 | 896 |
} |
897 |
} |
|
898 |
} |
|
899 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
900 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
901 |
static void rstrip(char *buf) |
0 | 902 |
{ |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
903 |
int i = strlen(buf); |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
904 |
while (i > 0 && (buf[i - 1] == '\r' || buf[i - 1] == '\n' || buf[i - 1] == ' ')) i--; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
905 |
buf[i] = '\0'; |
0 | 906 |
} |
907 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
908 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
909 |
static void ParseFile(const char *file, bool english) |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
910 |
{ |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
911 |
FILE *in; |
0 | 912 |
char buf[2048]; |
913 |
||
2459
a2f63b331830
(svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents:
2418
diff
changeset
|
914 |
_file = file; |
a2f63b331830
(svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents:
2418
diff
changeset
|
915 |
|
2087 | 916 |
// For each new file we parse, reset the genders. |
917 |
_numgenders = 0; |
|
918 |
// TODO:!! We can't reset the cases. In case the translated strings |
|
919 |
// derive some strings from english.... |
|
920 |
||
921 |
||
0 | 922 |
in = fopen(file, "r"); |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
923 |
if (in == NULL) fatal("Cannot open file"); |
0 | 924 |
_cur_line = 1; |
925 |
while (fgets(buf, sizeof(buf),in) != NULL) { |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
926 |
rstrip(buf); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
927 |
HandleString(buf, english); |
0 | 928 |
_cur_line++; |
929 |
} |
|
930 |
fclose(in); |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
931 |
} |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
932 |
|
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
933 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
934 |
static uint32 MyHashStr(uint32 hash, const char *s) |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
935 |
{ |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
936 |
for (; *s != '\0'; s++) { |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
937 |
hash = ROL(hash, 3) ^ *s; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
938 |
hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
939 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
940 |
return hash; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
941 |
} |
0 | 942 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
943 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
944 |
// make a hash of the file to get a unique "version number" |
2765
8fa792b6e525
(svn r3310) Fix a couple of warnings: Initialise all struct members, disambiguate cascaded if/else, remove an unused variable, use (void) for empty parameter lists
tron
parents:
2586
diff
changeset
|
945 |
static void MakeHashOfStrings(void) |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
946 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
947 |
uint32 hash = 0; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
948 |
uint i; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
949 |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
950 |
for (i = 0; i != lengthof(_strings); i++) { |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
951 |
const LangString* ls = _strings[i]; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
952 |
|
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
953 |
if (ls != NULL) { |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
954 |
const CmdStruct* cs; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
955 |
const char* s; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
956 |
char buf[256]; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
957 |
int argno; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
958 |
int casei; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
959 |
|
2087 | 960 |
s = ls->name; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
961 |
hash ^= i * 0x717239; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
962 |
hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
963 |
hash = MyHashStr(hash, s + 1); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
964 |
|
2087 | 965 |
s = ls->english; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
966 |
while ((cs = ParseCommandString(&s, buf, &argno, &casei)) != NULL) { |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
967 |
if (cs->flags & C_DONTCOUNT) continue; |
2087 | 968 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
969 |
hash ^= (cs - _cmd_structs) * 0x1234567; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3900
diff
changeset
|
970 |
hash = (hash & 1 ? hash >> 1 ^ 0xF00BAA4 : 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
|
971 |
} |
0 | 972 |
} |
973 |
} |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
974 |
_hash = hash; |
0 | 975 |
} |
976 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
977 |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
978 |
static uint CountInUse(uint grp) |
2059
6446d0b23ddc
(svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents:
2057
diff
changeset
|
979 |
{ |
0 | 980 |
int i; |
981 |
||
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
982 |
for (i = 0x800; --i >= 0;) if (_strings[(grp << 11) + i] != NULL) break; |
0 | 983 |
return i + 1; |
984 |
} |
|
985 |
||
986 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
987 |
bool CompareFiles(const char *n1, const char *n2) |
0 | 988 |
{ |
989 |
FILE *f1, *f2; |
|
990 |
char b1[4096]; |
|
991 |
char b2[4096]; |
|
992 |
size_t l1, l2; |
|
993 |
||
994 |
f2 = fopen(n2, "rb"); |
|
995 |
if (f2 == NULL) return false; |
|
996 |
||
997 |
f1 = fopen(n1, "rb"); |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
998 |
if (f1 == NULL) fatal("can't open %s", n1); |
0 | 999 |
|
1000 |
do { |
|
1001 |
l1 = fread(b1, 1, sizeof(b1), f1); |
|
1002 |
l2 = fread(b2, 1, sizeof(b2), f2); |
|
1003 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1004 |
if (l1 != l2 || memcmp(b1, b2, l1)) { |
0 | 1005 |
fclose(f2); |
1006 |
fclose(f1); |
|
1007 |
return false; |
|
1008 |
} |
|
1009 |
} while (l1); |
|
1010 |
||
1011 |
fclose(f2); |
|
1012 |
fclose(f1); |
|
1013 |
return true; |
|
1014 |
} |
|
1015 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1016 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1017 |
static void WriteStringsH(const char *filename) |
0 | 1018 |
{ |
1019 |
FILE *out; |
|
1020 |
int i; |
|
1021 |
int next = -1; |
|
1022 |
int lastgrp; |
|
1023 |
||
1024 |
out = fopen("tmp.xxx", "w"); |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
1025 |
if (out == NULL) fatal("can't open tmp.xxx"); |
0 | 1026 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1027 |
fprintf(out, "enum StringIdEnum {"); |
0 | 1028 |
|
1029 |
lastgrp = 0; |
|
1030 |
||
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1031 |
for (i = 0; i != lengthof(_strings); i++) { |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1032 |
if (_strings[i] != NULL) { |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1033 |
fprintf(out, next == i ? "\t%s,\n" : "\n\t%s = 0x%X,\n", _strings[i]->name, i); |
0 | 1034 |
next = i + 1; |
1035 |
} |
|
1036 |
} |
|
1037 |
||
1038 |
fprintf(out, "};\n"); |
|
1039 |
||
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
|
1040 |
fprintf(out, |
0 | 1041 |
"\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
|
1042 |
"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n" |
0 | 1043 |
"\tLANGUAGE_PACK_VERSION = 0x%X,\n" |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1044 |
"};\n", (uint)_hash |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1045 |
); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1046 |
|
0 | 1047 |
fclose(out); |
1048 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1049 |
if (CompareFiles("tmp.xxx", filename)) { |
0 | 1050 |
// files are equal. tmp.xxx is not needed |
1051 |
unlink("tmp.xxx"); |
|
1052 |
} else { |
|
1053 |
// else rename tmp.xxx into filename |
|
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2459
diff
changeset
|
1054 |
#if defined(WIN32) || defined(WIN64) |
0 | 1055 |
unlink(filename); |
1056 |
#endif |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
1057 |
if (rename("tmp.xxx", filename) == -1) fatal("rename() failed"); |
0 | 1058 |
} |
1059 |
} |
|
1060 |
||
2087 | 1061 |
static int TranslateArgumentIdx(int argidx) |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1062 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1063 |
int i, sum; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1064 |
|
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1065 |
if (argidx < 0 || argidx >= lengthof(_cur_pcs.cmd)) |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
1066 |
fatal("invalid argidx %d", argidx); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1067 |
|
2952 | 1068 |
for (i = sum = 0; i < argidx; i++) { |
2374
e4443eab6293
(svn r2900) Fix a bug, which incremented the counter of a loop twice and therefore calculated wrong argument indices
tron
parents:
2353
diff
changeset
|
1069 |
const CmdStruct *cs = _cur_pcs.cmd[i]; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1070 |
sum += (cs != NULL) ? cs->consumes : 1; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1071 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1072 |
|
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1073 |
return sum; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1074 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1075 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1076 |
static void PutArgidxCommand(void) |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1077 |
{ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
1078 |
PutUtf8(SCC_ARG_INDEX); |
2087 | 1079 |
PutByte(TranslateArgumentIdx(_cur_argidx)); |
1080 |
} |
|
1081 |
||
1082 |
||
1083 |
static void PutCommandString(const char *str) |
|
1084 |
{ |
|
1085 |
const CmdStruct *cs; |
|
1086 |
char param[256]; |
|
1087 |
int argno; |
|
1088 |
int casei; |
|
1089 |
||
1090 |
_cur_argidx = 0; |
|
1091 |
||
1092 |
while (*str != '\0') { |
|
1093 |
// Process characters as they are until we encounter a { |
|
1094 |
if (*str != '{') { |
|
1095 |
PutByte(*str++); |
|
1096 |
continue; |
|
1097 |
} |
|
1098 |
cs = ParseCommandString(&str, param, &argno, &casei); |
|
1099 |
if (cs == NULL) break; |
|
1100 |
||
1101 |
if (casei != -1) { |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
1102 |
PutUtf8(SCC_SETCASE); // {SETCASE} |
2087 | 1103 |
PutByte(casei); |
1104 |
} |
|
1105 |
||
1106 |
// For params that consume values, we need to handle the argindex properly |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1107 |
if (cs->consumes > 0) { |
2087 | 1108 |
// Check if we need to output a move-param command |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1109 |
if (argno != -1 && argno != _cur_argidx) { |
2087 | 1110 |
_cur_argidx = argno; |
1111 |
PutArgidxCommand(); |
|
1112 |
} |
|
1113 |
||
1114 |
// Output the one from the master string... it's always accurate. |
|
1115 |
cs = _cur_pcs.cmd[_cur_argidx++]; |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1116 |
if (cs == NULL) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
1117 |
fatal("%s: No argument exists at position %d", _cur_ident, _cur_argidx - 1); |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1118 |
} |
2087 | 1119 |
} |
1120 |
||
1121 |
cs->proc(param, cs->value); |
|
1122 |
} |
|
1123 |
} |
|
1124 |
||
1125 |
static void WriteLength(FILE *f, uint length) |
|
1126 |
{ |
|
1127 |
if (length < 0xC0) { |
|
1128 |
fputc(length, f); |
|
1129 |
} else if (length < 0x4000) { |
|
1130 |
fputc((length >> 8) | 0xC0, f); |
|
1131 |
fputc(length & 0xFF, f); |
|
1132 |
} else { |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
1133 |
fatal("string too long"); |
2087 | 1134 |
} |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1135 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1136 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1137 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1138 |
static void WriteLangfile(const char *filename, int show_todo) |
0 | 1139 |
{ |
1140 |
FILE *f; |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1141 |
uint in_use[32]; |
0 | 1142 |
LanguagePackHeader hdr; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1143 |
uint i; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1144 |
uint j; |
0 | 1145 |
|
1146 |
f = fopen(filename, "wb"); |
|
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
1147 |
if (f == NULL) fatal("can't open %s", filename); |
0 | 1148 |
|
1149 |
memset(&hdr, 0, sizeof(hdr)); |
|
2952 | 1150 |
for (i = 0; i != 32; i++) { |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1151 |
uint n = CountInUse(i); |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1152 |
|
0 | 1153 |
in_use[i] = n; |
1154 |
hdr.offsets[i] = TO_LE16(n); |
|
1155 |
} |
|
1156 |
||
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
|
1157 |
// 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
|
1158 |
hdr.ident = TO_LE32(0x474E414C); // Big Endian value for 'LANG' |
0 | 1159 |
hdr.version = TO_LE32(_hash); |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1160 |
hdr.plural_form = _lang_pluralform; |
0 | 1161 |
strcpy(hdr.name, _lang_name); |
1162 |
strcpy(hdr.own_name, _lang_ownname); |
|
1376
d4e1dd8eb7e5
(svn r1880) [Codechange] Added isocodes to langfiles and support code to strgen (Lauri Nurmi)
miham
parents:
1097
diff
changeset
|
1163 |
strcpy(hdr.isocode, _lang_isocode); |
0 | 1164 |
|
1165 |
fwrite(&hdr, sizeof(hdr), 1, f); |
|
1166 |
||
2952 | 1167 |
for (i = 0; i != 32; i++) { |
1168 |
for (j = 0; j != in_use[i]; j++) { |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1169 |
const LangString* ls = _strings[(i << 11) + j]; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1170 |
const Case* casep; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1171 |
const char* cmdp; |
0 | 1172 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1173 |
// For undefined strings, just set that it's an empty string |
2087 | 1174 |
if (ls == NULL) { |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1175 |
WriteLength(f, 0); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1176 |
continue; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1177 |
} |
0 | 1178 |
|
2087 | 1179 |
_cur_ident = ls->name; |
2566
75ae28a03460
(svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents:
2482
diff
changeset
|
1180 |
_cur_line = ls->line; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2069
diff
changeset
|
1181 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1182 |
// Produce a message if a string doesn't have a translation. |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1183 |
if (show_todo > 0 && ls->translated == NULL) { |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1184 |
if (show_todo == 2) { |
4922
dec2c076d5a7
(svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents:
4464
diff
changeset
|
1185 |
warning("'%s' is untranslated", ls->name); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1186 |
} else { |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1187 |
const char *s = "<TODO> "; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1188 |
while (*s != '\0') PutByte(*s++); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1189 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1190 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1191 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1192 |
// Extract the strings and stuff from the english command string |
2087 | 1193 |
ExtractCommandString(&_cur_pcs, ls->english, false); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1194 |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1195 |
if (ls->translated_case != NULL || ls->translated != NULL) { |
2087 | 1196 |
casep = ls->translated_case; |
1197 |
cmdp = ls->translated; |
|
1198 |
} else { |
|
1199 |
casep = ls->english_case; |
|
1200 |
cmdp = ls->english; |
|
1201 |
} |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1202 |
|
2586
1c0f0b67a70d
(svn r3123) eh, don't press enter after typing text, previous patch wasn't finished. Now strgen really behaves correctly. Thanks again glx
Darkvater
parents:
2585
diff
changeset
|
1203 |
_translated = _masterlang || (cmdp != ls->english); |
2585
fa2f94aa9de2
(svn r3122) - Fix (regression): recent change to strgen which 'fixed' all strings with wrong plural forms. Thanks for glx for pointing this out (after I changed his original patch which was correct..whohoo braindeadness; here I come)
Darkvater
parents:
2566
diff
changeset
|
1204 |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1205 |
if (casep != NULL) { |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1206 |
const Case* c; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1207 |
uint num; |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1208 |
|
2087 | 1209 |
// Need to output a case-switch. |
1210 |
// It has this format |
|
1211 |
// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT> |
|
1212 |
// Each LEN is printed using 2 bytes in big endian order. |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4922
diff
changeset
|
1213 |
PutUtf8(SCC_SWITCH_CASE); |
2087 | 1214 |
// Count the number of cases |
2952 | 1215 |
for (num = 0, c = casep; c; c = c->next) num++; |
2087 | 1216 |
PutByte(num); |
1217 |
||
1218 |
// Write each case |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1219 |
for (c = casep; c != NULL; c = c->next) { |
2087 | 1220 |
int pos; |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1221 |
|
2087 | 1222 |
PutByte(c->caseidx); |
1223 |
// Make some space for the 16-bit length |
|
1224 |
pos = _put_pos; |
|
1225 |
PutByte(0); |
|
1226 |
PutByte(0); |
|
1227 |
// Write string |
|
1228 |
PutCommandString(c->string); |
|
1229 |
PutByte(0); // terminate with a zero |
|
1230 |
// Fill in the length |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1231 |
_put_buf[pos + 0] = GB(_put_pos - (pos + 2), 8, 8); |
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1232 |
_put_buf[pos + 1] = GB(_put_pos - (pos + 2), 0, 8); |
0 | 1233 |
} |
2087 | 1234 |
} |
0 | 1235 |
|
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1236 |
if (cmdp != NULL) PutCommandString(cmdp); |
0 | 1237 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1238 |
WriteLength(f, _put_pos); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1239 |
fwrite(_put_buf, 1, _put_pos, f); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1240 |
_put_pos = 0; |
0 | 1241 |
} |
1242 |
} |
|
1243 |
||
1244 |
fputc(0, f); |
|
1245 |
fclose(f); |
|
1246 |
} |
|
1247 |
||
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1248 |
/** Multi-OS mkdirectory function */ |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1249 |
static inline void ottd_mkdir(const char *directory) |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1250 |
{ |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1251 |
#if defined(WIN32) || defined(__WATCOMC__) |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1252 |
mkdir(directory); |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1253 |
#else |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1254 |
mkdir(directory, 0755); |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1255 |
#endif |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1256 |
} |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1257 |
|
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1258 |
/** Create a path consisting of an already existing path, a possible |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1259 |
* path seperator and the filename. The seperator is only appended if the path |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1260 |
* does not already end with a seperator */ |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1261 |
static inline char *mkpath(char *buf, size_t buflen, const char *path, const char *file) |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1262 |
{ |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1263 |
char *p; |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1264 |
ttd_strlcpy(buf, path, buflen); // copy directory into buffer |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1265 |
|
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1266 |
p = strchr(buf, '\0'); // add path seperator if necessary |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1267 |
if (p[-1] != PATHSEPCHAR && (size_t)(p - buf) + 1 < buflen) *p++ = PATHSEPCHAR; |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1268 |
ttd_strlcpy(p, file, buflen - (size_t)(p - buf)); // catenate filename at end of buffer |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1269 |
return buf; |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1270 |
} |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1271 |
|
5503
036e83e9083a
(svn r7796) -Fix (r7759): cygwin does not need to rewrite the paths for strgen.
rubidium
parents:
5475
diff
changeset
|
1272 |
#if defined(__MINGW32__) |
4379
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1273 |
/** |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1274 |
* On MingW, it is common that both / as \ are accepted in the |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1275 |
* params. To go with those flow, we rewrite all incoming / |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1276 |
* simply to \, so internally we can safely assume \. |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1277 |
*/ |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1278 |
static inline char *replace_pathsep(char *s) |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1279 |
{ |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1280 |
char *c; |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1281 |
|
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1282 |
for (c = s; *c != '\0'; c++) if (*c == '/') *c = '\\'; |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1283 |
return s; |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1284 |
} |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1285 |
#else |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1286 |
static inline char *replace_pathsep(char *s) { return s; } |
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1287 |
#endif |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1288 |
|
250
733e18ca6e93
(svn r251) -Project ready for 0.3.4 release. Updated installer, readme and fileinformation
darkvater
parents:
236
diff
changeset
|
1289 |
int CDECL main(int argc, char* argv[]) |
0 | 1290 |
{ |
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1291 |
char pathbuf[256]; |
4461
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1292 |
const char *src_dir = "."; |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1293 |
const char *dest_dir = NULL; |
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1294 |
|
0 | 1295 |
int show_todo = 0; |
1296 |
||
4461
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1297 |
while (argc > 1 && *argv[1] == '-') { |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1298 |
if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) { |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1299 |
puts("$Revision$"); |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1300 |
return 0; |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1301 |
} |
0 | 1302 |
|
4461
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1303 |
if (strcmp(argv[1], "-t") == 0 || strcmp(argv[1], "--todo") == 0) { |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1304 |
show_todo = 1; |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1305 |
argc--, argv++; |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1306 |
continue; |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1307 |
} |
0 | 1308 |
|
4461
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1309 |
if (strcmp(argv[1], "-w") == 0 || strcmp(argv[1], "--warning") == 0) { |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1310 |
show_todo = 2; |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1311 |
argc--, argv++; |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1312 |
continue; |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1313 |
} |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1314 |
|
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1315 |
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) { |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1316 |
puts( |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1317 |
"strgen - $Revision$\n" |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1318 |
" -v | --version print version information and exit\n" |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1319 |
" -t | --todo replace any untranslated strings with '<TODO>'\n" |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1320 |
" -w | --warning print a warning for any untranslated strings\n" |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1321 |
" -h | -? | --help print this help message and exit\n" |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1322 |
" -s | --source_dir search for english.txt in the specified directory\n" |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1323 |
" -d | --dest_dir put output file in the specified directory, create if needed\n" |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1324 |
" Run without parameters and strgen will search for english.txt and parse it,\n" |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1325 |
" creating strings.h. Passing an argument, strgen will translate that language\n" |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1326 |
" file using english.txt as a reference and output <language>.lng." |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1327 |
); |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1328 |
return 0; |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1329 |
} |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1330 |
|
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1331 |
if (argc > 2 && (strcmp(argv[1], "-s") == 0 || strcmp(argv[1], "--source_dir") == 0)) { |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1332 |
src_dir = replace_pathsep(argv[2]); |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1333 |
argc -= 2, argv += 2; |
4464
08e89a8faa09
(svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents:
4461
diff
changeset
|
1334 |
continue; |
4461
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1335 |
} |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1336 |
|
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1337 |
if (argc > 2 && (strcmp(argv[1], "-d") == 0 || strcmp(argv[1], "--dest_dir") == 0)) { |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1338 |
dest_dir = replace_pathsep(argv[2]); |
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1339 |
argc -= 2, argv += 2; |
4464
08e89a8faa09
(svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents:
4461
diff
changeset
|
1340 |
continue; |
4461
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1341 |
} |
4464
08e89a8faa09
(svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents:
4461
diff
changeset
|
1342 |
|
08e89a8faa09
(svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents:
4461
diff
changeset
|
1343 |
fprintf(stderr, "Invalid arguments\n"); |
08e89a8faa09
(svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents:
4461
diff
changeset
|
1344 |
return 0; |
0 | 1345 |
} |
1346 |
||
4461
905cb9ca6fe5
(svn r6244) -Fix: allow any order for strgen parameters
glx
parents:
4447
diff
changeset
|
1347 |
if (dest_dir == NULL) dest_dir = src_dir; // if dest_dir is not specified, it equals src_dir |
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1348 |
|
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1349 |
/* strgen has two modes of operation. If no (free) arguments are passed |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1350 |
* strgen generates strings.h to the destination directory. If it is supplied |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1351 |
* with a (free) parameter the program will translate that language to destination |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1352 |
* directory. As input english.txt is parsed from the source directory */ |
0 | 1353 |
if (argc == 1) { |
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1354 |
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt"); |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1355 |
|
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1356 |
/* parse master file */ |
2586
1c0f0b67a70d
(svn r3123) eh, don't press enter after typing text, previous patch wasn't finished. Now strgen really behaves correctly. Thanks again glx
Darkvater
parents:
2585
diff
changeset
|
1357 |
_masterlang = true; |
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1358 |
ParseFile(pathbuf, true); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1359 |
MakeHashOfStrings(); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1360 |
if (_errors) return 1; |
0 | 1361 |
|
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1362 |
/* write strings.h */ |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1363 |
ottd_mkdir(dest_dir); |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1364 |
mkpath(pathbuf, lengthof(pathbuf), dest_dir, "strings.h"); |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1365 |
WriteStringsH(pathbuf); |
3015
f91a1b8fba79
(svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents:
2952
diff
changeset
|
1366 |
} else if (argc == 2) { |
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1367 |
char *r; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1368 |
|
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1369 |
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt"); |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1370 |
|
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1371 |
/* parse master file and check if target file is correct */ |
2586
1c0f0b67a70d
(svn r3123) eh, don't press enter after typing text, previous patch wasn't finished. Now strgen really behaves correctly. Thanks again glx
Darkvater
parents:
2585
diff
changeset
|
1372 |
_masterlang = false; |
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1373 |
ParseFile(pathbuf, true); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1374 |
MakeHashOfStrings(); |
4379
96eb926dcc1d
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents:
4373
diff
changeset
|
1375 |
ParseFile(replace_pathsep(argv[1]), false); // target file |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1376 |
if (_errors) return 1; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2060
diff
changeset
|
1377 |
|
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1378 |
/* get the targetfile, strip any directories and append to destination path */ |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1379 |
r = strrchr(argv[1], PATHSEPCHAR); |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1380 |
mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : argv[1]); |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1381 |
|
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1382 |
/* rename the .txt (input-extension) to .lng */ |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1383 |
r = strrchr(pathbuf, '.'); |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1384 |
if (r == NULL || strcmp(r, ".txt") != 0) r = strchr(pathbuf, '\0'); |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1385 |
ttd_strlcpy(r, ".lng", (size_t)(r - pathbuf)); |
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1386 |
WriteLangfile(pathbuf, show_todo); |
5360
d87dfdb62e5a
(svn r7540) -Codechange: Print a summary of the number of errors/warnings of a language when strgen is run with the -w flag.
Darkvater
parents:
5111
diff
changeset
|
1387 |
|
d87dfdb62e5a
(svn r7540) -Codechange: Print a summary of the number of errors/warnings of a language when strgen is run with the -w flag.
Darkvater
parents:
5111
diff
changeset
|
1388 |
/* if showing warnings, print a summary of the language */ |
d87dfdb62e5a
(svn r7540) -Codechange: Print a summary of the number of errors/warnings of a language when strgen is run with the -w flag.
Darkvater
parents:
5111
diff
changeset
|
1389 |
if (show_todo == 2) { |
5442
577bf6b7da95
(svn r7693) -Codechange (r7540): print a newline after the summary (strgen).
Darkvater
parents:
5360
diff
changeset
|
1390 |
fprintf(stdout, "%d warnings and %d errors for %s\n", _warnings, _errors, pathbuf); |
5360
d87dfdb62e5a
(svn r7540) -Codechange: Print a summary of the number of errors/warnings of a language when strgen is run with the -w flag.
Darkvater
parents:
5111
diff
changeset
|
1391 |
} |
0 | 1392 |
} else { |
4370
5beb8896ae3d
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents:
4344
diff
changeset
|
1393 |
fprintf(stderr, "Invalid arguments\n"); |
0 | 1394 |
} |
1395 |
||
1396 |
return 0; |
|
1397 |
} |