summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-12-17 17:03:38 +0000
committerrubidium <rubidium@openttd.org>2011-12-17 17:03:38 +0000
commit9c34bc52dbae216678aaf1f5d05a28540266e307 (patch)
treeef181fe022307be9ab3b7d6cbfedce88bc49e196 /src
parent17c0756da276971290d9caa0d218f25e09af48e9 (diff)
downloadopenttd-9c34bc52dbae216678aaf1f5d05a28540266e307.tar.xz
(svn r23574) -Codechange/Feature-ish: allow converting multiple translations with the same master language instance in a single strgen run
Diffstat (limited to 'src')
-rw-r--r--src/strgen/strgen.cpp64
1 files changed, 43 insertions, 21 deletions
diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp
index 795c244d4..e04a354dd 100644
--- a/src/strgen/strgen.cpp
+++ b/src/strgen/strgen.cpp
@@ -105,6 +105,16 @@ struct LangString {
free(this->translated);
delete this->translated_case;
}
+
+ /** Free all data related to the translation. */
+ void FreeTranslation()
+ {
+ free(this->translated);
+ this->translated = NULL;
+
+ delete this->translated_case;
+ this->translated_case = NULL;
+ }
};
/** Information about the currently known strings. */
@@ -136,6 +146,15 @@ struct StringData {
free(this->hash_heads);
}
+ /** Free all data related to the translation. */
+ void FreeTranslation()
+ {
+ for (size_t i = 0; i < this->max_strings; i++) {
+ LangString *ls = this->strings[i];
+ if (ls != NULL) ls->FreeTranslation();
+ }
+ }
+
/**
* Create a hash of the string for finding them back quickly.
* @param s The string to hash.
@@ -1017,6 +1036,7 @@ static void rstrip(char *buf)
void StringReader::ParseFile()
{
char buf[2048];
+ _warnings = _errors = 0;
_translation = this->master || this->translation;
_file = this->file;
@@ -1621,7 +1641,7 @@ int CDECL main(int argc, char *argv[])
HeaderFileWriter writer(pathbuf);
writer.WriteHeader(data);
writer.Finalise(data);
- } else if (mgo.numleft == 1) {
+ } else if (mgo.numleft >= 1) {
char *r;
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
@@ -1631,31 +1651,33 @@ int CDECL main(int argc, char *argv[])
FileStringReader master_reader(data, pathbuf, true, false);
master_reader.ParseFile();
- const char *translation = replace_pathsep(mgo.argv[0]);
- const char *file = strrchr(translation, PATHSEPCHAR);
- FileStringReader translation_reader(data, translation, false, file == NULL || strcmp(file + 1, "english.txt") != 0);
- translation_reader.ParseFile(); // target file
- if (_errors != 0) return 1;
+ for (int i = 0; i < mgo.numleft; i++) {
+ data.FreeTranslation();
- /* get the targetfile, strip any directories and append to destination path */
- r = strrchr(mgo.argv[0], PATHSEPCHAR);
- mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : mgo.argv[0]);
+ const char *translation = replace_pathsep(mgo.argv[i]);
+ const char *file = strrchr(translation, PATHSEPCHAR);
+ FileStringReader translation_reader(data, translation, false, file == NULL || strcmp(file + 1, "english.txt") != 0);
+ translation_reader.ParseFile(); // target file
+ if (_errors != 0) return 1;
- /* rename the .txt (input-extension) to .lng */
- r = strrchr(pathbuf, '.');
- if (r == NULL || strcmp(r, ".txt") != 0) r = strchr(pathbuf, '\0');
- ttd_strlcpy(r, ".lng", (size_t)(r - pathbuf));
+ /* get the targetfile, strip any directories and append to destination path */
+ r = strrchr(mgo.argv[i], PATHSEPCHAR);
+ mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : mgo.argv[i]);
- LanguageFileWriter writer(pathbuf);
- writer.WriteLang(data);
- writer.Finalise();
+ /* rename the .txt (input-extension) to .lng */
+ r = strrchr(pathbuf, '.');
+ if (r == NULL || strcmp(r, ".txt") != 0) r = strchr(pathbuf, '\0');
+ ttd_strlcpy(r, ".lng", (size_t)(r - pathbuf));
- /* if showing warnings, print a summary of the language */
- if ((_show_todo & 2) != 0) {
- fprintf(stdout, "%d warnings and %d errors for %s\n", _warnings, _errors, pathbuf);
+ LanguageFileWriter writer(pathbuf);
+ writer.WriteLang(data);
+ writer.Finalise();
+
+ /* if showing warnings, print a summary of the language */
+ if ((_show_todo & 2) != 0) {
+ fprintf(stdout, "%d warnings and %d errors for %s\n", _warnings, _errors, pathbuf);
+ }
}
- } else {
- fprintf(stderr, "Invalid arguments\n");
}
} catch (...) {
return 2;