genLang update

Last singleton gone, structure is now

handler (local in gLang.cxx) holds
   a variable of l10nMem
   a temporary convert_gen variable (to analyze file)

l10nMem contains hash list of all PO information

convert_xxx is inherited from convert_gen and instanciated
with a static function convert_gen::createInstance

the lex functions (in c) uses a "this" pointer to find back
to the class. This needs to be done better.

l10nMem contains a link to convert_PO, to save files, this
needs to be split.

Change-Id: I3ad31aac27aac739845062f8da61c8c1c3bf9c31
This commit is contained in:
jan iversen
2016-03-14 23:35:34 +01:00
parent 48c2e04bdb
commit 4043af8775
31 changed files with 98 additions and 267 deletions

View File

@@ -25,65 +25,40 @@
class convert_gen
{
public:
convert_gen(l10nMem& cMemory,
static convert_gen *mcImpl;
convert_gen(l10nMem& cMemory);
virtual ~convert_gen();
// Create instance
static convert_gen& createInstance(l10nMem& cMemory,
const std::string& sSourceDir,
const std::string& sTargetDir,
const std::string& sSourceFile);
~convert_gen();
// do extract/merge
bool execute(const bool bMerge, const bool bKid);
// ONLY po should implement these functions
void startSave(const std::string& sLanguage,
const std::string& sFile);
void save(const std::string& sFileName,
const std::string& sKey,
const std::string& sENUStext,
const std::string& sText,
bool bFuzzy);
void endSave();
static bool checkAccess(std::string& sFile);
static bool createDir(std::string& sDir, std::string& sFile);
};
/*****************************************************************************
**************************** G C O N . H X X ****************************
*****************************************************************************
* This is the class definition header for all converter classes,
* all classes and their interrelations is defined here
*****************************************************************************/
/******************* G L O B A L D E F I N I T I O N *******************/
/******************** C L A S S D E F I N I T I O N ********************/
class convert_gen_impl
{
public:
static convert_gen_impl *mcImpl;
convert_gen_impl(l10nMem& crMemory);
virtual ~convert_gen_impl();
// all converters MUST implement this function
virtual void execute() = 0;
// ONLY po should implement these functions
virtual void startSave(const std::string& sLanguage,
const std::string& sFile);
const std::string& sFile);
virtual void save(const std::string& sFileName,
const std::string& sKey,
const std::string& sENUStext,
const std::string& sText,
bool bFuzzy);
const std::string& sKey,
const std::string& sENUStext,
const std::string& sText,
bool bFuzzy);
virtual void endSave();
static bool checkAccess(std::string& sFile);
static bool createDir(std::string& sDir, std::string& sFile);
// utility functions for converters
void lexRead(char *sBuf, int *nResult, int nMax_size);
std::string& copySource(char const *yyText, bool bDoClear = true);
protected:
// generic variables
bool mbMergeMode;
bool mbLoadMode;
@@ -93,22 +68,14 @@ class convert_gen_impl
l10nMem& mcMemory;
std::string msCollector;
int miLineNo;
// utility functions for converters
void lexRead (char *sBuf, int *nResult, int nMax_size);
void writeSourceFile(const std::string& line);
std::string& copySource (char const *yyText, bool bDoClear = true);
protected:
std::string msSourceBuffer, msCopyText;
int miSourceReadIndex;
bool prepareFile();
private:
// utility functions for converters
void writeSourceFile(const std::string& line);
private:
std::ofstream mcOutputFile;
friend class convert_gen;
};
#endif

View File

