From f7f97dadcd33ed191ef04436fe630821c2330e3d Mon Sep 17 00:00:00 2001 From: jan iversen Date: Sat, 19 Mar 2016 16:57:19 +0100 Subject: update genlang, activated lex calls. All lex files no longer have a special namespace, instead yylex --> lex and therefore unique for the linker. Also corrected command line argument handler. Change-Id: Idfdec97bd43f3be8d2b217b9aac1bd74b202dc93 --- l10ntools/Executable_genlang.mk | 1 - l10ntools/inc/gConvDB.hxx | 39 ------ l10ntools/source/gConv.cxx | 1 - l10ntools/source/gConvDB.cxx | 86 ------------- l10ntools/source/gConvPo.cxx | 3 +- l10ntools/source/gConvSrc.cxx | 4 +- l10ntools/source/gConvTree.cxx | 3 +- l10ntools/source/gConvUlf.cxx | 4 +- l10ntools/source/gConvXcs.cxx | 3 +- l10ntools/source/gConvXcu.cxx | 3 +- l10ntools/source/gConvXhp.cxx | 3 +- l10ntools/source/gConvXrm.cxx | 3 +- l10ntools/source/gLang.cxx | 279 +++++++++++++++------------------------- l10ntools/source/gList.sh | 11 ++ 14 files changed, 133 insertions(+), 310 deletions(-) delete mode 100644 l10ntools/inc/gConvDB.hxx delete mode 100644 l10ntools/source/gConvDB.cxx create mode 100755 l10ntools/source/gList.sh (limited to 'l10ntools') diff --git a/l10ntools/Executable_genlang.mk b/l10ntools/Executable_genlang.mk index 0badea207b2b..7916d163aa1d 100644 --- a/l10ntools/Executable_genlang.mk +++ b/l10ntools/Executable_genlang.mk @@ -30,7 +30,6 @@ $(eval $(call gb_Executable_add_exception_objects,genlang,\ l10ntools/source/gL10nMem \ l10ntools/source/gConvProp \ l10ntools/source/gConv \ - l10ntools/source/gConvDB \ l10ntools/source/gConvPo \ l10ntools/source/gConvSrc \ l10ntools/source/gConvXrm \ diff --git a/l10ntools/inc/gConvDB.hxx b/l10ntools/inc/gConvDB.hxx deleted file mode 100644 index 23151836779d..000000000000 --- a/l10ntools/inc/gConvDB.hxx +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef GCONDN_HXX -#define GCONDN_HXX -#include "gConv.hxx" - - - -class convert_db : public convert_gen -{ - public: - convert_db(l10nMem& crMemory); - ~convert_db(); - - private: - static const int NUMFIELD = 16; - std::string msFields[NUMFIELD]; - int miSize; - - void execute() override; - bool collectLine(); -}; -#endif diff --git a/l10ntools/source/gConv.cxx b/l10ntools/source/gConv.cxx index 74f05ba2e068..f90a8b6f387c 100644 --- a/l10ntools/source/gConv.cxx +++ b/l10ntools/source/gConv.cxx @@ -21,7 +21,6 @@ #include "gL10nMem.hxx" #include "gConv.hxx" -#include "gConvDB.hxx" #include "gConvPo.hxx" #include "gConvProp.hxx" #include "gConvSrc.hxx" diff --git a/l10ntools/source/gConvDB.cxx b/l10ntools/source/gConvDB.cxx deleted file mode 100644 index 80940ad14a57..000000000000 --- a/l10ntools/source/gConvDB.cxx +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#include -#include - -#include "gL10nMem.hxx" -#include "gConvDB.hxx" - - - -convert_db::convert_db(l10nMem& crMemory) : convert_gen(crMemory) {} -convert_db::~convert_db() {} - - - -void convert_db::execute() -{ - std::string newKey; - int i; - - - msSourceBuffer += '\n'; - miSize = msSourceBuffer.size() -1; - miLineNo = 0; - - while (collectLine()) { - newKey = msFields[4]; - if (msFields[5].size()) - newKey += "." + msFields[5]; - if (msFields[3].size()) - newKey += "." + msFields[3]; - - for (; (i = msFields[1].find('\\')) != (int)std::string::npos;) - msFields[1][i] = '/'; - - // handle en-US or lang - mcMemory.loadEntryKey(miLineNo, msFields[1], newKey, msFields[10], msFields[10], false); - } -} - - - -bool convert_db::collectLine() -{ - int i, iStart; - bool bLineEnd; - - ++miLineNo; - - for (i = 0; i < NUMFIELD; ++i) - msFields[i].clear(); - - if (miSourceReadIndex >= miSize) - return false; - - for (i = 0, bLineEnd = false, iStart = miSourceReadIndex; !bLineEnd; ++miSourceReadIndex) { - if (msSourceBuffer[miSourceReadIndex] == '\r' || - msSourceBuffer[miSourceReadIndex] == '\n' || - miSourceReadIndex == miSize) - bLineEnd = true; - if (msSourceBuffer[miSourceReadIndex] == '\t' || bLineEnd) { - if (i >= NUMFIELD) { - l10nMem::showError("TOO many fields", miLineNo); - } - msFields[i++] = msSourceBuffer.substr(iStart, miSourceReadIndex - iStart); - iStart = miSourceReadIndex +1; - } - } - return true; -} diff --git a/l10ntools/source/gConvPo.cxx b/l10ntools/source/gConvPo.cxx index e43d1bf0ddc1..f4460da359a4 100644 --- a/l10ntools/source/gConvPo.cxx +++ b/l10ntools/source/gConvPo.cxx @@ -131,12 +131,13 @@ void convert_po::handleNL() +extern int polex(void); void convert_po::execute() { if (mbMergeMode) throw l10nMem::showError("Merge not implemented"); - // PoWrap::yylex(); + polex(); startLook(); } diff --git a/l10ntools/source/gConvSrc.cxx b/l10ntools/source/gConvSrc.cxx index 6b49cc53dedb..4eb41e681a43 100644 --- a/l10ntools/source/gConvSrc.cxx +++ b/l10ntools/source/gConvSrc.cxx @@ -43,10 +43,10 @@ convert_src::~convert_src() {} - +extern int srclex(void); void convert_src::execute() { - // SrcWrap::yylex(); + srclex(); } diff --git a/l10ntools/source/gConvTree.cxx b/l10ntools/source/gConvTree.cxx index a452240ff94d..8ce85df5ea05 100644 --- a/l10ntools/source/gConvTree.cxx +++ b/l10ntools/source/gConvTree.cxx @@ -48,6 +48,7 @@ convert_tree::~convert_tree() +extern int treelex(void); void convert_tree::execute() { std::string sLang; @@ -77,7 +78,7 @@ void convert_tree::execute() } // run analyzer - // TreeWrap::yylex(); + treelex(); // dump last line copySourceSpecial(nullptr,3); diff --git a/l10ntools/source/gConvUlf.cxx b/l10ntools/source/gConvUlf.cxx index 2e13ee424372..37b43147c3ee 100644 --- a/l10ntools/source/gConvUlf.cxx +++ b/l10ntools/source/gConvUlf.cxx @@ -28,10 +28,10 @@ convert_ulf::convert_ulf(l10nMem& crMemory) : convert_gen(crMemory) {} convert_ulf::~convert_ulf() {} - +extern int ulflex(void); void convert_ulf::execute() { - // UlfWrap::yylex(); + ulflex(); } diff --git a/l10ntools/source/gConvXcs.cxx b/l10ntools/source/gConvXcs.cxx index 5067fbfcd0a0..c5de41a6819d 100644 --- a/l10ntools/source/gConvXcs.cxx +++ b/l10ntools/source/gConvXcs.cxx @@ -38,13 +38,14 @@ convert_xcs::~convert_xcs() +extern int xcslex(void); void convert_xcs::execute() { if (mbMergeMode) throw l10nMem::showError("Merge not implemented"); // currently no .xcs files generate en-US translation, so stop trying - // XcsWrap::yylex(); + xcslex(); } diff --git a/l10ntools/source/gConvXcu.cxx b/l10ntools/source/gConvXcu.cxx index ccf1a953b4ed..668de0e09c6c 100644 --- a/l10ntools/source/gConvXcu.cxx +++ b/l10ntools/source/gConvXcu.cxx @@ -37,9 +37,10 @@ convert_xcu::~convert_xcu() +extern int xculex(void); void convert_xcu::execute() { - // XcuWrap::yylex(); + xculex(); } diff --git a/l10ntools/source/gConvXhp.cxx b/l10ntools/source/gConvXhp.cxx index 0297c6310d07..93da8019751d 100644 --- a/l10ntools/source/gConvXhp.cxx +++ b/l10ntools/source/gConvXhp.cxx @@ -47,6 +47,7 @@ convert_xhp::~convert_xhp() +extern int xhplex(void); void convert_xhp::execute() { std::string sLang; @@ -75,7 +76,7 @@ void convert_xhp::execute() } // run analyzer - // XhpWrap::yylex(); + xhplex(); // dump last line copySourceSpecial(nullptr,3); diff --git a/l10ntools/source/gConvXrm.cxx b/l10ntools/source/gConvXrm.cxx index 55a341d5b184..fb9f0dafca19 100644 --- a/l10ntools/source/gConvXrm.cxx +++ b/l10ntools/source/gConvXrm.cxx @@ -40,9 +40,10 @@ convert_xrm::~convert_xrm() +extern int xrmlex(void); void convert_xrm::execute() { - //// XrmWrap::yylex(); + xrmlex(); // write last part of file. if (mbMergeMode) diff --git a/l10ntools/source/gLang.cxx b/l10ntools/source/gLang.cxx index 8119171be290..264874f239e9 100644 --- a/l10ntools/source/gLang.cxx +++ b/l10ntools/source/gLang.cxx @@ -19,6 +19,7 @@ #include #include #include +using namespace std; #include "gL10nMem.hxx" #include "gConv.hxx" @@ -31,20 +32,18 @@ class handler handler() {}; ~handler() {}; - void showRunTimeError(std::string sErr); - void showUsage(std::string sErr); + void showRunTimeError(string sErr); + void showUsage(string sErr); void checkCommandLine(int argc, char *argv[]); void run(); private: bool mbForceSave; enum {DO_CONVERT, DO_EXTRACT, DO_MERGE_KID, DO_MERGE} meWorkMode; - std::string msTargetDir; - std::string msPoDir; - std::string msPotDir; - std::vector mvSourceFiles; - std::vector mvLanguages; - l10nMem mcMemory; + string msTargetDir; + string msPoDir; + vector mvSourceFiles; + l10nMem mcMemory; void showManual(); void loadL10MEM(bool onlyTemplates); @@ -55,39 +54,37 @@ class handler -void handler::showRunTimeError(std::string sErr) +void handler::showRunTimeError(string sErr) { - std::cerr << "runtime error: " - << (sErr.size() ? sErr : "No description") - << std::endl; + cerr << "runtime error: " + << (sErr.size() ? sErr : "No description") + << endl; exit(-1); } -void handler::showUsage(std::string sErr) +void handler::showUsage(string sErr) { if (sErr.size()) - std::cerr << "commandline error: " << sErr << std::endl; - - std::cout << "syntax oveview, use \"genLang help\" for full description\n" - " genLang \n" - " is one of\n" - " convert convert old pot/po files to new format\n" - " extract extract pot templates from sources\n" - " help show manual\n" - " merge merge po files back to sources\n" - " is a combination of\n" - " -d show debug information\n" - " -k generate key identifier version\n" - " -s save unconditionally\n" - " -v show progress information\n" - "\n" - " --files input file list\n" - " --languages language list (omitting is all)\n" - " --target target root directory\n" - " --po po root directory\n" - " --pot pot root directory\n"; + cerr << "commandline error: " << sErr << endl; + + cout << "syntax oveview, use \"genLang help\" for full description\n" + " genLang \n" + " is one of\n" + " convert convert old pot/po files to new format\n" + " extract extract pot templates from sources\n" + " help show manual\n" + " merge merge po files back to sources\n" + " is a combination of\n" + " -d show debug information\n" + " -k generate key identifier version\n" + " -s save unconditionally\n" + " -v show progress information\n" + "\n" + " --files input file list\n" + " --target target root directory\n" + " --po po root directory\n"; if (sErr.size()) exit(-1); @@ -98,7 +95,7 @@ void handler::showUsage(std::string sErr) void handler::showManual() { // give the correct usage - std::cout << + cout << "genLang(c) 2016 by Document Foundation\n" "=============================================\n" "As part of the L10N framework for LibreOffice,\n" @@ -116,51 +113,37 @@ void handler::showManual() showUsage(""); - std::cout << + cout << "\n" " genLang extract [-v] [-d] [-s]\n" - " --files --pot \n" - " extract text from , result is .pot template\n" - " files written to with a structure\n" + " --files --target \n" + " extract text from source (.ui etc) , result is .pot\n" + " templates files written to with a structure\n" "\n\n"; - std::cout << + cout << " genLang merge [-v] [-d] [-s] [-k]\n" - " --languages \n" + " --files \n" " --target \n" " --po \n" - " merges translations (--po) with source files\n" + " merges translations (--po) with source files (--files)\n" " and write the result to --target\n" "\n\n"; - std::cout << + cout << " genLang convert [-v] [-d] [-s]\n" + " --files \n" " --po \n" - " --pot \n" " --target \n" - " read old po (--po) and pot (--pot) files and updates\n" - " target po and pot files (--target), ready to be loaded\n" + " read old po (--po) and new po (--files) files and\n" + " write po files (--target), ready to be loaded\n" " in Pootle\n" "\n\n"; - std::cout << + cout << " genLang help\n" " this text\n" "\n\n"; - - std::cout << - "Parameters:\n" - " -d show debug information\n" - " -k generate key identifier version\n" - " -v show progress information\n" - " -s save unconditionally\n" - "\n" - " --files input file list\n" - " --languages language list (omitting is all)\n" - " --target target root directory\n" - " --po po root directory\n" - " --pot pot root directory\n"; - exit(0); } @@ -168,8 +151,9 @@ void handler::showManual() void handler::checkCommandLine(int argc, char *argv[]) { - std::string sWorkText; - int i; + string sWorkText; + int i; + bool bSourceFiles, bTargetDir, bPoDir; // Set default @@ -193,11 +177,12 @@ void handler::checkCommandLine(int argc, char *argv[]) if (sWorkText == "-d") { // show debug information mcMemory.setDebug(true); + mcMemory.setVerbose(true); } else if (sWorkText == "-k") { // generate key identifier version if (meWorkMode != DO_MERGE) - showUsage("-k requires \"merge\""); + throw "-k requires \"merge\""; meWorkMode = DO_MERGE_KID; } else if (sWorkText == "-v") { @@ -208,102 +193,51 @@ void handler::checkCommandLine(int argc, char *argv[]) // forced save mbForceSave = true; } - else if (sWorkText == "--files") { - // list of input files - if (meWorkMode != DO_EXTRACT) - showUsage("--files not valid for command"); - if (i == argc) - showUsage("--files missing filename arguments"); - - // Loop through filenames - for (; i < argc && argv[i][0] != '-'; ++i) - mvSourceFiles.push_back(argv[i]); - } - else if (sWorkText == "--languages") { - // list of languages - if (meWorkMode != DO_MERGE) - showUsage("--languages not valid for command"); - if (i == argc) - showUsage("--languages missing arguments"); - - // Loop through filenames - for (; i < argc && argv[i][0] != '-'; ++i) - mvLanguages.push_back(argv[i]); - } - else if (sWorkText == "--target") { - // target root directory - if (meWorkMode != DO_MERGE && meWorkMode != DO_CONVERT) - showUsage("--target not valid for command"); - if (i == argc) - showUsage("--target missing directory argument"); - - msTargetDir = argv[++i]; - } - else if (sWorkText == "--po") { - // po file root directory - if (meWorkMode != DO_MERGE && meWorkMode != DO_CONVERT) - showUsage("--po not valid for command"); - if (i == argc) - showUsage("--po missing directory argument"); - - msPoDir = argv[++i]; - } - else if (sWorkText == "--pot") { - // pot file root directory - if (meWorkMode != DO_EXTRACT && meWorkMode != DO_CONVERT) - showUsage("--pot not valid for command"); - if (i == argc) - showUsage("--pot missing directory argument"); - - msPotDir = argv[++i]; - } else { - // collect files - showUsage("unknown argument"); + // These arguments, all need and extra argument + if (i == argc - 1) + throw sWorkText + " missing filename arguments"; + + if (sWorkText == "--files") { + // Loop through filenames + for (++i; i < argc && argv[i][0] != '-'; ++i) + mvSourceFiles.push_back(argv[i]); + --i; + } + else if (sWorkText == "--target") + msTargetDir = argv[++i]; + else if (sWorkText == "--po") + msPoDir = argv[++i]; + else + throw "unknown argument"; } } // Check all the correct parameters are suplied - { - bool bSourceFiles, bLanguages, bTargetDir, bPoDir, bPotDir; - - bSourceFiles = bLanguages = bTargetDir = bPoDir = bPotDir = false; - switch (meWorkMode) - { - case DO_CONVERT: - bPoDir = bPotDir = bTargetDir = true; - break; - case DO_EXTRACT: - bPotDir = bSourceFiles = true; - break; - case DO_MERGE_KID: - case DO_MERGE: - bPoDir = bLanguages = bTargetDir = true; - break; - } - - if ( (mvSourceFiles.size() > 0) != bSourceFiles) - throw bSourceFiles ? "--files missing" : - "--files used, but not permitted"; - if ( (mvLanguages.size() > 0) != bLanguages) - throw bLanguages ? "--languages missing" : - "--languages used, but not permitted"; - if ( (msPoDir.size() > 0) != bPoDir) - throw bPoDir ? "--po missing" : - "--po used, but not permitted"; - if ( (msPotDir.size() > 0) != bPotDir) - throw bPotDir ? "--pot missing" : - "--pot used, but not permitted"; + bSourceFiles = bTargetDir = bPoDir = false; + switch (meWorkMode) { + case DO_CONVERT: + bSourceFiles = bPoDir = bTargetDir = true; + break; + case DO_EXTRACT: + bSourceFiles = bTargetDir = true; + break; + case DO_MERGE_KID: + case DO_MERGE: + bPoDir = bTargetDir = true; + break; } + + if ( (mvSourceFiles.size() > 0) != bSourceFiles) + throw bSourceFiles ? "--files missing" : "--files used, but not permitted"; + if ( (msPoDir.size() > 0) != bPoDir) + throw bPoDir ? "--po missing" : "--po used, but not permitted"; } void handler::run() { - // Start memory module - loadL10MEM( (meWorkMode == DO_EXTRACT) ); - // use workMode to start correct control part switch (meWorkMode) { @@ -318,8 +252,8 @@ void handler::run() void handler::loadL10MEM(bool onlyTemplates) { - std::string sLoad = msPoDir + "templates/"; - std::vector::iterator siLang; + string sLoad = msPoDir + "templates/"; + vector::iterator siLang; // no convert mcMemory.setConvert(false, false); @@ -336,26 +270,26 @@ void handler::loadL10MEM(bool onlyTemplates) return; // loop through all languages and load text - for (siLang = mvLanguages.begin(); siLang != mvLanguages.end(); ++siLang) - { - sLoad = msPoDir + *siLang + "/"; +//FIX for (siLang = mvLanguages.begin(); siLang != mvLanguages.end(); ++siLang) +//FIX { +//FIX sLoad = msPoDir + *siLang + "/"; // get converter and extract files - mcMemory.setLanguage(*siLang, true); +//FIX mcMemory.setLanguage(*siLang, true); // tell system - l10nMem::showDebug("genLang loading text from language file " + sLoad); +//FIX l10nMem::showDebug("genLang loading text from language file " + sLoad); - convert_gen::createInstance(mcMemory, sLoad, msTargetDir, "").execute(false, false); - } +//FIX convert_gen::createInstance(mcMemory, sLoad, msTargetDir, "").execute(false, false); +//FIX } } void handler::runConvert() { - std::vector::iterator siSource; - std::vector::iterator siLang; + vector::iterator siSource; + vector::iterator siLang; // convert @@ -372,20 +306,20 @@ void handler::runConvert() mcMemory.showNOconvert(); - for (siLang = mvLanguages.begin(); siLang != mvLanguages.end(); ++siLang) { - std::string sFilePath = *siLang + "/"; +//FIX for (siLang = mvLanguages.begin(); siLang != mvLanguages.end(); ++siLang) { +//FIX string sFilePath = *siLang + "/"; // get converter and extract files - mcMemory.setLanguage(*siLang, false); +//FIX mcMemory.setLanguage(*siLang, false); // tell system - l10nMem::showDebug("genLang convert text from file " + - sFilePath + *siSource + " language " + *siLang); +//FIX l10nMem::showDebug("genLang convert text from file " + +//FIX sFilePath + *siSource + " language " + *siLang); // get converter and extract files - convert_gen& convertObj = convert_gen::createInstance(mcMemory, sFilePath, msTargetDir, *siSource); - convertObj.execute(true, false); - } +//FIX convert_gen& convertObj = convert_gen::createInstance(mcMemory, sFilePath, msTargetDir, *siSource); +//FIX convertObj.execute(true, false); +//FIX } } // and generate language file @@ -396,8 +330,7 @@ void handler::runConvert() void handler::runExtract() { - std::vector::iterator siSource; - + vector::iterator siSource; // no convert mcMemory.setConvert(false, false); @@ -420,7 +353,7 @@ void handler::runExtract() void handler::runMerge(bool bKid) { - std::vector::iterator siSource; + vector::iterator siSource; // no convert mcMemory.setConvert(false, false); @@ -447,11 +380,11 @@ int main(int argc, char *argv[]) cHandler.checkCommandLine(argc, argv); } catch(const char *sErr) { - std::string myErr(sErr); + string myErr(sErr); cHandler.showUsage(myErr); exit(-1); } - catch(std::string sErr) { + catch(string sErr) { cHandler.showUsage(sErr); exit(-1); } @@ -461,11 +394,11 @@ int main(int argc, char *argv[]) cHandler.run(); } catch(const char *sErr) { - std::string myErr(sErr); + string myErr(sErr); cHandler.showRunTimeError(myErr); exit(-1); } - catch(std::string sErr) { + catch(string sErr) { cHandler.showRunTimeError(sErr); exit(-1); } diff --git a/l10ntools/source/gList.sh b/l10ntools/source/gList.sh new file mode 100755 index 000000000000..41d04f3d33d6 --- /dev/null +++ b/l10ntools/source/gList.sh @@ -0,0 +1,11 @@ +#!/bin/bash +find . -name \*.hrc > filelist_hrc.txt +find . -name \*.src > filelist_src.txt +find . -name \*.po > filelist_po.txt +find . -name \*.pot > filelist_pot.txt +find . -name \*.tree > filelist_tree.txt +find . -name \*.ulf > filelist_ulf.txt +find . -name \*.xcu > filelist_xcu.txt +find . -name \*.xhp > filelist_xhp.txt +find . -name \*.xrm > filelist_xrm.txt +find . -name \*.properties > filelist_properties.txt -- cgit