# strgen_tables.h

Go to the documentation of this file.

    00001 /* $Id: strgen_tables.h 19223 2010-02-23 23:26:37Z rubidium $ */
    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 typedef void (*ParseCmdProc)(char *buf, int value);
    00023
    00024 struct CmdStruct {
    00025   const char *cmd;
    00026   ParseCmdProc proc;
    00027   long value;
    00028   uint8 consumes;
    00029   CmdFlags flags;
    00030 };
    00031
    00032 static void EmitSingleChar(char *buf, int value);
    00033 static void EmitPlural(char *buf, int value);
    00034 static void EmitGender(char *buf, int value);
    00035
    00036 static const CmdStruct _cmd_structs[] = {
    00037   /* Font size */
    00038   {"TINYFONT",        EmitSingleChar, SCC_TINYFONT,           0, C_NONE},
    00039   {"BIGFONT",         EmitSingleChar, SCC_BIGFONT,            0, C_NONE},
    00040
    00041   /* Colors */
    00042   {"BLUE",            EmitSingleChar, SCC_BLUE,               0, C_NONE},
    00043   {"SILVER",          EmitSingleChar, SCC_SILVER,             0, C_NONE},
    00044   {"GOLD",            EmitSingleChar, SCC_GOLD,               0, C_NONE},
    00045   {"RED",             EmitSingleChar, SCC_RED,                0, C_NONE},
    00046   {"PURPLE",          EmitSingleChar, SCC_PURPLE,             0, C_NONE},
    00047   {"LTBROWN",         EmitSingleChar, SCC_LTBROWN,            0, C_NONE},
    00048   {"ORANGE",          EmitSingleChar, SCC_ORANGE,             0, C_NONE},
    00049   {"GREEN",           EmitSingleChar, SCC_GREEN,              0, C_NONE},
    00050   {"YELLOW",          EmitSingleChar, SCC_YELLOW,             0, C_NONE},
    00051   {"DKGREEN",         EmitSingleChar, SCC_DKGREEN,            0, C_NONE},
    00052   {"CREAM",           EmitSingleChar, SCC_CREAM,              0, C_NONE},
    00053   {"BROWN",           EmitSingleChar, SCC_BROWN,              0, C_NONE},
    00054   {"WHITE",           EmitSingleChar, SCC_WHITE,              0, C_NONE},
    00055   {"LTBLUE",          EmitSingleChar, SCC_LTBLUE,             0, C_NONE},
    00056   {"GRAY",            EmitSingleChar, SCC_GRAY,               0, C_NONE},
    00057   {"DKBLUE",          EmitSingleChar, SCC_DKBLUE,             0, C_NONE},
    00058   {"BLACK",           EmitSingleChar, SCC_BLACK,              0, C_NONE},
    00059
    00060   {"CURRCOMPACT",     EmitSingleChar, SCC_CURRENCY_COMPACT,   1, C_NONE}, // compact currency
    00061   {"REV",             EmitSingleChar, SCC_REVISION,           0, C_NONE}, // openttd revision string
    00062   {"SHORTCARGO",      EmitSingleChar, SCC_CARGO_SHORT,        2, C_NONE}, // short cargo description, only ### tons, or ### litres
    00063
    00064   {"STRING1",         EmitSingleChar, SCC_STRING1,            2, C_CASE | C_GENDER}, // included string that consumes the string id and ONE argument
    00065   {"STRING2",         EmitSingleChar, SCC_STRING2,            3, C_CASE | C_GENDER}, // included string that consumes the string id and TWO arguments
    00066   {"STRING3",         EmitSingleChar, SCC_STRING3,            4, C_CASE | C_GENDER}, // included string that consumes the string id and THREE arguments
    00067   {"STRING4",         EmitSingleChar, SCC_STRING4,            5, C_CASE | C_GENDER}, // included string that consumes the string id and FOUR arguments
    00068   {"STRING5",         EmitSingleChar, SCC_STRING5,            6, C_CASE | C_GENDER}, // included string that consumes the string id and FIVE arguments
    00069
    00070   {"STATIONFEATURES", EmitSingleChar, SCC_STATION_FEATURES,   1, C_NONE}, // station features string, icons of the features
    00071   {"INDUSTRY",        EmitSingleChar, SCC_INDUSTRY_NAME,      1, C_NONE | C_GENDER}, // industry, takes an industry #
    00072   {"CARGO",           EmitSingleChar, SCC_CARGO,              2, C_NONE | C_GENDER},
    00073   {"POWER",           EmitSingleChar, SCC_POWER,              1, C_NONE},
    00074   {"VOLUME",          EmitSingleChar, SCC_VOLUME,             1, C_NONE},
    00075   {"VOLUME_S",        EmitSingleChar, SCC_VOLUME_SHORT,       1, C_NONE},
    00076   {"WEIGHT",          EmitSingleChar, SCC_WEIGHT,             1, C_NONE},
    00077   {"WEIGHT_S",        EmitSingleChar, SCC_WEIGHT_SHORT,       1, C_NONE},
    00078   {"FORCE",           EmitSingleChar, SCC_FORCE,              1, C_NONE},
    00079   {"VELOCITY",        EmitSingleChar, SCC_VELOCITY,           1, C_NONE},
    00080
    00081   {"P",               EmitPlural,     0,                      0, C_DONTCOUNT}, // plural specifier
    00082   {"G",               EmitGender,     0,                      0, C_DONTCOUNT}, // gender specifier
    00083
    00084   {"DATE_TINY",       EmitSingleChar, SCC_DATE_TINY,          1, C_NONE},
    00085   {"DATE_SHORT",      EmitSingleChar, SCC_DATE_SHORT,         1, C_NONE},
    00086   {"DATE_LONG",       EmitSingleChar, SCC_DATE_LONG,          1, C_NONE},
    00087   {"DATE_ISO",        EmitSingleChar, SCC_DATE_ISO,           1, C_NONE},
    00088
    00089   {"STRING",          EmitSingleChar, SCC_STRING,             1, C_CASE | C_GENDER},
    00090   {"RAW_STRING",      EmitSingleChar, SCC_RAW_STRING_POINTER, 1, C_NONE | C_GENDER},
    00091
    00092   /* Numbers */
    00093   {"COMMA",           EmitSingleChar, SCC_COMMA,              1, C_NONE}, // Number with comma
    00094   {"NUM",             EmitSingleChar, SCC_NUM,                1, C_NONE}, // Signed number
    00095   {"ZEROFILL_NUM",    EmitSingleChar, SCC_ZEROFILL_NUM,       2, C_NONE}, // Unsigned number with zero fill, e.g. "02". First parameter is number, second minimum length
    00096   {"BYTES",           EmitSingleChar, SCC_BYTES,              1, C_NONE}, // Unsigned number with "bytes", i.e. "1.02 MiB or 123 KiB"
    00097
    00098   {"CURRENCY",        EmitSingleChar, SCC_CURRENCY,           1, C_NONE},
    00099
    00100   {"WAYPOINT",        EmitSingleChar, SCC_WAYPOINT_NAME,      1, C_NONE | C_GENDER}, // waypoint name
    00101   {"STATION",         EmitSingleChar, SCC_STATION_NAME,       1, C_NONE | C_GENDER},
    00102   {"TOWN",            EmitSingleChar, SCC_TOWN_NAME,          1, C_NONE | C_GENDER},
    00103   {"GROUP",           EmitSingleChar, SCC_GROUP_NAME,         1, C_NONE | C_GENDER},
    00104   {"SIGN",            EmitSingleChar, SCC_SIGN_NAME,          1, C_NONE | C_GENDER},
    00105   {"ENGINE",          EmitSingleChar, SCC_ENGINE_NAME,        1, C_NONE | C_GENDER},
    00106   {"VEHICLE",         EmitSingleChar, SCC_VEHICLE_NAME,       1, C_NONE | C_GENDER},
    00107   {"COMPANY",         EmitSingleChar, SCC_COMPANY_NAME,       1, C_NONE | C_GENDER},
    00108   {"COMPANYNUM",      EmitSingleChar, SCC_COMPANY_NUM,        1, C_NONE},
    00109   {"PRESIDENTNAME",   EmitSingleChar, SCC_PRESIDENT_NAME,     1, C_NONE | C_GENDER},
    00110
    00111   {"",                EmitSingleChar, '\n',                   0, C_DONTCOUNT},
    00112   {"{",               EmitSingleChar, '{',                    0, C_DONTCOUNT},
    00113   {"UPARROW",         EmitSingleChar, SCC_UPARROW,            0, C_DONTCOUNT},
    00114   {"SMALLUPARROW",    EmitSingleChar, SCC_SMALLUPARROW,       0, C_DONTCOUNT},
    00115   {"SMALLDOWNARROW",  EmitSingleChar, SCC_SMALLDOWNARROW,     0, C_DONTCOUNT},
    00116   {"TRAIN",           EmitSingleChar, SCC_TRAIN,              0, C_DONTCOUNT},
    00117   {"LORRY",           EmitSingleChar, SCC_LORRY,              0, C_DONTCOUNT},
    00118   {"BUS",             EmitSingleChar, SCC_BUS,                0, C_DONTCOUNT},
    00119   {"PLANE",           EmitSingleChar, SCC_PLANE,              0, C_DONTCOUNT},
    00120   {"SHIP",            EmitSingleChar, SCC_SHIP,               0, C_DONTCOUNT},
    00121   {"NBSP",            EmitSingleChar, 0xA0,                   0, C_DONTCOUNT},
    00122   {"CENT",            EmitSingleChar, 0xA2,                   0, C_DONTCOUNT},
    00123   {"POUNDSIGN",       EmitSingleChar, 0xA3,                   0, C_DONTCOUNT},
    00124   {"EURO",            EmitSingleChar, 0x20AC,                 0, C_DONTCOUNT},
    00125   {"YENSIGN",         EmitSingleChar, 0xA5,                   0, C_DONTCOUNT},
    00126   {"COPYRIGHT",       EmitSingleChar, 0xA9,                   0, C_DONTCOUNT},
    00127   {"DOWNARROW",       EmitSingleChar, SCC_DOWNARROW,          0, C_DONTCOUNT},
    00128   {"CHECKMARK",       EmitSingleChar, SCC_CHECKMARK,          0, C_DONTCOUNT},
    00129   {"CROSS",           EmitSingleChar, SCC_CROSS,              0, C_DONTCOUNT},
    00130   {"REGISTERED",      EmitSingleChar, 0xAE,                   0, C_DONTCOUNT},
    00131   {"RIGHTARROW",      EmitSingleChar, SCC_RIGHTARROW,         0, C_DONTCOUNT},
    00132   {"SMALLLEFTARROW",  EmitSingleChar, SCC_LESSTHAN,           0, C_DONTCOUNT},
    00133   {"SMALLRIGHTARROW", EmitSingleChar, SCC_GREATERTHAN,        0, C_DONTCOUNT},
    00134
    00135   /* The following are directional formatting codes used to get the RTL strings right:
    00136    * http://www.unicode.org/unicode/reports/tr9/#Directional_Formatting_Codes */
    00137   {"LRM",             EmitSingleChar, 0x200E,                 0, C_DONTCOUNT},
    00138   {"RLM",             EmitSingleChar, 0x200F,                 0, C_DONTCOUNT},
    00139   {"LRE",             EmitSingleChar, 0x202A,                 0, C_DONTCOUNT},
    00140   {"RLE",             EmitSingleChar, 0x202B,                 0, C_DONTCOUNT},
    00141   {"LRO",             EmitSingleChar, 0x202D,                 0, C_DONTCOUNT},
    00142   {"RLO",             EmitSingleChar, 0x202E,                 0, C_DONTCOUNT},
    00143   {"PDF",             EmitSingleChar, 0x202C,                 0, C_DONTCOUNT},
    00144 };
    00145
    00147 struct PluralForm {
    00148   int plural_count;
    00149   const char *description;
    00150 };
    00151
    00153 static const PluralForm _plural_forms[] = {
    00154   { 2, "Two forms, singular used for 1 only" },
    00155   { 1, "Only one form" },
    00156   { 2, "Two forms, singular used for zero and 1" },
    00157   { 3, "Three forms, special case for 0 and ending in 1, except those ending in 11" },
    00158   { 3, "Three forms, special case for 1 and 2" },
    00159   { 3, "Three forms, special case for numbers ending in 1[2-9]" },
    00160   { 3, "Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4]" },
    00161   { 3, "Three forms, special case for 1 and some numbers ending in 2, 3, or 4" },
    00162   { 4, "Four forms, special case for 1 and all numbers ending in 02, 03, or 04" },
    00163   { 2, "Two forms, singular used for everything ending in 1 but not in 11" },
    00164   { 3, "Three forms, special case for 1 and 2, 3, or 4" },
    00165   { 2, "Two forms, cases for numbers ending with a consonant and with a vowel" },
    00166 };
    00167
    00168 /* Flags:
    00169  * 0 = nothing
    00170  * t = translator editable
    00171  * l = ltr/rtl choice
    00172  * p = plural choice
    00173  * d = separator char (replace spaces with {NBSP})
    00174  * x1 = hexadecimal number of 1 byte
    00175  * x2 = hexadecimal number of 2 bytes
    00176  * g = gender
    00177  * c = cases
    00178  * a = array, i.e. list of strings
    00179  */
    00181 static const char * const _pragmas[][4] = {
    00182   /*  name         flags  default   description */
    00183   { "name",        "0",   "",       "English name for the language" },
    00184   { "ownname",     "t",   "",       "Localised name for the language" },
    00185   { "isocode",     "0",   "",       "ISO code for the language" },
    00186   { "plural",      "tp",  "0",      "Plural form to use" },
    00187   { "textdir",     "tl",  "ltr",    "Text direction. Either ltr (left-to-right) or rtl (right-to-left)" },
    00188   { "digitsep",    "td",  ",",      "Digit grouping separator for non-currency numbers" },
    00189   { "digitsepcur", "td",  ",",      "Digit grouping seprarator for currency numbers" },
    00190   { "decimalsep",  "td",  ".",      "Decimal separator" },
    00191   { "winlangid",   "x2",  "0x0000", "Language ID for Windows" },
    00192   { "grflangid",   "x1",  "0x00",   "Language ID for NewGRFs" },
    00193   { "gender",      "tag", "",       "List of genders" },
    00194   { "case",        "tac", "",       "List of cases" },
    00195 };