strgen/strgen.c
author peter1138
Mon, 23 Oct 2006 18:45:43 +0000
changeset 4930 708801d486c6
parent 4922 dec2c076d5a7
child 5108 aeaef6fe53b7
permissions -rw-r--r--
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2107
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2107
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     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"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include <stdio.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include <string.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include <stdlib.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
2482
374f6395847d (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2459
diff changeset
    11
#if (!defined(WIN32) && !defined(WIN64)) || defined(__CYGWIN__)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include <unistd.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    15
#if defined WIN32 || defined __WATCOMC__
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    16
#include <direct.h>
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    17
#endif /* WIN32 || __WATCOMC__ */
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    18
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
    19
#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
    20
#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
    21
#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
    22
#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
    23
#define stderr stdout
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    24
#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
    25
3395
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3342
diff changeset
    26
#ifdef __WATCOMC__
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3342
diff changeset
    27
	uint _map_log_x;     // an unpleasant hack required because Watcom is insisting on
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3342
diff changeset
    28
	uint _map_size_x;    // these variables being valid references in map.h
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3342
diff changeset
    29
	uint _map_size_y;
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3342
diff changeset
    30
	uint _map_tile_mask;
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3342
diff changeset
    31
	uint _map_size;
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    32
#endif /* __WATCOMC__ */
3395
edfd22fd92c9 (svn r4204) - Get trunk compiling again on OS/2
orudge
parents: 3342
diff changeset
    33
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
/* Compiles a list of strings into a compiled string list */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
typedef void (*ParseCmdProc)(char *buf, int value);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
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
    38
typedef struct LanguagePackHeader {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
	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
    40
	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
    41
	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
    42
	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
    43
	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
    44
	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
    45
	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
    46
	byte pad[3];        // pad header to be a multiple of 4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
} LanguagePackHeader;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
typedef struct CmdStruct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	const char *cmd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	ParseCmdProc proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	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
    53
	int8 consumes;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    54
	byte flags;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
} CmdStruct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    57
enum {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    58
	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
    59
	C_CASE      = 2,
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    60
};
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    61
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    62
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    63
typedef struct Case {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    64
	int caseidx;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    65
	char *string;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    66
	struct Case *next;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    67
} Case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    68
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
    69
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
    70
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
    71
static const char* _file = "(unknown file)";
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
    72
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
    73
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
    74
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    75
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
    76
	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
    77
	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
    78
	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
    79
	uint16 hash_next;      // next hash entry
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    80
	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
    81
	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
    82
	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
    83
	Case *translated_case; // cases for foreign
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    84
} LangString;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    85
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    86
static LangString *_strings[65536];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    87
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    88
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    89
#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
    90
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
    91
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    92
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
    93
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
    94
static int _next_string_id;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
    96
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
    97
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
    98
static byte _lang_pluralform;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    99
#define MAX_NUM_GENDER 8
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   100
static char _genders[MAX_NUM_GENDER][8];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   101
static int _numgenders;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   103
// contains the name of all cases.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   104
#define MAX_NUM_CASES 50
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   105
static char _cases[MAX_NUM_CASES][16];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   106
static int _numcases;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   107
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   108
// 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
   109
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
   110
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   111
static const char *_cur_ident;
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   112
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   113
typedef struct CmdPair {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   114
	const CmdStruct *a;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   115
	char *v;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   116
} CmdPair;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   117
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   118
typedef struct ParsedCommandStruct {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   119
	int np;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   120
	CmdPair pairs[32];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   121
	const CmdStruct *cmd[32]; // ordered by param #
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   122
} ParsedCommandStruct;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   123
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   124
// Used when generating some advanced commands.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   125
static ParsedCommandStruct _cur_pcs;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   126
static int _cur_argidx;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   127
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   128
static uint HashStr(const char *s)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   129
{
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   130
	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
   131
	for (; *s != '\0'; s++) hash = ROL(hash, 3) ^ *s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
	return hash % HASH_SIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
}
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   134
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   135
static void HashAdd(const char *s, LangString *ls)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   136
{
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   137
	uint hash = HashStr(s);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   138
	ls->hash_next = _hash_head[hash];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   139
	_hash_head[hash] = ls->index + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   142
static LangString *HashFind(const char *s)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   143
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   144
	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
   145
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   146
	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
   147
		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
   148
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
		if (strcmp(ls->name, s) == 0) return ls;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   150
		idx = ls->hash_next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
	}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   152
	return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   155
#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
   156
# 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
   157
#else
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   158
# 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
   159
