Changeset - r18941:8b8e5486e2f8
[Not reviewed]
master
0 4 0
frosch - 12 years ago 2012-01-15 15:49:01
frosch@openttd.org
(svn r23805) -Add: {STRING6} and {STRING7}.
4 files changed with 17 insertions and 44 deletions:
0 comments (0 inline, 0 general)
src/strgen/strgen_base.cpp
Show inline comments
 
@@ -606,48 +606,50 @@ static void ExtractCommandString(ParsedC
 
			if (argno != -1) argidx = argno;
 
			if (argidx < 0 || (uint)argidx >= lengthof(p->cmd)) strgen_fatal("invalid param idx %d", argidx);
 
			if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) strgen_fatal("duplicate param idx %d", argidx);
 

	
 
			p->cmd[argidx++] = ar;
 
		} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them
 
			if (p->np >= lengthof(p->pairs)) strgen_fatal("too many commands in string, max " PRINTF_SIZE, lengthof(p->pairs));
 
			p->pairs[p->np].a = ar;
 
			p->pairs[p->np].v = param[0] != '\0' ? strdup(param) : "";
 
			p->np++;
 
		}
 
	}
 
}
 

	
 

	
 
static const CmdStruct *TranslateCmdForCompare(const CmdStruct *a)
 
{
 
	if (a == NULL) return NULL;
 

	
 
	if (strcmp(a->cmd, "STRING1") == 0 ||
 
			strcmp(a->cmd, "STRING2") == 0 ||
 
			strcmp(a->cmd, "STRING3") == 0 ||
 
			strcmp(a->cmd, "STRING4") == 0 ||
 
			strcmp(a->cmd, "STRING5") == 0 ||
 
			strcmp(a->cmd, "STRING6") == 0 ||
 
			strcmp(a->cmd, "STRING7") == 0 ||
 
			strcmp(a->cmd, "RAW_STRING") == 0) {
 
		return FindCmd("STRING", 6);
 
	}
 

	
 
	return a;
 
}
 

	
 

	
 
static bool CheckCommandsMatch(char *a, char *b, const char *name)
 
