src/strgen/strgen.cpp
branchNewGRF_ports
changeset 6871 5a9dc001e1ad
parent 6743 cabfaa4a0295
child 6872 1c4a4a609f85
equal deleted inserted replaced
6870:ca3fd1fbe311 6871:5a9dc001e1ad
   219 
   219 
   220 size_t Utf8Validate(const char *s)
   220 size_t Utf8Validate(const char *s)
   221 {
   221 {
   222 	uint32 c;
   222 	uint32 c;
   223 
   223 
   224 	if (!HASBIT(s[0], 7)) {
   224 	if (!HasBit(s[0], 7)) {
   225 		/* 1 byte */
   225 		/* 1 byte */
   226 		return 1;
   226 		return 1;
   227 	} else if (GB(s[0], 5, 3) == 6 && IsUtf8Part(s[1])) {
   227 	} else if (GB(s[0], 5, 3) == 6 && IsUtf8Part(s[1])) {
   228 		/* 2 bytes */
   228 		/* 2 bytes */
   229 		c = GB(s[0], 0, 5) << 6 | GB(s[1], 0, 6);
   229 		c = GB(s[0], 0, 5) << 6 | GB(s[1], 0, 6);
  1012 static void WriteStringsH(const char *filename)
  1012 static void WriteStringsH(const char *filename)
  1013 {
  1013 {
  1014 	FILE *out;
  1014 	FILE *out;
  1015 	int i;
  1015 	int i;
  1016 	int next = -1;
  1016 	int next = -1;
  1017 	int lastgrp;
       
  1018 
  1017 
  1019 	out = fopen("tmp.xxx", "w");
  1018 	out = fopen("tmp.xxx", "w");
  1020 	if (out == NULL) fatal("can't open tmp.xxx");
  1019 	if (out == NULL) fatal("can't open tmp.xxx");
  1021 
  1020 
  1022 	fprintf(out, "/* This file is automatically generated. Do not modify */\n\n");
  1021 	fprintf(out, "/* This file is automatically generated. Do not modify */\n\n");
  1023 	fprintf(out, "#ifndef TABLE_STRINGS_H\n");
  1022 	fprintf(out, "#ifndef TABLE_STRINGS_H\n");
  1024 	fprintf(out, "#define TABLE_STRINGS_H\n");
  1023 	fprintf(out, "#define TABLE_STRINGS_H\n");
  1025 
       
  1026 	lastgrp = 0;
       
  1027 
  1024 
  1028 	for (i = 0; i != lengthof(_strings); i++) {
  1025 	for (i = 0; i != lengthof(_strings); i++) {
  1029 		if (_strings[i] != NULL) {
  1026 		if (_strings[i] != NULL) {
  1030 			if (next != i) fprintf(out, "\n");
  1027 			if (next != i) fprintf(out, "\n");
  1031 			fprintf(out, "static const StringID %s = 0x%X;\n", _strings[i]->name, i);
  1028 			fprintf(out, "static const StringID %s = 0x%X;\n", _strings[i]->name, i);
  1032 			next = i + 1;
  1029 			next = i + 1;
  1033 		}
  1030 		}
  1034 	}
  1031 	}
       
  1032 
       
  1033 	fprintf(out, "\nstatic const StringID STR_LAST_STRINGID = 0x%X;\n", next - 1);
  1035 
  1034 
  1036 	fprintf(out,
  1035 	fprintf(out,
  1037 		"\nenum {\n"
  1036 		"\nenum {\n"
  1038 		"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n"
  1037 		"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n"
  1039 		"\tLANGUAGE_PACK_VERSION = 0x%X,\n"
  1038 		"\tLANGUAGE_PACK_VERSION = 0x%X,\n"