Author: jani Date: Sun Apr 7 00:02:36 2013 New Revision: 1465315 URL: http://svn.apache.org/r1465315 Log: added automatic create dir in target (needed in e.g. unxlngx6.pro)
Modified: openoffice/branches/l10n/main/l10ntools/source/gCon.cxx openoffice/branches/l10n/main/l10ntools/source/gConTreeWrap.cxx openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx openoffice/branches/l10n/main/l10ntools/source/gLang.hxx Modified: openoffice/branches/l10n/main/l10ntools/source/gCon.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gCon.cxx?rev=1465315&r1=1465314&r2=1465315&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gCon.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gCon.cxx Sun Apr 7 00:02:36 2013 @@ -29,6 +29,17 @@ #include "gConXcu.hxx" #include "gConXhp.hxx" #include "gConXrm.hxx" +#ifdef _WIN32 +#include <io.h> +#include <direct.h> +#define OS_ACCESS(x,y) _access(x,y) +#define OS_MKDIR(x) _mkdir(x) +#else +#include <sys/stat.h> +#include <sys/types.h> +#define OS_ACCESS(x,y) access(x,y) +#define OS_MKDIR(x) mkdir(x,0777) +#endif @@ -166,6 +177,42 @@ void convert_gen_impl::endSave() /********************** I M P L E M E N T A T I O N **********************/ +bool convert_gen::checkAccess(std::string& sFile) +{ + return (OS_ACCESS(sFile.c_str(), 0) == 0); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +bool convert_gen::createDir(std::string& sDir, std::string& sFile) +{ + std::string sNewDir(sDir); + int newPos, oldPos; + + + for (oldPos = 0;; oldPos = newPos +1) + { + newPos = sFile.find_first_of("/\\", oldPos); + if (newPos == std::string::npos) + break; + + sNewDir += sFile.substr(oldPos, newPos-oldPos) + "/"; + + if (!checkAccess(sNewDir)) + { + OS_MKDIR((char *)sNewDir.c_str()); + } + + } + + + return true; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ convert_gen_impl::convert_gen_impl(l10nMem& crMemory) : mbMergeMode(false), mbLoadMode(false), @@ -221,8 +268,16 @@ bool convert_gen_impl::prepareFile() // open output file mcOutputFile.open((msTargetPath+msSourceFile).c_str(), std::ios::binary); - if (!mcOutputFile.is_open()) - throw l10nMem::showError("Cannot open file (" + msTargetPath+msSourceFile + ") for writing"); + if (mcOutputFile.is_open()) + return true; + + if (convert_gen::createDir(msTargetPath, msSourceFile)) + { + mcOutputFile.open((msTargetPath+msSourceFile).c_str(), std::ios::binary); + if (mcOutputFile.is_open()) + return true; + } + throw l10nMem::showError("Cannot open file (" + msTargetPath+msSourceFile + ") for writing"); } return true; Modified: openoffice/branches/l10n/main/l10ntools/source/gConTreeWrap.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConTreeWrap.cxx?rev=1465315&r1=1465314&r2=1465315&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gConTreeWrap.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gConTreeWrap.cxx Sun Apr 7 00:02:36 2013 @@ -71,7 +71,7 @@ namespace TreeWrap void convert_tree::execute() { std::string sLang; - std::string sFile; + std::string sFile, sFile2; // prepare list with languages if (mbMergeMode) @@ -81,10 +81,18 @@ void convert_tree::execute() for (int i = 0; mcMemory.getMergeLang(sLang, sFile); ++i) { - sFile = msTargetPath + sLang + "/" + msSourceFile; + sFile2 = sLang + "/" + msSourceFile; + sFile = msTargetPath + sFile2; mcOutputFiles[i].open(sFile.c_str(), std::ios::binary); if (!mcOutputFiles[i].is_open()) - throw l10nMem::showError("Cannot open file (" + sFile + ") for writing"); + { + 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"); + } } } @@ -112,10 +120,13 @@ void convert_tree::setString(char *yytex case STATE_VAL_ID: msId = copySourceSpecial(yytext, 0); + msId.erase(msId.size()-1); break; case STATE_VAL_TITLE: - copySourceSpecial(yytext, 1); + std::string sText = copySourceSpecial(yytext, 1); + sText.erase(sText.size()-1); + mcMemory.setSourceKey(miLineNo, msSourceFile, msId, sText); break; } meStateVal = STATE_VAL_NONE; @@ -127,7 +138,7 @@ void convert_tree::setString(char *yytex void convert_tree::setState(char *yytext, STATE_TAG eNewStateTag, STATE_VAL eNewStateVAL) { copySourceSpecial(yytext, 0); - + msCollector.clear(); meStateTag = eNewStateTag; meStateVal = eNewStateVAL; } @@ -137,6 +148,7 @@ void convert_tree::setState(char *yytext /********************** 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); copySourceSpecial(yytext, 2); meStateTag = STATE_TAG_NONE; @@ -149,7 +161,7 @@ void convert_tree::setValue(char *yytext std::string& convert_tree::copySourceSpecial(char *yytext, int iType) { std::string& sText = copySource(yytext, false); - std::string sLang; + std::string sLang, sTemp; int i; // Handling depends on iType @@ -171,12 +183,12 @@ std::string& convert_tree::copySourceSpe case 1: // Used for title token, are to replaced with languages if (mbMergeMode) { -// mcMemory.xhpSearchTreeTitle(msId); + mcMemory.prepareMerge(); for (i = 0; i < miCntLanguages; ++i) { writeSourceFile(msLine, i); - mcMemory.getMergeLang(sLang, sText); - writeSourceFile(sText,i); + mcMemory.getMergeLang(sLang, sTemp); + writeSourceFile(sTemp,i); } msLine.clear(); } @@ -185,12 +197,12 @@ std::string& convert_tree::copySourceSpe case 2: // Used for token at end of value, language text are to be inserted and then token written if (mbMergeMode) { -// mcMemory.xhpSearchTopicTitle(msId); + mcMemory.prepareMerge(); for (i = 0; i < miCntLanguages; ++i) { writeSourceFile(msLine, i); - mcMemory.getMergeLang(sLang, sText); - writeSourceFile(sText,i); + mcMemory.getMergeLang(sLang, sTemp); + writeSourceFile(sTemp,i); std::string sYY(yytext); writeSourceFile(sYY, i); } Modified: openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx?rev=1465315&r1=1465314&r2=1465315&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx Sun Apr 7 00:02:36 2013 @@ -72,7 +72,7 @@ namespace XhpWrap void convert_xhp::execute() { std::string sLang; - std::string sFile; + std::string sFile, sFile2; // prepare list with languages miCntLanguages = mcMemory.prepareMerge(); @@ -83,11 +83,18 @@ void convert_xhp::execute() for (int i = 0; mcMemory.getMergeLang(sLang, sFile); ++i) { - sFile = msTargetPath + sLang + "/" + msSourceFile; + sFile2 = sLang + "/" + msSourceFile; + sFile = msTargetPath + sFile2; mcOutputFiles[i].open(sFile.c_str(), std::ios::binary); if (!mcOutputFiles[i].is_open()) - throw l10nMem::showError("Cannot open file (" + sFile + ") for writing"); - + { + 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"); + } msLangText[i] = "xml-lang=\"" + sLang + "\""; } } Modified: openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx?rev=1465315&r1=1465314&r2=1465315&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx Sun Apr 7 00:02:36 2013 @@ -155,6 +155,9 @@ void handler::checkCommandLine(int argc, if (meWorkMode == DO_MERGE) throw "-t <target dir> is mandatory"; } + if (!convert_gen::checkAccess(msTargetDir)) + throw "<target dir> does not exist"; + if (msSourceDir.size()) { if (meWorkMode == DO_GENERATE) @@ -165,6 +168,8 @@ void handler::checkCommandLine(int argc, if (meWorkMode != DO_GENERATE) throw "-s <source dir> is mandatory"; } + if (!convert_gen::checkAccess(msSourceDir)) + throw "<source dir> does not exist"; // Key Identification generation if (bKid) Modified: openoffice/branches/l10n/main/l10ntools/source/gLang.hxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gLang.hxx?rev=1465315&r1=1465314&r2=1465315&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gLang.hxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gLang.hxx Sun Apr 7 00:02:36 2013 @@ -116,6 +116,8 @@ class convert_gen const std::string& sText, bool bFuzzy); void endSave(); + static bool checkAccess(std::string& sFile); + static bool createDir(std::string& sDir, std::string& sFile); };