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