File diff r221:56c7ed3a0581 → r222:4409829eb08f
strgen/strgen.c
Show inline comments
 
@@ -40,13 +40,13 @@ typedef struct CmdStruct {
 
} CmdStruct;
 

	
 
typedef struct LineName {
 
	struct LineName *hash_next;
 
	int value;
 
	char str[1];
 
} LineName; 
 
} LineName;
 

	
 
int _cur_line;
 
bool _warnings;
 

	
 
uint32 _hash;
 
char _lang_name[32], _lang_ownname[32];
 
@@ -215,13 +215,13 @@ static const CmdStruct _cmd_structs[] = 
 
	{"BIGFONT", EmitSingleByte, 9},
 

	
 
	// New line
 
	{"", EmitSingleByte, 10},
 

	
 
	// Colors
 
	{"BLUE", EmitSingleByte, 15},		
 
	{"BLUE", EmitSingleByte, 15},
 
	{"SILVER", EmitSingleByte, 16},
 
	{"GOLD", EmitSingleByte, 17},
 
	{"RED", EmitSingleByte, 18},
 
	{"PURPLE", EmitSingleByte, 19},
 
	{"LTBROWN", EmitSingleByte, 20},
 
	{"ORANGE", EmitSingleByte, 21},
 
@@ -232,28 +232,28 @@ static const CmdStruct _cmd_structs[] = 
 
	{"BROWN", EmitSingleByte, 26},
 
	{"WHITE", EmitSingleByte, 27},
 
	{"LTBLUE", EmitSingleByte, 28},
 
	{"GRAY", EmitSingleByte, 29},
 
	{"DKBLUE", EmitSingleByte, 30},
 
	{"BLACK", EmitSingleByte, 31},
 
	
 

	
 
	// 0x7B=123 is the LAST special character we may use.
 

	
 
	// Numbers
 
	{"COMMA32", EmitSingleByte, 0x7B},
 
	{"COMMA16", EmitSingleByte, 0x7C},
 
	{"COMMA8", EmitSingleByte, 0x7D},
 
	{"NUMU16", EmitSingleByte, 0x7E},
 

	
 
	{"CURRENCY", EmitSingleByte, 0x7F},
 
	
 

	
 
	{"CURRCOMPACT", EmitEscapedByte, 0}, // compact currency
 
	{"INT32", EmitEscapedByte, 1}, // compact currency
 
	{"REV", EmitEscapedByte, 2}, // openttd revision string
 
	{"SHORTCARGO", EmitEscapedByte, 3}, // short cargo description, only ### tons, or ### litres
 
	
 

	
 
	{"STRINL", EmitStringInl, 0x81},
 

	
 
	{"DATE_LONG", EmitSingleByte, 0x82},
 
	{"DATE_SHORT", EmitSingleByte, 0x83},
 

	
 
	{"VELOCITY", EmitSingleByte, 0x84},
 
@@ -385,13 +385,13 @@ bool check_commands_match(char *a, char 
 
	return true;
 
}
 

	
 
void handle_string(char *str, bool master) {
 
	char *s,*t,*r;
 
	int ent;
 
		
 

	
 
	if (*str == '#') {
 
		if (str[1] == '#' && str[2] != '#')
 
			handle_pragma(str + 2);
 
		return;
 
	}
 

	
 
@@ -468,23 +468,23 @@ uint32 my_hash_str(uint32 hash, const ch
 
{
 
	for(;*s;s++) {
 
		hash = ((hash << 3) | (hash >> 29)) ^ *s;
 
		if (hash & 1) hash = (hash>>1) ^ 0xDEADBEEF; else hash >>= 1;
 
	}
 
	return hash;
 
	
 

	
 
}
 

	
 
void parse_file(const char *file, bool english) {
 
	char buf[2048];
 
	int i;
 
	FILE *in;
 

	
 
	in = fopen(file, "r");
 
	if (in == NULL) { error("Cannot open file '%s'", file); }
 
	
 

	
 
	_cur_line = 1;
 
	while (fgets(buf, sizeof(buf),in) != NULL) {
 
		i = strlen(buf);
 
		while (i>0 && (buf[i-1]=='\r' || buf[i-1]=='\n' || buf[i-1] == ' ')) i--;
 
		buf[i] = 0;
 

	
 
@@ -509,13 +509,13 @@ void parse_file(const char *file, bool e
 
				while ((cs = parse_command_string(&s, buf, NULL)) != 0) {
 
					if ( (uint)cs >= 256) {
 
						hash ^= (cs - _cmd_structs) * 0x1234567;
 
						if (hash & 1) hash = (hash>>1) ^ 0xF00BAA4; else hash >>= 1;
 
					}
 
				}
 
			}	
 
			}
 
		}
 
		_hash = hash;
 
	}
 
}
 

	
 
