strgen/strgen.c
author Darkvater
Sun, 26 Mar 2006 22:41:56 +0000
changeset 3346 a0d4def7d934
parent 3342 cb9b5c6dd74c
child 3395 edfd22fd92c9
permissions -rw-r--r--
(svn r4130) - CodeChange: Add proper semantics for TownID for such variables instead of using the general uint16-type. We probably need to change GetTown() and IsTownIndex() as well to use TownID.
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
1721
e2887b445ac0 (svn r2225) -Fix: split the endian-detection to target/host. Now cross-compiling
truelight
parents: 1376
diff changeset
     3
#define STRGEN
e2887b445ac0 (svn r2225) -Fix: split the endian-detection to target/host. Now cross-compiling
truelight
parents: 1376
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#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
     6
#include "../macros.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include <stdio.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include <string.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include <stdlib.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
2482
374f6395847d (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2459
diff changeset
    12
#if (!defined(WIN32) && !defined(WIN64)) || defined(__CYGWIN__)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include <unistd.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
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
    16
#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
    17
#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
    18
#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
    19
#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
    20
#define stderr stdout
0b95567f2d0f (svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents: 0
diff changeset
    21
#endif // __MORPHOS__
0b95567f2d0f (svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents: 0
diff changeset
    22
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
/* 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
    24
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
typedef void (*ParseCmdProc)(char *buf, int value);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
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
    27
typedef struct LanguagePackHeader {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	uint32 ident;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	uint32 version;			// 32-bits of auto generated version info which is basically a hash of strings.h
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	char name[32];			// the international name of this language
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	char own_name[32];	// the localized name of this language
1376
d4e1dd8eb7e5 (svn r1880) [Codechange] Added isocodes to langfiles and support code to strgen (Lauri Nurmi)
miham
parents: 1097
diff changeset
    32
	char isocode[16];	// the ISO code for the language (not country code)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	uint16 offsets[32];	// the offsets
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
    34
	byte plural_form;		// plural form index
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
    35
	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
    36
} LanguagePackHeader;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
typedef struct CmdStruct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
	const char *cmd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	ParseCmdProc proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
	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
    42
	int8 consumes;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    43
	byte flags;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
} CmdStruct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    46
enum {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    47
	C_DONTCOUNT = 1,
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    48
	C_CASE = 2,
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    49
};
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    50
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    51
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    52
typedef struct Case {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    53
	int caseidx;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    54
	char *string;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    55
	struct Case *next;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    56
} Case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    57
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
    58
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
    59
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
    60
static const char* _file = "(unknown file)";
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
    61
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
    62
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
    63
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    64
typedef struct LangString {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    65
	char *name;							// Name of the string
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    66
	char *english;					// English text
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    67
	char *translated;				// Translated text
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    68
	uint16 hash_next;				// next hash entry
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    69
	uint16 index;
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
    70
	int line;               // line of string in source-file
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    71
	Case *english_case;			// cases for english
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    72
	Case *translated_case;	// cases for foreign
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    73
} LangString;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    74
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    75
static LangString *_strings[65536];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    76
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    77
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    78
#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
    79
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
    80
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    81
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
    82
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
    83
static int _next_string_id;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
    85
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
    86
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
    87
static byte _lang_pluralform;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    88
#define MAX_NUM_GENDER 8
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    89
static char _genders[MAX_NUM_GENDER][8];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    90
static int _numgenders;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    92
// contains the name of all cases.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    93
#define MAX_NUM_CASES 50
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    94
static char _cases[MAX_NUM_CASES][16];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    95
static int _numcases;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
    96
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
    97
// for each plural value, this is the number of plural forms.
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
    98
static const byte _plural_form_counts[] = { 2,1,2,3,3,3,3,3,4 };
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
    99
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   100
static const char *_cur_ident;
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   101
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   102
typedef struct CmdPair {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   103
	const CmdStruct *a;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   104
	char *v;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   105
} CmdPair;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   106
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   107
typedef struct ParsedCommandStruct {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   108
	int np;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   109
	CmdPair pairs[32];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   110
	const CmdStruct *cmd[32]; // ordered by param #
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   111
} ParsedCommandStruct;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   112
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   113
// Used when generating some advanced commands.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   114
static ParsedCommandStruct _cur_pcs;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   115
static int _cur_argidx;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   116
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   117
static uint HashStr(const char *s)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   118
{
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   119
	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
   120
	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
   121
	return hash % HASH_SIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
}
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   123
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   124
static void HashAdd(const char *s, LangString *ls)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   125
{
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   126
	uint hash = HashStr(s);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   127
	ls->hash_next = _hash_head[hash];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   128
	_hash_head[hash] = ls->index + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   131
static LangString *HashFind(const char *s)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   132
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   133
	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
   134
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   135
	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
   136
		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
   137
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   138
		if (strcmp(ls->name, s) == 0) return ls;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   139
		idx = ls->hash_next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   141
	return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
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
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   145
static void CDECL Warning(const char *s, ...)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   146
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	va_start(va, s);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	vsprintf(buf, s, va);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
	va_end(va);
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
   152
	fprintf(stderr, "%s:%d: 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
   153
	_warnings++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   156
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   157
static void CDECL Error(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
   158
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   159
	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
   160
	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
   161
	va_start(va, s);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   162
	vsprintf(buf, s, va);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   163
	va_end(va);
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
   164
	fprintf(stderr, "%s:%d: 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
   165
	_errors++;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   166
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   167
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   168
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   169
static void NORETURN CDECL Fatal(const char *s, ...)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   170
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	va_start(va, s);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
	vsprintf(buf, s, va);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	va_end(va);
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
   176
	fprintf(stderr, "%s:%d: FATAL: %s\n", _file, _cur_line, buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	exit(1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   180
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   181
static void ttd_strlcpy(char *dst, const char *src, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	assert(len > 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
   184
	while (--len > 0 && *src != '\0') *dst++ = *src++;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   185
	*dst = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   189
static void PutByte(byte c)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   190
{
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
   191
	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
   192
	_put_buf[_put_pos++] = c;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   196
static void EmitSingleByte(char *buf, int value)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   197
{
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
   198
	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
   199
	PutByte((byte)value);
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   203
static void EmitEscapedByte(char *buf, int value)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   204
{
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
   205
	if (*buf != '\0') Warning("Ignoring trailing letters in command");
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   206
	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
   207
	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
   208
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   210
static void EmitSetX(char *buf, int value)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   211
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
	char *err;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
	int x = strtol(buf, &err, 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
   214
	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
   215
	PutByte(1);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   216
	PutByte((byte)x);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   217
}
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   218
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   220
static void EmitSetXY(char *buf, int value)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   221
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
	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
   223
	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
   224
	int y;
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   225
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   226
	x = strtol(buf, &err, 0);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   227
	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
   228
	y = strtol(err + 1, &err, 0);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   229
	if (*err != 0) Fatal("SetXY param invalid");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   231
	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
   232
	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
   233
	PutByte((byte)y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   236
// The plural specifier looks like
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   237
// {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
   238
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   239
// This is encoded like
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   240
//  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
   241
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   242
bool ParseRelNum(char **buf, int *value)
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   243
{
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
   244
	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
   245
	char* end;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   246
	bool rel = false;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   247
	int v;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   248
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   249
	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
   250
	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
   251
		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
   252
		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
   253
	}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   254
	v = strtol(s, &end, 0);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   255
	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
   256
	if (rel || v < 0) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   257
		*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
   258
	} else {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   259
		*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
   260
	}
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   261
	*buf = end;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   262
	return true;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   263
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   264
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   265
// Parse out the next word, or NULL
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   266
char *ParseWord(char **buf)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   267
{
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   268
	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
   269
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   270
	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
   271
	if (*s == '\0') return NULL;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   272
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   273
	if (*s == '"') {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   274
		r = ++s;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   275
		// parse until next " or NUL
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   276
		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
   277
			if (*s == '\0') break;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   278
			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
   279
				*s++ = '\0';
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   280
				break;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   281
			}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   282
			s++;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   283
		}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   284
	} else {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   285
		// proceed until whitespace or NUL
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   286
		r = s;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   287
		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
   288
			if (*s == '\0') break;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   289
			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
   290
				*s++ = '\0';
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   291
				break;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   292
			}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   293
			s++;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   294
		}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   295
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   296
	*buf = s;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   297
	return r;
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
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   300
// Forward declaration
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   301
static int TranslateArgumentIdx(int arg);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   302
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
   303
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
   304
{
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
   305
	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
   306
	uint j;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   307
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   308
	PutByte(nw);
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   309
	for (i = 0; i < nw; i++) PutByte(strlen(words[i]));
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   310
	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
   311
		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
   312
	}
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
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   315
static void EmitPlural(char *buf, int value)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   316
{
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   317
	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
   318
	const char* words[5];
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   319
	int nw = 0;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   320
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   321
	// 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
   322
	if (!ParseRelNum(&buf, &argidx)) argidx--;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   323
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   324
	// 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
   325
	for (nw = 0; nw < 5; nw++) {
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   326
		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
   327
		if (words[nw] == NULL) break;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   328
	}
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
	if (nw == 0)
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
		Fatal("%s: No plural words", _cur_ident);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   332
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
   333
	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
   334
		if (_translated) {
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
   335
			Fatal("%s: Invalid number of plural forms. Expecting %d, found %d.", _cur_ident,
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
   336
				_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
   337
		} else {
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
   338
			Warning("'%s' is untranslated. Tweaking english string to allow compilation for plural forms", _cur_ident);
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
   339
			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
   340
				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
   341
			} else {
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   342
				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
   343
					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
   344
				}
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
			}
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
		}
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
   347
	}
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   348
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
   349
	PutByte(0x8D);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   350
	PutByte(TranslateArgumentIdx(argidx));
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   351
	EmitWordList(words, nw);
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   352
}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   353
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   354
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   355
static void EmitGender(char *buf, int value)
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   356
{
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   357
	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
   358
	uint nw;
2084
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
	if (buf[0] == '=') {
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   361
		buf++;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   362
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   363
		// This is a {G=DER} command
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   364
		for (nw = 0; ; nw++) {
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   365
			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
   366
			if (strcmp(buf, _genders[nw]) == 0) break;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   367
		}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   368
		// now nw contains the gender index
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   369
		PutByte(0x87);
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   370
		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
   371
	} 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
   372
		const char* words[8];
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
		// This is a {G 0 foo bar two} command.
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   375
		// If no relative number exists, default to +0
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   376
		if (!ParseRelNum(&buf, &argidx)) {}
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   377
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   378
		for (nw = 0; nw < 8; nw++) {
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   379
			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
   380
			if (words[nw] == NULL) break;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   381
		}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   382
		if (nw != _numgenders) Fatal("Bad # of arguments for gender command");
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   383
		PutByte(0x85);
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   384
		PutByte(13);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   385
		PutByte(TranslateArgumentIdx(argidx));
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   386
		EmitWordList(words, nw);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   387
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   388
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   389
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   390
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
static const CmdStruct _cmd_structs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
	// 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
   393
	{"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
   394
	{"SETXY", EmitSetXY, 2, 0, 0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
	// 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
   397
	{"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
   398
	{"BIGFONT",  EmitSingleByte, 9, 0, 0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
	// 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
   401
	{"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
   402
	{"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
   403
	{"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
   404
	{"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
   405
	{"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
   406
	{"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
   407
	{"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
   408
	{"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
   409
	{"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
   410
	{"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
   411
	{"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
   412
	{"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
   413
	{"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
   414
	{"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
   415
	{"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
   416
	{"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
   417
	{"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
   418
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
   419
	{"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
   420
	{"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
   421
	{"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
   422
	{"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
   423
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
   424
	// 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
   425
	// 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
   426
	{"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
   427
	{"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
   428
	{"VEHICLE",    EmitEscapedByte, 5, 1, 0},
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
	{"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
   431
	{"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
   432
	{"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
   433
	{"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
   434
	{"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
   435
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
   436
	{"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
   437
	{"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
   438
	{"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
   439
	{"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
   440
	{"CARGO",           EmitEscapedByte, 15, 2, 0},
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3015
diff changeset
   441
	{"POWER",           EmitEscapedByte, 16, 1, 0},
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3015
diff changeset
   442
	{"VOLUME_S",        EmitEscapedByte, 17, 1, 0},
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3015
diff changeset
   443
	{"WEIGHT",          EmitEscapedByte, 18, 1, 0},
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3015
diff changeset
   444
	{"WEIGHT_S",        EmitEscapedByte, 19, 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
   445
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   446
	{"P", EmitPlural, 0, 0, C_DONTCOUNT},					// plural specifier
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   447
	{"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
   448
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
   449
	{"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
   450
	{"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
   451
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
   452
	{"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
   453
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
   454
	// 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
   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
	{"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
   457
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   458
	{"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
   459
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
   460
	// 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
   461
	{"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
   462
	{"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
   463
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
   464
	{"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
   465
	{"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
   466
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
   467
	{"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
   468
	{"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
   469
	{"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
   470
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   471
	// 0x9D is used for the pseudo command SETCASE
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   472
	// 0x9E is used for case switching
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
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
	{"",               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
   475
	{"{",              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
   476
	{"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
   477
	{"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
   478
	{"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
   479
	{"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
   480
	{"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
   481
	{"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
   482
	{"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
   483
	{"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
   484
	{"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
   485
	{"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
   486
	{"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
   487
	{"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
   488
	{"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
   489
	{"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
   490
	{"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
   491
	{"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
   492
	{"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
   493
	{"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
   494
	{"RIGHTARROW",     EmitSingleByte, 0xAF, 0, C_DONTCOUNT},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   497
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   498
static const CmdStruct *FindCmd(const char *s, int len)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   499
{
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
   500
	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
   501
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   502
	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
   503
		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
   504
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
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
   508
static uint ResolveCaseName(const char *str, uint len)
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   509
{
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
   510
	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
   511
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   512
	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
   513
		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
   514
	}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   515
	Fatal("Invalid case-name '%s'", str);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   516
}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   517
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   519
// 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
   520
// else returns command struct
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   521
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
   522
{
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   523
	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
   524
	const CmdStruct *cmd;
2060
9f3855e81f4b (svn r2569) Get rid of some dubious casts and thus warnings on 64bit machines
tron
parents: 2059
diff changeset
   525
	byte c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   527
	*argno = -1;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   528
	*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
   529
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   530
	// 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
   531
	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
   532
		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
   533
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   534
	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
   535
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   536
	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
   537
		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
   538
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   539
		*argno = strtoul(s, &end, 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
   540
		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
   541
		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
   542
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
	// parse command name
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
	start = s;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   546
	do {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
		c = *s++;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   548
	} while (c != '}' && c != ' ' && c != '=' && c != '.' && c != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   550
	cmd = FindCmd(start, s - start - 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	if (cmd == NULL) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   552
		Error("Undefined command '%.*s'", s - start - 1, start);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   556
	if (c == '.') {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   557
		const char *casep = s;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   558
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   559
		if (!(cmd->flags & C_CASE))
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   560
			Fatal("Command '%s' can't have a case", cmd->cmd);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   561
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   562
		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
   563
		*casei = ResolveCaseName(casep, s - casep - 1);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   564
	}
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 (c == '\0') {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   567
		Error("Missing } from command '%s'", start);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   568
		return NULL;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   569
	}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   570
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   571
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   572
	if (c != '}') {
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   573
		if (c == '=') s--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
		// copy params
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
		start = s;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   576
		for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
			c = *s++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
			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
   579
			if (c == '\0') {
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   580
				Error("Missing } from command '%s'", start);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
				return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
			}
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
   583
			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
   584
			*param++ = c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
	}
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   587
	*param = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
	*str = s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
	return cmd;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   595
static void HandlePragma(char *str)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   597
	if (!memcmp(str, "id ", 3)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
		_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
   599
	} else if (!memcmp(str, "name ", 5)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
		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
   601
	} else if (!memcmp(str, "ownname ", 8)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
		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
   603
	} 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
   604
		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
   605
	} else if (!memcmp(str, "plural ", 7)) {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   606
		_lang_pluralform = atoi(str + 7);
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   607
		if (_lang_pluralform >= lengthof(_plural_form_counts))
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   608
			Fatal("Invalid pluralform %d", _lang_pluralform);
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   609
	} 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
   610
		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
   611
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   612
		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
   613
			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
   614
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   615
			if (s == NULL) break;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   616
			if (_numgenders >= MAX_NUM_GENDER) Fatal("Too many genders, max %d", MAX_NUM_GENDER);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   617
			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
   618
			_numgenders++;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   619
		}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   620
	} 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
   621
		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
   622
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   623
		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
   624
			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
   625
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   626
			if (s == NULL) break;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   627
			if (_numcases >= MAX_NUM_CASES) Fatal("Too many cases, max %d", MAX_NUM_CASES);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   628
			ttd_strlcpy(_cases[_numcases], s, sizeof(_cases[_numcases]));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   629
			_numcases++;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   630
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
	} else {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   632
		Fatal("unknown pragma '%s'", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   636
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
   637
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
	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
   639
	int argno;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   640
	int argidx = 0;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   641
	int casei;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   643
	memset(p, 0, sizeof(*p));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   645
	for (;;) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   646
		// 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
   647
		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
   648
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   649
		if (ar == NULL) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   651
		// Sanity checking
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
   652
		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
   653
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   654
		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
   655
			if (argno != -1) argidx = argno;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   656
			if (argidx < 0 || argidx >= lengthof(p->cmd)) Fatal("invalid param idx %d", argidx);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   657
			if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) Fatal("duplicate param idx %d", argidx);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   658
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   659
			p->cmd[argidx++] = ar;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   660
		} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   661
			if (p->np >= lengthof(p->pairs)) Fatal("too many commands in string, max %d", lengthof(p->pairs));
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   662
			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
   663
			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
   664
			p->np++;
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
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   669
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   670
static const CmdStruct *TranslateCmdForCompare(const CmdStruct *a)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   671
{
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
   672
	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
   673
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
   674
	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
   675
			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
   676
			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
   677
			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
   678
			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
   679
		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
   680
	}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   681
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
   682
	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
   683
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   684
	return a;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   685
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   686
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   687
2069
30294fb11fc1 (svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents: 2063
diff changeset
   688
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
   689
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   690
	ParsedCommandStruct templ;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   691
	ParsedCommandStruct lang;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   692
	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
   693
	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
   694
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   695
	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
   696
	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
   697
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   698
	// 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
   699
	if (templ.np != lang.np) {
2069
30294fb11fc1 (svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents: 2063
diff changeset
   700
		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
   701
		result = false;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   702
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   703
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   704
	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
   705
		// 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
   706
		bool found = false;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   707
		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
   708
			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
   709
					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
   710
				// 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
   711
				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
   712
				found = true;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   713
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   714
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   715
		}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   716
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   717
		if (!found) {
2069
30294fb11fc1 (svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents: 2063
diff changeset
   718
			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
   719
			result = false;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   720
		}
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
	// 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
   724
	// Check if the non consumer commands match up also.
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   725
	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
   726
		if (TranslateCmdForCompare(templ.cmd[i]) != TranslateCmdForCompare(lang.cmd[i])) {
2069
30294fb11fc1 (svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents: 2063
diff changeset
   727
			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
   728
				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
   729
				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
   730
			result = false;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   731
		}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   732
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   733
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   734
	return result;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   735
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   736
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   737
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
   738
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   739
	char *s,*t;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   740
	LangString *ent;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   741
	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
   742
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
	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
   744
		if (str[1] == '#' && str[2] != '#') HandlePragma(str + 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
	// 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
   749
	if (*str == ';' || *str == ' ' || *str == '\0') return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
	s = strchr(str, ':');
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
	if (s == NULL) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   753
		Error("Line has no ':' delimiter");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   757
	// Trim spaces.
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   758
	// 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
   759
	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
   760
	*t = 0;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   761
	s++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   763
	// Check if the string has a case..
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   764
	// The syntax for cases is IDENTNAME.case
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   765
	casep = strchr(str, '.');
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   766
	if (casep) *casep++ = 0;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   767
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   768
	// 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
   769
	ent = HashFind(str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
	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
   772
		if (ent != NULL && 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
   773
			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
   774
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   777
		if (ent == NULL && casep != NULL) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   778
			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
   779
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   782
		if (ent == NULL) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   783
			if (_strings[_next_string_id]) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   784
				Error("String ID 0x%X for '%s' already in use by '%s'", ent, str, _strings[_next_string_id]->name);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   785
				return;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   786
			}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   787
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   788
			// Allocate a new LangString
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   789
			ent = calloc(sizeof(LangString), 1);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   790
			_strings[_next_string_id] = ent;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   791
			ent->index = _next_string_id++;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   792
			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
   793
			ent->line = _cur_line;
2087
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
			HashAdd(str, ent);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   796
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   797
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   798
		if (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
   799
			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
   800
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   801
			c->caseidx = ResolveCaseName(casep, strlen(casep));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   802
			c->string = strdup(s);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   803
			c->next = ent->english_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   804
			ent->english_case = c;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   805
		} else {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   806
			ent->english = strdup(s);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   807
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   808
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
	} else {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   810
		if (ent == NULL) {
2069
30294fb11fc1 (svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents: 2063
diff changeset
   811
			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
   812
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
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
   815
		if (ent->translated && 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
   816
			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
   817
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   820
		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
   821
			// Special syntax :: means we should just inherit the master string
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   822
			ent->translated = strdup(ent->english);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
		} else {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   824
			// 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
   825
			if (!CheckCommandsMatch(s, ent->english, str)) return;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   826
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
   827
			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
   828
				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
   829
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   830
				c->caseidx = ResolveCaseName(casep, strlen(casep));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   831
				c->string = strdup(s);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   832
				c->next = ent->translated_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   833
				ent->translated_case = c;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   834
			} else {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   835
				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
   836
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   841
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   842
static void rstrip(char *buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   844
	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
   845
	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
   846
	buf[i] = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   849
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   850
static void ParseFile(const char *file, bool english)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   851
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   852
	FILE *in;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
	char buf[2048];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
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
   855
	_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
   856
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   857
	// For each new file we parse, reset the genders.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   858
	_numgenders = 0;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   859
	// 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
   860
	// derive some strings from english....
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   861
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   862
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
	in = fopen(file, "r");
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
   864
	if (in == NULL) Fatal("Cannot open file");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
	_cur_line = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
	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
   867
		rstrip(buf);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   868
		HandleString(buf, english);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
		_cur_line++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
	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
   872
}
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   873
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   874
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   875
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
   876
{
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
   877
	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
   878
		hash = ROL(hash, 3) ^ *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
   879
		if (hash & 1) hash = (hash >> 1) ^ 0xDEADBEEF; else 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
   880
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   881
	return hash;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   882
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   884
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   885
// 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
   886
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
   887
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   888
	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
   889
	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
   890
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
   891
	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
   892
		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
   893
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   894
		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
   895
			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
   896
			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
   897
			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
   898
			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
   899
			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
   900
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   901
			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
   902
			hash ^= i * 0x717239;
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
   903
			if (hash & 1) hash = (hash >> 1) ^ 0xDEADBEEF; else 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
   904
			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
   905
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   906
			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
   907
			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
   908
				if (cs->flags & C_DONTCOUNT) continue;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   909
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   910
				hash ^= (cs - _cmd_structs) * 0x1234567;
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
   911
				if (hash & 1) hash = (hash >> 1) ^ 0xF00BAA4; else hash >>= 1;
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 181
diff changeset
   912
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
	}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   915
	_hash = hash;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   918
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
   919
static uint CountInUse(uint grp)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   920
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
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
   923
	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
   924
	return i + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   928
bool CompareFiles(const char *n1, const char *n2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
	FILE *f1, *f2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
	char b1[4096];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
	char b2[4096];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
	size_t l1, l2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
	f2 = fopen(n2, "rb");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
	if (f2 == NULL) return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
	f1 = fopen(n1, "rb");
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   939
	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
   940
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
		l1 = fread(b1, 1, sizeof(b1), f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
		l2 = fread(b2, 1, sizeof(b2), f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   945
		if (l1 != l2 || memcmp(b1, b2, l1)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
			fclose(f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
			fclose(f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
	} while (l1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
	fclose(f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
	fclose(f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   957
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   958
static void WriteStringsH(const char *filename)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
	FILE *out;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
	int next = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
	int lastgrp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
	out = fopen("tmp.xxx", "w");
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   966
	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
   967
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
	fprintf(out, "enum {");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
	lastgrp = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
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
   972
	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
   973
		if (_strings[i] != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
			if (lastgrp != (i >> 11)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
				lastgrp = (i >> 11);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
				fprintf(out, "};\n\nenum {");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
			}
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
   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
			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
   980
			next = i + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
	fprintf(out, "};\n");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
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
   986
	fprintf(out,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
		"\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
   988
		"\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
   989
		"\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
   990
		"};\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
   991
	);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   992
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
	fclose(out);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   995
	if (CompareFiles("tmp.xxx", filename)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
		// files are equal. tmp.xxx is not needed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
		unlink("tmp.xxx");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
		// 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
  1000
#if defined(WIN32) || defined(WIN64)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
		unlink(filename);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
#endif
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1003
		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
  1004
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1007
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
  1008
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1009
	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
  1010
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1011
	if (argidx < 0 || argidx >= lengthof(_cur_pcs.cmd))
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1012
		Fatal("invalid argidx %d", argidx);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1013
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1014
	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
  1015
		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
  1016
		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
  1017
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1018
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1019
	return sum;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1020
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1021
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1022
static void PutArgidxCommand(void)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1023
{
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
  1024
	PutByte(0x8C);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1025
	PutByte(TranslateArgumentIdx(_cur_argidx));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1026
}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1027
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1028
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1029
static void PutCommandString(const char *str)
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1030
{
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1031
	const CmdStruct *cs;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1032
	char param[256];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1033
	int argno;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1034
	int casei;
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
	_cur_argidx = 0;
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
	while (*str != '\0') {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1039
		// Process characters as they are until we encounter a {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1040
		if (*str != '{') {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1041
			PutByte(*str++);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1042
			continue;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1043
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1044
		cs = ParseCommandString(&str, param, &argno, &casei);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1045
		if (cs == NULL) break;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1046
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1047
		if (casei != -1) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1048
			PutByte(0x9D); // {SETCASE}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1049
			PutByte(casei);
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
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1052
		// 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
  1053
		if (cs->consumes > 0) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1054
			// 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
  1055
			if (argno != -1 && argno != _cur_argidx) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1056
				_cur_argidx = argno;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1057
				PutArgidxCommand();
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
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1060
			// Output the one from the master string... it's always accurate.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1061
			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
  1062
			if (cs == 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
  1063
				Fatal("%s: No argument exists at position %d", _cur_ident, _cur_argidx - 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
  1064
			}
2087
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
		cs->proc(param, cs->value);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1068
	}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1069
}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1070
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1071
static void WriteLength(FILE *f, uint length)
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
	if (length < 0xC0) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1074
		fputc(length, f);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1075
	} else if (length < 0x4000) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1076
		fputc((length >> 8) | 0xC0, f);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1077
		fputc(length & 0xFF, f);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1078
	} else {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1079
		Fatal("string too long");
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1080
	}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1081
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1082
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1083
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1084
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
  1085
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
	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
  1087
	uint in_use[32];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
	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
  1089
	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
  1090
	uint j;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
	f = fopen(filename, "wb");
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1093
	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
  1094
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	memset(&hdr, 0, sizeof(hdr));
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1096
	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
  1097
		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
  1098
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
		in_use[i] = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
		hdr.offsets[i] = TO_LE16(n);
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
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
  1103
	// 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
  1104
	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
  1105
	hdr.version = TO_LE32(_hash);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1106
	hdr.plural_form = _lang_pluralform;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
	strcpy(hdr.name, _lang_name);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
	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
  1109
	strcpy(hdr.isocode, _lang_isocode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
	fwrite(&hdr, sizeof(hdr), 1, f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1113
	for (i = 0; i != 32; i++) {
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1114
		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
  1115
			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
  1116
			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
  1117
			const char* cmdp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1119
			// 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
  1120
			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
  1121
				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
  1122
				continue;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1123
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1125
			_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
  1126
			_cur_line = ls->line;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1127
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1128
			// 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
  1129
			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
  1130
				if (show_todo == 2) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1131
					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
  1132
				} else {
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1133
					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
  1134
					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
  1135
				}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1136
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1137
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1138
			// Extract the strings and stuff from the english command string
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1139
			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
  1140
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
			if (ls->translated_case != NULL || ls->translated != NULL) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1142
				casep = ls->translated_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1143
				cmdp = ls->translated;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1144
			} else {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1145
				casep = ls->english_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1146
				cmdp = ls->english;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1147
			}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1148
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
  1149
			_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
  1150
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1151
			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
  1152
				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
  1153
				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
  1154
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1155
				// Need to output a case-switch.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1156
				// It has this format
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1157
				// <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
  1158
				// Each LEN is printed using 2 bytes in big endian order.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1159
				PutByte(0x9E);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1160
				// Count the number of cases
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1161
				for (num = 0, c = casep; c; c = c->next) num++;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1162
				PutByte(num);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1163
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1164
				// 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
  1165
				for (c = casep; c != NULL; c = c->next) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1166
					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
  1167
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1168
					PutByte(c->caseidx);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1169
					// Make some space for the 16-bit length
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1170
					pos = _put_pos;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1171
					PutByte(0);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1172
					PutByte(0);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1173
					// Write string
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1174
					PutCommandString(c->string);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1175
					PutByte(0); // terminate with a zero
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1176
					// 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
  1177
					_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
  1178
					_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
  1179
				}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1180
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
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
  1182
			if (cmdp != NULL) PutCommandString(cmdp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1184
			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
  1185
			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
  1186
			_put_pos = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
	fputc(0, f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
	fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1194
250
733e18ca6e93 (svn r251) -Project ready for 0.3.4 release. Updated installer, readme and fileinformation
darkvater
parents: 236
diff changeset
  1195
int CDECL main(int argc, char* argv[])
0
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
	int show_todo = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
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
  1199
	if (argc > 1 && (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) {
2418
ce15155b77f5 (svn r2944) Add Revision keyword to the file for --version/-v
Darkvater
parents: 2411
diff changeset
  1200
		puts("$Revision$");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
		return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
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
  1204
	if (argc > 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
  1205
			(strcmp(argv[1], "-t") == 0 || strcmp(argv[1], "--todo") == 0)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
		show_todo = 1;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1207
		argc--, argv++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
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
  1210
	if (argc > 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
  1211
			(strcmp(argv[1], "-w") == 0 || strcmp(argv[1], "--warning") == 0)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
		show_todo = 2;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1213
		argc--, argv++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
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
  1216
	if (argc > 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
  1217
				strcmp(argv[1], "-h") == 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
  1218
				strcmp(argv[1], "--help") == 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
  1219
				strcmp(argv[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
  1220
			)) {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1221
		puts(
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1222
			"strgen - $Revision$\n"
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1223
			" -v | --version    print version information and exit\n"
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1224
			" -h | -? | --help  print this help message and exit\n"
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1225
			" -t | --todo       replace any untranslated strings with '<TODO>'\n"
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1226
			" -w | --warning    print a warning for any untranslated strings\n"
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1227
			" Run without parameters strgen will search for lang/english.txt and\n"
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1228
			" parse it. Passing an argument, strgen will translate that language\n"
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1229
			" file with lang/english.txt as a reference."
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1230
		);
2904
1075bac76b72 (svn r3459) - CodeChange: add help-output to strgen and also verbose variants of the switches
Darkvater
parents: 2765
diff changeset
  1231
		return 0;
1075bac76b72 (svn r3459) - CodeChange: add help-output to strgen and also verbose variants of the switches
Darkvater
parents: 2765
diff changeset
  1232
	}
1075bac76b72 (svn r3459) - CodeChange: add help-output to strgen and also verbose variants of the switches
Darkvater
parents: 2765
diff changeset
  1233
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
	if (argc == 1) {
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
  1235
		_masterlang = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
		// parse master file
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1237
		ParseFile("lang/english.txt", true);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1238
		MakeHashOfStrings();
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1239
		if (_errors) return 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
		// write english.lng and strings.h
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 181
diff changeset
  1242
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1243
		WriteLangfile("lang/english.lng", 0);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1244
		WriteStringsH("table/strings.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
  1245
	} else if (argc == 2) {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1246
		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
  1247
		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
  1248
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
  1249
		_masterlang = false;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1250
		ParseFile("lang/english.txt", true);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1251
		MakeHashOfStrings();
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1252
		ParseFile(argv[1], false);
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 181
diff changeset
  1253
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1254
		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
  1255
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
		strcpy(buf, argv[1]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
		r = strrchr(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
  1258
		if (r == NULL || strcmp(r, ".txt") != 0) r = strchr(buf, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
		strcpy(r, ".lng");
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1260
		WriteLangfile(buf, show_todo);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
		fprintf(stderr, "invalid arguments\n");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
}