# strgen_tables.h

Go to the documentation of this file.

    00001 /* $Id: strgen_tables.h 24910 2013-01-12 17:21:30Z frosch $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #include "../core/enum_type.hpp"
    00013
    00014 enum CmdFlags {
    00015   C_NONE      = 0x0,
    00016   C_DONTCOUNT = 0x1,
    00017   C_CASE      = 0x2,
    00018   C_GENDER    = 0x4,
    00019 };
    00020 DECLARE_ENUM_AS_BIT_SET(CmdFlags)
    00021
    00022 struct Buffer;
    00023 typedef void (*ParseCmdProc)(Buffer *buffer, char *buf, int value);
    00024
    00025 struct CmdStruct {
    00026   const char *cmd;
    00027   ParseCmdProc proc;
    00028   long value;
    00029   uint8 consumes;
    00030   CmdFlags flags;
    00031 };
    00032
    00033 extern void EmitSingleChar(Buffer *buffer, char *buf, int value);
    00034 extern void EmitPlural(Buffer *buffer, char *buf, int value);
    00035 extern void EmitGender(Buffer *buffer, char *buf, int value);
    00036
    00037 static const CmdStruct _cmd_structs[] = {
    00038   /* Font size */
    00039   {"TINY_FONT",         EmitSingleChar, SCC_TINYFONT,           0, C_NONE},
    00040   {"BIG_FONT",          EmitSingleChar, SCC_BIGFONT,            0, C_NONE},
    00041
    00042   /* Colours */
    00043   {"BLUE",              EmitSingleChar, SCC_BLUE,               0, C_NONE},
    00044   {"SILVER",            EmitSingleChar, SCC_SILVER,             0, C_NONE},
    00045   {"GOLD",              EmitSingleChar, SCC_GOLD,               0, C_NONE},
    00046   {"RED",               EmitSingleChar, SCC_RED,                0, C_NONE},
    00047   {"PURPLE",            EmitSingleChar, SCC_PURPLE,             0, C_NONE},
    00048   {"LTBROWN",           EmitSingleChar, SCC_LTBROWN,            0, C_NONE},
    00049   {"ORANGE",            EmitSingleChar, SCC_ORANGE,             0, C_NONE},
    00050   {"GREEN",             EmitSingleChar, SCC_GREEN,              0, C_NONE},
    00051   {"YELLOW",            EmitSingleChar, SCC_YELLOW,             0, C_NONE},
    00052   {"DKGREEN",           EmitSingleChar, SCC_DKGREEN,            0, C_NONE},
    00053   {"CREAM",             EmitSingleChar, SCC_CREAM,              0, C_NONE},
    00054   {"BROWN",             EmitSingleChar, SCC_BROWN,              0, C_NONE},
    00055   {"WHITE",             EmitSingleChar, SCC_WHITE,              0, C_NONE},
    00056   {"LTBLUE",            EmitSingleChar, SCC_LTBLUE,             0, C_NONE},
    00057   {"GRAY",              EmitSingleChar, SCC_GRAY,               0, C_NONE},
    00058   {"DKBLUE",            EmitSingleChar, SCC_DKBLUE,             0, C_NONE},
    00059   {"BLACK",             EmitSingleChar, SCC_BLACK,              0, C_NONE},
    00060
    00061   {"REV",               EmitSingleChar, SCC_REVISION,           0, C_NONE}, // openttd revision string
    00062
    00063   {"STRING1",           EmitSingleChar, SCC_STRING1,            2, C_CASE | C_GENDER}, // included string that consumes the string id and ONE argument
    00064   {"STRING2",           EmitSingleChar, SCC_STRING2,            3, C_CASE | C_GENDER}, // included string that consumes the string id and TWO arguments
    00065   {"STRING3",           EmitSingleChar, SCC_STRING3,            4, C_CASE | C_GENDER}, // included string that consumes the string id and THREE arguments
    00066   {"STRING4",           EmitSingleChar, SCC_STRING4,            5, C_CASE | C_GENDER}, // included string that consumes the string id and FOUR arguments
    00067   {"STRING5",           EmitSingleChar, SCC_STRING5,            6, C_CASE | C_GENDER}, // included string that consumes the string id and FIVE arguments
    00068   {"STRING6",           EmitSingleChar, SCC_STRING6,            7, C_CASE | C_GENDER}, // included string that consumes the string id and SIX arguments
    00069   {"STRING7",           EmitSingleChar, SCC_STRING7,            8, C_CASE | C_GENDER}, // included string that consumes the string id and SEVEN arguments
    00070
    00071   {"STATION_FEATURES",  EmitSingleChar, SCC_STATION_FEATURES,   1, C_NONE}, // station features string, icons of the features
    00072   {"INDUSTRY",          EmitSingleChar, SCC_INDUSTRY_NAME,      1, C_CASE | C_GENDER}, // industry, takes an industry #, can have cases
    00073   {"CARGO_LONG",        EmitSingleChar, SCC_CARGO_LONG,         2, C_NONE | C_GENDER},
    00074   {"CARGO_SHORT",       EmitSingleChar, SCC_CARGO_SHORT,        2, C_NONE}, // short cargo description, only ### tons, or ### litres
    00075   {"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
    00076   {"CARGO_LIST",        EmitSingleChar, SCC_CARGO_LIST,         1, C_CASE},
    00077   {"POWER",             EmitSingleChar, SCC_POWER,              1, C_NONE},
    00078   {"VOLUME_LONG",       EmitSingleChar, SCC_VOLUME_LONG,        1, C_NONE},
    00079   {"VOLUME_SHORT",      EmitSingleChar, SCC_VOLUME_SHORT,       1, C_NONE},
    00080   {"WEIGHT_LONG",       EmitSingleChar, SCC_WEIGHT_LONG,        1, C_NONE},
    00081   {"WEIGHT_SHORT",      EmitSingleChar, SCC_WEIGHT_SHORT,       1, C_NONE},
    00082   {"FORCE",             EmitSingleChar, SCC_FORCE,              1, C_NONE},
    00083   {"VELOCITY",          EmitSingleChar, SCC_VELOCITY,           1, C_NONE},
    00084   {"HEIGHT",            EmitSingleChar, SCC_HEIGHT,             1, C_NONE},
    00085
    00086   {"P",                 EmitPlural,     0,                      0, C_DONTCOUNT}, // plural specifier
    00087   {"G",                 EmitGender,     0,                      0, C_DONTCOUNT}, // gender specifier
    00088
    00089   {"DATE_TINY",         EmitSingleChar, SCC_DATE_TINY,          1, C_NONE},
    00090   {"DATE_SHORT",        EmitSingleChar, SCC_DATE_SHORT,         1, C_CASE},
    00091   {"DATE_LONG",         EmitSingleChar, SCC_DATE_LONG,          1, C_CASE},
    00092   {"DATE_ISO",          EmitSingleChar, SCC_DATE_ISO,           1, C_NONE},
    00093
    00094   {"STRING",            EmitSingleChar, SCC_STRING,             1, C_CASE | C_GENDER},
    00095   {"RAW_STRING",        EmitSingleChar, SCC_RAW_STRING_POINTER, 1, C_NONE | C_GENDER},
    00096
    00097   /* Numbers */
    00098   {"COMMA",             EmitSingleChar, SCC_COMMA,              1, C_NONE}, // Number with comma
    00099   {"DECIMAL",           EmitSingleChar, SCC_DECIMAL,            2, C_NONE}, // Number with comma and fractional part. Second parameter is number of fractional digits, first parameter is number times 10**(second parameter).
    00100   {"NUM",               EmitSingleChar, SCC_NUM,                1, C_NONE}, // Signed number
    00101   {"ZEROFILL_NUM",      EmitSingleChar, SCC_ZEROFILL_NUM,       2, C_NONE}, // Unsigned number with zero fill, e.g. "02". First parameter is number, second minimum length
    00102   {"BYTES",             EmitSingleChar, SCC_BYTES,              1, C_NONE}, // Unsigned number with "bytes", i.e. "1.02 MiB or 123 KiB"
    00103   {"HEX",               EmitSingleChar, SCC_HEX,                1, C_NONE}, // Hexadecimally printed number
    00104
    00105   {"CURRENCY_LONG",     EmitSingleChar, SCC_CURRENCY_LONG,      1, C_NONE},
    00106   {"CURRENCY_SHORT",    EmitSingleChar, SCC_CURRENCY_SHORT,     1, C_NONE}, // compact currency
    00107
    00108   {"WAYPOINT",          EmitSingleChar, SCC_WAYPOINT_NAME,      1, C_NONE | C_GENDER}, // waypoint name
    00109   {"STATION",           EmitSingleChar, SCC_STATION_NAME,       1, C_NONE | C_GENDER},
    00110   {"DEPOT",             EmitSingleChar, SCC_DEPOT_NAME,         2, C_NONE | C_GENDER},
    00111   {"TOWN",              EmitSingleChar, SCC_TOWN_NAME,          1, C_NONE | C_GENDER},
    00112   {"GROUP",             EmitSingleChar, SCC_GROUP_NAME,         1, C_NONE | C_GENDER},
    00113   {"SIGN",              EmitSingleChar, SCC_SIGN_NAME,          1, C_NONE | C_GENDER},
    00114   {"ENGINE",            EmitSingleChar, SCC_ENGINE_NAME,        1, C_NONE | C_GENDER},
    00115   {"VEHICLE",           EmitSingleChar, SCC_VEHICLE_NAME,       1, C_NONE | C_GENDER},
    00116   {"COMPANY",           EmitSingleChar, SCC_COMPANY_NAME,       1, C_NONE | C_GENDER},
    00117   {"COMPANY_NUM",       EmitSingleChar, SCC_COMPANY_NUM,        1, C_NONE},
    00118   {"PRESIDENT_NAME",    EmitSingleChar, SCC_PRESIDENT_NAME,     1, C_NONE | C_GENDER},
    00119
    00120   {"",                  EmitSingleChar, '\n',                   0, C_DONTCOUNT},
    00121   {"{",                 EmitSingleChar, '{',                    0, C_DONTCOUNT},
    00122   {"UP_ARROW",          EmitSingleChar, SCC_UP_ARROW,           0, C_DONTCOUNT},
    00123   {"SMALL_UP_ARROW",    EmitSingleChar, SCC_SMALL_UP_ARROW,     0, C_DONTCOUNT},
    00124   {"SMALL_DOWN_ARROW",  EmitSingleChar, SCC_SMALL_DOWN_ARROW,   0, C_DONTCOUNT},
    00125   {"TRAIN",             EmitSingleChar, SCC_TRAIN,              0, C_DONTCOUNT},
    00126   {"LORRY",             EmitSingleChar, SCC_LORRY,              0, C_DONTCOUNT},
    00127   {"BUS",               EmitSingleChar, SCC_BUS,                0, C_DONTCOUNT},
    00128   {"PLANE",             EmitSingleChar, SCC_PLANE,              0, C_DONTCOUNT},
    00129   {"SHIP",              EmitSingleChar, SCC_SHIP,               0, C_DONTCOUNT},
    00130   {"NBSP",              EmitSingleChar, 0xA0,                   0, C_DONTCOUNT},
    00131   {"CENT",              EmitSingleChar, 0xA2,                   0, C_DONTCOUNT},
    00132   {"POUND_SIGN",        EmitSingleChar, 0xA3,                   0, C_DONTCOUNT},
    00133   {"EURO",              EmitSingleChar, 0x20AC,                 0, C_DONTCOUNT},
    00134   {"YEN_SIGN",          EmitSingleChar, 0xA5,                   0, C_DONTCOUNT},
    00135   {"COPYRIGHT",         EmitSingleChar, 0xA9,                   0, C_DONTCOUNT},
    00136   {"DOWN_ARROW",        EmitSingleChar, SCC_DOWN_ARROW,         0, C_DONTCOUNT},
    00137   {"CHECKMARK",         EmitSingleChar, SCC_CHECKMARK,          0, C_DONTCOUNT},
    00138   {"CROSS",             EmitSingleChar, SCC_CROSS,              0, C_DONTCOUNT},
    00139   {"REGISTERED",        EmitSingleChar, 0xAE,                   0, C_DONTCOUNT},
    00140   {"RIGHT_ARROW",       EmitSingleChar, SCC_RIGHT_ARROW,        0, C_DONTCOUNT},
    00141   {"SMALL_LEFT_ARROW",  EmitSingleChar, SCC_LESS_THAN,          0, C_DONTCOUNT},
    00142   {"SMALL_RIGHT_ARROW", EmitSingleChar, SCC_GREATER_THAN,       0, C_DONTCOUNT},
    00143
    00144   /* The following are directional formatting codes used to get the RTL strings right:
    00145    * http://www.unicode.org/unicode/reports/tr9/#Directional_Formatting_Codes */
    00146   {"LRM",               EmitSingleChar, CHAR_TD_LRM,            0, C_DONTCOUNT},
    00147   {"RLM",               EmitSingleChar, CHAR_TD_RLM,            0, C_DONTCOUNT},
    00148   {"LRE",               EmitSingleChar, CHAR_TD_LRE,            0, C_DONTCOUNT},
    00149   {"RLE",               EmitSingleChar, CHAR_TD_RLE,            0, C_DONTCOUNT},
    00150   {"LRO",               EmitSingleChar, CHAR_TD_LRO,            0, C_DONTCOUNT},
    00151   {"RLO",               EmitSingleChar, CHAR_TD_RLO,            0, C_DONTCOUNT},
    00152   {"PDF",               EmitSingleChar, CHAR_TD_PDF,            0, C_DONTCOUNT},
    00153 };
    00154
    00156 struct PluralForm {
    00157   int plural_count;
    00158   const char *description;
    00159   const char *names;
    00160 };
    00161
    00163 static const PluralForm _plural_forms[] = {
    00164   { 2, "Two forms: special case for 1.", "\"1\" \"other\"" },
    00165   { 1, "Only one form.", "\"other\"" },
    00166   { 2, "Two forms: special case for 0 to 1.", "\"0..1\" \"other\"" },
    00167   { 3, "Three forms: special cases for 0, and numbers ending in 1 except when ending in 11.", "\"1,21,31,...\" \"other\" \"0\"" },
    00168   { 5, "Five forms: special cases for 1, 2, 3 to 6, and 7 to 10.", "\"1\" \"2\" \"3..6\" \"7..10\" \"other\"" },
    00169   { 3, "Three forms: special cases for numbers ending in 1 except when ending in 11, and 2 to 9 except when ending in 12 to 19.", "\"1,21,31,...\" \"2..9,22..29,32..39,...\" \"other\"" },
    00170   { 3, "Three forms: special cases for numbers ending in 1 except when ending in 11, and 2 to 4 except when ending in 12 to 14.", "\"1,21,31,...\" \"2..4,22..24,32..34,...\" \"other\"" },
    00171   { 3, "Three forms: special cases for 1, and numbers ending in 2 to 4 except when ending in 12 to 14.", "\"1\" \"2..4,22..24,32..34,...\" \"other\"" },
    00172   { 4, "Four forms: special cases for numbers ending in 01, 02, and 03 to 04.", "\"1,101,201,...\" \"2,102,202,...\" \"3..4,103..104,203..204,...\" \"other\"" },
    00173   { 2, "Two forms: special case for numbers ending in 1 except when ending in 11.", "\"1,21,31,...\" \"other\"" },
    00174   { 3, "Three forms: special cases for 1, and 2 to 4.", "\"1\" \"2..4\" \"other\"" },
    00175   { 2, "Two forms: cases for numbers ending with a consonant, and with a vowel.", "\"yeong,il,sam,yuk,chil,pal\" \"i,sa,o,gu\"" },
    00176   { 4, "Four forms: special cases for 1, 0 and numbers ending in 02 to 10, and numbers ending in 11 to 19.", "\"1\" \"0,2..10,102..110,202..210,...\" \"11..19,111..119,211..219,...\" \"other\"" },
    00177 };
    00178
    00179 /* Flags:
    00180  * 0 = nothing
    00181  * t = translator editable
    00182  * l = ltr/rtl choice
    00183  * p = plural choice
    00184  * d = separator char (replace spaces with {NBSP})
    00185  * x1 = hexadecimal number of 1 byte
    00186  * x2 = hexadecimal number of 2 bytes
    00187  * g = gender
    00188  * c = cases
    00189  * a = array, i.e. list of strings
    00190  */
    00192 static const char * const _pragmas[][4] = {
    00193   /*  name         flags  default   description */
    00194   { "name",        "0",   "",       "English name for the language" },
    00195   { "ownname",     "t",   "",       "Localised name for the language" },
    00196   { "isocode",     "0",   "",       "ISO code for the language" },
    00197   { "plural",      "tp",  "0",      "Plural form to use" },
    00198   { "textdir",     "tl",  "ltr",    "Text direction. Either ltr (left-to-right) or rtl (right-to-left)" },
    00199   { "digitsep",    "td",  ",",      "Digit grouping separator for non-currency numbers" },
    00200   { "digitsepcur", "td",  ",",      "Digit grouping separator for currency numbers" },
    00201   { "decimalsep",  "td",  ".",      "Decimal separator" },
    00202   { "winlangid",   "x2",  "0x0000", "Language ID for Windows" },
    00203   { "grflangid",   "x1",  "0x00",   "Language ID for NewGRFs" },
    00204   { "gender",      "tag", "",       "List of genders" },
    00205   { "case",        "tac", "",       "List of cases" },
    00206 };