Mercurial > hg > openttd
changeset 18726:9e987e309252 draft
(svn r23574) -Codechange/Feature-ish: allow converting multiple translations with the same master language instance in a single strgen run
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 17 Dec 2011 17:03:38 +0000 |
parents | 495cef967740 |
children | 6f49f2276a02 |
files | src/strgen/strgen.cpp |
diffstat | 1 files changed, 43 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -105,6 +105,16 @@ 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 @@ 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 @@ void StringReader::ParseFile() { char buf[2048]; + _warnings = _errors = 0; _translation = this->master || this->translation; _file = this->file; @@ -1621,7 +1641,7 @@ 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 @@ 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; + + /* 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]); - /* 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)); + /* 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)); - LanguageFileWriter writer(pathbuf); - writer.WriteLang(data); - writer.Finalise(); + 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); + /* 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;