the genLang project aims at replacing all l10ntools with more modern versions, based on C++ and lex. The current extract works basically as a standalone "find" over the source tree. genLang can use that, but also a more efficient way, by having translation-worthy files declared in the makefile stubs. genLang itself is a C++ framework, where each file type is defined as a class, making it easy to add new file types. genLang can easily be adopted to transform the help files into e.g. mediawiki format, and later merge a url back into the code. The project was first developed (solely by the author) in a non published branch of OO. This branch was never merged but deleted and therefore never published. The files have been adapted to the LO build system and setup. The primary commit is just to raise awareness, that this is being developed. The following commit, will update the source code to LO standard. Before replacing the old modules a dedicated review will be asked for. Change-Id: I4504992474333c476c179903f822bfaf1441cca9 Reviewed-on: https://gerrit.libreoffice.org/22819 Reviewed-by: jan iversen <jani@documentfoundation.org> Tested-by: jan iversen <jani@documentfoundation.org>
235 lines
6.7 KiB
C++
235 lines
6.7 KiB
C++
/* -*- 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 "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),
|
|
mcOutputFiles(NULL),
|
|
meStateTag(STATE_TAG_NONE),
|
|
meStateVal(STATE_VAL_NONE),
|
|
miCntLanguages(0)
|
|
|
|
{
|
|
// 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;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/********************** 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");
|
|
}
|
|
}
|
|
}
|
|
|
|
// run analyzer
|
|
// TreeWrap::yylex();
|
|
|
|
// dump last line
|
|
copySourceSpecial(NULL,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;
|
|
}
|
|
|
|
|
|
|
|
/********************** 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;
|
|
}
|
|
|
|
|
|
|
|
/********************** 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);
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
/********************** 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());
|
|
}
|