[Scummvm-cvs-logs] SF.net SVN: scummvm:[50239] scummvm/trunk

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Thu Jun 24 23:59:27 CEST 2010


Revision: 50239
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50239&view=rev
Author:   lordhoto
Date:     2010-06-24 21:59:27 +0000 (Thu, 24 Jun 2010)

Log Message:
-----------
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.

Modified Paths:
--------------
    scummvm/trunk/common/messages.cpp
    scummvm/trunk/tools/po2c

Modified: scummvm/trunk/common/messages.cpp
===================================================================
--- scummvm/trunk/common/messages.cpp	2010-06-24 21:59:03 UTC (rev 50238)
+++ scummvm/trunk/common/messages.cpp	2010-06-24 21:59:27 UTC (rev 50239)
@@ -1,4 +1,4 @@
-/* generated by po2c 1.0.2 - Do not modify */
+// generated by po2c 1.0.2-scummvm - Do not modify
 
 #include <stdio.h>
 #include <string.h>
@@ -320,12 +320,12 @@
 	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 at 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 <sev at scummvm.org>\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 @@
 	{ -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 at 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 <criezy at scummvm.org>\nLanguage-Team: French <scummvm-devel at lists.sf.net>\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 @@
 	{ -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 at 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 <alexbevi at gmail.com>\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, "<alap\351rtelmezett>" },
 	{ 19, "AdLib vezet :" },
@@ -1000,112 +1000,99 @@
 	{ -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);
+		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;
 }

Modified: scummvm/trunk/tools/po2c
===================================================================
--- scummvm/trunk/tools/po2c	2010-06-24 21:59:03 UTC (rev 50238)
+++ scummvm/trunk/tools/po2c	2010-06-24 21:59:27 UTC (rev 50239)
@@ -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 @@
 	$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 <stdio.h>\n";
 print "#include <string.h>\n\n";
 
@@ -123,16 +123,16 @@
 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 @@
 
 # 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 @@
 
 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;
+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);
+		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


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list