[Libreoffice-commits] core.git: l10ntools/inc l10ntools/source
jan Iversen
jani at documentfoundation.org
Mon May 2 12:37:43 UTC 2016
l10ntools/inc/gConvSrc.hxx | 32 ++++---
l10ntools/source/gConvSrc.cxx | 174 +++++++++++++++++++---------------------
l10ntools/source/gLexSrc.l | 182 ++++++++++++++++++++++++++----------------
l10ntools/source/gRun.sh | 2
4 files changed, 218 insertions(+), 172 deletions(-)
New commits:
commit 8aed53c10425fab4813b439abe3ee60939dc9a14
Author: jan Iversen <jani at documentfoundation.org>
Date: Mon May 2 11:46:13 2016 +0000
genLang .src conversion, first version.
LO uses the .src quite differently, so a new implementation
was made.
The unused old functions are hanging in a #if 0, and will
be removed later.
Change-Id: Ic466a1b97f9f65c9f658612bd2aa325396e929c3
diff --git a/l10ntools/inc/gConvSrc.hxx b/l10ntools/inc/gConvSrc.hxx
index 3f3f9a2..77922c9 100644
--- a/l10ntools/inc/gConvSrc.hxx
+++ b/l10ntools/inc/gConvSrc.hxx
@@ -28,26 +28,29 @@ extern int srclex(void);
class convert_src : public convert_gen
{
public:
- bool mbExpectValue;
+// bool mbExpectValue;
convert_src(l10nMem& crMemory);
~convert_src() override {};
- void setValue (char *syyText, char *sbuildValue);
- void setLang (char *syyText, bool bEnUs);
- void setId (char *syyText, bool bIde);
- void setText (char *syyText);
- void setName (char *syyText);
- void setCmd (char *syyText);
- void setMacro (char *syyText);
- void setList (char *syyText);
- void setListItem (char const *syyText, bool bIsStart);
- void setNL (char *syyText, bool bMacro);
- void startBlock (char *syyText);
- void stopBlock (char *syyText);
+ void setValue(string& syyText);
+ bool setLang(string& syyText);
+ void setName(string& syyText);
+ void setCmd(string& syyText);
+ void startBlock();
+ void stopBlock();
+
+// void setId (char *syyText, bool bIde);
+// void setText (char *syyText);
+// void setMacro (char *syyText);
+// void setList (char *syyText);
+// void setListItem (char const *syyText, bool bIsStart);
+// void setNL (char *syyText, bool bMacro);
private:
vector<string> mcStack;
+ void doExecute() override;
+#if 0
string msValue;
string msName;
string msTextName;
@@ -62,9 +65,10 @@ class convert_src : public convert_gen
bool mbInListItem;
int miListCount;
int miMacroLevel;
- void doExecute() override;
+
static void trim(string& sText);
void buildKey(string& sKey);
void insertLanguagePart(string& sKey, string& sTextType);
+#endif
};
#endif
diff --git a/l10ntools/source/gConvSrc.cxx b/l10ntools/source/gConvSrc.cxx
index 2be9ce6..20085a0 100644
--- a/l10ntools/source/gConvSrc.cxx
+++ b/l10ntools/source/gConvSrc.cxx
@@ -29,7 +29,9 @@ using namespace std;
convert_src::convert_src(l10nMem& crMemory)
- : convert_gen(crMemory),
+ : convert_gen(crMemory)
+#if 0
+ ,
mbExpectValue(false),
mbEnUs(false),
mbExpectName(false),
@@ -38,6 +40,7 @@ convert_src::convert_src(l10nMem& crMemory)
mbValuePresent(false),
mbInList(false),
mbInListItem(false)
+#endif
{
}
@@ -50,112 +53,116 @@ void convert_src::doExecute()
-void convert_src::setValue(char *syyText, char *sbuildValue)
+void convert_src::setValue(string& syyText)
{
- copySource(syyText);
-
- if (mbInList && !mbInListItem) {
- setListItem("", true);
- setListItem("", false);
+ int stackSize = mcStack.size();
+ string cleanValue = syyText.substr(1, syyText.size() - 1);
+ {
+ cout << "test value\n";
+ for (int i = 0; i < stackSize; i++)
+ cout << mcStack[i] << "\n";
}
- msValue = sbuildValue;
- if (mbInListItem)
- msGroup = msValue;
- mbValuePresent = true;
- mbExpectValue = false;
+ string subid = (stackSize > 3) ? mcStack[2] : mcStack[0];
+ l10nMem::keyToLower(subid);
+
+ mcMemory.setSourceKey(miLineNo, msSourceFile, mcStack[1], cleanValue, "", subid, mcStack[stackSize-1], false);
+ mcStack.pop_back();
}
-void convert_src::setLang(char *syyText, bool bEnUs)
+bool convert_src::setLang(string& syyText)
{
- string useText = copySource(syyText) + " is no en-US language";
+ if (syyText == "en-US")
+ return true;
+ else if (syyText != "x-comment")
+ l10nMem::showError(syyText + " non legal language");
+ return false;
+}
+
+
- mbEnUs = bEnUs;
- if (!bEnUs && mbExpectValue)
- l10nMem::showError(useText);
+void convert_src::setName(string& syyText)
+{
+ mcStack.push_back(syyText);
}
-void convert_src::setId(char *syyText, bool bId)
+void convert_src::setCmd(string& syyText)
{
- copySource(syyText);
- if (bId || !mcStack.back().size())
- mbExpectName = mbAutoPush = true;
+ mcStack.push_back(syyText);
}
-void convert_src::setText(char *syyText)
+void convert_src::startBlock()
{
- msTextName = copySource(syyText);
- mbExpectValue = true;
- mbEnUs = false;
- trim(msTextName);
}
-void convert_src::setName(char *syyText)
+void convert_src::stopBlock()
{
- string useText = copySource(syyText);
-
- trim(useText);
- if (mbExpectName) {
- mbExpectName = false;
- if (!mbAutoPush) {
- if (msName.length())
- msGroup = useText;
- else
- msName = useText;
- }
- else {
- mbAutoPush = false;
- if (mcStack.size())
- mcStack.pop_back();
- mcStack.push_back(useText);
- }
- }
+ // check for correct node/prop relations
+ if (mcStack.size())
+ mcStack.pop_back();
}
-void convert_src::setCmd(char *syyText)
+#if 0
+void convert_src::setId(char *syyText, bool bId)
{
- msCmd = copySource(syyText);
- mbExpectName = true;
- mbInList = false;
- trim(msCmd);
- l10nMem::keyToLower(msCmd);
+ copySource(syyText);
+ if (bId || !mcStack.back().size())
+ mbExpectName = mbAutoPush = true;
}
+#endif
+#if 0
+void convert_src::setText(char *syyText)
+{
+ msTextName = copySource(syyText);
+ mbExpectValue = true;
+ mbEnUs = false;
+ trim(msTextName);
+}
+#endif
+
+
+
+#if 0
void convert_src::setMacro(char *syyText)
{
- msCmd = copySource(syyText);
- mbExpectName =
- mbExpectMacro =
- mbAutoPush = true;
- miMacroLevel = mcStack.size();
+ msCmd = copySource(syyText);
+ mbExpectName =
+ mbExpectMacro =
+ mbAutoPush = true;
+ miMacroLevel = mcStack.size();
mcStack.push_back("");
trim(msCmd);
}
+#endif
+#if 0
void convert_src::setList(char *syyText)
{
- msCmd = copySource(syyText);
+ msCmd = copySource(syyText);
miListCount = 0;
- mbInList = true;
+ mbInList = true;
trim(msCmd);
l10nMem::keyToLower(msCmd);
}
+#endif
+#if 0
void convert_src::setNL(char *syyText, bool bMacro)
{
int nL;
@@ -168,19 +175,19 @@ void convert_src::setNL(char *syyText, bool bMacro)
buildKey(sKey);
for (nL = -1;;) {
- nL = msValue.find("\\\"", nL+1);
+ nL = msValue.find("\\\"", nL + 1);
if (nL == (int)string::npos)
break;
- msValue.erase(nL,1);
+ msValue.erase(nL, 1);
}
for (nL = -1;;) {
- nL = msValue.find("\\\\", nL+1);
+ nL = msValue.find("\\\\", nL + 1);
if (nL == (int)string::npos)
break;
- msValue.erase(nL,1);
+ msValue.erase(nL, 1);
}
-//FIX sKey += "." + msCmd + "." + msTextName;
+ //FIX sKey += "." + msCmd + "." + msTextName;
if (msValue.size() && msValue != "-") {
mcMemory.setSourceKey(miLineNo, msSourceFile, sKey, msValue, "", msCmd, msGroup, mbMergeMode);
if (mbMergeMode)
@@ -192,43 +199,21 @@ void convert_src::setNL(char *syyText, bool bMacro)
if (!bMacro && mbExpectMacro) {
while ((int)mcStack.size() > miMacroLevel)
mcStack.pop_back();
- mbEnUs =
- mbExpectMacro = false;
+ mbEnUs =
+ mbExpectMacro = false;
}
mbValuePresent =
- mbExpectName =
- mbAutoPush = false;
+ mbExpectName =
+ mbAutoPush = false;
msValue.clear();
msTextName.clear();
}
+#endif
-void convert_src::startBlock(char *syyText)
-{
- copySource(syyText);
-
- mcStack.push_back(msName);
-}
-
-
-
-void convert_src::stopBlock(char *syyText)
-{
- copySource(syyText);
-
- // check for correct node/prop relations
- if (mcStack.size())
- mcStack.pop_back();
-
- mbInList =
- mbEnUs = false;
- msName.clear();
-}
-
-
-
+#if 0
void convert_src::setListItem(char const *syyText, bool bIsStart)
{
copySource(syyText);
@@ -266,9 +251,11 @@ void convert_src::setListItem(char const *syyText, bool bIsStart)
}
}
}
+#endif
+#if 0
void convert_src::trim(string& sText)
{
int nL;
@@ -281,9 +268,11 @@ void convert_src::trim(string& sText)
if (nL != (int)sText.size())
sText.erase(nL);
}
+#endif
+#if 0
void convert_src::buildKey(string& sKey)
{
int nL;
@@ -297,9 +286,11 @@ void convert_src::buildKey(string& sKey)
// FIX jan
sKey = mcStack[0];
}
+#endif
+#if 0
void convert_src::insertLanguagePart(string& sKey, string& sTextType)
{
string sLang, sText, sTagText;
@@ -317,3 +308,4 @@ void convert_src::insertLanguagePart(string& sKey, string& sTextType)
writeSourceFile(sTagText);
}
}
+#endif
diff --git a/l10ntools/source/gLexSrc.l b/l10ntools/source/gLexSrc.l
index d559562..e3c98a9 100644
--- a/l10ntools/source/gLexSrc.l
+++ b/l10ntools/source/gLexSrc.l
@@ -39,16 +39,13 @@ using namespace std;
%p 24000
%e 1200
%n 500
-%x CMD
+%x CMD ID LANG LANG2 LANG3 LANG4
-PRE ^[ \t]*
-SUF [ \t\r\n\\]
-SUFT [ \t\r\n\[]
SPACE [ \t]*
IDENT ([(a-zA-Z0-9_][ a-zA-Z0-9_\-\+\*(,&]*[a-zA-Z0-9)_]|[a-zA-Z0-9_])
-KEYID [a-zA-Z0-9_-]+
+SUF [ \t\r\n\\]+
%%
-
+f
"/*" {
@@ -66,13 +63,80 @@ KEYID [a-zA-Z0-9_-]+
}
+
"//".* {
LOCptr->copySource(yytext);
}
-"\"" {
+"{" {
+ LOCptr->copySource(yytext);
+ LOCptr->startBlock();
+}
+
+
+
+"}"{SPACE}";"* {
+ LOCptr->copySource(yytext);
+ LOCptr->stopBlock();
+}
+
+
+
+[iI][dD][eE][nN][tT][iI][fF][iI][eE][rR] {
+ LOCptr->copySource(yytext);
+ BEGIN(ID);
+}
+
+
+
+<ID>{SPACE}[=]*{SPACE} {
+ LOCptr->copySource(yytext);
+}
+
+
+
+<ID>{IDENT} {
+ LOCptr->setName(LOCptr->copySource(yytext));
+ BEGIN(INITIAL);
+}
+
+
+
+[tT][eE][xX][tT] {
+ LOCptr->copySource(yytext);
+ BEGIN(LANG);
+}
+
+
+
+<LANG>{SPACE}"["{SPACE} {
+ LOCptr->copySource(yytext);
+ BEGIN(LANG2);
+}
+
+
+
+<LANG2>{IDENT} {
+ if (LOCptr->setLang(LOCptr->copySource(yytext))) {
+ BEGIN(LANG3);
+ }
+ else {
+ BEGIN(INITIAL);
+ }
+}
+
+
+
+<LANG3>{SPACE}"]"{SPACE}"="{SPACE} {
+ LOCptr->copySource(yytext);
+ BEGIN(LANG4);
+}
+
+
+
+<LANG4>"\"" {
char buildValue[8000];
int j, i;
@@ -84,31 +148,65 @@ KEYID [a-zA-Z0-9_-]+
if (yytext[i] == '\\')
buildValue[++j] = yytext[++i] = yyinput();
--j;
- // Look for termination or continuation
- if (LOCptr->mbExpectValue)
- for (; (yytext[++i] = yyinput()) != ';' && yytext[i] != '\"';) ;
- else
- break;
+ for (; (yytext[++i] = yyinput()) != ';' && yytext[i] != '\"';) ;
}
yytext[++i] =
buildValue[j+1] = '\0';
- LOCptr->setValue(yytext, &buildValue[1]);
+ LOCptr->setValue(LOCptr->copySource(buildValue));
+ BEGIN(INITIAL);
}
-"{" {
- LOCptr->startBlock(yytext);
+[mM][eE][nN][uU] |
+[mM][eE][nN][uU][iI][tT][eE][mM] |
+[sS][tT][rR][iI][nN][gG] {
+ LOCptr->setCmd(LOCptr->copySource(yytext));
+ BEGIN(CMD);
}
-"}"{SPACE}";"* {
- LOCptr->stopBlock(yytext);
+<CMD>{IDENT} {
+ LOCptr->setName(LOCptr->copySource(yytext));
+ BEGIN(INITIAL);
+}
+
+
+
+<CMD>{SPACE} {
+ LOCptr->copySource(yytext);
}
+<CMD>{SUF} {
+ LOCptr->copySource(yytext);
+ BEGIN(INITIAL);
+}
+
+
+
+. {
+ LOCptr->copySource(yytext);
+
+ // Just to please compiler.
+ if (false)
+ REJECT;
+}
+
+%%
+
+
+
+#if 0
+PRE ^[ \t]*
+SUFT [ \t\r\n\[]
+KEYID [a-zA-Z0-9_-]+
+%%
+
+
+
{PRE}"<"{SUF} {
yyless(strlen(yytext)-1);
LOCptr->setListItem(yytext, true);
@@ -135,18 +233,6 @@ KEYID [a-zA-Z0-9_-]+
-"["{SPACE}en-US{SPACE}"]" {
- LOCptr->setLang(yytext, true);
-}
-
-
-
-"["{SPACE}{KEYID}{SPACE}"]" {
- LOCptr->setLang(yytext, false);
-}
-
-
-
{PRE}[bB][iI][tT][mM][aA][pP]{SUF} |
{PRE}[bB][uU][tT][tT][oO][nN][iI][mM][aA][gG][eE]{SUF} |
{PRE}[cC][aA][nN][cC][eE][lL][bB][uU][tT][tT][oO][nN]{SUF} |
@@ -168,9 +254,7 @@ KEYID [a-zA-Z0-9_-]+
{PRE}[iI][mM][aA][gG][eE][rR][aA][dD][iI][oO][bB][uU][tT][tT][oO][nN]{SUF} |
{PRE}[iI][nN][fF][oO][bB][oO][xX]{SUF} |
{PRE}[lL][iI][sS][tT][bB][oO][xX]{SUF} |
-{PRE}[mM][eE][nN][uU]{SUF} |
{PRE}[mM][eE][nN][uU][bB][uU][tT][tT][oO][nN]{SUF} |
-{PRE}[mM][eE][nN][uU][iI][tT][eE][mM]{SUF} |
{PRE}[mM][eE][sS][sS][bB][oO][xX]{SUF} |
{PRE}[mM][eE][tT][rR][iI][cC][fF][iI][eE][lL][dD]{SUF} |
{PRE}[mM][oO][dD][aA][lL][dD][iI][aA][lL][oO][gG]{SUF} |
@@ -188,7 +272,6 @@ KEYID [a-zA-Z0-9_-]+
{PRE}[sS][fF][xX][sS][tT][yY][lL][eE][fF][aA][mM][iI][lL][iI][eS][sS]{SUF} |
{PRE}[sS][fF][xX][sS][tT][yY][lL][eE][fF][aA][mM][iI][lL][yY][iI][tT][eE][mM]{SUF} |
{PRE}[sS][pP][iI][nN][fF][iI][eE][lL][dD]{SUF} |
-{PRE}[sS][tT][rR][iI][nN][gG]{SUF} |
{PRE}[sS][tT][rR][iI][nN][gG][aA][rR][rR][aA][yY]{SUF} |
{PRE}[tT][aA][bB][cC][oO][nN][tT][rR][oO][lL]{SUF} |
{PRE}[tT][aA][bB][dD][iI][aA][lL][oO][gG]{SUF} |
@@ -200,24 +283,6 @@ KEYID [a-zA-Z0-9_-]+
{PRE}[wW][aA][rR][nN][iI][nN][gG][bB][oO][xX]{SUF} |
{PRE}[wW][iI][nN][dD][oO][wW]{SUF} |
{PRE}[wW][oO][rR][kK][wW][iI][nN][dD][oO][wW]{SUF} {
- yyless(strlen(yytext)-1);
- LOCptr->setCmd(yytext);
- BEGIN(CMD);
-}
-
-<CMD>{IDENT} {
- LOCptr->setName(yytext);
- BEGIN(INITIAL);
-}
-
-<CMD>[ \t=]+ {
- LOCptr->copySource(yytext);
-}
-
-<CMD>.|\n|\r {
- yyless(0);
- BEGIN(INITIAL);
-}
@@ -229,10 +294,6 @@ KEYID [a-zA-Z0-9_-]+
{PRE}[sS][tT][yY][lL][eE][fF][aA][mM][iI][lL][yY]{SUF} |
-{PRE}[iI][dD][eE][nN][tT][iI][fF][iI][eE][rR]{SUF} {
- yyless(strlen(yytext)-1);
- LOCptr->setId(yytext, true);
-}
@@ -277,18 +338,7 @@ KEYID [a-zA-Z0-9_-]+
LOCptr->setName(yytext);
}
-
-
-. {
- LOCptr->copySource(yytext);
-
- // Just to please compiler.
- if (false)
- REJECT;
-}
-
-%%
-
+#endif
void src_dummyJustForCompiler()
diff --git a/l10ntools/source/gRun.sh b/l10ntools/source/gRun.sh
index 867291e..4187122 100755
--- a/l10ntools/source/gRun.sh
+++ b/l10ntools/source/gRun.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-cd ${LODE_HOME}/dev/work
+cd ${LODE_HOME}/dev/core
MYCMD='./workdir/LinkTarget/Executable/genlang.exe extract -s --target workdir/jan '
More information about the Libreoffice-commits
mailing list