summaryrefslogtreecommitdiff
path: root/l10ntools/source/gConvTree.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'l10ntools/source/gConvTree.cxx')
-rw-r--r--l10ntools/source/gConvTree.cxx264
1 files changed, 117 insertions, 147 deletions
diff --git a/l10ntools/source/gConvTree.cxx b/l10ntools/source/gConvTree.cxx
index cac25a44ecfc..a452240ff94d 100644
--- a/l10ntools/source/gConvTree.cxx
+++ b/l10ntools/source/gConvTree.cxx
@@ -31,197 +31,167 @@ convert_tree::convert_tree(l10nMem& crMemory)
miCntLanguages(0)
{
- // tree files are written through a local routine
- mbLoadMode = true;
+ // tree files are written through a local routine
+ mbLoadMode = true;
}
-/********************** I M P L E M E N T A T I O N **********************/
convert_tree::~convert_tree()
{
- if (mcOutputFiles)
- {
- for (int i = 0; i < miCntLanguages; ++i)
- mcOutputFiles[i].close();
- delete[] mcOutputFiles;
- }
+ if (mcOutputFiles) {
+ for (int i = 0; i < miCntLanguages; ++i)
+ mcOutputFiles[i].close();
+ delete[] mcOutputFiles;
+ }
}
-/********************** I M P L E M E N T A T I O N **********************/
-//namespace TreeWrap
-//{
-//#define IMPLptr convert_gen_impl::mcImpl
-//#define LOCptr ((convert_tree *)convert_gen_impl::mcImpl)
-//#include "gConTree_yy.c"
-//}
-
-
-
-/********************** I M P L E M E N T A T I O N **********************/
void convert_tree::execute()
{
- std::string sLang;
- std::string sFile, sFile2;
-
- if (mbMergeMode)
- throw l10nMem::showError("Merge not implemented");
-
- // prepare list with languages
- if (mbMergeMode)
- {
- miCntLanguages = mcMemory.prepareMerge();
- mcOutputFiles = new std::ofstream[miCntLanguages];
-
- for (int i = 0; mcMemory.getMergeLang(sLang, sFile); ++i)
- {
- sFile2 = sLang + "/" + msSourceFile;
- sFile = msTargetPath + sFile2;
- mcOutputFiles[i].open(sFile.c_str(), std::ios::binary);
- if (!mcOutputFiles[i].is_open())
- {
- if (!convert_gen::createDir(msTargetPath, sFile2))
- throw l10nMem::showError("Cannot create missing directories (" + sFile + ") for writing");
-
- mcOutputFiles[i].open(sFile.c_str(), std::ios::binary);
- if (!mcOutputFiles[i].is_open())
- throw l10nMem::showError("Cannot open file (" + sFile + ") for writing");
- }
+ std::string sLang;
+ std::string sFile, sFile2;
+
+ if (mbMergeMode)
+ throw l10nMem::showError("Merge not implemented");
+
+ // prepare list with languages
+ if (mbMergeMode) {
+ miCntLanguages = mcMemory.prepareMerge();
+ mcOutputFiles = new std::ofstream[miCntLanguages];
+
+ for (int i = 0; mcMemory.getMergeLang(sLang, sFile); ++i) {
+ sFile2 = sLang + "/" + msSourceFile;
+ sFile = msTargetPath + sFile2;
+ mcOutputFiles[i].open(sFile.c_str(), std::ios::binary);
+ if (!mcOutputFiles[i].is_open()) {
+ if (!convert_gen::createDir(msTargetPath, sFile2))
+ throw l10nMem::showError("Cannot create missing directories (" + sFile + ") for writing");
+
+ mcOutputFiles[i].open(sFile.c_str(), std::ios::binary);
+ if (!mcOutputFiles[i].is_open())
+ throw l10nMem::showError("Cannot open file (" + sFile + ") for writing");
+ }
+ }
}
- }
- // run analyzer
-// TreeWrap::yylex();
+ // run analyzer
+ // TreeWrap::yylex();
- // dump last line
- copySourceSpecial(nullptr,3);
+ // dump last line
+ copySourceSpecial(nullptr,3);
}
-/********************** I M P L E M E N T A T I O N **********************/
void convert_tree::setString(char *yytext)
{
- switch (meStateVal)
- {
- case STATE_VAL_NONE:
- copySourceSpecial(yytext, 0);
- break;
-
- case STATE_VAL_APPL:
- msAppl = copySourceSpecial(yytext, 0);
- break;
-
- case STATE_VAL_ID:
- msId = copySourceSpecial(yytext, 0);
- msId.erase(msId.size()-1);
- break;
-
- case STATE_VAL_TITLE:
- std::string sText = copySourceSpecial(yytext, 1);
- sText.erase(sText.size()-1);
- mcMemory.setSourceKey(miLineNo, msSourceFile, msId, sText, mbMergeMode);
- break;
- }
- meStateVal = STATE_VAL_NONE;
+ switch (meStateVal) {
+ case STATE_VAL_NONE:
+ copySourceSpecial(yytext, 0);
+ break;
+
+ case STATE_VAL_APPL:
+ msAppl = copySourceSpecial(yytext, 0);
+ break;
+
+ case STATE_VAL_ID:
+ msId = copySourceSpecial(yytext, 0);
+ msId.erase(msId.size()-1);
+ break;
+
+ case STATE_VAL_TITLE:
+ std::string sText = copySourceSpecial(yytext, 1);
+ sText.erase(sText.size()-1);
+ mcMemory.setSourceKey(miLineNo, msSourceFile, msId, sText, mbMergeMode);
+ break;
+ }
+ meStateVal = STATE_VAL_NONE;
}
-/********************** I M P L E M E N T A T I O N **********************/
void convert_tree::setState(char *yytext, STATE_TAG eNewStateTag, STATE_VAL eNewStateVAL)
{
- copySourceSpecial(yytext, 0);
- msCollector.clear();
- meStateTag = eNewStateTag;
- meStateVal = eNewStateVAL;
+ copySourceSpecial(yytext, 0);
+ msCollector.clear();
+ meStateTag = eNewStateTag;
+ meStateVal = eNewStateVAL;
}
-/********************** I M P L E M E N T A T I O N **********************/
void convert_tree::setValue(char *yytext)
{
- mcMemory.setSourceKey(miLineNo, msSourceFile, msId, msCollector, mbMergeMode);
- copySourceSpecial(yytext, 2);
+ mcMemory.setSourceKey(miLineNo, msSourceFile, msId, msCollector, mbMergeMode);
+ copySourceSpecial(yytext, 2);
- meStateTag = STATE_TAG_NONE;
- meStateVal = STATE_VAL_NONE;
+ meStateTag = STATE_TAG_NONE;
+ meStateVal = STATE_VAL_NONE;
}
-/********************** I M P L E M E N T A T I O N **********************/
std::string& convert_tree::copySourceSpecial(char *yytext, int iType)
{
- std::string& sText = copySource(yytext, false);
- std::string sLang, sTemp;
- int i;
-
- // Handling depends on iType
- switch (iType)
- {
- case 0: // Used for tokens that are to be copied 1-1,
- if (mbMergeMode)
- {
- msLine += yytext;
- if (*yytext == '\n')
- {
- for (i = 0; i < miCntLanguages; ++i)
- writeSourceFile(msLine, i);
- msLine.clear();
- }
- }
- break;
-
- case 1: // Used for title token, are to replaced with languages
- if (mbMergeMode)
- {
- mcMemory.prepareMerge();
- for (i = 0; i < miCntLanguages; ++i)
- {
- writeSourceFile(msLine, i);
- mcMemory.getMergeLang(sLang, sTemp);
- writeSourceFile(sTemp,i);
- }
- msLine.clear();
- }
- break;
-
- case 2: // Used for token at end of value, language text are to be inserted and then token written
- if (mbMergeMode)
- {
- mcMemory.prepareMerge();
- for (i = 0; i < miCntLanguages; ++i)
- {
- writeSourceFile(msLine, i);
- mcMemory.getMergeLang(sLang, sTemp);
- writeSourceFile(sTemp,i);
- std::string sYY(yytext);
- writeSourceFile(sYY, i);
- }
- msLine.clear();
- }
- break;
-
- case 3: // Used for EOF
- if (mbMergeMode)
- {
- for (i = 0; i < miCntLanguages; ++i)
- writeSourceFile(msLine, i);
- }
- break;
- }
- return sText;
+ std::string& sText = copySource(yytext, false);
+ std::string sLang, sTemp;
+ int i;
+
+ // Handling depends on iType
+ switch (iType) {
+ case 0: // Used for tokens that are to be copied 1-1,
+ if (mbMergeMode) {
+ msLine += yytext;
+ if (*yytext == '\n') {
+ for (i = 0; i < miCntLanguages; ++i)
+ writeSourceFile(msLine, i);
+ msLine.clear();
+ }
+ }
+ break;
+
+ case 1: // Used for title token, are to replaced with languages
+ if (mbMergeMode) {
+ mcMemory.prepareMerge();
+ for (i = 0; i < miCntLanguages; ++i) {
+ writeSourceFile(msLine, i);
+ mcMemory.getMergeLang(sLang, sTemp);
+ writeSourceFile(sTemp,i);
+ }
+ msLine.clear();
+ }
+ break;
+
+ case 2: // Used for token at end of value, language text are to be inserted and then token written
+ if (mbMergeMode) {
+ mcMemory.prepareMerge();
+ for (i = 0; i < miCntLanguages; ++i) {
+ writeSourceFile(msLine, i);
+ mcMemory.getMergeLang(sLang, sTemp);
+ writeSourceFile(sTemp,i);
+ std::string sYY(yytext);
+ writeSourceFile(sYY, i);
+ }
+ msLine.clear();
+ }
+ break;
+
+ case 3: // Used for EOF
+ if (mbMergeMode) {
+ for (i = 0; i < miCntLanguages; ++i)
+ writeSourceFile(msLine, i);
+ }
+ break;
+ }
+ return sText;
}
-/********************** I M P L E M E N T A T I O N **********************/
void convert_tree::writeSourceFile(std::string& sText, int inx)
{
- if (sText.size() && mcOutputFiles[inx].is_open())
- mcOutputFiles[inx].write(sText.c_str(), sText.size());
+ if (sText.size() && mcOutputFiles[inx].is_open())
+ mcOutputFiles[inx].write(sText.c_str(), sText.size());
}