Changeset - r5344:713e0cc79bc9
[Not reviewed]
master
0 1 0
Darkvater - 18 years ago 2006-12-20 17:03:14
darkvater@openttd.org
(svn r7515) -Codechange [newgrf]: Ignore ascii code 0x0A in text. Newline is 0x0D.
1 file changed with 2 insertions and 1 deletions:
0 comments (0 inline, 0 general)
newgrf_text.c
Show inline comments
 
@@ -86,193 +86,194 @@ typedef struct iso_grf {
 
 *   with newgrf bit positionning language id
 
 * 2-its shift part is used to know what is the shift to
 
 *   watch for when inserting new strings, hence analysing newgrf langid
 
 */
 
const iso_grf iso_codes[] = {
 
	{"en_US", GRFLX_AMERICAN},
 
	{"en_GB", GRFLX_ENGLISH},
 
	{"de_DE", GRFLX_GERMAN},
 
	{"fr_FR", GRFLX_FRENCH},
 
	{"es_ES", GRFLX_SPANISH},
 
	{"af_ZA", GRFLX_AFRIKAANS},
 
	{"hr_HR", GRFLX_CROATIAN},
 
	{"cs_CS", GRFLX_CZECH},
 
	{"ca_ES", GRFLX_CATALAN},
 
	{"da_DA", GRFLX_DANISH},
 
	{"nl_NL", GRFLX_DUTCH},
 
	{"et_ET", GRFLX_ESTONIAN},
 
	{"fi_FI", GRFLX_FINNISH},
 
	{"fy_NL", GRFLX_FRISIAN},
 
	{"gl_ES", GRFLX_GALICIAN},
 
	{"el_GR", GRFLX_GREEK},
 
	{"hu_HU", GRFLX_HUNGARIAN},
 
	{"is_IS", GRFLX_ICELANDIC},
 
	{"it_IT", GRFLX_ITALIAN},
 
	{"lv_LV", GRFLX_LATVIAN},
 
	{"lt_LT", GRFLX_LITHUANIAN},
 
	{"nb_NO", GRFLX_NORWEGIAN},
 
	{"pl_PL", GRFLX_POLISH},
 
	{"pt_PT", GRFLX_PORTUGUESE},
 
	{"pt_BR", GRFLX_BRAZILIAN},
 
	{"ro_RO", GRFLX_ROMANIAN},
 
	{"ru_RU", GRFLX_RUSSIAN},
 
	{"sk_SK", GRFLX_SLOVAK},
 
	{"sl_SL", GRFLX_SLOVENIAN},
 
	{"sv_SE", GRFLX_SWEDISH},
 
	{"tr_TR", GRFLX_TURKISH},
 
	{"uk_UA", GRFLX_UKRAINIAN},
 
	{"gen",   GRFLB_GENERIC}   //this is not iso code, but there has to be something...
 
};
 

	
 

	
 
/**
 
 * Element of the linked list.
 
 * Each of those elements represent the string,
 
 * but according to a different lang.
 
 */
 
typedef struct GRFText {
 
	struct GRFText *next;
 
	byte langid;
 
	char text[VARARRAY_SIZE];
 
} GRFText;
 

	
 

	
 
/**
 
 * Holder of the above structure.
 
 * Putting both grfid and stringid together allows us to avoid duplicates,
 
 * since it is NOT SUPPOSED to happen.
 
 */
 
typedef struct GRFTextEntry {
 
	uint32 grfid;
 
	uint16 stringid;
 
	StringID def_string;
 
	GRFText *textholder;
 
} GRFTextEntry;
 

	
 

	
 
static uint _num_grf_texts = 0;
 
static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
 
static byte _currentLangID = GRFLX_ENGLISH;  //by default, english is used.
 

	
 

	
 
char *TranslateTTDPatchCodes(const char *str)
 
{
 
	char *tmp = malloc(strlen(str) * 10 + 1); /* Allocate space to allow for expansion */
 
	char *d = tmp;
 
	bool unicode = false;
 
	WChar c;
 
	size_t len = Utf8Decode(&c, str);
 

	
 
	if (c == 0x00DE) {
 
		/* The thorn ('รพ') indicates a unicode string to TTDPatch */
 
		unicode = true;
 
		str += len;
 
	}
 

	
 
	for (;;) {
 
		const char *tmp = str; /* Used for UTF-8 decoding */
 

	
 
		c = (byte)*str++;
 
		if (c == 0) break;
 

	
 
		switch (c) {
 
			case 0x01:
 
				d += Utf8Encode(d, SCC_SETX);
 
				*d++ = *str++;
 
				break;
 
			case 0x0D: *d++ = 10; break;
 
			case 0x0A: break;
 
			case 0x0D: *d++ = 0x0A; break;
 
			case 0x0E: d += Utf8Encode(d, SCC_TINYFONT); break;
 
			case 0x0F: d += Utf8Encode(d, SCC_BIGFONT); break;
 
			case 0x1F:
 
				d += Utf8Encode(d, SCC_SETXY);
 
				*d++ = *str++;
 
				*d++ = *str++;
 
				break;
 
			case 0x7B:
 
			case 0x7C:
 
			case 0x7D:
 
			case 0x7E: d += Utf8Encode(d, SCC_NUM); break;
 
			case 0x7F: d += Utf8Encode(d, SCC_CURRENCY); break;
 
			case 0x80: d += Utf8Encode(d, SCC_STRING); break;
 
			case 0x81: {
 
				StringID string;
 
				string  = *str++;
 
				string |= *str++ << 8;
 
				d += Utf8Encode(d, SCC_STRING_ID);
 
				d += Utf8Encode(d, string);
 
				break;
 
			}
 
			case 0x82: d += Utf8Encode(d, SCC_DATE_TINY); break;
 
			case 0x83: d += Utf8Encode(d, SCC_DATE_SHORT); break;
 
			case 0x84: d += Utf8Encode(d, SCC_VELOCITY); break;
 
			case 0x85: d += Utf8Encode(d, SCC_SKIP);    break;
 
			case 0x86: /* "Rotate down top 4 words on stack" */ break;
 
			case 0x87: d += Utf8Encode(d, SCC_VOLUME);  break;
 
			case 0x88: d += Utf8Encode(d, SCC_BLUE);    break;
 
			case 0x89: d += Utf8Encode(d, SCC_SILVER);  break;
 
			case 0x8A: d += Utf8Encode(d, SCC_GOLD);    break;
 
			case 0x8B: d += Utf8Encode(d, SCC_RED);     break;
 
			case 0x8C: d += Utf8Encode(d, SCC_PURPLE);  break;
 
			case 0x8D: d += Utf8Encode(d, SCC_LTBROWN); break;
 
			case 0x8E: d += Utf8Encode(d, SCC_ORANGE);  break;
 
			case 0x8F: d += Utf8Encode(d, SCC_GREEN);   break;
 
			case 0x90: d += Utf8Encode(d, SCC_YELLOW);  break;
 
			case 0x91: d += Utf8Encode(d, SCC_DKGREEN); break;
 
			case 0x92: d += Utf8Encode(d, SCC_CREAM);   break;
 
			case 0x93: d += Utf8Encode(d, SCC_BROWN);   break;
 
			case 0x94: d += Utf8Encode(d, SCC_WHITE);   break;
 
			case 0x95: d += Utf8Encode(d, SCC_LTBLUE);  break;
 
			case 0x96: d += Utf8Encode(d, SCC_GRAY);    break;
 
			case 0x97: d += Utf8Encode(d, SCC_DKBLUE);  break;
 
			case 0x98: d += Utf8Encode(d, SCC_BLACK);   break;
 
			case 0x9E: d += Utf8Encode(d, 0x20AC); break; // Euro
 
			case 0x9F: d += Utf8Encode(d, 0x0178); break; // Y with diaeresis
 
			case 0xA0: d += Utf8Encode(d, SCC_UPARROW); break;
 
			case 0xAA: d += Utf8Encode(d, SCC_DOWNARROW); break;
 
			case 0xAC: d += Utf8Encode(d, SCC_CHECKMARK); break;
 
			case 0xAD: d += Utf8Encode(d, SCC_CROSS); break;
 
			case 0xAF: d += Utf8Encode(d, SCC_RIGHTARROW); break;
 
			case 0xB4: d += Utf8Encode(d, SCC_TRAIN); break;
 
			case 0xB5: d += Utf8Encode(d, SCC_LORRY); break;
 
			case 0xB6: d += Utf8Encode(d, SCC_BUS); break;
 
			case 0xB7: d += Utf8Encode(d, SCC_PLANE); break;
 
			case 0xB8: d += Utf8Encode(d, SCC_SHIP); break;
 
			default:
 
				if (unicode) {
 
					d += Utf8Encode(d, Utf8Consume(&tmp));
 
					str = tmp;
 
					break;
 
				}
 

	
 
				/* Validate any unhandled character */
 
				if (!IsValidChar(c, CS_ALPHANUMERAL)) c = '?';
 
				d += Utf8Encode(d, c);
 
				break;
 
		}
 
	}
 

	
 
	*d = '\0';
 
	return realloc(tmp, strlen(tmp) + 1);
 
}
 

	
 

	
 
/**
 
 * Add the new read string into our structure.
 
 */
 
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, const char *text_to_add, StringID def_string)
 
{
 
	char *translatedtext;
 
	GRFText *newtext;
 
	uint id;
 

	
 
	/* When working with the old language scheme (grf_version is less than 7) and
 
	 * English or American is among the set bits, simply add it as English in
 
	 * the new scheme, i.e. as langid = 1.
 
	 * If English is set, it is pretty safe to assume the translations are not
 
	 * actually translated.
 
	 */
 
	if (!new_scheme) {
 
		if (HASBITS(langid_to_add, GRFLB_AMERICAN | GRFLB_ENGLISH)) {
 
			langid_to_add = GRFLX_ENGLISH;
 
		} else {
 
			StringID ret = STR_EMPTY;
 
			if (langid_to_add & GRFLB_GERMAN)  ret = AddGRFString(grfid, stringid, GRFLX_GERMAN,  true, text_to_add, def_string);
0 comments (0 inline, 0 general)