From 63cab52b854bedb33d5b2ef478c7f2568440a589 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 24 Jun 2010 21:59:27 +0000 Subject: Adapt po2c's output to better mach our code formatting conventions. Along with it I added a suffix "-scummvm" to the version variable, since we also feature some custom extensions like the charset specification. svn-id: r50239 --- common/messages.cpp | 129 +++++++++++++++++++++++----------------------------- tools/po2c | 128 +++++++++++++++++++++++---------------------------- 2 files changed, 115 insertions(+), 142 deletions(-) diff --git a/common/messages.cpp b/common/messages.cpp index 7be2a62598..ec79ae7476 100644 --- a/common/messages.cpp +++ b/common/messages.cpp @@ -1,4 +1,4 @@ -/* generated by po2c 1.0.2 - Do not modify */ +// generated by po2c 1.0.2-scummvm - Do not modify #include #include @@ -320,12 +320,12 @@ static const char * const _po2c_msgids[] = { NULL }; -struct _po2c_msg { +struct PoMessageEntry { int msgid; - const char * msgstr; + const char *msgstr; }; -static const struct _po2c_msg _po2c_lang_ru_RU[] = { +static const PoMessageEntry _po2c_lang_ru_RU[] = { { 0, "Project-Id-Version: ScummVM VERSION\nReport-Msgid-Bugs-To: scummvm-devel@lists.sf.net\nPOT-Creation-Date: 2010-06-24 23:22+0200\nPO-Revision-Date: 2010-06-13 20:55+0300\nLast-Translator: Eugene Sandulenko \nLanguage-Team: Russian\nLanguage: \nMIME-Version: 1.0\nContent-Type: text/plain; charset=cp1251\nContent-Transfer-Encoding: 8bit\nPlural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" }, { 1, " \302\373 \363\342\345\360\345\355\373, \367\362\356 \365\356\362\350\362\345 \342\373\351\362\350? " }, { 2, " \310\371\363 \357\353\340\343\350\355 \361 \357\356\344\344\345\360\346\352\356\351 \375\362\356\343\356 gameid... " }, @@ -638,7 +638,7 @@ static const struct _po2c_msg _po2c_lang_ru_RU[] = { { -1, NULL } }; -static const struct _po2c_msg _po2c_lang_fr_FR[] = { +static const PoMessageEntry _po2c_lang_fr_FR[] = { { 0, "Project-Id-Version: ScummVM 1.2.0svn\nReport-Msgid-Bugs-To: scummvm-devel@lists.sf.net\nPOT-Creation-Date: 2010-06-24 23:22+0200\nPO-Revision-Date: 2010-06-19 23:43+0100\nLast-Translator: Thierry Crozat \nLanguage-Team: French \nLanguage: fr\nMIME-Version: 1.0\nContent-Type: text/plain; charset=iso-8859-1\nContent-Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2; plural=n>1;\nX-Poedit-Language: French\nX-Poedit-Country: FRANCE\nX-Poedit-Basepath: /Users/criezy/Dev/scummvm/scummvm/trunk\n" }, { 1, "Voulez-vous vraiment quitter?" }, { 2, "Recherche d'un plugin supportant cet ID..." }, @@ -944,7 +944,7 @@ static const struct _po2c_msg _po2c_lang_fr_FR[] = { { -1, NULL } }; -static const struct _po2c_msg _po2c_lang_hu_HU[] = { +static const PoMessageEntry _po2c_lang_hu_HU[] = { { 0, "Project-Id-Version: ScummVM VERSION\nReport-Msgid-Bugs-To: scummvm-devel@lists.sf.net\nPOT-Creation-Date: 2010-06-24 23:22+0200\nPO-Revision-Date: 2009-11-25 07:42-0500\nLast-Translator: Alex Bevilacqua \nLanguage-Team: Hungarian\nLanguage: \nMIME-Version: 1.0\nContent-Type: text/plain; charset=cp1250\nContent-Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2; plural=(n != 1);\n" }, { 17, "" }, { 19, "AdLib vezet :" }, @@ -1000,112 +1000,99 @@ static const struct _po2c_msg _po2c_lang_hu_HU[] = { { -1, NULL } }; -static const struct { - const char * lang; - const char * charset; - const struct _po2c_msg * msgs; -} _po2c_langs[] = { +struct PoLangEntry { + const char *lang; + const char *charset; + const PoMessageEntry *msgs; +}; + +const PoLangEntry _po2c_langs[] = { { "ru_RU", "cp1251", _po2c_lang_ru_RU }, { "fr_FR", "iso-8859-1", _po2c_lang_fr_FR }, { "hu_HU", "cp1250", _po2c_lang_hu_HU }, { NULL, NULL, NULL } }; -/* code */ +// code -static const struct _po2c_msg * _po2c_lang=NULL; -static int _po2c_lang_size=0; -static const char * _po2c_charset=NULL; +static const struct PoMessageEntry *_po2c_lang = NULL; +static int _po2c_lang_size = 0; +static const char * _po2c_charset = NULL; -void po2c_setlang(const char * lang) -{ - int n; +void po2c_setlang(const char *lang) { + _po2c_lang = NULL; + _po2c_lang_size = 0; + _po2c_charset = NULL; - _po2c_lang=NULL; - _po2c_lang_size=0; - _po2c_charset=NULL; - - /* if lang is NULL or "", deactivate it */ - if(lang == NULL || *lang == '\0') + // if lang is NULL or "", deactivate it + if (lang == NULL || *lang == '\0') return; - /* searches for a valid language array */ - for(n=0;_po2c_lang == NULL && _po2c_langs[n].lang != NULL;n++) - { - if(strcmp(lang, _po2c_langs[n].lang) == 0) { - _po2c_lang=_po2c_langs[n].msgs; - _po2c_charset=_po2c_langs[n].charset; + // searches for a valid language array + for (int i = 0; _po2c_lang == NULL && _po2c_langs[i].lang != NULL; ++i) { + if (strcmp(lang, _po2c_langs[i].lang) == 0) { + _po2c_lang = _po2c_langs[i].msgs; + _po2c_charset = _po2c_langs[i].charset; } } - /* try partial searches */ - for(n=0;_po2c_lang == NULL && _po2c_langs[n].lang != NULL;n++) - { - if(strncmp(lang, _po2c_langs[n].lang, 2) == 0) { - _po2c_lang=_po2c_langs[n].msgs; - _po2c_charset=_po2c_langs[n].charset; + // try partial searches + for (int i = 0; _po2c_lang == NULL && _po2c_langs[i].lang != NULL; ++i) { + if (strncmp(lang, _po2c_langs[i].lang, 2) == 0) { + _po2c_lang = _po2c_langs[i].msgs; + _po2c_charset = _po2c_langs[i].charset; } } - /* if found, count entries */ - if(_po2c_lang != NULL) - { - const struct _po2c_msg * m; - - for(m=_po2c_lang;m->msgid != -1;m++) - _po2c_lang_size++; + // if found, count entries + if (_po2c_lang != NULL) { + for (const PoMessageEntry *m = _po2c_lang; m->msgid != -1; ++m) + ++_po2c_lang_size; } } -const char * po2c_gettext(const char * msgid) -{ - const struct _po2c_msg * m; - int b, t, n, c; +const char *po2c_gettext(const char *msgid) { + // if no language is set or msgid is empty, return msgid as is + if (_po2c_lang == NULL || *msgid == '\0') + return msgid; - /* if no language is set or msgid is empty, return msgid as is */ - if(_po2c_lang == NULL || *msgid == '\0') - return(msgid); + // binary-search for the msgid + int leftIndex = 0; + int rightIndex = _po2c_lang_size - 1; - /* binary-search for the msgid */ - b=0; t=_po2c_lang_size - 1; + while (rightIndex >= leftIndex) { + const int midIndex = (leftIndex + rightIndex) / 2; + const struct PoMessageEntry * const m = &_po2c_lang[midIndex]; - while(t >= b) - { - n=(b + t) / 2; - m=&_po2c_lang[n]; + const int compareResult = strcmp(msgid, _po2c_msgids[m->msgid]); - c=strcmp(msgid, _po2c_msgids[m->msgid]); - - if(c == 0) - return(m->msgstr); - else - if(c < 0) - t=n - 1; + if (compareResult == 0) + return m->msgstr; + else if (compareResult < 0) + rightIndex = midIndex - 1; else - b=n + 1; + leftIndex = midIndex + 1; } - return(msgid); + return msgid; } -const char * po2c_getcharset(void) -{ +const char *po2c_getcharset(void) { if (_po2c_charset) return _po2c_charset; else return "ASCII"; } -int po2c_getnumlangs(void) -{ +int po2c_getnumlangs(void) { int n = 0; + while (_po2c_langs[n].lang) n++; return n; } -const char * po2c_getlang(int num) -{ +const char *po2c_getlang(int num) { return _po2c_langs[num].lang; } diff --git a/tools/po2c b/tools/po2c index f6aff97404..a2b006cd6b 100755 --- a/tools/po2c +++ b/tools/po2c @@ -22,7 +22,7 @@ # http://www.triptico.com # -$VERSION = "1.0.2"; +$VERSION = "1.0.2-scummvm"; if(scalar(@ARGV) == 0) { @@ -106,9 +106,9 @@ for(my $n = 0;$n < scalar(@msgids);$n++) $msgids{$msgids[$n]} = $n; } -# stage 3: dump as C code +# stage 3: dump as C++ code -print "/* generated by po2c $VERSION - Do not modify */\n\n"; +print "// generated by po2c $VERSION - Do not modify\n\n"; print "#include \n"; print "#include \n\n"; @@ -123,16 +123,16 @@ for(my $n = 0;$n < scalar(@msgids);$n++) print "\tNULL\n};\n\n"; # dump the lang structure -print "struct _po2c_msg {\n"; +print "struct PoMessageEntry {\n"; print "\tint msgid;\n"; -print "\tconst char * msgstr;\n"; +print "\tconst char *msgstr;\n"; print "};\n\n"; # dump now each language foreach my $l (keys(%msgs)) { - print "static const struct _po2c_msg _po2c_lang_${l}\[\] = {\n"; + print "static const PoMessageEntry _po2c_lang_${l}\[\] = {\n"; # get the translation table for the language $l my ($m) = $msgs{$l}; @@ -160,11 +160,12 @@ foreach my $l (keys(%msgs)) # finally, dump the languages -print "static const struct {\n"; -print "\tconst char * lang;\n"; -print "\tconst char * charset;\n"; -print "\tconst struct _po2c_msg * msgs;\n"; -print "} _po2c_langs[] = {\n"; +print "struct PoLangEntry {\n"; +print "\tconst char *lang;\n"; +print "\tconst char *charset;\n"; +print "\tconst PoMessageEntry *msgs;\n"; +print "};\n\n"; +print "const PoLangEntry _po2c_langs[] = {\n"; foreach my $l (keys(%msgs)) { @@ -176,103 +177,88 @@ foreach my $l (keys(%msgs)) print "\t{ NULL, NULL, NULL }\n};\n\n"; -print "/* code */\n"; +print "// code\n"; print << 'EOF'; -static const struct _po2c_msg * _po2c_lang=NULL; -static int _po2c_lang_size=0; -static const char * _po2c_charset=NULL; - -void po2c_setlang(const char * lang) -{ - int n; +static const struct PoMessageEntry *_po2c_lang = NULL; +static int _po2c_lang_size = 0; +static const char * _po2c_charset = NULL; - _po2c_lang=NULL; - _po2c_lang_size=0; - _po2c_charset=NULL; +void po2c_setlang(const char *lang) { + _po2c_lang = NULL; + _po2c_lang_size = 0; + _po2c_charset = NULL; - /* if lang is NULL or "", deactivate it */ - if(lang == NULL || *lang == '\0') + // if lang is NULL or "", deactivate it + if (lang == NULL || *lang == '\0') return; - /* searches for a valid language array */ - for(n=0;_po2c_lang == NULL && _po2c_langs[n].lang != NULL;n++) - { - if(strcmp(lang, _po2c_langs[n].lang) == 0) { - _po2c_lang=_po2c_langs[n].msgs; - _po2c_charset=_po2c_langs[n].charset; + // searches for a valid language array + for (int i = 0; _po2c_lang == NULL && _po2c_langs[i].lang != NULL; ++i) { + if (strcmp(lang, _po2c_langs[i].lang) == 0) { + _po2c_lang = _po2c_langs[i].msgs; + _po2c_charset = _po2c_langs[i].charset; } } - /* try partial searches */ - for(n=0;_po2c_lang == NULL && _po2c_langs[n].lang != NULL;n++) - { - if(strncmp(lang, _po2c_langs[n].lang, 2) == 0) { - _po2c_lang=_po2c_langs[n].msgs; - _po2c_charset=_po2c_langs[n].charset; + // try partial searches + for (int i = 0; _po2c_lang == NULL && _po2c_langs[i].lang != NULL; ++i) { + if (strncmp(lang, _po2c_langs[i].lang, 2) == 0) { + _po2c_lang = _po2c_langs[i].msgs; + _po2c_charset = _po2c_langs[i].charset; } } - /* if found, count entries */ - if(_po2c_lang != NULL) - { - const struct _po2c_msg * m; - - for(m=_po2c_lang;m->msgid != -1;m++) - _po2c_lang_size++; + // if found, count entries + if (_po2c_lang != NULL) { + for (const PoMessageEntry *m = _po2c_lang; m->msgid != -1; ++m) + ++_po2c_lang_size; } } -const char * po2c_gettext(const char * msgid) -{ - const struct _po2c_msg * m; - int b, t, n, c; +const char *po2c_gettext(const char *msgid) { + // if no language is set or msgid is empty, return msgid as is + if (_po2c_lang == NULL || *msgid == '\0') + return msgid; - /* if no language is set or msgid is empty, return msgid as is */ - if(_po2c_lang == NULL || *msgid == '\0') - return(msgid); + // binary-search for the msgid + int leftIndex = 0; + int rightIndex = _po2c_lang_size - 1; - /* binary-search for the msgid */ - b=0; t=_po2c_lang_size - 1; + while (rightIndex >= leftIndex) { + const int midIndex = (leftIndex + rightIndex) / 2; + const struct PoMessageEntry * const m = &_po2c_lang[midIndex]; - while(t >= b) - { - n=(b + t) / 2; - m=&_po2c_lang[n]; - - c=strcmp(msgid, _po2c_msgids[m->msgid]); + const int compareResult = strcmp(msgid, _po2c_msgids[m->msgid]); - if(c == 0) - return(m->msgstr); + if (compareResult == 0) + return m->msgstr; + else if (compareResult < 0) + rightIndex = midIndex - 1; else - if(c < 0) - t=n - 1; - else - b=n + 1; + leftIndex = midIndex + 1; } - return(msgid); + return msgid; } -const char * po2c_getcharset(void) -{ +const char *po2c_getcharset(void) { if (_po2c_charset) return _po2c_charset; else return "ASCII"; } -int po2c_getnumlangs(void) -{ +int po2c_getnumlangs(void) { int n = 0; + while (_po2c_langs[n].lang) n++; return n; } -const char * po2c_getlang(int num) -{ +const char *po2c_getlang(int num) { return _po2c_langs[num].lang; } EOF -- cgit v1.2.3