~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/strgen/strgen.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matthijs Kooijman, Matthijs Kooijman
  • Date: 2009-10-01 22:52:59 UTC
  • mfrom: (1.1.8 upstream) (2.1.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091001225259-5kpkp4sthbszpyif
[ Matthijs Kooijman ]
* New upstream release
* Use printf instead of echo -en in openttd-wrapper to make it POSIX
  compatible (Closes: #547758).
* Remove three patches that are now included in upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: strgen.cpp 16273 2009-05-10 21:33:55Z rubidium $ */
 
1
/* $Id: strgen.cpp 17158 2009-08-12 15:22:50Z rubidium $ */
2
2
 
3
3
/** @file strgen.cpp Tool to create computer readable (stand-alone) translation files. */
4
4
 
58
58
 
59
59
static bool _masterlang;
60
60
static bool _translated;
 
61
static bool _translation; ///< Is the current file actually a translation or not
61
62
static const char *_file = "(unknown file)";
62
63
static int _cur_line;
63
64
static int _errors, _warnings, _show_todo;
99
100
static uint _numcases;
100
101
 
101
102
/* for each plural value, this is the number of plural forms. */
102
 
static const byte _plural_form_counts[] = { 2, 1, 2, 3, 3, 3, 3, 3, 4, 2, 3 };
 
103
static const byte _plural_form_counts[] = { 2, 1, 2, 3, 3, 3, 3, 3, 4, 2, 3, 2 };
103
104
 
104
105
static const char *_cur_ident;
105
106
 
348
349
        uint j;
349
350
 
350
351
        PutByte(nw);
351
 
        for (i = 0; i < nw; i++) PutByte(strlen(words[i]));
 
352
        for (i = 0; i < nw; i++) PutByte(strlen(words[i]) + 1);
352
353
        for (i = 0; i < nw; i++) {
353
354
                for (j = 0; words[i][j] != '\0'; j++) PutByte(words[i][j]);
 
355
                PutByte(0);
354
356
        }
355
357
}
356
358
 
755
757
                return FindCmd("STRING", 6);
756
758
        }
757
759
 
758
 
        if (strcmp(a->cmd, "SKIP") == 0) return NULL;
759
 
 
760
760
        return a;
761
761
}
762
762
 
763
763
 
764
764
static bool CheckCommandsMatch(char *a, char *b, const char *name)
765
765
{
 
766
        /* If we're not translating, i.e. we're compiling the base language,
 
767
         * it is pointless to do all these checks as it'll always be correct.
 
768
         * After all, all checks are based on the base language.
 
769
         */
 
770
        if (!_translation) return true;
 
771
 
766
772
        ParsedCommandStruct templ;
767
773
        ParsedCommandStruct lang;
768
774
        uint i, j;
799
805
        /* if we reach here, all non consumer commands match up.
800
806
         * Check if the non consumer commands match up also. */
801
807
        for (i = 0; i < lengthof(templ.cmd); i++) {
802
 
                if (TranslateCmdForCompare(templ.cmd[i]) != TranslateCmdForCompare(lang.cmd[i])) {
 
808
                if (TranslateCmdForCompare(templ.cmd[i]) != lang.cmd[i]) {
803
809
                        strgen_warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i,
804
 
                                lang.cmd[i]  == NULL ? "<empty>" : lang.cmd[i]->cmd,
 
810
                                lang.cmd[i]  == NULL ? "<empty>" : TranslateCmdForCompare(lang.cmd[i])->cmd,
805
811
                                templ.cmd[i] == NULL ? "<empty>" : templ.cmd[i]->cmd);
806
812
                        result = false;
807
813
                }
832
838
 
833
839
        /* Trim spaces.
834
840
         * After this str points to the command name, and s points to the command contents */
835
 
        for (t = s; t > str && (t[-1] == ' ' || t[-1] == '\t'); t--);
 
841
        for (t = s; t > str && (t[-1] == ' ' || t[-1] == '\t'); t--) {}
836
842
        *t = 0;
837
843
        s++;
838
844
 
938
944
        FILE *in;
939
945
        char buf[2048];
940
946
 
 
947
        /* Only look at the final filename to determine whether it's be base language or not */
 
948
        const char *cur_file = strrchr(_file, PATHSEPCHAR);
 
949
        const char *next_file = strrchr(file, PATHSEPCHAR);
 
950
        _translation = next_file != NULL && cur_file != NULL && strcmp(cur_file, next_file) != 0;
941
951
        _file = file;
942
952
 
943
953
        /* For each new file we parse, reset the genders, and language codes */
1334
1344
 
1335
1345
        while (argc > 1 && *argv[1] == '-') {
1336
1346
                if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
1337
 
                        puts("$Revision: 16273 $");
 
1347
                        puts("$Revision: 17158 $");
1338
1348
                        return 0;
1339
1349
                }
1340
1350
 
1352
1362
 
1353
1363
                if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) {
1354
1364
                        puts(
1355
 
                                "strgen - $Revision: 16273 $\n"
 
1365
                                "strgen - $Revision: 17158 $\n"
1356
1366
                                " -v | --version    print version information and exit\n"
1357
1367
                                " -t | --todo       replace any untranslated strings with '<TODO>'\n"
1358
1368
                                " -w | --warning    print a warning for any untranslated strings\n"