#endif
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   160
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   161
static void CDECL warning(const char *s, ...)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   162
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
	va_start(va, s);
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
   166
	vsnprintf(buf, lengthof(buf), s, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
	va_end(va);
4447
486395ec1e06 (svn r6225) -Codechange: change the warning/error format of strgen to show up
Darkvater
parents: 4434
diff changeset
   168
	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
   169
	_warnings++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   172
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
   173
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   174
	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
   175
	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
   176
	va_start(va, s);
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
   177
	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
   178
	va_end(va);
4447
486395ec1e06 (svn r6225) -Codechange: change the warning/error format of strgen to show up
Darkvater
parents: 4434
diff changeset
   179
	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
   180
	_errors++;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   181
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   182
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   183
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   184
static void NORETURN CDECL fatal(const char *s, ...)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   185
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	va_start(va, s);
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
   189
	vsnprintf(buf, lengthof(buf), s, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
	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
   191
	fprintf(stderr, "%s" LINE_NUM_FMT ": FATAL: %s\n", _file, _cur_line, buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	exit(1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   195
static void PutByte(byte c)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   196
{
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   197
	if (_put_pos == lengthof(_put_buf)) fatal("Put buffer too small");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	_put_buf[_put_pos++] = c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   202
static void EmitSingleByte(char *buf, int value)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   203
{
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   204
	if (*buf != '\0') warning("Ignoring trailing letters in command");
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   205
	PutByte((byte)value);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   209
static void EmitEscapedByte(char *buf, int value)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   210
{
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   211
	if (*buf != '\0') warning("Ignoring trailing letters in 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
   212
	PutByte(0x85);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   213
	PutByte((byte)value);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   214
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   216
static void EmitSetX(char *buf, int value)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   217
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	char *err;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
	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
   220
	if (*err != 0) fatal("SetX param invalid");
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   221
	PutByte(1);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   222
	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
   223
}
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   224
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   226
static void EmitSetXY(char *buf, int value)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   227
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	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
   229
	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
   230
	int y;
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   231
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   232
	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
   233
	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
   234
	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
   235
	if (*err != 0) fatal("SetXY param invalid");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   237
	PutByte(2);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   238
	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
   239
	PutByte((byte)y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   242
// The plural specifier looks like
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   243
// {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
   244
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   245
// This is encoded like
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   246
//  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
   247
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   248
bool ParseRelNum(char **buf, int *value)
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   249
{
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
   250
	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
   251
	char* end;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   252
	bool rel = false;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   253
	int v;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   254
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   255
	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
   256
	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
   257
		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
   258
		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
   259
	}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   260
	v = strtol(s, &end, 0);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   261
	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
   262
	if (rel || v < 0) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   263
		*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
   264
	} else {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   265
		*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
   266
	}
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   267
	*buf = end;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   268
	return true;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   269
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   270
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   271
// Parse out the next word, or NULL
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   272
char *ParseWord(char **buf)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   273
{
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   274
	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
   275
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   276
	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
   277
	if (*s == '\0') return NULL;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   278
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   279
	if (*s == '"') {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   280
		r = ++s;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   281
		// parse until next " or NUL
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   282
		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
   283
			if (*s == '\0') break;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   284
			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
   285
				*s++ = '\0';
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   286
				break;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   287
			}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   288
			s++;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   289
		}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   290
	} else {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   291
		// proceed until whitespace or NUL
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   292
		r = s;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   293
		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
   294
			if (*s == '\0') break;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   295
			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
   296
				*s++ = '\0';
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   297
				break;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   298
			}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   299
			s++;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   300
		}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   301
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   302
	*buf = s;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   303
	return r;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   304
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   305
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   306
// Forward declaration
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   307
static int TranslateArgumentIdx(int arg);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   308
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
   309
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
   310
{
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
   311
	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
   312
	uint j;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   313
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   314
	PutByte(nw);
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   315
	for (i = 0; i < nw; i++) PutByte(strlen(words[i]));
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   316
	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
   317
		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
   318
	}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   319
}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   320
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   321
static void EmitPlural(char *buf, int value)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   322
{
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   323
	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
   324
	const char* words[5];
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   325
	int nw = 0;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   326
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   327
	// 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
   328
	if (!ParseRelNum(&buf, &argidx)) argidx--;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   329
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   330
	// 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
   331
	for (nw = 0; nw < 5; nw++) {
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   332
		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
   333
		if (words[nw] == NULL) break;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   334
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   335
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   336
	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
   337
		fatal("%s: No plural words", _cur_ident);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   338
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
   339
	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
   340
		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
   341
			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
   342
				_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
   343
		} else {
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   344
			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
   345
			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
   346
				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
   347
			} else {
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   348
				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
   349
					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
   350
				}
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
   351
			}
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
   352
		}
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
   353
	}
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   354
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
   355
	PutByte(0x8D);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   356
	PutByte(TranslateArgumentIdx(argidx));
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   357
	EmitWordList(words, nw);
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   358
}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   359
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   360
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   361
static void EmitGender(char *buf, int value)
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   362
{
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   363
	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
   364
	uint nw;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   365
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   366
	if (buf[0] == '=') {
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   367
		buf++;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   368
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   369
		// This is a {G=DER} command
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   370
		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
   371
			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
   372
			if (strcmp(buf, _genders[nw]) == 0) break;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   373
		}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   374
		// now nw contains the gender index
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   375
		PutByte(0x87);
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   376
		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
   377
	} 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
   378
		const char* words[8];
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   379
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   380
		// This is a {G 0 foo bar two} command.
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   381
		// If no relative number exists, default to +0
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   382
		if (!ParseRelNum(&buf, &argidx)) {}
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   383
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   384
		for (nw = 0; nw < 8; nw++) {
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   385
			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
   386
			if (words[nw] == NULL) break;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   387
		}
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   388
		if (nw != _numgenders) fatal("Bad # of arguments for gender command");
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   389
		PutByte(0x85);
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   390
		PutByte(13);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   391
		PutByte(TranslateArgumentIdx(argidx));
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   392
		EmitWordList(words, nw);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   393
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   394
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   395
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   396
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
static const CmdStruct _cmd_structs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
	// Update position
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
   399
	{"SETX",  EmitSetX,  1, 0, 0},
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
   400
	{"SETXY", EmitSetXY, 2, 0, 0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
	// Font size
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
   403
	{"TINYFONT", EmitSingleByte, 8, 0, 0},
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
   404
	{"BIGFONT",  EmitSingleByte, 9, 0, 0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
	// Colors
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
   407
	{"BLUE",    EmitSingleByte, 15, 0, 0},
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
   408
	{"SILVER",  EmitSingleByte, 16, 0, 0},
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
   409
	{"GOLD",    EmitSingleByte, 17, 0, 0},
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
   410
	{"RED",     EmitSingleByte, 18, 0, 0},
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
   411
	{"PURPLE",  EmitSingleByte, 19, 0, 0},
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
   412
	{"LTBROWN", EmitSingleByte, 20, 0, 0},
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
   413
	{"ORANGE",  EmitSingleByte, 21, 0, 0},
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
   414
	{"GREEN",   EmitSingleByte, 22, 0, 0},
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
   415
	{"YELLOW",  EmitSingleByte, 23, 0, 0},
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
   416
	{"DKGREEN", EmitSingleByte, 24, 0, 0},
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
   417
	{"CREAM",   EmitSingleByte, 25, 0, 0},
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
   418
	{"BROWN",   EmitSingleByte, 26, 0, 0},
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
   419
	{"WHITE",   EmitSingleByte, 27, 0, 0},
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
   420
	{"LTBLUE",  EmitSingleByte, 28, 0, 0},
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
   421
	{"GRAY",    EmitSingleByte, 29, 0, 0},
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
   422
	{"DKBLUE",  EmitSingleByte, 30, 0, 0},
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
   423
	{"BLACK",   EmitSingleByte, 31, 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
   424
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
   425
	{"CURRCOMPACT",   EmitEscapedByte, 0, 1, 0}, // compact currency (32 bits)
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
   426
	{"REV",           EmitEscapedByte, 2, 0, 0}, // openttd revision string
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
   427
	{"SHORTCARGO",    EmitEscapedByte, 3, 2, 0}, // short cargo description, only ### tons, or ### litres
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
   428
	{"CURRCOMPACT64", EmitEscapedByte, 4, 2, 0}, // compact currency 64 bits
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
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
	// 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
   431
	// The first string includes the second string.
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   432
	{"COMPANY",    EmitEscapedByte, 5, 1, 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
   433
	{"PLAYERNAME", EmitEscapedByte, 5, 1, 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
   434
	{"VEHICLE",    EmitEscapedByte, 5, 1, 0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
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
   436
	{"STRING1", EmitEscapedByte, 5, 1, C_CASE}, // included string that consumes ONE argument
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   437
	{"STRING2", EmitEscapedByte, 6, 2, C_CASE}, // included string that consumes TWO arguments
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   438
	{"STRING3", EmitEscapedByte, 7, 3, C_CASE}, // included string that consumes THREE arguments
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   439
	{"STRING4", EmitEscapedByte, 8, 4, C_CASE}, // included string that consumes FOUR arguments
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   440
	{"STRING5", EmitEscapedByte, 9, 5, C_CASE}, // included string that consumes FIVE arguments
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   441
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
   442
	{"STATIONFEATURES", EmitEscapedByte, 10, 1, 0}, // station features string, icons of the features
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
   443
	{"INDUSTRY",        EmitEscapedByte, 11, 1, 0}, // industry, takes an industry #
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
   444
	{"VOLUME",          EmitEscapedByte, 12, 1, 0},
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
   445
	{"DATE_TINY",       EmitEscapedByte, 14, 1, 0},
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
   446
	{"CARGO",           EmitEscapedByte, 15, 2, 0},
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3015
diff changeset
   447
	{"POWER",           EmitEscapedByte, 16, 1, 0},
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3015
diff changeset
   448
	{"VOLUME_S",        EmitEscapedByte, 17, 1, 0},
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3015
diff changeset
   449
	{"WEIGHT",          EmitEscapedByte, 18, 1, 0},
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3015
diff changeset
   450
	{"WEIGHT_S",        EmitEscapedByte, 19, 1, 0},
3489
497361c60b90 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3395
diff changeset
   451
	{"FORCE",           EmitEscapedByte, 20, 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
   452
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
   453
	{"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
   454
	{"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
   455
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
   456
	{"DATE_LONG",  EmitSingleByte, 0x82, 1, 0},
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
   457
	{"DATE_SHORT", EmitSingleByte, 0x83, 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
   458
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
   459
	{"VELOCITY", EmitSingleByte, 0x84, 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
   460
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
   461
	// 0x85 is the marker for escaped commands
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   462
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
   463
	{"SKIP", EmitSingleByte, 0x86, 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
   464
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   465
	{"STRING", EmitSingleByte, 0x88, 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
   466
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
   467
	// Numbers
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
   468
	{"COMMA", EmitSingleByte, 0x8B, 1, 0}, // Number with comma
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
   469
	{"NUM",   EmitSingleByte, 0x8E, 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
   470
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
   471
	{"CURRENCY",   EmitSingleByte, 0x8F, 1, 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
   472
	{"CURRENCY64", EmitSingleByte, 0x9C, 2, 0},
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
   473
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
   474
	{"WAYPOINT", EmitSingleByte, 0x99, 1, 0}, // waypoint name
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   475
	{"STATION",  EmitSingleByte, 0x9A, 1, 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
   476
	{"TOWN",     EmitSingleByte, 0x9B, 1, 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
   477
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   478
	// 0x9D is used for the pseudo command SETCASE
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   479
	// 0x9E is used for case switching
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   480
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
   481
	{"",               EmitSingleByte, '\n', 0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   482
	{"{",              EmitSingleByte, '{',  0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   483
	{"UPARROW",        EmitSingleByte, 0x80, 0, 0},
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
   484
	{"SMALLUPARROW",   EmitSingleByte, 0x90, 0, 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
   485
	{"SMALLDOWNARROW", EmitSingleByte, 0x91, 0, 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
   486
	{"TRAIN",          EmitSingleByte, 0x94, 0, 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
   487
	{"LORRY",          EmitSingleByte, 0x95, 0, 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
   488
	{"BUS",            EmitSingleByte, 0x96, 0, 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
   489
	{"PLANE",          EmitSingleByte, 0x97, 0, 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
   490
	{"SHIP",           EmitSingleByte, 0x98, 0, 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
   491
	{"NBSP",           EmitSingleByte, 0xA0, 0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   492
	{"CENT",           EmitSingleByte, '¢',  0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   493
	{"POUNDSIGN",      EmitSingleByte, '£',  0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   494
	{"EURO",           EmitSingleByte, '¤',  0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   495
	{"YENSIGN",        EmitSingleByte, '¥',  0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   496
	{"COPYRIGHT",      EmitSingleByte, '©',  0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   497
	{"DOWNARROW",      EmitSingleByte, 0xAA, 0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   498
	{"CHECKMARK",      EmitSingleByte, 0xAC, 0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   499
	{"CROSS",          EmitSingleByte, 0xAD, 0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   500
	{"REGISTERED",     EmitSingleByte, '®',  0, C_DONTCOUNT},
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   501
	{"RIGHTARROW",     EmitSingleByte, 0xAF, 0, C_DONTCOUNT},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   504
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   505
static const CmdStruct *FindCmd(const char *s, int len)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   506
{
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
   507
	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
   508
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   509
	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
   510
		if (strncmp(cs->cmd, s, len) == 0 && cs->cmd[len] == '\0') return cs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
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
   515
static uint ResolveCaseName(const char *str, uint len)
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   516
{
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
	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
   518
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   519
	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
   520
		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
   521
	}
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   522
	fatal("Invalid case-name '%s'", str);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   523
}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   524
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   526
// 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
   527
// else returns command struct
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   528
static const CmdStruct *ParseCommandString(const char **str, char *param, int *argno, int *casei)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
{
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   530
	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
   531
	const CmdStruct *cmd;
2060
9f3855e81f4b (svn r2569) Get rid of some dubious casts and thus warnings on 64bit machines
tron
parents: 2059
diff changeset
   532
	byte c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   534
	*argno = -1;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   535
	*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
   536
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   537
	// Scan to the next command, exit if there's no next command.
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   538
	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
   539
		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
   540
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   541
	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
   542
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   543
	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
   544
		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
   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
		*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
   547
		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
   548
		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
   549
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	// parse command name
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
	start = s;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   553
	do {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
		c = *s++;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   555
	} while (c != '}' && c != ' ' && c != '=' && c != '.' && c != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   557
	cmd = FindCmd(start, s - start - 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
	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
   559
		error("Undefined command '%.*s'", s - start - 1, start);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   563
	if (c == '.') {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   564
		const char *casep = s;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   565
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   566
		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
   567
			fatal("Command '%s' can't have a case", cmd->cmd);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   568
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   569
		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
   570
		*casei = ResolveCaseName(casep, s - casep - 1);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   571
	}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   572
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   573
	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
   574
		error("Missing } from command '%s'", start);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   575
		return NULL;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   576
	}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   577
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   578
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   579
	if (c != '}') {
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   580
		if (c == '=') s--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
		// copy params
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
		start = s;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   583
		for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
			c = *s++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
			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
   586
			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
   587
				error("Missing } from command '%s'", start);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
				return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
			}
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   590
			if (s - start == 250) fatal("param command too long");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
			*param++ = c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
	}
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
   594
	*param = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
	*str = s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
	return cmd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   602
static void HandlePragma(char *str)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   604
	if (!memcmp(str, "id ", 3)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
		_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
   606
	} else if (!memcmp(str, "name ", 5)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
		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
   608
	} else if (!memcmp(str, "ownname ", 8)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
		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
   610
	} 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
   611
		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
   612
	} else if (!memcmp(str, "plural ", 7)) {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   613
		_lang_pluralform = atoi(str + 7);
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   614
		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
   615
			fatal("Invalid pluralform %d", _lang_pluralform);
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   616
	} 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
   617
		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
   618
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   619
		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
   620
			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
   621
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   622
			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
   623
			if (_numgenders >= MAX_NUM_GENDER) fatal("Too many genders, max %d", MAX_NUM_GENDER);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   624
			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
   625
			_numgenders++;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   626
		}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   627
	} 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
   628
		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
   629
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   630
		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
   631
			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
   632
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   633
			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
   634
			if (_numcases >= MAX_NUM_CASES) fatal("Too many cases, max %d", MAX_NUM_CASES);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   635
			ttd_strlcpy(_cases[_numcases], s, sizeof(_cases[_numcases]));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   636
			_numcases++;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   637
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
	} else {
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   639
		fatal("unknown pragma '%s'", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
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
   643
static void ExtractCommandString(ParsedCommandStruct* p, const char* s, bool warnings)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
	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
   646
	int argno;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   647
	int argidx = 0;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   648
	int casei;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   650
	memset(p, 0, sizeof(*p));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   652
	for (;;) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   653
		// 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
   654
		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
   655
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   656
		if (ar == NULL) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   658
		// 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
   659
		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
   660
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   661
		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
   662
			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
   663
			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
   664
			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
   665
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   666
			p->cmd[argidx++] = ar;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   667
		} 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
   668
			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
   669
			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
   670
			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
   671
			p->np++;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   672
		}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   673
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   676
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   677
static const CmdStruct *TranslateCmdForCompare(const CmdStruct *a)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   678
{
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
   679
	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
   680
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
   681
	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
   682
			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
   683
			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
   684
			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
   685
			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
   686
		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
   687
	}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   688
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
   689
	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
   690
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   691
	return a;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   692
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   693
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   694
2069
30294fb11fc1 (svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents: 2063
diff changeset
   695
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
   696
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   697
	ParsedCommandStruct templ;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   698
	ParsedCommandStruct lang;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   699
	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
   700
	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
   701
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   702
	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
   703
	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
   704
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   705
	// 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
   706
	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
   707
		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
   708
		result = false;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   709
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   710
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   711
	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
   712
		// 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
   713
		bool found = false;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   714
		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
   715
			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
   716
					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
   717
				// 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
   718
				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
   719
				found = true;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   720
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   721
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   722
		}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   723
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   724
		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
   725
			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
   726
			result = false;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   727
		}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   728
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   729
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   730
	// 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
   731
	// Check if the non consumer commands match up also.
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   732
	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
   733
		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
   734
			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
   735
				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
   736
				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
   737
			result = false;
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
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   740
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   741
	return result;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   742
}
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
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
   745
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   746
	char *s,*t;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   747
	LangString *ent;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   748
	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
   749
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	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
   751
		if (str[1] == '#' && str[2] != '#') HandlePragma(str + 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
	// 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
   756
	if (*str == ';' || *str == ' ' || *str == '\0') return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
	s = strchr(str, ':');
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
	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
   760
		error("Line has no ':' delimiter");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   764
	// Trim spaces.
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   765
	// 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
   766
	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
   767
	*t = 0;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   768
	s++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   770
	// Check if the string has a case..
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   771
	// The syntax for cases is IDENTNAME.case
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   772
	casep = strchr(str, '.');
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   773
	if (casep) *casep++ = 0;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   774
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   775
	// 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
   776
	ent = HashFind(str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
	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
   779
		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
   780
			error("String name '%s' is used multiple times", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
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
   784
		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
   785
			error("Base string name '%s' doesn't exist yet. Define it before defining a case.", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   789
		if (ent == NULL) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   790
			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
   791
				error("String ID 0x%X for '%s' already in use by '%s'", ent, str, _strings[_next_string_id]->name);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   792
				return;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   793
			}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   794
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   795
			// Allocate a new LangString
3718
7e99107bbe2f (svn r4689) - Codechange: correct parameter order or calloc, and use the sizeof the variable rather than a struct
peter1138
parents: 3489
diff changeset
   796
			ent = calloc(1, sizeof(*ent));
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   797
			_strings[_next_string_id] = ent;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   798
			ent->index = _next_string_id++;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   799
			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
   800
			ent->line = _cur_line;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   801
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   802
			HashAdd(str, ent);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   803
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   804
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
   805
		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
   806
			Case* c = malloc(sizeof(*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
   807
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   808
			c->caseidx = ResolveCaseName(casep, strlen(casep));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   809
			c->string = strdup(s);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   810
			c->next = ent->english_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   811
			ent->english_case = c;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   812
		} else {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   813
			ent->english = strdup(s);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   814
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   815
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
	} else {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   817
		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
   818
			warning("String name '%s' does not exist in master file", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
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
   822
		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
   823
			error("String name '%s' is used multiple times", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   827
		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
   828
			// Special syntax :: means we should just inherit the master string
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   829
			ent->translated = strdup(ent->english);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
		} else {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   831
			// 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
   832
			if (!CheckCommandsMatch(s, ent->english, str)) return;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   833
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
   834
			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
   835
				Case* c = malloc(sizeof(*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
   836
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   837
				c->caseidx = ResolveCaseName(casep, strlen(casep));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   838
				c->string = strdup(s);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   839
				c->next = ent->translated_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   840
				ent->translated_case = c;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   841
			} else {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   842
				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
   843
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   848
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   849
static void rstrip(char *buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   851
	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
   852
	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
   853
	buf[i] = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   856
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   857
static void ParseFile(const char *file, bool english)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   858
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   859
	FILE *in;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
	char buf[2048];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
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
   862
	_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
   863
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   864
	// For each new file we parse, reset the genders.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   865
	_numgenders = 0;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   866
	// TODO:!! We can't reset the cases. In case the translated strings
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   867
	// derive some strings from english....
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   868
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   869
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
	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
   871
	if (in == NULL) fatal("Cannot open file");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
	_cur_line = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
	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
   874
		rstrip(buf);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   875
		HandleString(buf, english);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
		_cur_line++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
	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
   879
}
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   880
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   881
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   882
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
   883
{
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
	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
   885
		hash = ROL(hash, 3) ^ *s;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3900
diff changeset
   886
		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
   887
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   888
	return hash;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   889
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   891
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   892
// 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
   893
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
   894
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   895
	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
   896
	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
   897
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
   898
	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
   899
		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
   900
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   901
		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
   902
			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
   903
			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
   904
			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
   905
			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
   906
			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
   907
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   908
			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
   909
			hash ^= i * 0x717239;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3900
diff changeset
   910
			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
   911
			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
   912
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   913
			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
   914
			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
   915
				if (cs->flags & C_DONTCOUNT) continue;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   916
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   917
				hash ^= (cs - _cmd_structs) * 0x1234567;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3900
diff changeset
   918
				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
   919
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
	}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   922
	_hash = hash;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   925
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
   926
static uint CountInUse(uint grp)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   927
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
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
   930
	for (i = 0x800; --i >= 0;) if (_strings[(grp << 11) + i] != NULL) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
	return i + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   935
bool CompareFiles(const char *n1, const char *n2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
	FILE *f1, *f2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
	char b1[4096];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	char b2[4096];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
	size_t l1, l2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
	f2 = fopen(n2, "rb");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
	if (f2 == NULL) return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
	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
   946
	if (f1 == NULL) fatal("can't open %s", n1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
		l1 = fread(b1, 1, sizeof(b1), f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
		l2 = fread(b2, 1, sizeof(b2), f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   952
		if (l1 != l2 || memcmp(b1, b2, l1)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
			fclose(f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
			fclose(f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	} while (l1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
	fclose(f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
	fclose(f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   964
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   965
static void WriteStringsH(const char *filename)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
	FILE *out;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
	int next = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
	int lastgrp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
	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
   973
	if (out == NULL) fatal("can't open tmp.xxx");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
	fprintf(out, "enum {");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
	lastgrp = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
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
   979
	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
   980
		if (_strings[i] != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
			if (lastgrp != (i >> 11)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
				lastgrp = (i >> 11);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
				fprintf(out, "};\n\nenum {");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
			}
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 181
diff changeset
   985
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
   986
			fprintf(out, next == i ? "\t%s,\n" : "\n\t%s = 0x%X,\n", _strings[i]->name, i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
			next = i + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
	fprintf(out, "};\n");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
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
   993
	fprintf(out,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
		"\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
   995
		"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
		"\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
   997
		"};\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
   998
	);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   999
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
	fclose(out);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1002
	if (CompareFiles("tmp.xxx", filename)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
		// files are equal. tmp.xxx is not needed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
		unlink("tmp.xxx");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
		// 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
  1007
#if defined(WIN32) || defined(WIN64)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
		unlink(filename);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
#endif
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
  1010
		if (rename("tmp.xxx", filename) == -1) fatal("rename() failed");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1014
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
  1015
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1016
	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
  1017
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1018
	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
  1019
		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
  1020
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1021
	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
  1022
		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
  1023
		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
  1024
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1025
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1026
	return sum;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1027
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1028
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1029
static void PutArgidxCommand(void)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1030
{
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
  1031
	PutByte(0x8C);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1032
	PutByte(TranslateArgumentIdx(_cur_argidx));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1033
}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1034
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1035
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1036
static void PutCommandString(const char *str)
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1037
{
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1038
	const CmdStruct *cs;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1039
	char param[256];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1040
	int argno;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1041
	int casei;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1042
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1043
	_cur_argidx = 0;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1044
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1045
	while (*str != '\0') {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1046
		// Process characters as they are until we encounter a {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1047
		if (*str != '{') {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1048
			PutByte(*str++);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1049
			continue;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1050
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1051
		cs = ParseCommandString(&str, param, &argno, &casei);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1052
		if (cs == NULL) break;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1053
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1054
		if (casei != -1) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1055
			PutByte(0x9D); // {SETCASE}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1056
			PutByte(casei);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1057
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1058
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1059
		// 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
  1060
		if (cs->consumes > 0) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1061
			// 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
  1062
			if (argno != -1 && argno != _cur_argidx) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1063
				_cur_argidx = argno;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1064
				PutArgidxCommand();
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1065
			}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1066
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1067
			// Output the one from the master string... it's always accurate.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1068
			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
  1069
			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
  1070
				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
  1071
			}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1072
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1073
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1074
		cs->proc(param, cs->value);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1075
	}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1076
}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1077
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1078
static void WriteLength(FILE *f, uint length)
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1079
{
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1080
	if (length < 0xC0) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1081
		fputc(length, f);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1082
	} else if (length < 0x4000) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1083
		fputc((length >> 8) | 0xC0, f);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1084
		fputc(length & 0xFF, f);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1085
	} else {
4922
dec2c076d5a7 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
  1086
		fatal("string too long");
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1087
	}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1088
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1089
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1090
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1091
static void WriteLangfile(const char *filename, int show_todo)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
	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
  1094
	uint in_use[32];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	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
  1096
	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
  1097
	uint j;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
	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
  1100
	if (f == NULL) fatal("can't open %s", filename);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
	memset(&hdr, 0, sizeof(hdr));
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1103
	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
  1104
		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
  1105
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
		in_use[i] = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
		hdr.offsets[i] = TO_LE16(n);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
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
  1110
	// 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
  1111
	hdr.ident = TO_LE32(0x474E414C); // Big Endian value for 'LANG'
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
	hdr.version = TO_LE32(_hash);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1113
	hdr.plural_form = _lang_pluralform;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
	strcpy(hdr.name, _lang_name);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
	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
  1116
	strcpy(hdr.isocode, _lang_isocode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
	fwrite(&hdr, sizeof(hdr), 1, f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1120
	for (i = 0; i != 32; i++) {
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1121
		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
  1122
			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
  1123
			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
  1124
			const char* cmdp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1126
			// For undefined strings, just set that it's an empty string
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1127
			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
  1128
				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
  1129
				continue;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1130
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1132
			_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
  1133
			_cur_line = ls->line;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  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
			// 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
  1136
			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
  1137
				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
  1138
					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
  1139
				} else {
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1140
					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
  1141
					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
  1142
				}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1143
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1144
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1145
			// Extract the strings and stuff from the english command string
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1146
			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
  1147
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
  1148
			if (ls->translated_case != NULL || ls->translated != NULL) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1149
				casep = ls->translated_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1150
				cmdp = ls->translated;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1151
			} else {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1152
				casep = ls->english_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1153
				cmdp = ls->english;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1154
			}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1155
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
  1156
			_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
  1157
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
  1158
			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
  1159
				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
  1160
				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
  1161
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1162
				// Need to output a case-switch.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1163
				// It has this format
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1164
				// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT>
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1165
				// Each LEN is printed using 2 bytes in big endian order.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1166
				PutByte(0x9E);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1167
				// Count the number of cases
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1168
				for (num = 0, c = casep; c; c = c->next) num++;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1169
				PutByte(num);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1170
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1171
				// 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
  1172
				for (c = casep; c != NULL; c = c->next) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1173
					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
  1174
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1175
					PutByte(c->caseidx);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1176
					// Make some space for the 16-bit length
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1177
					pos = _put_pos;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1178
					PutByte(0);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1179
					PutByte(0);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1180
					// Write string
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1181
					PutCommandString(c->string);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1182
					PutByte(0); // terminate with a zero
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1183
					// 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
  1184
					_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
  1185
					_put_buf[pos + 1] = GB(_put_pos - (pos + 2), 0, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
				}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1187
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
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
  1189
			if (cmdp != NULL) PutCommandString(cmdp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1191
			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
  1192
			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
  1193
			_put_pos = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
	fputc(0, f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
	fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1201
/** Multi-OS mkdirectory function */
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1202
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
  1203
{
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1204
#if defined(WIN32) || defined(__WATCOMC__)
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1205
		mkdir(directory);
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1206
#else
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1207
		mkdir(directory, 0755);
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1208
#endif
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1209
}
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1210
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1211
/** 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
  1212
 * 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
  1213
 * 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
  1214
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
  1215
{
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1216
	char *p;
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1217
	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
  1218
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1219
	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
  1220
	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
  1221
	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
  1222
	return buf;
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1223
}
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1224
4379
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1225
#if defined(__MINGW32__) || defined(__CYGWIN__)
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1226
/**
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1227
 * 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
  1228
 * 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
  1229
 * 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
  1230
 */
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1231
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
  1232
{
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1233
	char *c;
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1234
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1235
	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
  1236
	return s;
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1237
}
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1238
#else
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1239
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
  1240
#endif
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1241
250
733e18ca6e93 (svn r251) -Project ready for 0.3.4 release. Updated installer, readme and fileinformation
darkvater
parents: 236
diff changeset
  1242
int CDECL main(int argc, char* argv[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
{
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1244
	char pathbuf[256];
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1245
	const char *src_dir = ".";
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1246
	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
  1247
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
	int show_todo = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1250
	while (argc > 1 && *argv[1] == '-') {
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1251
		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
  1252
			puts("$Revision$");
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1253
			return 0;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1254
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1256
		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
  1257
			show_todo = 1;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1258
			argc--, argv++;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1259
			continue;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1260
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1262
		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
  1263
			show_todo = 2;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1264
			argc--, argv++;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1265
			continue;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1266
		}
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1267
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1268
		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
  1269
			puts(
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1270
				"strgen - $Revision$\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1271
				" -v | --version    print version information and exit\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1272
				" -t | --todo       replace any untranslated strings with '<TODO>'\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1273
				" -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
  1274
				" -h | -? | --help  print this help message and exit\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1275
				" -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
  1276
				" -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
  1277
				" 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
  1278
				" 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
  1279
				" 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
  1280
			);
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1281
			return 0;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1282
		}
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1283
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1284
		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
  1285
			src_dir = replace_pathsep(argv[2]);
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1286
			argc -= 2, argv += 2;
4464
08e89a8faa09 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1287
			continue;
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1288
		}
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1289
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1290
		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
  1291
			dest_dir = replace_pathsep(argv[2]);
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1292
			argc -= 2, argv += 2;
4464
08e89a8faa09 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1293
			continue;
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1294
		}
4464
08e89a8faa09 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1295
08e89a8faa09 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1296
		fprintf(stderr, "Invalid arguments\n");
08e89a8faa09 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1297
		return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1300
	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
  1301
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1302
	/* 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
  1303
	 * 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
  1304
	 * 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
  1305
	 * directory. As input english.txt is parsed from the source directory */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
	if (argc == 1) {
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1307
		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
  1308
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1309
		/* 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
  1310
		_masterlang = true;
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1311
		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
  1312
		MakeHashOfStrings();
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1313
		if (_errors) return 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1315
		/* write strings.h */
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1316
		ottd_mkdir(dest_dir);
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1317
		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
  1318
		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
  1319
	} else if (argc == 2) {
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1320
		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
  1321
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1322
		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
  1323
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1324
		/* 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
  1325
		_masterlang = false;
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1326
		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
  1327
		MakeHashOfStrings();
4379
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1328
		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
  1329
		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
  1330
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1331
		/* 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
  1332
		r = strrchr(argv[1], PATHSEPCHAR);
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1333
		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
  1334
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1335
		/* 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
  1336
		r = strrchr(pathbuf, '.');
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1337
		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
  1338
		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
  1339
		WriteLangfile(pathbuf, show_todo);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
	} else {
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1341
		fprintf(stderr, "Invalid arguments\n");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
}