@@ -32,7 +32,7 @@
/******************** C L A S S D E F I N I T I O N ********************/
class convert_db : public convert_gen_impl
class convert_db : public convert_gen
{
public:
convert_db(l10nMem& crMemory);

View File

@@ -32,7 +32,7 @@
/******************** C L A S S D E F I N I T I O N ********************/
class convert_po : public convert_gen_impl
class convert_po : public convert_gen
{
public:
bool mbExpectId;

View File

@@ -32,7 +32,7 @@
/******************** C L A S S D E F I N I T I O N ********************/
class convert_prop : public convert_gen_impl
class convert_prop : public convert_gen
{
public:
convert_prop(l10nMem& crMemory);

View File

@@ -31,7 +31,7 @@
/******************** C L A S S D E F I N I T I O N ********************/
class convert_src : public convert_gen_impl
class convert_src : public convert_gen
{
public:
bool mbExpectValue;

View File

@@ -32,7 +32,7 @@
/******************** C L A S S D E F I N I T I O N ********************/
class convert_tree : public convert_gen_impl
class convert_tree : public convert_gen
{
public:
typedef enum

View File

@@ -32,7 +32,7 @@
/******************** C L A S S D E F I N I T I O N ********************/
class convert_ulf : public convert_gen_impl
class convert_ulf : public convert_gen
{
public:
convert_ulf(l10nMem& crMemory);

View File

@@ -32,7 +32,7 @@
/******************** C L A S S D E F I N I T I O N ********************/
class convert_xcs : public convert_gen_impl
class convert_xcs : public convert_gen
{
public:
convert_xcs(l10nMem& crMemory);

View File

@@ -33,7 +33,7 @@
/******************** C L A S S D E F I N I T I O N ********************/
class xcu_stack_entry;
class convert_xcu : public convert_gen_impl
class convert_xcu : public convert_gen
{
public:
bool mbNoCollectingData;

View File

@@ -32,7 +32,7 @@
/******************** C L A S S D E F I N I T I O N ********************/
class convert_xhp : public convert_gen_impl
class convert_xhp : public convert_gen
{
public:
convert_xhp(l10nMem& crMemory);

View File

@@ -32,7 +32,7 @@
/******************** C L A S S D E F I N I T I O N ********************/
class convert_xrm : public convert_gen_impl
class convert_xrm : public convert_gen
{
public:
bool mbNoCollectingData;

View File

@@ -45,31 +45,25 @@
#endif
/*****************************************************************************
**************************** G C O N . C X X ****************************
*****************************************************************************
* This is the generic conversion module, it handles all generic work of the
* conversion, and offer utility functions to the specific conversion classes
*****************************************************************************/
/******************* G L O B A L D E F I N I T I O N *******************/
convert_gen_impl * convert_gen_impl::mcImpl = nullptr;
convert_gen * convert_gen::mcImpl = NULL;
/********************** I M P L E M E N T A T I O N **********************/
convert_gen::convert_gen(l10nMem& cMemory,
convert_gen::convert_gen(l10nMem& cMemory)
: mcMemory(cMemory)
{
mcImpl = this;
}
convert_gen::~convert_gen()
{
}
convert_gen& convert_gen::createInstance(l10nMem& cMemory,
const std::string& sSourceDir,
const std::string& sTargetDir,
const std::string& sSourceFile)
{
// do we have an old object
if (convert_gen_impl::mcImpl)
delete convert_gen_impl::mcImpl;
// did the user give a .xxx with the source file ?
int nInx = sSourceFile.rfind(".");
if (nInx == (int)std::string::npos)
@@ -77,30 +71,24 @@ convert_gen::convert_gen(l10nMem& cMemory,
// find correct conversion class and create correct object
std::string sExtension = sSourceFile.substr(nInx+1);
if (sExtension == "hrc") convert_gen_impl::mcImpl = new convert_src(cMemory);
else if (sExtension == "src") convert_gen_impl::mcImpl = new convert_src(cMemory);
else if (sExtension == "po") convert_gen_impl::mcImpl = new convert_po(cMemory);
else if (sExtension == "pot") convert_gen_impl::mcImpl = new convert_po(cMemory);
else if (sExtension == "tree") convert_gen_impl::mcImpl = new convert_tree(cMemory);
else if (sExtension == "ulf") convert_gen_impl::mcImpl = new convert_ulf(cMemory);
else if (sExtension == "xcu") convert_gen_impl::mcImpl = new convert_xcu(cMemory);
else if (sExtension == "xhp") convert_gen_impl::mcImpl = new convert_xhp(cMemory);
else if (sExtension == "xrm") convert_gen_impl::mcImpl = new convert_xrm(cMemory);
else if (sExtension == "properties") convert_gen_impl::mcImpl = new convert_prop(cMemory);
convert_gen *x;
if (sExtension == "hrc") x = new convert_src(cMemory);
else if (sExtension == "src") x = new convert_src(cMemory);
else if (sExtension == "po") x = new convert_po(cMemory);
else if (sExtension == "pot") x = new convert_po(cMemory);
else if (sExtension == "tree") x = new convert_tree(cMemory);
else if (sExtension == "ulf") x = new convert_ulf(cMemory);
else if (sExtension == "xcu") x = new convert_xcu(cMemory);
else if (sExtension == "xhp") x = new convert_xhp(cMemory);
else if (sExtension == "xrm") x = new convert_xrm(cMemory);
else if (sExtension == "properties") x = new convert_prop(cMemory);
else throw l10nMem::showError("unknown extension on source file: "+sSourceFile);
// and set environment
convert_gen_impl::mcImpl->msSourceFile = sSourceFile;
convert_gen_impl::mcImpl->msTargetPath = sTargetDir;
convert_gen_impl::mcImpl->msSourcePath = sSourceDir + sSourceFile;
}
/********************** I M P L E M E N T A T I O N **********************/
convert_gen::~convert_gen()
{
delete convert_gen_impl::mcImpl;
x->msSourceFile = sSourceFile;
x->msTargetPath = sTargetDir;
x->msSourcePath = sSourceDir + sSourceFile;
return *x;
}
@@ -108,17 +96,17 @@ convert_gen::~convert_gen()
/********************** I M P L E M E N T A T I O N **********************/
bool convert_gen::execute(const bool bMerge, const bool bKid)
{
convert_gen_impl::mcImpl->mbMergeMode = bMerge;
mbMergeMode = bMerge;
if (bKid)
throw l10nMem::showError("not implemented");
// and load file
if (!convert_gen_impl::mcImpl->prepareFile())
if (!prepareFile())
return false;
// and execute conversion
convert_gen_impl::mcImpl->execute();
execute();
return true;
}
@@ -128,11 +116,6 @@ bool convert_gen::execute(const bool bMerge, const bool bKid)
/********************** I M P L E M E N T A T I O N **********************/
void convert_gen::startSave(const std::string& sLanguage,
const std::string& sFile)
{
convert_gen_impl::mcImpl->startSave(sLanguage, sFile);
}
void convert_gen_impl::startSave(const std::string& sLanguage,
const std::string& sFile)
{
std::string x;
@@ -143,20 +126,11 @@ void convert_gen_impl::startSave(const std::string& sLanguage,
/********************** I M P L E M E N T A T I O N **********************/
void convert_gen::save(const std::string& sFileName,
const std::string& sKey,
const std::string& sENUStext,
const std::string& sText,
bool bFuzzy)
{
convert_gen_impl::mcImpl->save(sFileName, sKey, sENUStext, sText, bFuzzy);
}
void convert_gen_impl::save(const std::string& sFileName,
const std::string& sKey,
const std::string& sENUStext,
const std::string& sText,
bool bFuzzy)
{
std::string x;
@@ -167,12 +141,7 @@ void convert_gen_impl::save(const std::string& sFileName,
/********************** I M P L E M E N T A T I O N **********************/
void convert_gen::endSave()
{
convert_gen_impl::mcImpl->endSave();
}
void convert_gen_impl::endSave()
{
throw l10nMem::showError("endSave called with non .po file");
}
@@ -216,26 +185,7 @@ bool convert_gen::createDir(std::string& sDir, std::string& sFile)
/********************** 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),
mcMemory(crMemory),
miLineNo(1)
{
}
/********************** I M P L E M E N T A T I O N **********************/
convert_gen_impl::~convert_gen_impl()
{
mcImpl = nullptr;
}
/********************** I M P L E M E N T A T I O N **********************/
bool convert_gen_impl::prepareFile()
bool convert_gen::prepareFile()
{
std::ifstream inputFile(msSourcePath.c_str(), std::ios::binary);
@@ -290,7 +240,7 @@ bool convert_gen_impl::prepareFile()
/********************** I M P L E M E N T A T I O N **********************/
void convert_gen_impl::lexRead(char *sBuf, int *nResult, int nMax_size)
void convert_gen::lexRead(char *sBuf, int *nResult, int nMax_size)
{
// did we hit eof
if (miSourceReadIndex == -1)
@@ -320,7 +270,7 @@ void convert_gen_impl::lexRead(char *sBuf, int *nResult, int nMax_size)
/********************** I M P L E M E N T A T I O N **********************/
void convert_gen_impl::writeSourceFile(const std::string& line)
void convert_gen::writeSourceFile(const std::string& line)
{
if (!line.size())
return;
@@ -332,7 +282,7 @@ void convert_gen_impl::writeSourceFile(const std::string& line)
/********************** I M P L E M E N T A T I O N **********************/
std::string& convert_gen_impl::copySource(char const *yyText, bool bDoClear)
std::string& convert_gen::copySource(char const *yyText, bool bDoClear)
{
int nL;

View File

@@ -24,16 +24,7 @@
/*****************************************************************************
************************** G C O N D B . C X X **************************
*****************************************************************************
* This includes the c code generated by flex
*****************************************************************************/
/************ I N T E R F A C E I M P L E M E N T A T I O N ************/
convert_db::convert_db(l10nMem& crMemory) : convert_gen_impl(crMemory) {}
convert_db::convert_db(l10nMem& crMemory) : convert_gen(crMemory) {}
convert_db::~convert_db() {}

View File

@@ -37,7 +37,7 @@
/************ I N T E R F A C E I M P L E M E N T A T I O N ************/
convert_po::convert_po(l10nMem& crMemory)
: convert_gen_impl(crMemory),
: convert_gen(crMemory),
mbExpectId(false),
mbExpectStr(false),
mbFuzzy(false)

View File

@@ -24,16 +24,7 @@
/*****************************************************************************
************************ G C O N P R O P . C X X ************************
*****************************************************************************
* This is the conversion for .properties files
*****************************************************************************/
/********************** I M P L E M E N T A T I O N **********************/
convert_prop::convert_prop(l10nMem& crMemory) : convert_gen_impl(crMemory)
convert_prop::convert_prop(l10nMem& crMemory) : convert_gen(crMemory)
{
// throw l10nMem::showError(std::string("convert_prop not implemented"));
}

View File

@@ -28,17 +28,8 @@
#include <sstream>
/*****************************************************************************
********************* G C O N S R C W R A P . C X X *********************
*****************************************************************************
* This includes the c code generated by flex
*****************************************************************************/
/************ I N T E R F A C E I M P L E M E N T A T I O N ************/
convert_src::convert_src(l10nMem& crMemory)
: convert_gen_impl(crMemory),
: convert_gen(crMemory),
mbExpectValue(false),
mbEnUs(false),
mbExpectName(false),

View File

@@ -23,18 +23,8 @@
#include "gConvTree.hxx"
/*****************************************************************************
******************** G C O N T R E E W R A P . C X X ********************
*****************************************************************************
* This includes the c code generated by flex
*****************************************************************************/
/********************** I M P L E M E N T A T I O N **********************/
convert_tree::convert_tree(l10nMem& crMemory)
: convert_gen_impl(crMemory),
: convert_gen(crMemory),
mcOutputFiles(nullptr),
meStateTag(STATE_TAG_NONE),
meStateVal(STATE_VAL_NONE),

View File

@@ -24,16 +24,7 @@
/*****************************************************************************
********************* G C O N X C S W R A P . C X X *********************
*****************************************************************************
* This includes the c code generated by flex
*****************************************************************************/
/********************** I M P L E M E N T A T I O N **********************/
convert_ulf::convert_ulf(l10nMem& crMemory) : convert_gen_impl(crMemory) {}
convert_ulf::convert_ulf(l10nMem& crMemory) : convert_gen(crMemory) {}
convert_ulf::~convert_ulf() {}

View File

@@ -24,17 +24,8 @@
/*****************************************************************************
********************* G C O N X C S W R A P . C X X *********************
*****************************************************************************
* This includes the c code generated by flex
*****************************************************************************/
/************ I N T E R F A C E I M P L E M E N T A T I O N ************/
convert_xcs::convert_xcs(l10nMem& crMemory)
: convert_gen_impl(crMemory),
: convert_gen(crMemory),
mbCollectingData(false)
{
}

View File

@@ -21,19 +21,8 @@
#include "gL10nMem.hxx"
#include "gConvXcu.hxx"
/*****************************************************************************
********************* G C O N X C U W R A P . C X X *********************
*****************************************************************************
* This includes the c code generated by flex
*****************************************************************************/
/************ I N T E R F A C E I M P L E M E N T A T I O N ************/
convert_xcu::convert_xcu(l10nMem& crMemory)
: convert_gen_impl(crMemory),
: convert_gen(crMemory),
mbNoCollectingData(true),
miLevel(0),
mbNoTranslate(false)

View File

@@ -21,20 +21,8 @@
#include "gL10nMem.hxx"
#include "gConvXhp.hxx"
/*****************************************************************************
********************* G C O N X H P W R A P . C X X *********************
*****************************************************************************
* This includes the c code generated by flex
*****************************************************************************/
/************ I N T E R F A C E I M P L E M E N T A T I O N ************/
convert_xhp::convert_xhp(l10nMem& crMemory)
: convert_gen_impl(crMemory),
: convert_gen(crMemory),
meExpectValue(VALUE_NOT_USED),
msLangText(nullptr),
mcOutputFiles(nullptr),

View File

@@ -23,17 +23,9 @@
#include "gConvXrm.hxx"
/*****************************************************************************
********************* G C O N X R M W R A P . C X X *********************
*****************************************************************************
* This includes the c code generated by flex
*****************************************************************************/
/************ I N T E R F A C E I M P L E M E N T A T I O N ************/
convert_xrm::convert_xrm(l10nMem& crMemory)
: convert_gen_impl(crMemory),
: convert_gen(crMemory),
mbNoCollectingData(true),
mbIsTag(false),
mbIsLang(false)

View File

@@ -330,7 +330,7 @@ void handler::loadL10MEM(bool onlyTemplates)
// and load file
mcMemory.setLanguage("", true);
convert_gen (mcMemory, sLoad, msTargetDir, "").execute(false, false);
convert_gen::createInstance(mcMemory, sLoad, msTargetDir, "").execute(false, false);
if (onlyTemplates)
return;
@@ -346,7 +346,7 @@ void handler::loadL10MEM(bool onlyTemplates)
// tell system
l10nMem::showDebug("genLang loading text from language file " + sLoad);
convert_gen(mcMemory, sLoad, msTargetDir, "").execute(false, false);
convert_gen::createInstance(mcMemory, sLoad, msTargetDir, "").execute(false, false);
}
}
@@ -368,7 +368,7 @@ void handler::runConvert()
l10nMem::showDebug("genLang compare template " + *siSource);
// get converter and extract files
convert_gen convertObj(mcMemory, "./", msTargetDir, *siSource);
convert_gen& convertObj = convert_gen::createInstance(mcMemory, "./", msTargetDir, *siSource);
convertObj.execute(false, false);
mcMemory.showNOconvert();
@@ -385,7 +385,7 @@ void handler::runConvert()
sFilePath + *siSource + " language " + *siLang);
// get converter and extract files
//convert_gen convertObj(mcMemory, sFilePath, msTargetDir, *siSource);
convert_gen& convertObj = convert_gen::createInstance(mcMemory, sFilePath, msTargetDir, *siSource);
convertObj.execute(true, false);
}
}
@@ -411,7 +411,7 @@ void handler::runExtract()
l10nMem::showDebug("genLang extracting text from file " + *siSource);
// get converter and extract file
convert_gen convertObj(mcMemory, "", msTargetDir, *siSource);
convert_gen& convertObj = convert_gen::createInstance(mcMemory, "", msTargetDir, *siSource);
convertObj.execute(false, false);
}
@@ -435,7 +435,7 @@ void handler::runMerge(bool bKid)
l10nMem::showDebug("genLang merging translated text to file " + *siSource);
// get converter and extract file
convert_gen convertObj(mcMemory, "", msTargetDir, *siSource);
convert_gen& convertObj = convert_gen::createInstance(mcMemory, "", msTargetDir, *siSource);
convertObj.execute(true, bKid);
}
}

View File

@@ -41,8 +41,8 @@
#include "gL10nMem.hxx"
#include "gConvPo.hxx"
#define IMPLptr convert_gen_impl::mcImpl
#define LOCptr ((convert_po *)convert_gen_impl::mcImpl)
#define IMPLptr convert_gen::mcImpl
#define LOCptr ((convert_po *)convert_gen::mcImpl)
/* enlarge token buffer to tokenize whole std::strings */
#undef YYLMAX

View File

@@ -26,8 +26,8 @@
#include "gL10nMem.hxx"
#include "gConvSrc.hxx"
#define IMPLptr convert_gen_impl::mcImpl
#define LOCptr ((convert_src *)convert_gen_impl::mcImpl)
#define IMPLptr convert_gen::mcImpl
#define LOCptr ((convert_src *)convert_gen::mcImpl)
/* enlarge token buffer to tokenize whole std::strings */
#undef YYLMAX

View File

@@ -26,8 +26,8 @@
#include "gL10nMem.hxx"
#include "gConvTree.hxx"
#define IMPLptr convert_gen_impl::mcImpl
#define LOCptr ((convert_tree *)convert_gen_impl::mcImpl)
#define IMPLptr convert_gen::mcImpl
#define LOCptr ((convert_tree *)convert_gen::mcImpl)
/* enlarge token buffer to tokenize whole std::strings */
#undef YYLMAX

View File

@@ -26,8 +26,8 @@
#include "gL10nMem.hxx"
#include "gConvUlf.hxx"
#define IMPLptr convert_gen_impl::mcImpl
#define LOCptr ((convert_ulf *)convert_gen_impl::mcImpl)
#define IMPLptr convert_gen::mcImpl
#define LOCptr ((convert_ulf *)convert_gen::mcImpl)
/* enlarge token buffer to tokenize whole std::strings */
#undef YYLMAX

View File

@@ -26,8 +26,8 @@
#include "gL10nMem.hxx"
#include "gConvXcs.hxx"
#define IMPLptr convert_gen_impl::mcImpl
#define LOCptr ((convert_xcs *)convert_gen_impl::mcImpl)
#define IMPLptr convert_gen::mcImpl
#define LOCptr ((convert_xcs *)convert_gen::mcImpl)
/* enlarge token buffer to tokenize whole std::strings */
#undef YYLMAX

View File

@@ -26,8 +26,8 @@
#include "gL10nMem.hxx"
#include "gConvXcu.hxx"
#define IMPLptr convert_gen_impl::mcImpl
#define LOCptr ((convert_xcu *)convert_gen_impl::mcImpl)
#define IMPLptr convert_gen::mcImpl
#define LOCptr ((convert_xcu *)convert_gen::mcImpl)
/* enlarge token buffer to tokenize whole std::strings */
#undef YYLMAX

View File

@@ -26,8 +26,8 @@
#include "gL10nMem.hxx"
#include "gConvXhp.hxx"
#define IMPLptr convert_gen_impl::mcImpl
#define LOCptr ((convert_xhp *)convert_gen_impl::mcImpl)
#define IMPLptr convert_gen::mcImpl
#define LOCptr ((convert_xhp *)convert_gen::mcImpl)
/* enlarge token buffer to tokenize whole std::strings */
#undef YYLMAX

View File

@@ -26,8 +26,8 @@
#include "gL10nMem.hxx"
#include "gConvXrm.hxx"
#define IMPLptr convert_gen_impl::mcImpl
#define LOCptr ((convert_xrm *)convert_gen_impl::mcImpl)
#define IMPLptr convert_gen::mcImpl
#define LOCptr ((convert_xrm *)convert_gen::mcImpl)
/* enlarge token buffer to tokenize whole std::strings */
#undef YYLMAX