{
 
	/* If we're not translating, i.e. we're compiling the base language,
 
	 * it is pointless to do all these checks as it'll always be correct.
 
	 * After all, all checks are based on the base language.
 
	 */
 
	if (!_translation) return true;
 

	
 
	ParsedCommandStruct templ;
 
	ParsedCommandStruct lang;
 
	bool result = true;
 

	
 
	ExtractCommandString(&templ, b, true);
 
	ExtractCommandString(&lang, a, true);
 

	
 
	/* For each string in templ, see if we find it in lang */
src/strings.cpp
Show inline comments
 
@@ -947,93 +947,59 @@ static char *FormatString(char *buff, co
 
			case SCC_STRING_ID: // {STRINL}
 
				if (game_script) break;
 
				buff = GetStringWithArgs(buff, Utf8Consume(&str), args, last);
 
				break;
 

	
 
			case SCC_RAW_STRING_POINTER: { // {RAW_STRING}
 
				if (game_script) break;
 
				const char *str = (const char *)(size_t)args->GetInt64(SCC_RAW_STRING_POINTER);
 
				buff = FormatString(buff, str, args, last);
 
				break;
 
			}
 

	
 
			case SCC_STRING: {// {STRING}
 
				StringID str = args->GetInt32(SCC_STRING);
 
				if (game_script && GB(str, TAB_COUNT_OFFSET, TAB_COUNT_BITS) != GAME_TEXT_TAB) break;
 
				/* WARNING. It's prohibited for the included string to consume any arguments.
 
				 * For included strings that consume argument, you should use STRING1, STRING2 etc.
 
				 * To debug stuff you can set argv to NULL and it will tell you */
 
				StringParameters tmp_params(args->GetDataPointer(), args->num_param - args->offset, NULL);
 
				buff = GetStringWithArgs(buff, str, &tmp_params, last, next_substr_case_index, game_script);
 
				next_substr_case_index = 0;
 
				break;
 
			}
 

	
 
			case SCC_STRING1: { // {STRING1}
 
				/* String that consumes ONE argument */
 
				StringID str = args->GetInt32(SCC_STRING1);
 
				if (game_script && GB(str, TAB_COUNT_OFFSET, TAB_COUNT_BITS) != GAME_TEXT_TAB) break;
 
				StringParameters sub_args(*args, 1);
 
				buff = GetStringWithArgs(buff, str, &sub_args, last, next_substr_case_index, game_script);
 
				next_substr_case_index = 0;
 
				break;
 
			}
 

	
 
			case SCC_STRING2: { // {STRING2}
 
				/* String that consumes TWO arguments */
 
				StringID str = args->GetInt32(SCC_STRING2);
 
			case SCC_STRING1:
 
			case SCC_STRING2:
 
			case SCC_STRING3:
 
			case SCC_STRING4:
 
			case SCC_STRING5:
 
			case SCC_STRING6:
 
			case SCC_STRING7: { // {STRING1..7}
 
				/* Strings that consume arguments */
 
				StringID str = args->GetInt32(b);
 
				if (game_script && GB(str, TAB_COUNT_OFFSET, TAB_COUNT_BITS) != GAME_TEXT_TAB) break;
 
				StringParameters sub_args(*args, 2);
 
				buff = GetStringWithArgs(buff, str, &sub_args, last, next_substr_case_index, game_script);
 
				next_substr_case_index = 0;
 
				break;
 
			}
 

	
 
			case SCC_STRING3: { // {STRING3}
 
				/* String that consumes THREE arguments */
 
				StringID str = args->GetInt32(SCC_STRING3);
 
				if (game_script && GB(str, TAB_COUNT_OFFSET, TAB_COUNT_BITS) != GAME_TEXT_TAB) break;
 
				StringParameters sub_args(*args, 3);
 
				buff = GetStringWithArgs(buff, str, &sub_args, last, next_substr_case_index, game_script);
 
				next_substr_case_index = 0;
 
				break;
 
			}
 

	
 
			case SCC_STRING4: { // {STRING4}
 
				/* String that consumes FOUR arguments */
 
				StringID str = args->GetInt32(SCC_STRING4);
 
				if (game_script && GB(str, TAB_COUNT_OFFSET, TAB_COUNT_BITS) != GAME_TEXT_TAB) break;
 
				StringParameters sub_args(*args, 4);
 
				buff = GetStringWithArgs(buff, str, &sub_args, last, next_substr_case_index, game_script);
 
				next_substr_case_index = 0;
 
				break;
 
			}
 

	
 
			case SCC_STRING5: { // {STRING5}
 
				/* String that consumes FIVE arguments */
 
				StringID str = args->GetInt32(SCC_STRING5);
 
				if (game_script && GB(str, TAB_COUNT_OFFSET, TAB_COUNT_BITS) != GAME_TEXT_TAB) break;
 
				StringParameters sub_args(*args, 5);
 
				StringParameters sub_args(*args, b - SCC_STRING1 + 1);
 
				buff = GetStringWithArgs(buff, str, &sub_args, last, next_substr_case_index, game_script);
 
				next_substr_case_index = 0;
 
				break;
 
			}
 

	
 
			case SCC_COMMA: // {COMMA}
 
				buff = FormatCommaNumber(buff, args->GetInt64(SCC_COMMA), last);
 
				break;
 

	
 
			case SCC_DECIMAL: {// {DECIMAL}
 
				int64 number = args->GetInt64(SCC_DECIMAL);
 
				int digits = args->GetInt32(SCC_DECIMAL);
 
				buff = FormatCommaNumber(buff, number, last, digits);
 
				break;
 
			}
 

	
 
			case SCC_NUM: // {NUM}
 
				buff = FormatNoCommaNumber(buff, args->GetInt64(SCC_NUM), last);
 
				break;
 

	
 
			case SCC_ZEROFILL_NUM: { // {ZEROFILL_NUM}
 
				int64 num = args->GetInt64();
 
				buff = FormatZerofillNumber(buff, num, args->GetInt64(), last);
 
				break;
src/table/control_codes.h
Show inline comments
 
@@ -44,53 +44,56 @@ enum StringControlCode {
 
	SCC_COMPANY_NAME,
 
	SCC_PRESIDENT_NAME,
 
	SCC_ENGINE_NAME,
 

	
 
	SCC_CURRENCY_SHORT,
 
	SCC_CURRENCY_LONG,
 

	
 
	SCC_CARGO_LONG,
 
	SCC_CARGO_SHORT,
 
	SCC_CARGO_TINY,
 
	SCC_POWER,
 
	SCC_VOLUME_LONG,
 
	SCC_VOLUME_SHORT,
 
	SCC_WEIGHT_LONG,
 
	SCC_WEIGHT_SHORT,
 
	SCC_FORCE,
 
	SCC_VELOCITY,
 
	SCC_HEIGHT,
 

	
 
	SCC_DATE_TINY,
 
	SCC_DATE_SHORT,
 
	SCC_DATE_LONG,
 
	SCC_DATE_ISO,
 

	
 
	/* Must be consecutive */
 
	SCC_STRING1,
 
	SCC_STRING2,
 
	SCC_STRING3,
 
	SCC_STRING4,
 
	SCC_STRING5,
 
	SCC_STRING6,
 
	SCC_STRING7,
 

	
 
	SCC_ENCODED,
 

	
 
	SCC_STRING,
 
	SCC_COMMA,
 
	SCC_DECIMAL,
 
	SCC_NUM,
 
	SCC_ZEROFILL_NUM,
 
	SCC_HEX,
 
	SCC_BYTES,
 

	
 
	SCC_STRING_ID,
 
	SCC_RAW_STRING_POINTER,
 
	SCC_PLURAL_LIST,
 
	SCC_GENDER_LIST,
 
	SCC_GENDER_INDEX,
 
	SCC_ARG_INDEX,
 
	SCC_SET_CASE,
 
	SCC_SWITCH_CASE,
 

	
 
	/* Colour codes */
 
	SCC_BLUE,
 
	SCC_SILVER,
 
	SCC_GOLD,
src/table/strgen_tables.h
Show inline comments
 
@@ -44,48 +44,50 @@ static const CmdStruct _cmd_structs[] = 
 
	{"SILVER",            EmitSingleChar, SCC_SILVER,             0, C_NONE},
 
	{"GOLD",              EmitSingleChar, SCC_GOLD,               0, C_NONE},
 
	{"RED",               EmitSingleChar, SCC_RED,                0, C_NONE},
 
	{"PURPLE",            EmitSingleChar, SCC_PURPLE,             0, C_NONE},
 
	{"LTBROWN",           EmitSingleChar, SCC_LTBROWN,            0, C_NONE},
 
	{"ORANGE",            EmitSingleChar, SCC_ORANGE,             0, C_NONE},
 
	{"GREEN",             EmitSingleChar, SCC_GREEN,              0, C_NONE},
 
	{"YELLOW",            EmitSingleChar, SCC_YELLOW,             0, C_NONE},
 
	{"DKGREEN",           EmitSingleChar, SCC_DKGREEN,            0, C_NONE},
 
	{"CREAM",             EmitSingleChar, SCC_CREAM,              0, C_NONE},
 
	{"BROWN",             EmitSingleChar, SCC_BROWN,              0, C_NONE},
 
	{"WHITE",             EmitSingleChar, SCC_WHITE,              0, C_NONE},
 
	{"LTBLUE",            EmitSingleChar, SCC_LTBLUE,             0, C_NONE},
 
	{"GRAY",              EmitSingleChar, SCC_GRAY,               0, C_NONE},
 
	{"DKBLUE",            EmitSingleChar, SCC_DKBLUE,             0, C_NONE},
 
	{"BLACK",             EmitSingleChar, SCC_BLACK,              0, C_NONE},
 

	
 
	{"REV",               EmitSingleChar, SCC_REVISION,           0, C_NONE}, // openttd revision string
 

	
 
	{"STRING1",           EmitSingleChar, SCC_STRING1,            2, C_CASE | C_GENDER}, // included string that consumes the string id and ONE argument
 
	{"STRING2",           EmitSingleChar, SCC_STRING2,            3, C_CASE | C_GENDER}, // included string that consumes the string id and TWO arguments
 
	{"STRING3",           EmitSingleChar, SCC_STRING3,            4, C_CASE | C_GENDER}, // included string that consumes the string id and THREE arguments
 
	{"STRING4",           EmitSingleChar, SCC_STRING4,            5, C_CASE | C_GENDER}, // included string that consumes the string id and FOUR arguments
 
	{"STRING5",           EmitSingleChar, SCC_STRING5,            6, C_CASE | C_GENDER}, // included string that consumes the string id and FIVE arguments
 
	{"STRING6",           EmitSingleChar, SCC_STRING6,            7, C_CASE | C_GENDER}, // included string that consumes the string id and SIX arguments
 
	{"STRING7",           EmitSingleChar, SCC_STRING7,            8, C_CASE | C_GENDER}, // included string that consumes the string id and SEVEN arguments
 

	
 
	{"STATION_FEATURES",  EmitSingleChar, SCC_STATION_FEATURES,   1, C_NONE}, // station features string, icons of the features
 
	{"INDUSTRY",          EmitSingleChar, SCC_INDUSTRY_NAME,      1, C_CASE | C_GENDER}, // industry, takes an industry #, can have cases
 
	{"CARGO_LONG",        EmitSingleChar, SCC_CARGO_LONG,         2, C_NONE | C_GENDER},
 
	{"CARGO_SHORT",       EmitSingleChar, SCC_CARGO_SHORT,        2, C_NONE}, // short cargo description, only ### tons, or ### litres
 
	{"CARGO_TINY",        EmitSingleChar, SCC_CARGO_TINY,         2, C_NONE}, // tiny cargo description with only the amount, not a specifier for the amount or the actual cargo name
 
	{"POWER",             EmitSingleChar, SCC_POWER,              1, C_NONE},
 
	{"VOLUME_LONG",       EmitSingleChar, SCC_VOLUME_LONG,        1, C_NONE},
 
	{"VOLUME_SHORT",      EmitSingleChar, SCC_VOLUME_SHORT,       1, C_NONE},
 
	{"WEIGHT_LONG",       EmitSingleChar, SCC_WEIGHT_LONG,        1, C_NONE},
 
	{"WEIGHT_SHORT",      EmitSingleChar, SCC_WEIGHT_SHORT,       1, C_NONE},
 
	{"FORCE",             EmitSingleChar, SCC_FORCE,              1, C_NONE},
 
	{"VELOCITY",          EmitSingleChar, SCC_VELOCITY,           1, C_NONE},
 
	{"HEIGHT",            EmitSingleChar, SCC_HEIGHT,             1, C_NONE},
 

	
 
	{"P",                 EmitPlural,     0,                      0, C_DONTCOUNT}, // plural specifier
 
	{"G",                 EmitGender,     0,                      0, C_DONTCOUNT}, // gender specifier
 

	
 
	{"DATE_TINY",         EmitSingleChar, SCC_DATE_TINY,          1, C_NONE},
 
	{"DATE_SHORT",        EmitSingleChar, SCC_DATE_SHORT,         1, C_CASE},
 
	{"DATE_LONG",         EmitSingleChar, SCC_DATE_LONG,          1, C_CASE},
 
	{"DATE_ISO",          EmitSingleChar, SCC_DATE_ISO,           1, C_NONE},
 

	
 
	{"STRING",            EmitSingleChar, SCC_STRING,             1, C_CASE | C_GENDER},
0 comments (0 inline, 0 general)