int count_inuse(int grp) {
 
@@ -576,13 +576,13 @@ void gen_output(FILE *f) {
 
	fwrite(in_use_file, 32*sizeof(uint16), 1, f);
 

	
 
	for(i=0; i!=32; i++) {
 
		for(j=0; j!=in_use[i]; j++) {
 
			char *s = allstr[(i<<11)+j];
 
			if (s == NULL) error("Internal error, s==NULL");
 
			
 

	
 
			write_length(f, *(uint16*)s);
 
			fwrite(s + sizeof(uint16), *(uint16*)s , 1, f);
 
			tot_str--;
 
		}
 
	}
 

	
 
@@ -639,21 +639,21 @@ void write_strings_h(const char *filenam
 
	for(i = 0; i!=65536; i++) {
 
		if (allstr[i]) {
 
			if (lastgrp != (i >> 11)) {
 
				lastgrp = (i >> 11);
 
				fprintf(out, "};\n\nenum {");
 
			}
 
			
 

	
 
			fprintf(out, next == i ? "%s,\n" : "\n%s = 0x%X,\n", allstr[i] + 1, i);
 
			next = i + 1;
 
		}
 
	}
 

	
 
	fprintf(out, "};\n");
 

	
 
	fprintf(out, 
 
	fprintf(out,
 
		"\nenum {\n"
 
		"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n"
 
		"\tLANGUAGE_PACK_VERSION = 0x%X,\n"
 
		"};\n", (unsigned int)_hash);
 

	
 

	
 
@@ -687,13 +687,13 @@ void write_langfile(const char *filename
 
	for(i=0; i!=32; i++) {
 
		int n = count_inuse(i);
 
		in_use[i] = n;
 
		hdr.offsets[i] = TO_LE16(n);
 
	}
 

	
 
	// see line 655: fprintf(..."\tLANGUAGE_PACK_IDENT = 0x474E414C,...) 
 
	// see line 655: fprintf(..."\tLANGUAGE_PACK_IDENT = 0x474E414C,...)
 
	hdr.ident = TO_LE32(0x474E414C); // Big Endian value for 'LANG'
 
	hdr.version = TO_LE32(_hash);
 
	strcpy(hdr.name, _lang_name);
 
	strcpy(hdr.own_name, _lang_ownname);
 

	
 
	fwrite(&hdr, sizeof(hdr), 1, f);
 
@@ -709,13 +709,13 @@ void write_langfile(const char *filename
 
				str = s + 2 + strlen(s + 1);
 

	
 
				if (show_todo && s[0]) {
 
					if (show_todo == 2) {
 
						fprintf(stderr, "Warning:%s: String '%s' is untranslated\n", filename, s + 1);
 
					} else {
 
						char *s = "<TODO> ";
 
						const char *s = "<TODO> ";
 
						while(*s) put_byte(*s++);
 
					}
 
				}
 

	
 
				for(;;) {
 
					cs = parse_command_string(&str, param, s[0] ? "english.lng" : filename);
 
@@ -766,16 +766,16 @@ int main(int argc, char* argv[])
 
	if (argc == 1) {
 
		// parse master file
 
		parse_file("lang/english.txt", true);
 
		if (_warnings) return 1;
 

	
 
		// write english.lng and strings.h
 
		
 

	
 
		write_langfile("lang/english.lng", 0);
 
		write_strings_h("table/strings.h");
 
		
 

	
 
	} else if (argc == 2) {
 
		parse_file("lang/english.txt", true);
 
		parse_file(argv[1], false);
 
		if (_warnings) return 1;
 
		strcpy(buf, argv[1]);
 
		r = strrchr(buf, '.');