# strgen_tables.h

Go to the documentation of this file.

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