(svn r4888) CodeChange : Newgrf : little cleanup and additions
-Add 4 new langIDs (Afrikaans, greek, ukrainian,croatian) -Only allocate memory when the string will be inserted -In order to avoid the UTF-8 marker, compare based on length of defined iso_code (thanks peter1138) -Synch with lang files iso_code cleanup
This commit is contained in:
		| @@ -45,6 +45,8 @@ typedef enum grf_extended_languages { | |||||||
| 	GRFLX_RUSSIAN     = 0x07, | 	GRFLX_RUSSIAN     = 0x07, | ||||||
| 	GRFLX_CZECH       = 0x15, | 	GRFLX_CZECH       = 0x15, | ||||||
| 	GRFLX_SLOVAK      = 0x16, | 	GRFLX_SLOVAK      = 0x16, | ||||||
|  | 	GRFLX_AFRIKAANS   = 0x1B, | ||||||
|  | 	GRFLX_GREEK       = 0x1E, | ||||||
| 	GRFLX_DUTCH       = 0x1F, | 	GRFLX_DUTCH       = 0x1F, | ||||||
| 	GRFLX_CATALAN     = 0x22, | 	GRFLX_CATALAN     = 0x22, | ||||||
| 	GRFLX_HUNGARIAN   = 0x24, | 	GRFLX_HUNGARIAN   = 0x24, | ||||||
| @@ -60,10 +62,12 @@ typedef enum grf_extended_languages { | |||||||
| 	GRFLX_POLISH      = 0x30, | 	GRFLX_POLISH      = 0x30, | ||||||
| 	GRFLX_GALICIAN    = 0x31, | 	GRFLX_GALICIAN    = 0x31, | ||||||
| 	GRFLX_FRISIAN     = 0x32, | 	GRFLX_FRISIAN     = 0x32, | ||||||
|  | 	GRFLX_UKRAINIAN   = 0x33, | ||||||
| 	GRFLX_ESTONIAN    = 0x34, | 	GRFLX_ESTONIAN    = 0x34, | ||||||
| 	GRFLX_FINNISH     = 0x35, | 	GRFLX_FINNISH     = 0x35, | ||||||
| 	GRFLX_PORTUGUESE  = 0x36, | 	GRFLX_PORTUGUESE  = 0x36, | ||||||
| 	GRFLX_BRAZILIAN   = 0x37, | 	GRFLX_BRAZILIAN   = 0x37, | ||||||
|  | 	GRFLX_CROATIAN    = 0x38, | ||||||
| 	GRFLX_TURKISH     = 0x3E, | 	GRFLX_TURKISH     = 0x3E, | ||||||
| 	GRFLX_UNSPECIFIED = 0x7F, | 	GRFLX_UNSPECIFIED = 0x7F, | ||||||
| } grf_language; | } grf_language; | ||||||
| @@ -85,32 +89,36 @@ typedef struct iso_grf { | |||||||
| const iso_grf iso_codes[] = { | const iso_grf iso_codes[] = { | ||||||
| 	{"en_US", GRFLX_AMERICAN}, | 	{"en_US", GRFLX_AMERICAN}, | ||||||
| 	{"en_GB", GRFLX_ENGLISH}, | 	{"en_GB", GRFLX_ENGLISH}, | ||||||
| 	{"de",    GRFLX_GERMAN}, | 	{"de_DE", GRFLX_GERMAN}, | ||||||
| 	{"fr",    GRFLX_FRENCH}, | 	{"fr_FR", GRFLX_FRENCH}, | ||||||
| 	{"es",    GRFLX_SPANISH}, | 	{"es_ES", GRFLX_SPANISH}, | ||||||
| 	{"cs",    GRFLX_CZECH}, | 	{"af_ZA", GRFLX_AFRIKAANS}, | ||||||
| 	{"ca",    GRFLX_CATALAN}, | 	{"hr_HR", GRFLX_CROATIAN}, | ||||||
| 	{"da",    GRFLX_DANISH}, | 	{"cs_CS", GRFLX_CZECH}, | ||||||
| 	{"nl",    GRFLX_DUTCH}, | 	{"ca_ES", GRFLX_CATALAN}, | ||||||
| 	{"et",    GRFLX_ESTONIAN}, | 	{"da_DA", GRFLX_DANISH}, | ||||||
| 	{"fi",    GRFLX_FINNISH}, | 	{"nl_NL", GRFLX_DUTCH}, | ||||||
| 	{"fy",    GRFLX_FRISIAN}, | 	{"et_ET", GRFLX_ESTONIAN}, | ||||||
| 	{"gl",    GRFLX_GALICIAN}, | 	{"fi_FI", GRFLX_FINNISH}, | ||||||
| 	{"hu",    GRFLX_HUNGARIAN}, | 	{"fy_NL", GRFLX_FRISIAN}, | ||||||
| 	{"is",    GRFLX_ICELANDIC}, | 	{"gl_ES", GRFLX_GALICIAN}, | ||||||
| 	{"it",    GRFLX_ITALIAN}, | 	{"el_GR", GRFLX_GREEK}, | ||||||
| 	{"lv",    GRFLX_LATVIAN}, | 	{"hu_HU", GRFLX_HUNGARIAN}, | ||||||
| 	{"lt",    GRFLX_LITHUANIAN}, | 	{"is_IS", GRFLX_ICELANDIC}, | ||||||
| 	{"nb",    GRFLX_NORWEGIAN}, | 	{"it_IT", GRFLX_ITALIAN}, | ||||||
| 	{"pl",    GRFLX_POLISH}, | 	{"lv_LV", GRFLX_LATVIAN}, | ||||||
| 	{"pt",    GRFLX_PORTUGUESE}, | 	{"lt_LT", GRFLX_LITHUANIAN}, | ||||||
|  | 	{"nb_NO", GRFLX_NORWEGIAN}, | ||||||
|  | 	{"pl_PL", GRFLX_POLISH}, | ||||||
|  | 	{"pt_PT", GRFLX_PORTUGUESE}, | ||||||
| 	{"pt_BR", GRFLX_BRAZILIAN}, | 	{"pt_BR", GRFLX_BRAZILIAN}, | ||||||
| 	{"ro",    GRFLX_ROMANIAN}, | 	{"ro_RO", GRFLX_ROMANIAN}, | ||||||
| 	{"ru",    GRFLX_RUSSIAN}, | 	{"ru_RU", GRFLX_RUSSIAN}, | ||||||
| 	{"sk",    GRFLX_SLOVAK}, | 	{"sk_SK", GRFLX_SLOVAK}, | ||||||
| 	{"sl",    GRFLX_SLOVENIAN}, | 	{"sl_SL", GRFLX_SLOVENIAN}, | ||||||
| 	{"sv",    GRFLX_SWEDISH}, | 	{"sv_SE", GRFLX_SWEDISH}, | ||||||
| 	{"tr",    GRFLX_TURKISH}, | 	{"tr_TR", GRFLX_TURKISH}, | ||||||
|  | 	{"uk_UA", GRFLX_UKRAINIAN}, | ||||||
| 	{"gen",   GRFLB_GENERIC}   //this is not iso code, but there has to be something... | 	{"gen",   GRFLB_GENERIC}   //this is not iso code, but there has to be something... | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -189,13 +197,6 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	newtext = calloc(1, sizeof(*newtext)); |  | ||||||
| 	newtext->langid = GB(langid_to_add, 0, 6); |  | ||||||
| 	newtext->text   = strdup(text_to_add); |  | ||||||
| 	newtext->next   = NULL; |  | ||||||
|  |  | ||||||
| 	TranslateTTDPatchCodes(newtext->text); |  | ||||||
|  |  | ||||||
| 	for (id = 0; id < _num_grf_texts; id++) { | 	for (id = 0; id < _num_grf_texts; id++) { | ||||||
| 		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) { | 		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) { | ||||||
| 			break; | 			break; | ||||||
| @@ -205,6 +206,13 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne | |||||||
| 	/* Too many strings allocated, return empty */ | 	/* Too many strings allocated, return empty */ | ||||||
| 	if (id == lengthof(_grf_text)) return STR_EMPTY; | 	if (id == lengthof(_grf_text)) return STR_EMPTY; | ||||||
|  |  | ||||||
|  | 	newtext = calloc(1, sizeof(*newtext)); | ||||||
|  | 	newtext->langid = GB(langid_to_add, 0, 6); | ||||||
|  | 	newtext->text   = strdup(text_to_add); | ||||||
|  | 	newtext->next   = NULL; | ||||||
|  |  | ||||||
|  | 	TranslateTTDPatchCodes(newtext->text); | ||||||
|  |  | ||||||
| 	/* If we didn't find our stringid and grfid in the list, allocate a new id */ | 	/* If we didn't find our stringid and grfid in the list, allocate a new id */ | ||||||
| 	if (id == _num_grf_texts) _num_grf_texts++; | 	if (id == _num_grf_texts) _num_grf_texts++; | ||||||
|  |  | ||||||
| @@ -285,7 +293,7 @@ void SetCurrentGrfLangID(const char *iso_name) | |||||||
| 	ret = GRFLX_ENGLISH; | 	ret = GRFLX_ENGLISH; | ||||||
|  |  | ||||||
| 	for (i=0; i < lengthof(iso_codes); i++) { | 	for (i=0; i < lengthof(iso_codes); i++) { | ||||||
| 		if (strcmp(iso_codes[i].code, iso_name) == 0) { | 		if (strncmp(iso_codes[i].code, iso_name, strlen(iso_codes[i].code) == 0)) { | ||||||
| 			/* We found a match, so let's use it. */ | 			/* We found a match, so let's use it. */ | ||||||
| 			ret = i; | 			ret = i; | ||||||
| 			break; | 			break; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 belugas
					belugas