diff options
39 files changed, 6796 insertions, 0 deletions
diff --git a/Repository.mk b/Repository.mk index 61173d380134..36416cec5fea 100644 --- a/Repository.mk +++ b/Repository.mk @@ -33,6 +33,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \ genconv_dict \ gendict \ genindex_data \ + genlang \ helpex \ idxdict \ langsupport \ diff --git a/l10ntools/Executable_genlang.mk b/l10ntools/Executable_genlang.mk new file mode 100644 index 000000000000..b6656c225533 --- /dev/null +++ b/l10ntools/Executable_genlang.mk @@ -0,0 +1,73 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# 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/. +# + +$(eval $(call gb_Executable_Executable,genlang)) + +$(eval $(call gb_Executable_set_include,genlang,\ + -I$(SRCDIR)/l10ntools/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_Executable_add_scanners,genlang,\ + l10ntools/source/gLexPo \ + l10ntools/source/gLexSrc \ + l10ntools/source/gLexXcu \ + l10ntools/source/gLexXcs \ + l10ntools/source/gLexXrm \ + l10ntools/source/gLexXhp \ + l10ntools/source/gLexUlf \ + l10ntools/source/gLexTree \ +)) + +$(eval $(call gb_Executable_add_exception_objects,genlang,\ + l10ntools/source/gLang \ + l10ntools/source/gL10nMem \ + l10ntools/source/gL10nMemDB \ + l10ntools/source/gHandler \ + l10ntools/source/gConvProp \ + l10ntools/source/gConv \ + l10ntools/source/gConvDB \ + l10ntools/source/gConvPo \ + l10ntools/source/gConvSrc \ + l10ntools/source/gConvXrm \ + l10ntools/source/gConvXhp \ + l10ntools/source/gConvXcs \ + l10ntools/source/gConvXcu \ + l10ntools/source/gConvUlf \ + l10ntools/source/gConvTree \ +)) + +# vim:set noet sw=4 ts=4: + + + + +# localizer for new l10n framework +APP1TARGET= genLang +APP1OBJS= $(OBJFILES) +APP1RPATH= NONE +APP1LINKTYPE= STATIC + +APP1LIBS= +APP1STDLIBS= +APP1LIBSALCPPRT= + + +# --- Targets ------------------------------------------------------ +.INCLUDE : target.mk + +$(MISC)$/%_yy.c : %lex.l + flex -l -w -8 -o$@ $< + +# --- Files -------------------------------------------------------- + + +genPO: ALLTAR + +$(PERL) $(SOLARENV)/bin/deliver.pl + diff --git a/l10ntools/Module_l10ntools.mk b/l10ntools/Module_l10ntools.mk index d391ed7463c7..0c2e18e643a7 100644 --- a/l10ntools/Module_l10ntools.mk +++ b/l10ntools/Module_l10ntools.mk @@ -10,6 +10,7 @@ $(eval $(call gb_Module_Module,l10ntools)) $(eval $(call gb_Module_add_targets_for_build,l10ntools,\ + Executable_genlang \ Executable_helpex \ Executable_idxdict \ Executable_ulfex \ diff --git a/l10ntools/inc/gConv.hxx b/l10ntools/inc/gConv.hxx new file mode 100644 index 000000000000..5b79e4ad55a4 --- /dev/null +++ b/l10ntools/inc/gConv.hxx @@ -0,0 +1,92 @@ +/* -*- 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 GCON_HXX +#define GCON_HXX +#include "gLang.hxx" + +#include <iostream> +#include <fstream> + + + +/***************************************************************************** + **************************** 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); + virtual void save(const std::string& sFileName, + const std::string& sKey, + const std::string& sENUStext, + const std::string& sText, + bool bFuzzy); + virtual void endSave(); + + // generic variables + bool mbMergeMode; + bool mbLoadMode; + std::string msSourcePath; + std::string msTargetPath; + std::string msSourceFile; + 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 *yyText, bool bDoClear = true); + + protected: + std::string msSourceBuffer, msCopyText; + int miSourceReadIndex; + + bool prepareFile(); + + private: + std::ofstream mcOutputFile; + + friend class convert_gen; +}; +#endif diff --git a/l10ntools/inc/gConvDB.hxx b/l10ntools/inc/gConvDB.hxx new file mode 100644 index 000000000000..54dba4e00c28 --- /dev/null +++ b/l10ntools/inc/gConvDB.hxx @@ -0,0 +1,49 @@ +/* -*- 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" + + + +/***************************************************************************** + ************************** G C O N D B . H X X ************************** + ***************************************************************************** + * This is the class header for loading/writing internal "object" files + *****************************************************************************/ + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class convert_db : public convert_gen_impl +{ + public: + convert_db(l10nMem& crMemory); + ~convert_db(); + + private: + static const int NUMFIELD = 16; + std::string msFields[NUMFIELD]; + int miSize; + + void execute(); + bool collectLine(); +}; +#endif diff --git a/l10ntools/inc/gConvPo.hxx b/l10ntools/inc/gConvPo.hxx new file mode 100644 index 000000000000..7d2d8f25ac44 --- /dev/null +++ b/l10ntools/inc/gConvPo.hxx @@ -0,0 +1,71 @@ +/* -*- 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 GCONPO_HXX +#define GCONPO_HXX +#include "gConv.hxx" + + + +/***************************************************************************** + ************************** G C O N P O . H X X ************************** + ***************************************************************************** + * This is the class header for .po conversion + *****************************************************************************/ + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class convert_po : public convert_gen_impl +{ + public: + bool mbExpectId; + bool mbExpectStr; + + + convert_po(l10nMem& crMemory); + ~convert_po(); + + void startLook (); + void setValue (char *syyText, int iLineCnt); + void setFuzzy (); + void setKey (char *syyText); + void setMsgId (); + void setMsgStr (); + void handleNL (); + + private: + std::string msId; + std::string msStr; + std::string msKey; + bool mbFuzzy; + std::filebuf outBuffer; + + void execute(); + + 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(); +}; +#endif diff --git a/l10ntools/inc/gConvProp.hxx b/l10ntools/inc/gConvProp.hxx new file mode 100644 index 000000000000..ce2ee3833411 --- /dev/null +++ b/l10ntools/inc/gConvProp.hxx @@ -0,0 +1,45 @@ +/* -*- 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 GCONPROP_HXX +#define GCONPROP_HXX +#include "gConv.hxx" + + + +/***************************************************************************** + ************************ G C O N P R O P . H X X ************************ + ***************************************************************************** + * This is the class header for .proporties conversion + *****************************************************************************/ + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class convert_prop : public convert_gen_impl +{ + public: + convert_prop(l10nMem& crMemory); + ~convert_prop(); + + + private: + void execute(); +}; +#endif diff --git a/l10ntools/inc/gConvSrc.hxx b/l10ntools/inc/gConvSrc.hxx new file mode 100644 index 000000000000..e8de3708a359 --- /dev/null +++ b/l10ntools/inc/gConvSrc.hxx @@ -0,0 +1,75 @@ +/* -*- 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 GCONSRCHXX +#define GCONSRCHXX +#include "gConv.hxx" + + +/***************************************************************************** + ************************* G C O N S R C . H X X ************************* + ***************************************************************************** + * This is the class header for .src conversion + *****************************************************************************/ + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class convert_src : public convert_gen_impl +{ + public: + bool mbExpectValue; + + convert_src(l10nMem& crMemory); + ~convert_src(); + + 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 *syyText, bool bIsStart); + void setNL (char *syyText, bool bMacro); + void startBlock (char *syyText); + void stopBlock (char *syyText); + + private: + std::vector<std::string> mcStack; + std::string msValue; + std::string msName; + std::string msTextName; + std::string msCmd; + bool mbEnUs; + bool mbExpectName; + bool mbExpectMacro; + bool mbAutoPush; + bool mbValuePresent; + bool mbInList; + bool mbInListItem; + int miListCount; + int miMacroLevel; + void execute(); + void trim(std::string& sText); + void buildKey(std::string& sKey); + void insertLanguagePart(std::string& sKey, std::string& sTextType); +}; +#endif diff --git a/l10ntools/inc/gConvTree.hxx b/l10ntools/inc/gConvTree.hxx new file mode 100644 index 000000000000..0ec25ade4cb2 --- /dev/null +++ b/l10ntools/inc/gConvTree.hxx @@ -0,0 +1,75 @@ +/* -*- 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 GCONTREE_HXX +#define GCONTREE_HXX +#include "gConv.hxx" + + + +/***************************************************************************** + ************************ G C O N T R E E . H X X ************************ + ***************************************************************************** + * This is the class header for .tree conversion + *****************************************************************************/ + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class convert_tree : public convert_gen_impl +{ + public: + typedef enum + { + STATE_TAG_NONE, + STATE_TAG_HELPSEC, + STATE_TAG_NODE, + STATE_TAG_TOPIC, + STATE_TAG_VALUE + } STATE_TAG; + typedef enum + { + STATE_VAL_NONE, + STATE_VAL_APPL, + STATE_VAL_ID, + STATE_VAL_TITLE + } STATE_VAL; + + convert_tree(l10nMem& crMemory); + ~convert_tree(); + + void setString (char *yytext); + void setState (char *yytext, STATE_TAG eNewStateTag, STATE_VAL eNewStateVAL); + void setValue (char *yytext); + std::string& copySourceSpecial (char *yytext, int iType); + void writeSourceFile (std::string& sText, int inx); + + + private: + std::string msLine; + std::string msId; + std::string msAppl; + std::ofstream *mcOutputFiles; + STATE_TAG meStateTag; + STATE_VAL meStateVal; + int miCntLanguages; + + void execute(); +}; +#endif diff --git a/l10ntools/inc/gConvUlf.hxx b/l10ntools/inc/gConvUlf.hxx new file mode 100644 index 000000000000..30e79ad6ccca --- /dev/null +++ b/l10ntools/inc/gConvUlf.hxx @@ -0,0 +1,52 @@ +/* -*- 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 GCONULF_HXX +#define GCONULF_HXX +#include "gConv.hxx" + + + +/***************************************************************************** + ************************* G C O N U L F . H X X ************************* + ***************************************************************************** + * This is the class header for .ulf conversion + *****************************************************************************/ + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class convert_ulf : public convert_gen_impl +{ + public: + convert_ulf(l10nMem& crMemory); + ~convert_ulf(); + + void setKey(char *syyText); + void setText(char *syyText, bool bIsEnUs); + void setValue(char *syyText); + + private: + std::string msKey; + + + void execute(); + void handleLines(); +}; +#endif diff --git a/l10ntools/inc/gConvXcs.hxx b/l10ntools/inc/gConvXcs.hxx new file mode 100644 index 000000000000..d1b241eb81cd --- /dev/null +++ b/l10ntools/inc/gConvXcs.hxx @@ -0,0 +1,52 @@ +/* -*- 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 GCONXCS_HXX +#define GCONXCS_HXX +#include "gConv.hxx" + + + +/***************************************************************************** + ************************* G C O N X C S . H X X ************************* + ***************************************************************************** + * This is the class header for .xcs conversion + *****************************************************************************/ + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class convert_xcs : public convert_gen_impl +{ + public: + convert_xcs(l10nMem& crMemory); + ~convert_xcs(); + + void setKey(char *syyText); + void unsetKey(char *syyText); + void startCollectData(char *syyText); + void stopCollectData(char *syyText); + + private: + std::string msKey; + bool mbCollectingData; + + void execute(); +}; +#endif diff --git a/l10ntools/inc/gConvXcu.hxx b/l10ntools/inc/gConvXcu.hxx new file mode 100644 index 000000000000..db106278b630 --- /dev/null +++ b/l10ntools/inc/gConvXcu.hxx @@ -0,0 +1,60 @@ +/* -*- 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 GCONXCU_HXX +#define GCONXCU_HXX +#include "gConv.hxx" + + + +/***************************************************************************** + ************************* G C O N X C U . H X X ************************* + ***************************************************************************** + * This is the class header for .xcu conversion + *****************************************************************************/ + + + +/******************** 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 +{ + public: + bool mbNoCollectingData; + + convert_xcu(l10nMem& crMemory); + ~convert_xcu(); + + void pushKey(char *syyText); + void popKey(char *syyText); + + void startCollectData(char *syyText); + void stopCollectData(char *syyText); + void copySpecial(char *syyText); + void copyNL(char *syyText); + void addLevel(); + + private: + std::vector<std::string> mcStack; + int miLevel; + bool mbNoTranslate; + + void execute(); +}; +#endif diff --git a/l10ntools/inc/gConvXhp.hxx b/l10ntools/inc/gConvXhp.hxx new file mode 100644 index 000000000000..857966f16d0c --- /dev/null +++ b/l10ntools/inc/gConvXhp.hxx @@ -0,0 +1,77 @@ +/* -*- 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 GCONXHP_HXX +#define GCONXHP_HXX +#include "gConv.hxx" + + + +/***************************************************************************** + ************************* G C O N X H P . H X X ************************* + ***************************************************************************** + * This is the class definition header xhp converter + *****************************************************************************/ + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class convert_xhp : public convert_gen_impl +{ + public: + convert_xhp(l10nMem& crMemory); + ~convert_xhp(); + + void setString(char *yytext); + void openTag(char *yytext); + void closeTag(char *yytext); + void closeTagNOvalue(char *yytext); + void setId(char *yytext); + void setLang(char *yytext); + void setRef(char *yytext); + void openTransTag(char *yytext); + void closeTransTag(char *yytext); + void stopTransTag(char *yytext); + void startComment(char *yytext); + void stopComment(char *yytext); + void handleSpecial(char *yytext); + void handleDataEnd(char *yytext); + void duplicate(char *yytext); + std::string& copySourceSpecial(char *yytext, int iType); + void writeSourceFile(std::string& sText, int inx); + + private: + typedef enum + { + VALUE_NOT_USED, + VALUE_IS_TAG, + VALUE_IS_TAG_TRANS, + VALUE_IS_VALUE, + VALUE_IS_VALUE_TAG + } STATE; + STATE meExpectValue, mePushValue; + std::string msKey, msPushCollect; + std::string msLine; + + std::string *msLangText; + std::ofstream *mcOutputFiles; + int miCntLanguages; + void execute(); +}; +#endif diff --git a/l10ntools/inc/gConvXrm.hxx b/l10ntools/inc/gConvXrm.hxx new file mode 100644 index 000000000000..e10d9998383d --- /dev/null +++ b/l10ntools/inc/gConvXrm.hxx @@ -0,0 +1,56 @@ +/* -*- 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 GCONXRM_HXX +#define GCONXRM_HXX +#include "gConv.hxx" + + + +/***************************************************************************** + ************************* G C O N X R M . H X X ************************* + ***************************************************************************** + * This is the class definition header xrm converter + *****************************************************************************/ + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class convert_xrm : public convert_gen_impl +{ + public: + bool mbNoCollectingData; + convert_xrm(l10nMem& crMemory); + ~convert_xrm(); + + void setId(char *yytext); + void setLang(char *yytext); + void setTag(char *yytext); + void startCollectData(char *yytext); + void stopCollectData(char *yytext); + + private: + std::string msKey; + bool mbIsTag; + bool mbIsLang; + std::string msTag; + + void execute(); +}; +#endif diff --git a/l10ntools/inc/gL10nMem.hxx b/l10ntools/inc/gL10nMem.hxx new file mode 100644 index 000000000000..1da50af28bcc --- /dev/null +++ b/l10ntools/inc/gL10nMem.hxx @@ -0,0 +1,217 @@ +/* -*- 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 GL10NMEM_HXX +#define GL10NMEM_HXX +#include "gLang.hxx" + + + +/***************************************************************************** + ************************ G L 1 0 N M E M . H X X ************************ + ***************************************************************************** + * This is the class definition header of the l10n localizer program, + * all global classes and their interrelations is defined here + *****************************************************************************/ + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class l10nMem_lang_entry +{ + public: + l10nMem_lang_entry(const std::string& sMsgStr, bool bFuzzy); + ~l10nMem_lang_entry(); + + std::string msMsgStr; // translated text from po file + bool mbFuzzy; // fuzzy flag +}; + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class l10nMem_enus_entry +{ + public: + l10nMem_enus_entry(const std::string& sKey, + const std::string& sMsgId, + int iLineNo, + int iFileInx, + int iLangSize, + l10nMem::ENTRY_STATE eState); + ~l10nMem_enus_entry(); + + std::string msKey; // key in po file and source file + std::string msMsgId; // en-US text from source file + l10nMem::ENTRY_STATE meState; // status information + int miFileInx; // index of file name + int miLineNo; // line number + std::vector<l10nMem_lang_entry> mcLangText; // language texts (index is languageId) +}; + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class l10nMem_file_entry +{ + public: + l10nMem_file_entry(const std::string& sFileName, int iStart); + ~l10nMem_file_entry(); + + std::string msFileName; // file Name with relative path + std::string msPureName; // just filename + int miStart; // start index of entries in mcMasterEntries (l10Mem_db::mcENUS) + int miEnd; // last index of entries in mcMasterEntries (l10Mem_db::mcENUS) +}; + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class l10nMem_lang_list_entry +{ + public: + l10nMem_lang_list_entry(const std::string& sName); + ~l10nMem_lang_list_entry(); + + std::string msName; // language Name + bool mbChanged; // used for "convert", true if language is modified +}; + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class l10nMem_db +{ + public: + l10nMem_db(); + ~l10nMem_db(); + + int miCurFileInx; + int miCurLangInx; + int miCurENUSinx; + bool mbNeedWrite; + bool mbConvertMode; + bool mbStrictMode; + std::vector<l10nMem_enus_entry> mcENUSlist; + std::vector<l10nMem_file_entry> mcFileList; + std::vector<l10nMem_lang_list_entry> mcLangList; + + + void loadENUSkey (int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId); + void setLanguage (const std::string& sLanguage, + bool bCreate); + void setConvert (bool bConvert, + bool bStrict); + bool findFileName (const std::string& sSourceFile); + void loadLangKey (int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + const std::string& sMsgStr, + bool bFuzzy); + + + bool locateKey (int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + bool bThrow); + void reorganize (bool bConvert); + void addKey (int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + l10nMem::ENTRY_STATE eStat); + + int prepareMerge (); + bool getMergeLang (std::string& sLang, + std::string& sText); + bool getLangList (std::string& sLang); + +static void keyToUpper(std::string& sKey); +}; + + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class l10nMem_impl +{ + public: + l10nMem_impl(); + ~l10nMem_impl(); + + int showError (const std::string& sText, int iLineNo); + int showWarning (const std::string& sText, int iLineNo); + void showDebug (const std::string& sText, int iLineNo); + void showVerbose (const std::string& sText, int iLineNo); + + void setModuleName (const std::string& sModuleName); + const std::string& getModuleName (void); + void loadEntryKey (int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + const std::string& sMsgStr, + bool bIsFuzzy); + void setSourceKey (int iLineNo, + const std::string& sFilename, + const std::string& sKey, + const std::string& sMsgId, + bool bMustExist); + + void saveTemplates (l10nMem& cMem, + const std::string& sTargetDir, + bool bKid, + bool bForce); + void saveLanguages (l10nMem& cMem, + const std::string& sTargetDir, + bool bForce); + void dumpMem (const std::string& sTargetDir); + void showNOconvert(); + + void convertToInetString(std::string& sText); + void convertFromInetString(std::string& sText); + + private: + static bool mbVerbose; + static bool mbDebug; + static l10nMem_impl *mcImpl; + l10nMem_db mcDb; + std::string msModuleName; + bool mbInError; + + void formatAndShowText(const std::string& sType, int iLineNo, const std::string& sText); + bool needWrite (const std::string sFileName, bool bForce); + bool convFilterWarning(const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId); + void convEntryKey (int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + const std::string& sMsgStr, + bool bIsFuzzy); + + friend class l10nMem; +}; +#endif diff --git a/l10ntools/inc/gLang.hxx b/l10ntools/inc/gLang.hxx new file mode 100644 index 000000000000..be1422ba3f8f --- /dev/null +++ b/l10ntools/inc/gLang.hxx @@ -0,0 +1,164 @@ +/* -*- 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 GLANG_HXX +#define GLANG_HXX +#include <string> +#include <vector> + + + +/***************************************************************************** + *************************** G L A N G . H X X *************************** + ***************************************************************************** + * This is the class definition header of the l10n localizer program, + * all global 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 l10nMem_impl; +class l10nMem +{ + public: + l10nMem(); + ~l10nMem(); + + typedef enum + { + ENTRY_DELETED, + ENTRY_ADDED, + ENTRY_CHANGED, + ENTRY_NORMAL + } ENTRY_STATE; + + static void setShowVerbose (); + static void setShowDebug (); + + static int showError (const std::string& sText, int iLineNo = 0); + static int showWarning (const std::string& sText, int iLineNo = 0); + static void showDebug (const std::string& sText, int iLineNo = 0); + static void showVerbose (const std::string& sText, int iLineNo = 0); + bool isError (); + + void setModuleName (const std::string& sModuleName); + const std::string& getModuleName (void); + void setLanguage (const std::string& sLanguage, + bool bCreate); + void setConvert (bool bConvert, + bool bStrict); + void loadEntryKey (int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sOrgText, + const std::string& sText, + bool bIsFuzzy); + + void setSourceKey (int iLineNo, + const std::string& sFilename, + const std::string& sKey, + const std::string& sText, + bool bMustExist); + + void saveTemplates (const std::string& sTargetDir, + bool bKid, + bool bForce); + void saveLanguages (const std::string& sTargetDir, + bool bForce); + void dumpMem (const std::string& sTargetDir); + + int prepareMerge (); + bool getMergeLang (std::string& sLang, + std::string& sText); + void showNOconvert (); + + void convertToInetString(std::string& sText); + void convertFromInetString(std::string& sText); +}; + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class convert_gen +{ + public: + convert_gen(l10nMem& cMemory, + const std::string& sSourceDir, + const std::string& sTargetDir, + const std::string& sSourceFile); + ~convert_gen(); + + // do extract/merge + bool execute(const bool bMerge); + + // 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); +}; + + + +/******************** C L A S S D E F I N I T I O N ********************/ +class handler +{ + public: + handler(); + ~handler(); + + void checkCommandLine(int argc, char *argv[]); + void run(); + + private: + enum {DO_CONVERT, DO_CONVERT_POT, DO_EXTRACT, DO_EXTRACT_KID, DO_MERGE} meWorkMode; + l10nMem mcMemory; + std::string msModuleName; + std::string msPoOutDir; + std::string msPoDir; + std::string msSourceDir; + std::string msTargetDir; + bool mbForceSave; + std::vector<std::string> mvSourceFiles; + std::vector<std::string> mvLanguages; + + void runConvert(bool bPot); + void runExtract(bool bKid); + void runMerge(); + + void showUsage(std::string& sErr); + void showManual(); + void loadL10MEM(bool onlyTemplates); + void readFileWithSources(); +}; +#endif diff --git a/l10ntools/source/gConv.cxx b/l10ntools/source/gConv.cxx new file mode 100644 index 000000000000..562d87aa1b14 --- /dev/null +++ b/l10ntools/source/gConv.cxx @@ -0,0 +1,363 @@ +/* -*- 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 "gConv.hxx" +#include "gConvDB.hxx" +#include "gConvPo.hxx" +#include "gConvProp.hxx" +#include "gConvSrc.hxx" +#include "gConvTree.hxx" +#include "gConvUlf.hxx" +#include "gConvXcs.hxx" +#include "gConvXcu.hxx" +#include "gConvXhp.hxx" +#include "gConvXrm.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 <unistd.h> +#include <sys/stat.h> +#include <sys/types.h> +#define OS_ACCESS(x,y) access(x,y) +#define OS_MKDIR(x) mkdir(x,0777) +#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 = NULL; + + + +/********************** I M P L E M E N T A T I O N **********************/ +convert_gen::convert_gen(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) + throw l10nMem::showError("source file: "+sSourceFile+" missing extension"); + + // 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); + 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; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +bool convert_gen::execute(const bool bMerge) +{ + convert_gen_impl::mcImpl->mbMergeMode = bMerge; + + // and load file + if (!convert_gen_impl::mcImpl->prepareFile()) + return false; + + // and execute conversion + convert_gen_impl::mcImpl->execute(); + + return true; +} + + + +/********************** 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; + + x = sLanguage; + x = sFile; + throw l10nMem::showError("startSave called with non .po file"); +} + + + +/********************** 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; + + if (bFuzzy) + x = sFileName + sKey + sENUStext + sText; + throw l10nMem::showError("save called with non .po file"); +} + + + +/********************** 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"); +} + + + +/********************** 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 == (int)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), + 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 = NULL; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +bool convert_gen_impl::prepareFile() +{ + std::ifstream inputFile(msSourcePath.c_str(), std::ios::binary); + + + if (!inputFile.is_open()) + { + if (mbLoadMode) + { + l10nMem::showWarning("Cannot open file (" + msSourcePath + ")"); + return false; + } + else + throw l10nMem::showError("Cannot open file (" + msSourcePath + ") for reading"); + } + + // get length of file: + miSourceReadIndex = 0; + inputFile.seekg (0, std::ios::end); + msSourceBuffer.resize((unsigned int)inputFile.tellg()); + inputFile.seekg (0, std::ios::beg); + + // get size, prepare std::string and read whole file + inputFile.read((char *)msSourceBuffer.c_str(), msSourceBuffer.size()); + if ((unsigned int)inputFile.gcount() != msSourceBuffer.size()) + throw l10nMem::showError("cannot read whole file"); + inputFile.close(); + + if (mbMergeMode && !mbLoadMode) + { + // close previous file + if (mcOutputFile.is_open()) + mcOutputFile.close(); + + // open output file + mcOutputFile.open((msTargetPath+msSourceFile).c_str(), std::ios::binary); + 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; +} + + + + +/********************** 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) +{ + // did we hit eof + if (miSourceReadIndex == -1) + { + *nResult = 0; + return; + } + + // assume we can copy all that are left. + *nResult = msSourceBuffer.size() - miSourceReadIndex; + + // space enough for the whole line ? + if (*nResult <= nMax_size) + { + msSourceBuffer.copy(sBuf, *nResult, miSourceReadIndex); + miSourceReadIndex = -1; + } + else + { + msSourceBuffer.copy(sBuf, nMax_size, miSourceReadIndex); + *nResult = nMax_size; + miSourceReadIndex += 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) +{ + if (!line.size()) + return; + + if (mcOutputFile.is_open()) + mcOutputFile.write(line.c_str(), line.size()); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +std::string& convert_gen_impl::copySource(char *yyText, bool bDoClear) +{ + int nL; + + + if (!yyText) + { + msCopyText.clear(); + return msCopyText; + } + msCopyText = yyText; + + // write text for merge + if (mbMergeMode) + writeSourceFile(msCopyText); + + if (bDoClear) + msCollector.clear(); + else + msCollector += msCopyText; + + // remove any CR + for (nL = 0; nL < (int)msCopyText.size(); ++nL) + { + if (msCopyText[nL] == '\r') + { + msCopyText.erase(nL, 1); + --nL; + continue; + } + if (msCopyText[nL] == '\n') + ++miLineNo; + } + + return msCopyText; +} diff --git a/l10ntools/source/gConvDB.cxx b/l10ntools/source/gConvDB.cxx new file mode 100644 index 000000000000..88224141d0ae --- /dev/null +++ b/l10ntools/source/gConvDB.cxx @@ -0,0 +1,97 @@ +/* -*- 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 "gConvDB.hxx" + + + +/***************************************************************************** + ************************** 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() {} + + + +/********************** I M P L E M E N T A T I O N **********************/ +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); + } +} + + +/********************** I M P L E M E N T A T I O N **********************/ +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((char*)"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 new file mode 100644 index 000000000000..8bbedc71f405 --- /dev/null +++ b/l10ntools/source/gConvPo.cxx @@ -0,0 +1,243 @@ +/* -*- 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 "gConvPo.hxx" +#include <iostream> +#include <fstream> +#include <cstdlib> + + + +/***************************************************************************** + ********************** G C O N P O 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_po::convert_po(l10nMem& crMemory) + : convert_gen_impl(crMemory), + mbExpectId(false), + mbExpectStr(false), + mbFuzzy(false) +{ + // Po files are handled special + mbLoadMode = true; +} + + + +/************ 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() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +//namespace PoWrap +//{ +//#define IMPLptr convert_gen_impl::mcImpl +//#define LOCptr ((convert_po *)convert_gen_impl::mcImpl) +//#include "gConPo_yy.c" +//} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::startLook() +{ + std::string sFileName, sNewKey; + int i; + + + if (!msKey.size() || !msId.size()) + return; + + // split key into filename and real key + i = msKey.find("#"); + sFileName = msKey.substr(0, i); + sNewKey = msKey.substr(i+1); + + // load in db + if (msId.size()) + mcMemory.loadEntryKey(miLineNo, sFileName, sNewKey, msId, msStr, mbFuzzy); + + // and prepare for new entry + msKey.clear(); + msId.clear(); + msStr.clear(); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::setValue(char *syyText, int iLineCnt) +{ + if (mbExpectId) + msId = syyText; + if (mbExpectStr) + msStr = syyText; + mbExpectId = + mbExpectStr = false; + miLineNo += iLineCnt; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::setFuzzy() +{ + mbFuzzy = true; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::setKey(char *syyText) +{ + int i; + + + // Activate "look for msg" mode. + startLook(); + + // skip "#:" and any blanks + for (syyText += 2; *syyText == ' ' || *syyText == '\t'; ++syyText) ; + msKey = syyText; + + // remove trailing blanks + for (i = msKey.size() -1; msKey[i] == '\r' || msKey[i] == ' ' || msKey[i] == '\t'; --i) ; + msKey.erase(i+1); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::setMsgId() +{ + mbExpectId = true; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::setMsgStr() +{ + mbExpectStr = true; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::handleNL() +{ + ++miLineNo; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::execute() +{ + if (mbMergeMode) + throw l10nMem::showError("Merge not implemented"); + +// PoWrap::yylex(); + startLook(); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::startSave(const std::string& sLanguage, + const std::string& sFile) +{ + std::string sFilePath = msTargetPath + sLanguage + sFile; + outBuffer.open(sFilePath.c_str(), std::ios::out); + + if (!outBuffer.is_open()) + throw l10nMem::showError("Cannot open " + sFilePath + " for writing"); + + l10nMem::showDebug("writing file (" + sFilePath + ")"); + + std::ostream outFile(&outBuffer); + + // Set license header + outFile << "#*************************************************************" << std::endl + << "#*" << std::endl + << "#* Licensed to the Apache Software Foundation (ASF) under one" << std::endl + << "#* or more contributor license agreements. See the NOTICE file" << std::endl + << "#* distributed with this work for additional information" << std::endl + << "#* regarding copyright ownership. The ASF licenses this file" << std::endl + << "#* to you under the Apache License, Version 2.0 (the" << std::endl + << "#* \"License\"); you may not use this file except in compliance" << std::endl + << "#* with the License. You may obtain a copy of the License at" << std::endl + << "#*" << std::endl + << "#* http://www.apache.org/licenses/LICENSE-2.0" << std::endl + << "#*" << std::endl + << "#* Unless required by applicable law or agreed to in writing," << std::endl + << "#* software distributed under the License is distributed on an" << std::endl + << "#* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY" << std::endl + << "#* KIND, either express or implied. See the License for the" << std::endl + << "#* specific language governing permissions and limitations" << std::endl + << "#* under the License." << std::endl + << "#*" << std::endl + << "#************************************************************" << std::endl + << "msgid \"\"" << std::endl + << "msgstr \"\"" << std::endl + << "\"Project-Id-Version: AOO-4-xx\\n\"" << std::endl + << "\"POT-Creation-Date: \\n\"" << std::endl + << "\"PO-Revision-Date: \\n\"" << std::endl + << "\"Last-Translator: genLang (build process)\\n\"" << std::endl + << "\"Language-Team: \\n\"" << std::endl + << "\"MIME-Version: 1.0\\n\"" << std::endl + << "\"Content-Type: text/plain; charset=UTF-8\\n\"" << std::endl + << "\"Content-Transfer-Encoding: 8bit\\n\"" << std::endl + << "\"X-Generator: genLang\\n\"" << std::endl + << std::endl; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::save(const std::string& sFileName, + const std::string& sKey, + const std::string& sENUStext, + const std::string& sText, + bool bFuzzy) +{ + std::ostream outFile(&outBuffer); + + outFile << std::endl << "#: " << sFileName << "#" << sKey << std::endl; + if (bFuzzy) + outFile << "#, fuzzy" << std::endl; + outFile << "msgid \"" << sENUStext << "\"" << std::endl + << "msgstr \"" << sText << "\"" << std::endl; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::endSave() +{ + outBuffer.close(); +} diff --git a/l10ntools/source/gConvProp.cxx b/l10ntools/source/gConvProp.cxx new file mode 100644 index 000000000000..d03455c16415 --- /dev/null +++ b/l10ntools/source/gConvProp.cxx @@ -0,0 +1,51 @@ +/* -*- 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 "gConvProp.hxx" + + + +/***************************************************************************** + ************************ 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) +{ + throw mcMemory.showError(std::string("convert_prop not implemented")); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +convert_prop::~convert_prop() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_prop::execute() +{ + throw mcMemory.showError(std::string("convert_prop::execute not implemented")); +} diff --git a/l10ntools/source/gConvSrc.cxx b/l10ntools/source/gConvSrc.cxx new file mode 100644 index 000000000000..b65f2d2d49dd --- /dev/null +++ b/l10ntools/source/gConvSrc.cxx @@ -0,0 +1,353 @@ +/* -*- 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 "gConvSrc.hxx" +#include <iostream> +#include <fstream> +#include <cstdlib> +#include <sstream> +#include <string.h> + + +/***************************************************************************** + ********************* 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), + mbExpectValue(false), + mbEnUs(false), + mbExpectName(false), + mbExpectMacro(false), + mbAutoPush(false), + mbValuePresent(false), + mbInList(false), + mbInListItem(false) +{} +convert_src::~convert_src() +{} + + + +/********************** I M P L E M E N T A T I O N **********************/ +//namespace SrcWrap +//{ +//#define IMPLptr convert_gen_impl::mcImpl +//#define LOCptr ((convert_src *)convert_gen_impl::mcImpl) +//#include "gConSrc_yy.c" +//} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::execute() +{ +// SrcWrap::yylex(); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::setValue(char *syyText, char *sbuildValue) +{ + copySource(syyText); + + if (mbInList && !mbInListItem) + { + setListItem((char *)"", true); + setListItem((char *)"", false); + } + msValue = sbuildValue; + mbValuePresent = true; + mbExpectValue = false; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::setLang(char *syyText, bool bEnUs) +{ + std::string useText = copySource(syyText) + " is no en-US language"; + + mbEnUs = bEnUs; + if (!bEnUs && mbExpectValue) + mcMemory.showError(useText); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::setId(char *syyText, bool bId) +{ + copySource(syyText); + if (bId || !mcStack.back().size()) + mbExpectName = mbAutoPush = true; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::setText(char *syyText) +{ + msTextName = copySource(syyText); + mbExpectValue = true; + mbEnUs = false; + trim(msTextName); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::setName(char *syyText) +{ + std::string useText = copySource(syyText); + + trim(useText); + if (mbExpectName) + { + mbExpectName = false; + if (!mbAutoPush) + msName = useText; + else + { + mbAutoPush = false; + if (mcStack.size()) + mcStack.pop_back(); + mcStack.push_back(useText); + } + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::setCmd(char *syyText) +{ + msCmd = copySource(syyText); + mbExpectName = true; + mbInList = false; + trim(msCmd); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::setMacro(char *syyText) +{ + msCmd = copySource(syyText); + mbExpectName = + mbExpectMacro = + mbAutoPush = true; + miMacroLevel = mcStack.size(); + mcStack.push_back(""); + trim(msCmd); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::setList(char *syyText) +{ + msCmd = copySource(syyText); + miListCount = 0; + mbInList = true; + trim(msCmd); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::setNL(char *syyText, bool bMacro) +{ + int nL; + std::string sKey; + + copySource(syyText); + + if (msTextName.size() && mbValuePresent && mbEnUs) + { + // locate key and extract it + buildKey(sKey); + + for (nL = -1;;) + { + nL = msValue.find("\\\"", nL+1); + if (nL == (int)std::string::npos) + break; + msValue.erase(nL,1); + } + for (nL = -1;;) + { + nL = msValue.find("\\\\", nL+1); + if (nL == (int)std::string::npos) + break; + msValue.erase(nL,1); + } + + sKey += "." + msCmd + "." + msTextName; + if (msValue.size() && msValue != "-") + { + mcMemory.setSourceKey(miLineNo, msSourceFile, sKey, msValue, mbMergeMode); + if (mbMergeMode) + insertLanguagePart(sKey, msTextName); + } + } + + if (!bMacro && mbExpectMacro) + { + while ((int)mcStack.size() > miMacroLevel) + mcStack.pop_back(); + mbEnUs = + mbExpectMacro = false; + } + + mbValuePresent = + mbExpectName = + mbAutoPush = false; + msValue.clear(); + msTextName.clear(); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::startBlock(char *syyText) +{ + copySource(syyText); + + mcStack.push_back(msName); + msName.clear(); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::stopBlock(char *syyText) +{ + copySource(syyText); + + // check for correct node/prop relations + if (mcStack.size()) + mcStack.pop_back(); + + mbInList = + mbEnUs = false; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::setListItem(char *syyText, bool bIsStart) +{ + copySource(syyText); + + if (bIsStart) + { + if (!miListCount) + { + mcStack.pop_back(); + msName = "dummy"; + mcStack.push_back(msName); + } + msTextName = "item"; + mbExpectValue = + mbExpectName = + mbInListItem = true; + msName.clear(); + } + else + { + if (mbInListItem) + { + std::stringstream ssBuf; + std::string myKey; + + + ++miListCount; + mcStack.pop_back(); + if (mbExpectName) + { + ssBuf << miListCount; + msName = "item" + ssBuf.str(); + } + mcStack.push_back(msName); + mbInListItem = + mbExpectName = false; + + // check key or add seq. + buildKey(myKey); + } + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::trim(std::string& sText) +{ + int nL; + + + while (sText[0] == ' ' || sText[0] == '\t') + sText.erase(0,1); + for (nL = sText.size(); sText[nL-1] == ' ' || sText[nL-1] == '\t'; --nL); + if (nL != (int)sText.size()) + sText.erase(nL); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::buildKey(std::string& sKey) +{ + int nL; + + + sKey.clear(); + for (nL = 0; nL < (int)mcStack.size(); ++nL) + if (mcStack[nL].size()) + sKey += (sKey.size() ? "." : "") + mcStack[nL]; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_src::insertLanguagePart(std::string& sKey, std::string& sTextType) +{ + std::string sLang, sText, sTagText; + + + // just to please compiler + sKey = sKey; + + // prepare to read all languages + mcMemory.prepareMerge(); + for (; mcMemory.getMergeLang(sLang, sText);) + { + // Prepare tag start and end + sTagText = sTextType + "[ " + sLang + " ] = \"" + sText + "\" ;" + + (mbExpectMacro ? "\\" : "") + "\n"; + writeSourceFile(sTagText); + } +} diff --git a/l10ntools/source/gConvTree.cxx b/l10ntools/source/gConvTree.cxx new file mode 100644 index 000000000000..06f577d2574b --- /dev/null +++ b/l10ntools/source/gConvTree.cxx @@ -0,0 +1,234 @@ +/* -*- 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()); +} diff --git a/l10ntools/source/gConvUlf.cxx b/l10ntools/source/gConvUlf.cxx new file mode 100644 index 000000000000..7f220b1724f4 --- /dev/null +++ b/l10ntools/source/gConvUlf.cxx @@ -0,0 +1,105 @@ +/* -*- 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 "gConvUlf.hxx" +#include <iostream> +#include <fstream> +#include <cstdlib> + + + +/***************************************************************************** + ********************* 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() {} + + + +/********************** I M P L E M E N T A T I O N **********************/ +//namespace UlfWrap +//{ +//#define IMPLptr convert_gen_impl::mcImpl +//#define LOCptr ((convert_ulf *)convert_gen_impl::mcImpl) +//#include "gConUlf_yy.c" +//} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_ulf::execute() +{ +// UlfWrap::yylex(); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_ulf::setKey(char *syyText) +{ + std::string sText = copySource(syyText); + + // locate key (is any) + msKey = sText.substr(1,sText.size()-2); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_ulf::setText(char *syyText, bool bIsEnUs) +{ + std::string sText = copySource(syyText) + " is not en-US"; + + + if (!bIsEnUs) + mcMemory.showError(sText); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_ulf::setValue(char *syyText) +{ + std::string sLang, sText = copySource(syyText); + int nL; + + sText.erase(0,1); + nL = sText.rfind("\""); + sText.erase(nL); + + mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, sText, mbMergeMode); + + if (mbMergeMode) + { + // prepare to read all languages + mcMemory.prepareMerge(); + for (; mcMemory.getMergeLang(sLang, sText);) + { + // Prepare tag + sText = "\n" + sLang + " = \"" + sText + "\""; + writeSourceFile(sText); + } + } +} diff --git a/l10ntools/source/gConvXcs.cxx b/l10ntools/source/gConvXcs.cxx new file mode 100644 index 000000000000..6133bbb6ed3a --- /dev/null +++ b/l10ntools/source/gConvXcs.cxx @@ -0,0 +1,161 @@ +/* -*- 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 "gConvXcs.hxx" +#include <iostream> +#include <fstream> +#include <cstdlib> + + + +/***************************************************************************** + ********************* 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), + mbCollectingData(false) +{ +} + + + +/************ 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() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +//namespace XcsWrap +//{ +//#define IMPLptr convert_gen_impl::mcImpl +//#define LOCptr ((convert_xcs *)convert_gen_impl::mcImpl) +//#include "gConXcs_yy.c" +//} + + + +/********************** I M P L E M E N T A T I O N **********************/ +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(); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcs::setKey(char *syyText) +{ + int nL; + std::string sHead, sText = copySource(syyText); + + // is it to be translated + if (sText.find("oor:localized=") == std::string::npos) + return; + + // locate key (is any) + nL = sText.find("oor:name=\""); + if (nL == (int)std::string::npos) + return; + sHead = sText.substr(nL+10); + nL = sHead.find("\""); + msKey = sHead.substr(0,nL); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcs::unsetKey(char *syyText) +{ + copySource(syyText); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcs::startCollectData(char *syyText) +{ + copySource(syyText); + if (!msKey.size()) + return; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcs::stopCollectData(char *syyText) +{ + std::string sHead, sKey, sLang, sText, sCollectedText = copySource(syyText, false); + int nL; + + + // get type of tag + msCollector += sCollectedText; + nL = msCollector.find("<p"); + if (nL != (int)std::string::npos) + sHead = msCollector.substr(nL+1, 1); + else + { + nL = msCollector.find("<h"); + sHead = msCollector.substr(nL+1, 2); + } + + // locate key and extract it + nL = msCollector.find("id=") +4; + sKey = msCollector.substr(nL, msCollector.find("\"", nL+1) - nL); + nL = msCollector.find("xml:lang=\"") + 10; + sLang = msCollector.substr(nL, msCollector.find("\"", nL+1) - nL); + nL = msCollector.find(">") +1; + sText = msCollector.substr(nL, msCollector.find("\"", nL+1) - nL); + msCollector.clear(); + + if (mbMergeMode) + { +#if 0 + // get all languages (includes en-US) + std::vector<l10nMem_entry *>& cExtraLangauges = mcMemory.getLanguagesForKey(sKey); + std::string sNewLine; + nL = cExtraLangauges.size(); + + for (int i = 0; i < nL; ++i) + { + sNewLine = "\n<" + sHead + " id=\"" + sKey + "\"" + " xml:lang=\"" + + cExtraLangauges[i]->msLanguage + "\">" + + cExtraLangauges[i]->msText + + "</" + sHead + ">"; + + writeSourceFile(sNewLine); + } +#endif + } + + mcMemory.setSourceKey(miLineNo, msSourceFile, sKey, sText, mbMergeMode); + mbCollectingData = false; +} diff --git a/l10ntools/source/gConvXcu.cxx b/l10ntools/source/gConvXcu.cxx new file mode 100644 index 000000000000..972e54638baa --- /dev/null +++ b/l10ntools/source/gConvXcu.cxx @@ -0,0 +1,218 @@ +/* -*- 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 "gConvXcu.hxx" +#include <iostream> +#include <fstream> +#include <cstdlib> + + +/***************************************************************************** + ********************* 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), + mbNoCollectingData(true), + miLevel(0), + mbNoTranslate(false) +{ +} + + + +/************ 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() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +//namespace XcuWrap +//{ +//#define IMPLptr convert_gen_impl::mcImpl +//#define LOCptr ((convert_xcu *)convert_gen_impl::mcImpl) +//#include "gConXcu_yy.c" +//} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcu::execute() +{ +// XcuWrap::yylex(); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcu::pushKey(char *syyText) +{ + std::string sKey, sTag = copySource(syyText); + int nL, nE; + + // find key in tag + nL = sTag.find("oor:name=\""); + if (nL != (int)std::string::npos) + { + // find end of key + nL += 10; + nE = sTag.find("\"", nL); + if (nE != (int)std::string::npos) + sKey = sTag.substr(nL, nE - nL); + } + mcStack.push_back(sKey); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcu::popKey(char *syyText) +{ + copySource(syyText); + + // check for correct node/prop relations + if (mcStack.size()) + mcStack.pop_back(); + + mbNoTranslate = false; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcu::startCollectData(char *syyText) +{ + int nL; + std::string sTag = copySource(syyText); + + if (mbNoTranslate) + return; + + // locate object name + nL = sTag.find("xml:lang=\""); + if (nL != (int)std::string::npos) + { + // test langauge + nL += 10; + if (sTag.substr(nL,5) == "en-US") + mbNoCollectingData = false; + else if (sTag.substr(nL,14) == "x-no-translate") + mbNoTranslate = true; + else + { + std::string sErr = sTag.substr(nL,5) + " is not en-US"; + mcMemory.showError(sErr); + } + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcu::stopCollectData(char *syyText) +{ + int nL; + std::string useKey, useText = msCollector; + + copySource(syyText); + + // time to do something ? + if (mbNoCollectingData || mbNoTranslate) + return; + + // remove any newline + for (nL = 0;;) + { + nL = useText.find("\n"); + if (nL == (int)std::string::npos) + break; + useText.erase(nL,1); + } + + mbNoCollectingData = true; + + if (useText.size()) + { + // locate key and extract it + for (nL = 0; nL < (int)mcStack.size(); ++nL) + useKey += (useKey.size() ? "." : "" ) + mcStack[nL]; + mcMemory.setSourceKey(miLineNo, msSourceFile, useKey, useText, mbMergeMode); + } + + if (mbMergeMode) + { + std::string sLang, sText, sNewLine; + + + // prepare to read all languages + mcMemory.prepareMerge(); + for (; mcMemory.getMergeLang(sLang, sText);) + { + sNewLine = "\n<value xml:lang=\"" + sLang + "\">" + sText + "</value>"; + mcMemory.convertToInetString(sNewLine); + writeSourceFile(sNewLine); + } + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcu::copySpecial(char *syyText) +{ + int nx = msCollector.size(); + std::string sText = copySource(syyText, mbNoCollectingData); + + if (!mbNoCollectingData) + { + msCollector.erase(nx); + mcMemory.convertFromInetString(sText); + msCollector += sText; + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcu::copyNL(char *syyText) +{ + int nX = msCollector.size(); + std::string sText = copySource(syyText, mbNoCollectingData); + + if (!mbNoCollectingData) + { + msCollector.erase(nX); + msCollector += ' '; + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xcu::addLevel() +{ + ++miLevel; +} diff --git a/l10ntools/source/gConvXhp.cxx b/l10ntools/source/gConvXhp.cxx new file mode 100644 index 000000000000..6222e2a6668f --- /dev/null +++ b/l10ntools/source/gConvXhp.cxx @@ -0,0 +1,438 @@ +/* -*- 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 "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), + meExpectValue(VALUE_NOT_USED), + msLangText(NULL), + mcOutputFiles(NULL), + miCntLanguages(0) +{ + // xhp files are written through a local routine + mbLoadMode = true; +} + + + +/************ 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() +{ + if (mcOutputFiles) + { + for (int i = 0; i < miCntLanguages; ++i) + mcOutputFiles[i].close(); + delete[] mcOutputFiles; + } + if (msLangText) + delete[] msLangText; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +//namespace XhpWrap +//{ +//#define IMPLptr convert_gen_impl::mcImpl +//#define LOCptr ((convert_xhp *)convert_gen_impl::mcImpl) +//#include "gConXhp_yy.c" +//} + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::execute() +{ + std::string sLang; + std::string sFile, sFile2; + + // prepare list with languages + miCntLanguages = mcMemory.prepareMerge(); + if (mbMergeMode) + { + mcOutputFiles = new std::ofstream[miCntLanguages]; + msLangText = new std::string[miCntLanguages]; + + for (int i = 0; mcMemory.getMergeLang(sLang, sFile); ++i) + { + sFile2 = sLang + "/text/" + mcMemory.getModuleName().substr(5) + "/" + 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"); + } + msLangText[i] = "xml-lang=\"" + sLang + "\""; + } + } + + // run analyzer +// XhpWrap::yylex(); + + // dump last line + copySourceSpecial(NULL,3); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::setString(char *yytext) +{ + copySourceSpecial(yytext, 0); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::openTag(char *yytext) +{ + if (meExpectValue == VALUE_IS_VALUE) + { + meExpectValue = VALUE_IS_VALUE_TAG; +//FIX msCollector += "\\"; + } + copySourceSpecial(yytext, 0); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::closeTag(char *yytext) +{ + STATE newState = meExpectValue; + + switch (meExpectValue) + { + case VALUE_IS_VALUE_TAG: + newState = VALUE_IS_VALUE; +//FIX msCollector += "\\"; + break; + + case VALUE_IS_TAG_TRANS: + if (msKey.size()) + newState = VALUE_IS_VALUE; + break; + + case VALUE_IS_TAG: + msKey.clear(); + newState = VALUE_NOT_USED; + break; + case VALUE_NOT_USED: + case VALUE_IS_VALUE: + break; + } + copySourceSpecial(yytext, 0); + meExpectValue = newState; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::closeTagNOvalue(char *yytext) +{ + copySourceSpecial(yytext, 0); + if (meExpectValue == VALUE_IS_VALUE_TAG) + meExpectValue = VALUE_IS_VALUE; + else + meExpectValue = VALUE_NOT_USED; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::setId(char *yytext) +{ + int nL, nE; + std::string& sText = copySourceSpecial(yytext, 0); + + + nL = sText.find("\""); + nE = sText.find("\"", nL+1); + if (nL == (int)std::string::npos || nE == (int)std::string::npos) + return; + + switch (meExpectValue) + { + case VALUE_IS_TAG: + case VALUE_IS_TAG_TRANS: + msKey = sText.substr(nL+1, nE - nL -1) + msKey; + break; + + case VALUE_IS_VALUE_TAG: + case VALUE_NOT_USED: + case VALUE_IS_VALUE: + break; + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::setLang(char *yytext) +{ + int nL, nE; + std::string sLang; + std::string& sText = copySourceSpecial(yytext, 1); + + + nL = sText.find("\""); + nE = sText.find("\"", nL+1); + if (nL == (int)std::string::npos || nE == (int)std::string::npos) + return; + + switch (meExpectValue) + { + case VALUE_IS_TAG: + sLang = sText.substr(nL+1, nE - nL -1); + if (sLang == "en-US") + meExpectValue = VALUE_IS_TAG_TRANS; + else + mcMemory.showError(sLang + " is no en-US language"); + break; + + case VALUE_IS_VALUE_TAG: + msCollector.erase(msCollector.size() - sText.size() -1); + break; + + case VALUE_NOT_USED: + case VALUE_IS_TAG_TRANS: + case VALUE_IS_VALUE: + break; + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::setRef(char *yytext) +{ + int nL, nE; + std::string& sText = copySourceSpecial(yytext, 0); + + + nL = sText.find("\""); + nE = sText.find("\"", nL+1); + if (nL == (int)std::string::npos || nE == (int)std::string::npos) + return; + + switch (meExpectValue) + { + case VALUE_IS_TAG: + case VALUE_IS_TAG_TRANS: + msKey += "." + sText.substr(nL+1, nE - nL -1); + break; + + case VALUE_IS_VALUE_TAG: + case VALUE_NOT_USED: + case VALUE_IS_VALUE: + break; + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::openTransTag(char *yytext) +{ + copySourceSpecial(yytext, 0); + msKey.clear(); + meExpectValue = VALUE_IS_TAG; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::closeTransTag(char *yytext) +{ + int iType = 0; + + + if (meExpectValue == VALUE_IS_VALUE || meExpectValue == VALUE_IS_VALUE_TAG) + { + if (msCollector.size() && msCollector != "-") + mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, msCollector, mbMergeMode); + msKey.clear(); + iType = 2; + } + meExpectValue = VALUE_NOT_USED; + copySourceSpecial(yytext, iType); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::stopTransTag(char *yytext) +{ + copySourceSpecial(yytext, 0); + meExpectValue = VALUE_NOT_USED; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::startComment(char *yytext) +{ + mePushValue = meExpectValue; + msPushCollect = msCollector; + meExpectValue = VALUE_NOT_USED; + copySourceSpecial(yytext, 0); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::stopComment(char *yytext) +{ + copySourceSpecial(yytext, 0); + meExpectValue = mePushValue; + msCollector = msPushCollect; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::handleSpecial(char *yytext) +{ + if (meExpectValue != VALUE_IS_VALUE || meExpectValue != VALUE_IS_VALUE_TAG) + { + std::string sText(yytext); + mcMemory.convertFromInetString(sText); + msCollector += sText; + } + else + copySourceSpecial(yytext, 0); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::handleDataEnd(char *yytext) +{ + int nX = msCollector.size(); + copySourceSpecial(yytext, 0); + + if (meExpectValue == VALUE_IS_VALUE || meExpectValue == VALUE_IS_VALUE_TAG) + msCollector.erase(nX); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xhp::duplicate(char *yytext) +{ + copySourceSpecial(yytext, 0); + + if (meExpectValue == VALUE_IS_VALUE || meExpectValue == VALUE_IS_VALUE_TAG) + msCollector += msCollector[msCollector.size()-1]; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +std::string& convert_xhp::copySourceSpecial(char *yytext, int iType) +{ + bool doingValue = (meExpectValue == VALUE_IS_VALUE || meExpectValue == VALUE_IS_VALUE_TAG); + std::string& sText = copySource(yytext, !doingValue); + std::string sLang; + int i; + + + // Do NOT write data while collecting a value (will be replaced by language text) + if (doingValue) + return sText; + + // Handling depends o + 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 language token, are to replaced with languages + if (mbMergeMode) + { + for (i = 0; i < miCntLanguages; ++i) + { + writeSourceFile(msLine, i); + writeSourceFile(msLangText[i], 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, sText); + writeSourceFile(sText,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_xhp::writeSourceFile(std::string& sText, int inx) +{ + if (sText.size() && mcOutputFiles[inx].is_open()) + mcOutputFiles[inx].write(sText.c_str(), sText.size()); +} diff --git a/l10ntools/source/gConvXrm.cxx b/l10ntools/source/gConvXrm.cxx new file mode 100644 index 000000000000..daac9adb9203 --- /dev/null +++ b/l10ntools/source/gConvXrm.cxx @@ -0,0 +1,171 @@ +/* -*- 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 "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), + mbNoCollectingData(true), + mbIsTag(false), + mbIsLang(false) +{ +} + + + +/************ 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() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +//namespace XrmWrap +//{ +//#define IMPLptr convert_gen_impl::mcImpl +//#define LOCptr ((convert_xrm *)convert_gen_impl::mcImpl) +//#include "gConXrm_yy.c" +//} + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xrm::execute() +{ +//// XrmWrap::yylex(); + + // write last part of file. + if (mbMergeMode) + writeSourceFile(msCollector); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xrm::setId(char *yytext) +{ + std::string& sText = copySource(yytext, mbNoCollectingData); + int nL, nE; + + + if (mbIsTag) + { + nL = sText.find("\""); + nE = sText.find("\"", nL+1); + if (nL == (int)std::string::npos || nE == (int)std::string::npos) + return; + + msKey = sText.substr(nL+1, nE - nL -1); + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xrm::setLang(char *yytext) +{ + std::string& sText = copySource(yytext, mbNoCollectingData); + std::string sLang; + int nL, nE; + + + if (mbIsTag) + { + nL = sText.find("\""); + nE = sText.find("\"", nL+1); + if (nL == (int)std::string::npos || nE == (int)std::string::npos) + return; + + sLang = sText.substr(nL+1, nE - nL -1); + if (sLang == "en-US") + mbIsLang = true; + else + mcMemory.showError(sLang + " is no en-US language"); + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xrm::setTag(char *yytext) +{ + msTag = copySource(yytext); + + msKey.clear(); + mbIsLang = false; + mbIsTag = true; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xrm::startCollectData(char *yytext) +{ + copySource(yytext, mbNoCollectingData); + + if (mbIsTag && mbIsLang && msKey.size()) + mbNoCollectingData = false; + + mbIsTag = mbIsLang = false; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_xrm::stopCollectData(char *yytext) +{ + std::string sTagText, sTagEnd, sLang, sText = msCollector; + + copySource(yytext); + if (!mbNoCollectingData) + { + mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, sText, mbMergeMode); + mbNoCollectingData = true; + if (mbMergeMode) + { + sTagEnd = "</" + msTag.substr(1,msTag.size()-2) + ">\n"; + msTag += "id=\"" + msKey + "\" xml:lang=\""; + + // prepare to read all languages + mcMemory.prepareMerge(); + for (; mcMemory.getMergeLang(sLang, sText);) + { + // replace \" with " + for (int i = 0; (i = sText.find("\\\"", i)) != (int)std::string::npos;) + sText.erase(i,1); + + // Prepare tag start and end + sTagText = msTag + sLang + "\">" + sText + sTagEnd; + writeSourceFile(sTagText); + } + } + msKey.clear(); + } + mbIsTag = false; +} diff --git a/l10ntools/source/gHandler.cxx b/l10ntools/source/gHandler.cxx new file mode 100644 index 000000000000..be955638f8d7 --- /dev/null +++ b/l10ntools/source/gHandler.cxx @@ -0,0 +1,531 @@ +/* -*- 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 <iostream> +#include "gLang.hxx" +#include <cstdlib> +#include <iostream> +#include <fstream> + + + +/***************************************************************************** + ************************ G H A N D L E R . C X X ************************ + ***************************************************************************** + * This is the control module, that interpret the command line and implement + * the different work types + * extract / merge / generate / convert + *****************************************************************************/ + + + +/********************** I M P L E M E N T A T I O N **********************/ +handler::handler() + : + mbForceSave(false) +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +handler::~handler() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void handler::checkCommandLine(int argc, char *argv[]) +{ + enum {ARG_NONE, ARG_F, ARG_O, ARG_S, ARG_T} eGotArg = ARG_NONE; + std::string sWorkText, sLangText; + int argNow, nLen; + + + // make internal throw test (to avoid if cascades + try + { + // check for fixed parameter: genLang <cmd> <module> <po dir> <languages> + if (argc <= 5) + throw "Not enough parameters"; + + // check for working mode + sWorkText = argv[1]; + if (sWorkText == "convert") meWorkMode = DO_CONVERT; + else if (sWorkText == "extract") meWorkMode = DO_EXTRACT; + else if (sWorkText == "merge") meWorkMode = DO_MERGE; + else if (sWorkText == "help") showManual(); + else throw "<command> is mandatory"; + + // and set fixed parameters + msModuleName = argv[2]; + msPoOutDir = msPoDir = argv[3]; + sLangText = argv[4]; + if (sLangText[0] == '\"') + sLangText.erase(0,1); + nLen = sLangText.size() -1; + if (nLen > 0 && sLangText[nLen] == '\"') + sLangText.erase(nLen); + + // decode parameters and translate to variables + for (argNow = 5; argNow < argc;) + { + std::string sArg(argv[argNow++]); + + // all -x is followed by a directory/file name + if (sArg[0] == '-') + { + // Terminate collection ? + if (eGotArg == ARG_F) + eGotArg = ARG_NONE; + + // Are we waiting for a directory + if (eGotArg != ARG_NONE) + throw std::string("missing argument to ") + argv[argNow-1]; + + // is it a known parameter + if (sArg == "-d") {l10nMem::setShowDebug(); } + else if (sArg == "-f") {eGotArg = ARG_F; } + else if (sArg == "-k") {if (meWorkMode == DO_EXTRACT) + meWorkMode = DO_EXTRACT_KID; + else + throw "-k is not valid"; } + else if (sArg == "-o") {eGotArg = ARG_O; mbForceSave = true; } + else if (sArg == "-p") {if (meWorkMode == DO_CONVERT) + meWorkMode = DO_CONVERT_POT; + else + throw "-p is not valid"; } + else if (sArg == "-s") {eGotArg = ARG_S; } + else if (sArg == "-t") {eGotArg = ARG_T; } + else if (sArg == "-v") {l10nMem::setShowVerbose(); } + else throw std::string("unknown parameter: ") + sArg; + } + else + { + switch (eGotArg) + { + case ARG_NONE: break; + case ARG_F: mvSourceFiles.push_back(sArg); break; + case ARG_O: msPoOutDir = sArg; eGotArg = ARG_NONE; break; + case ARG_S: msSourceDir = sArg; eGotArg = ARG_NONE; break; + case ARG_T: msTargetDir = sArg; eGotArg = ARG_NONE; break; + } + } + } + + // Check parameters mandatory for all commands + if (!msModuleName.size()) + throw "<module name> is mandatory"; + if (!msPoDir.size()) + throw "<po dir> is mandatory"; + + // control parameter usage according to selected action; + { + int useLangText, useSoption, useToption; + useLangText = useSoption = useToption = -1; + + if (!mvSourceFiles.size()) + throw "-f <files> is missing or empty"; + + switch (meWorkMode) + { + case DO_EXTRACT: + case DO_EXTRACT_KID: + break; + + case DO_MERGE: + useSoption = 0; + useLangText = 1; + useToption = 1; + break; + + case DO_CONVERT: + useLangText = 1; + case DO_CONVERT_POT: + useToption = 1; + break; + } + + if (sLangText.size() && useLangText == -1) + throw "<languages> must be empty"; + if (!sLangText.size() && useLangText == 1) + throw "<languages> is mandatory"; + if (msSourceDir.size() && useSoption == -1) + throw "-s <source dir> is not valid"; + if (msSourceDir.size() && useSoption == 1) + throw "-s <source dir> is mandatory"; + if (msTargetDir.size() && useToption == -1) + throw "-t <target dir> is not valid"; + if (!msTargetDir.size() && useToption == 1) + throw "-t <target dir> is mandatory"; + } + + if (msTargetDir.size() && !convert_gen::checkAccess(msTargetDir)) + throw "<target dir> does not exist"; + if (msSourceDir.size() && !convert_gen::checkAccess(msSourceDir)) + throw "<source dir> does not exist"; + } + catch(const char *sErr) + { + std::string myErr(sErr); + showUsage(myErr); + exit(-1); + } + catch(std::string sErr) + { + showUsage(sErr); + exit(-1); + } + + // update directories to include final / + nLen = msSourceDir.size(); + if (nLen && msSourceDir.at(nLen-1) != '/') + msSourceDir.append("/"); + nLen = msTargetDir.size(); + if (nLen && msTargetDir.at(nLen-1) != '/') + msTargetDir.append("/"); + nLen = msPoDir.size(); + if (nLen && msPoDir.at(nLen-1) != '/') + msPoDir.append("/"); + nLen = msPoOutDir.size(); + if (nLen && msPoOutDir.at(nLen-1) != '/') + msPoOutDir.append("/"); + + // and convert language to a vector + if (sLangText.size()) + { + int current; + int next = -1; + do + { + current = next + 1; + next = sLangText.find_first_of( " ", current ); + std::string sNewLang = sLangText.substr(current,next-current); + if (sNewLang != "en-US") + mvLanguages.push_back(sLangText.substr(current,next-current)); + } + while (next != (int)std::string::npos); + } + + // check if source files list needs to be coverted + if (mvSourceFiles[0] == "USEFILE:") + readFileWithSources(); + + // tell system + l10nMem::showVerbose("genLang starting to " + sWorkText + " from module " + msModuleName); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void handler::run() +{ + try + { + // prepare translation memory to module type + mcMemory.setModuleName(msModuleName); + + // build list of languages (to be loaded and later written + if (msPoDir.size()) + loadL10MEM( (meWorkMode == DO_EXTRACT) ); + + // use workMode to start correct control part + switch (meWorkMode) + { + case DO_EXTRACT: runExtract(false); break; + case DO_EXTRACT_KID: runExtract(true); break; + case DO_MERGE: runMerge(); break; + case DO_CONVERT: runConvert(false); break; + case DO_CONVERT_POT: runConvert(true); break; + } + } + catch(int) + { + exit(-1); + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void handler::runExtract(bool bKid) +{ + // just to satisfy compiler + if (bKid) + return; + + // no convert + mcMemory.setConvert(false, false); + + // loop through all source files, and extract messages from each file + for (std::vector<std::string>::iterator siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource) + { + // tell system + l10nMem::showDebug("genLang extracting text from file " + msSourceDir + *siSource); + + // get converter and extract file + convert_gen convertObj(mcMemory, msSourceDir, msTargetDir, *siSource); + convertObj.execute(false); + } + + // and generate language file + mcMemory.saveTemplates(msPoOutDir, false, mbForceSave); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void handler::runMerge() +{ + // no convert + mcMemory.setConvert(false, false); + + // loop through all source files, and extract messages from each file + for (std::vector<std::string>::iterator siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource) + { + // tell system + l10nMem::showDebug("genLang merging translated text to file " + msSourceDir + *siSource); + + // get converter and extract file + convert_gen convertObj(mcMemory, msSourceDir, msTargetDir, *siSource); + convertObj.execute(true); + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void handler::runConvert(bool bPot) +{ + // convert + mcMemory.setConvert(true, bPot); + + // loop through all source files, and extract messages from each file + for (std::vector<std::string>::iterator siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource) + { + // handle .pot (templates) + if (bPot) + { + // tell system + l10nMem::showDebug("genLang compare template " + msSourceDir + *siSource); + + // get converter and extract files + convert_gen convertObj(mcMemory, "./", msTargetDir, *siSource); + convertObj.execute(false); + + if (bPot) + mcMemory.showNOconvert(); + } + else + for (std::vector<std::string>::iterator siLang = mvLanguages.begin(); siLang != mvLanguages.end(); ++siLang) + { + std::string sFilePath = msSourceDir + *siLang + "/"; + + // get converter and extract files + mcMemory.setLanguage(*siLang, false); + + // tell system + l10nMem::showDebug("genLang convert text from file " + sFilePath + *siSource + " language " + *siLang); + + // get converter and extract files + convert_gen convertObj(mcMemory, sFilePath, msTargetDir, *siSource); + convertObj.execute(true); + } + } + + // and generate language file + if (!bPot) + mcMemory.saveLanguages(msPoOutDir, mbForceSave); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void handler::showUsage(std::string& sErr) +{ + // do we have an error text ? + if (sErr.size()) + std::cerr << "commandline error:" << sErr << std::endl; + + std::cout << + "syntax oveview, use \"genLang help\" for full description\n" + "genLang <cmd> <module> <po dir> <languages> [-d] [-f <files>] [-k] [-o <dir>] [-p] [-s <dir>] [-t <dir>] [-v]\n" + "<cmd> is one of \"convert\", \"extract\", \"help\", \"merge\",\n"; + + exit(-1); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void handler::showManual() +{ + // give the correct usage + std::cout << + "genLang (c)2013 by Apache Software Foundation\n" + "=============================================\n" + "As part of the L10N framework for Apache Open Office (AOO),\n" + "genLang extracts en-US texts sources of the following types:\n" + " .xrm, .xhp, .xcu, .xcs, .ulf, .tree, .src, .prop and .po (.pot)\n" + "and merges with .po files in different languages.\n" + "genLang uses .po files and AOO sources to generate language sources.\n" + "\n" + "genLang can also convert old .po files (generated from .sdf)\n" + "\n"; + + std::cout << + "Syntax:\n" + " genLang extract <module> <po dir> \"\" [-v] [-d] \\\n" + " -f <files> [-s <source dir>]\n" + " if -s is omitted . is used\n" + " extract text from <source dir>/<files>, result is merged and\n" + " written to <po dir>/<module>.pot\n" + "\n"; + std::cout << + " genLang merge <module> <po dir> <languages> [-v] [-d] [-k]\\\n" + " [-o <po outdir>] -f <files> [-s <source dir>] \\\n" + " -t <target dir>\n" + " works as \"extract\" and additionally merges\n" + " <source dir>/<files> with all native language text\n" + " from <po dir>/*lang/<module>.po\n" + " The result is stored in <target dir>/<files>\n" + "\n"; + std::cout << + " genLang convert <module> <po dir> <languages> [-v] [-d]\\\n" + " [-p] [-o <po outdir>] -s <source dir> -f <files>\n" + " reads sdf generated .po <files> from\n" + " <source dir>/*lang/<module>.po\n" + " and merges with\n" + " <po dir>/*lang/<module>.po\n" + " Result is written to <po outdir>/*lang/<module>.po if\n" + " present or <po dir>/*lang/<module>.po is overwritten\n" + " - Keys in <source dir>, not in <module>.po\n" + " are shown as warnings\n" + " - Keys in <source dir>, with changed translation\n" + " are marked \"fuzzy\"\n" + " - Keys in source files not in .po files (new keys)\n" + " are added and marked \"fuzzy\"\n" + " if -p is used, .pot files is assumed, and a compare is made\n" + "\n"; + std::cout << + " genLang help\n" + " this text\n" + "\n"; + std::cout << + "Parameters:\n" + " <module>\n" + " name of module (directory in main)\n" + " <po dir>\n" + " directory containing a directory for each language which contains\n" + " a .po file for each module or a module.dbpo file for fast loading\n" + " <languages>\n" + " comma separated string with langauge id to be used\n" + "\n" + " -d\n" + " extensive verbose mode, tells what genLang is doing in detail\n" + " -f <files>\n" + " list of files containing messages to be extracted\n" + " \"convert\" expect sdf generated po files, to be converted\n" + " instead of passing a list of files, it is possible to pass\n" + " a file contains the list, by using:\n" + " -f USEFILE: <filename>\n" + " -k\n" + " generate kid id (hex) for all messages in the source code,\n" + " solely for QA\n" + " -o <po outdir>\n" + " directory to write .po files, same structure as -p\n" + " -p\n" + " used with convert, when comparing .pot files (old system == new system)\n" + " -s <source dir>\n" + " directory containing all source files (root path for <files>\n" + " -t <target dir>\n" + " <directory> used to write merged source files (root path for <files>\n" + " -v\n" + " verbose mode, tells what genLang is doing\n"; + + exit(0); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void handler::loadL10MEM(bool onlyTemplates) +{ + std::string sMod = msModuleName + ".pot"; + std::string sLoad = msPoDir + "templates/"; + + // no convert + mcMemory.setConvert(false, false); + + // load texts from en-US po file (master) + // tell system + l10nMem::showDebug("genLang loading master text from file " + sLoad + sMod); + + // and load file + mcMemory.setLanguage("", true); + convert_gen (mcMemory, sLoad, msTargetDir, sMod).execute(false); + + if (onlyTemplates) + return; + + // loop through all languages and load text + sMod = msModuleName + ".po"; + for (std::vector<std::string>::iterator siLang = mvLanguages.begin(); siLang != mvLanguages.end(); ++siLang) + { + sLoad = msPoDir + *siLang + "/"; + + // get converter and extract files + mcMemory.setLanguage(*siLang, true); + + // tell system + l10nMem::showDebug("genLang loading text from language file " + sLoad + sMod); + + convert_gen(mcMemory, sLoad, msTargetDir, sMod).execute(false); + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void handler::readFileWithSources() +{ + std::ifstream fInput; + char buf[256]; + + + if (mvSourceFiles.size() < 2) + throw l10nMem::showError("missing file with sources (-f USEFILE: <filename>)"); + + fInput.open (mvSourceFiles[1].c_str(), std::ifstream::in); + if (!fInput.is_open()) + throw l10nMem::showError("Cannot open file with sources (-f), trying to open" + mvSourceFiles[1]); + + mvSourceFiles.clear(); + + while (fInput.good()) + { + fInput.getline(buf, sizeof(buf)); + if (!buf[0]) + continue; + mvSourceFiles.push_back(buf); + } + + fInput.close(); +} diff --git a/l10ntools/source/gL10nMem.cxx b/l10ntools/source/gL10nMem.cxx new file mode 100644 index 000000000000..f0acb080eb0b --- /dev/null +++ b/l10ntools/source/gL10nMem.cxx @@ -0,0 +1,739 @@ +/* -*- 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 "gL10nMem.hxx" +//#include <algorithm> +#include <iostream> +#include <fstream> +#include <sstream> + + + +/***************************************************************************** + ************************ G L 1 0 N M E M . C X X ************************ + ***************************************************************************** + * This is the interface to translation memory that links between the converts + * and to the language files. The memory contains the actual text info + ***********************d******************************************************/ + + + +/******************* G L O B A L D E F I N I T I O N *******************/ +l10nMem_impl * l10nMem_impl::mcImpl = NULL; +bool l10nMem_impl::mbVerbose = false; +bool l10nMem_impl::mbDebug = false; + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem::l10nMem() +{ + l10nMem_impl::mcImpl = new l10nMem_impl(); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem::~l10nMem() +{ + delete l10nMem_impl::mcImpl; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem::setShowVerbose() +{ + l10nMem_impl::mbVerbose = true; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem::setShowDebug() +{ + l10nMem_impl::mbDebug = true; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +int l10nMem::showError(const std::string& sText, int iLineNo) + { return l10nMem_impl::mcImpl->showError(sText, iLineNo); } +int l10nMem::showWarning(const std::string& sText, int iLineNo) + { return l10nMem_impl::mcImpl->showWarning(sText, iLineNo); } +void l10nMem::showDebug(const std::string& sText, int iLineNo) + { l10nMem_impl::mcImpl->showDebug(sText, iLineNo); } +void l10nMem::showVerbose(const std::string& sText, int iLineNo) + { l10nMem_impl::mcImpl->showVerbose(sText, iLineNo); } +bool l10nMem::isError() + { return l10nMem_impl::mcImpl->mbInError; } +void l10nMem::setModuleName(const std::string& sM) + { l10nMem_impl::mcImpl->setModuleName(sM); } +const std::string& l10nMem::getModuleName () + { return l10nMem_impl::mcImpl->getModuleName(); } +void l10nMem::setLanguage(const std::string& sL, bool bC) + { l10nMem_impl::mcImpl->mcDb.setLanguage(sL, bC); } +void l10nMem::setConvert(bool bC, bool bS) + { l10nMem_impl::mcImpl->mcDb.setConvert(bC, bS); } +void l10nMem::loadEntryKey(int iL, const std::string& sS, const std::string& sK, const std::string& sO, const std::string& sT, bool bI) + { l10nMem_impl::mcImpl->loadEntryKey(iL, sS, sK, sO, sT, bI); } +void l10nMem::setSourceKey(int iL, const std::string& sF, const std::string& sK, const std::string& sT, bool bM) + { l10nMem_impl::mcImpl->setSourceKey(iL, sF, sK, sT, bM); } +void l10nMem::saveTemplates(const std::string& sT, bool bK, bool bF) + { l10nMem_impl::mcImpl->saveTemplates(*this, sT, bK, bF); } +void l10nMem::saveLanguages(const std::string& sT, bool bF) + { l10nMem_impl::mcImpl->saveLanguages(*this, sT, bF); } +void l10nMem::showNOconvert () + { l10nMem_impl::mcImpl->showNOconvert(); } +void l10nMem::convertToInetString(std::string& sT) + { l10nMem_impl::mcImpl->convertToInetString(sT); } +void l10nMem::convertFromInetString(std::string& sT) + { l10nMem_impl::mcImpl->convertFromInetString(sT); } + +int l10nMem::prepareMerge() + { return l10nMem_impl::mcImpl->mcDb.prepareMerge(); } +void l10nMem::dumpMem(const std::string& sT) + { l10nMem_impl::mcImpl->dumpMem(sT); } +bool l10nMem::getMergeLang(std::string& sL, std::string& sT) + { return l10nMem_impl::mcImpl->mcDb.getMergeLang(sL, sT); } + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_impl::l10nMem_impl() + : + mbInError(false) +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_impl::~l10nMem_impl() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +int l10nMem_impl::showError(const std::string& sText, int iLineNo) +{ + mbInError = true; + formatAndShowText("ERROR", iLineNo, sText); + return 1; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +int l10nMem_impl::showWarning(const std::string& sText, int iLineNo) +{ + formatAndShowText("WARNING", iLineNo, sText); + return 2; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::showDebug(const std::string& sText, int iLineNo) +{ + if (mbDebug) + formatAndShowText("DEBUG", iLineNo, sText); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::showVerbose(const std::string& sText, int iLineNo) +{ + if (mbVerbose) + formatAndShowText("INFO", iLineNo, sText); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::setModuleName(const std::string& sModuleName) +{ + msModuleName = sModuleName; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +const std::string& l10nMem_impl::getModuleName() +{ + return msModuleName; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::loadEntryKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + const std::string& sMsgStr, + bool bIsFuzzy) +{ + if (mcDb.mbConvertMode) + convEntryKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy); + else if (!mcDb.miCurLangInx) + mcDb.loadENUSkey(iLineNo, sSourceFile, sKey, sMsgId); + else + mcDb.loadLangKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::setSourceKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + bool bMustExist) +{ + std::string newText(sMsgId); + int i; + + // time to escape " and \ if contained in text or key + for (i = 0; (i = newText.find("\\", i)) != (int)std::string::npos;) + { + ++i; + if (i < (int)newText.size() && + (newText[i] == '\\' || newText[i] == '<' || newText[i] == '>' || + newText[i] == 'n' || newText[i] == 't' || newText[i] == 'r' || + newText[i] == '\'')) + ++i; + else + { + newText.insert(i-1, "\\"); + ++i; + } + } + for (i = 0; (i = newText.find("\"", i)) != (int)std::string::npos;) + { + newText.insert(i, "\\"); + i += 2; + } + + // if key exist update state + if (mcDb.locateKey(iLineNo, sSourceFile, sKey, newText, false)) + { + mcDb.mcENUSlist[mcDb.miCurENUSinx].meState = l10nMem::ENTRY_NORMAL; + } + else + { + if (bMustExist) + throw l10nMem::showError("key " + sKey + " does not exist"); + else + // add key, if changed text, this is wrong but handled in reorganize + mcDb.addKey(iLineNo, sSourceFile, sKey, newText, l10nMem::ENTRY_ADDED); + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::saveTemplates(l10nMem& cMem, const std::string& sTargetDir, bool bKid, bool bForce) +{ + int iE, iEsize = mcDb.mcENUSlist.size(); + std::string sFileName = msModuleName + ".pot"; + + // Dummy to satisfy compiler + if (bKid) + return; + + // and reorganize db if needed + mcDb.miCurFileInx = 0; + mcDb.reorganize(false); + + // no save if there has been errors + if(!needWrite(sFileName, bForce)) + return; + + //JIX save HANDLE KID + + // Save en-US + convert_gen savePo(cMem, sTargetDir, sTargetDir, sFileName); + + savePo.startSave("templates/", sFileName); + for (iE = 1; iE < iEsize; ++iE) + { + l10nMem_enus_entry& cE = mcDb.mcENUSlist[iE]; + + // remove deleted entries + if (cE.meState == l10nMem::ENTRY_DELETED) + continue; + + savePo.save(mcDb.mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, "", false); + } + savePo.endSave(); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::saveLanguages(l10nMem& cMem, const std::string& sTargetDir, bool bForce) +{ + int iE, iEsize = mcDb.mcENUSlist.size(); + int iL, iLsize = mcDb.mcLangList.size(); + std::string sFileName = msModuleName + ".po"; + + + // and reorganize db if needed + mcDb.miCurFileInx = 0; + mcDb.reorganize(true); + + // no save if there has been errors + if(!needWrite(sFileName, bForce)) + return; + + // save all languages + for (iL = 1; iL < iLsize; ++iL) + { + // only save language file if modified + if (!mcDb.mcLangList[iL].mbChanged) + continue; + + mcDb.mcLangList[iL].mbChanged = false; + convert_gen savePo(cMem, sTargetDir, sTargetDir, sFileName); + + savePo.startSave(mcDb.mcLangList[iL].msName + "/", sFileName); + for (iE = 1; iE < iEsize; ++iE) + { + l10nMem_enus_entry& cE = mcDb.mcENUSlist[iE]; + l10nMem_lang_entry& cL = cE.mcLangText[iL]; + bool bF = cL.mbFuzzy; + + // remove deleted entries + if (cE.meState == l10nMem::ENTRY_DELETED) + continue; + + savePo.save(mcDb.mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, cL.msMsgStr, bF); + } + savePo.endSave(); + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::showNOconvert () +{ + int iE, iEsize = mcDb.mcENUSlist.size(); + + for (iE = 1; iE < iEsize; ++iE) + { + l10nMem_enus_entry& cE = mcDb.mcENUSlist[iE]; + + if (cE.meState == l10nMem::ENTRY_DELETED) + { + showError("template key(" + cE.msKey + ") msgId(" + cE.msMsgId + ") not in pot file", 0); + } + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::dumpMem(const std::string& sFileName) +{ + // and reorganize db if needed + mcDb.reorganize(false); + + // no save if there has been errors + if(!needWrite(sFileName, true)) + return; + + // JIX (dumpMem) +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::formatAndShowText(const std::string& sType, int iLineNo, const std::string& sText) +{ + std::cout << sType; + if (mcDb.miCurFileInx > 0) + std::cout << " in " << mcDb.mcFileList[mcDb.miCurFileInx].msFileName; + if (iLineNo) + std::cout << "(" << iLineNo << ")"; + std::cout << ": " << sText << std::endl; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +bool l10nMem_impl::needWrite(const std::string sFileName, bool bForce) +{ + int iE, iEsize = mcDb.mcENUSlist.size(); + int iCntDeleted = 0, iCntChanged = 0, iCntAdded = 0; + + // no save if there has been errors + if (mbInError) + throw l10nMem::showError("Cannot save due to previous errors"); + + // Check number of changes + for (iE = 1; iE < iEsize; ++iE) + { + l10nMem_enus_entry& cur = mcDb.mcENUSlist[iE]; + if (cur.meState == l10nMem::ENTRY_ADDED) + ++iCntAdded; + if (cur.meState == l10nMem::ENTRY_CHANGED) + { + ++iCntChanged; + if (mcDb.mbStrictMode) + cur.meState = l10nMem::ENTRY_NORMAL; + } + if (cur.meState == l10nMem::ENTRY_DELETED) + ++iCntDeleted; + } + if (!mcDb.mbConvertMode) + iCntDeleted -= iCntChanged; + if (!iCntAdded && !iCntChanged && !iCntDeleted) + { + std::cout << "genLang: No changes in " << sFileName; + if (bForce) + std::cout << ", -o switch used, so files are saved" << std::endl; + else + std::cout << " skipping \"save\"" << std::endl; + return bForce; + } + + std::cout << "genLang statistics: " << iCntDeleted << " deleted, " + << iCntChanged << " changed, " + << iCntAdded << " added entries in " + << sFileName << std::endl; + return true; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +bool l10nMem_impl::convFilterWarning(const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId) +{ + // silent ignore deleted messages + if (sMsgId == "-" || sMsgId == "") + return true; + + if (msModuleName == "help_sbasic") + { + if (sSourceFile == "sbasic.tree") + return true; + } + if (msModuleName == "help_scalc") + { + if (sSourceFile == "scalc.tree") + return true; + } + if (msModuleName == "help_schart") + { + if (sSourceFile == "schart.tree") + return true; + } + if (msModuleName == "help_shared") + { + if (sSourceFile == "shared.tree") + return true; + } + if (msModuleName == "help_simpress") + { + if (sSourceFile == "simpress.tree") + return true; + } + if (msModuleName == "help_smath") + { + if (sSourceFile == "smath.tree") + return true; + } + if (msModuleName == "help_swriter") + { + if (sSourceFile == "swriter.tree") + return true; + } + if (msModuleName == "officecfg") + { + if (sSourceFile == "registry/data/org/openoffice/Office/Writer.xcu" && sKey == "Writer.Insert.Caption.CaptionOrderNumberingFirst") + return true; + if (sSourceFile == "registry/data/org/openoffice/Office/Writer.xcu" && sKey == "Writer.Layout.Other.TabStop") + return true; + if (sSourceFile == "registry/data/org/openoffice/Office/UI/WriterCommands.xcu" && sKey == "WriterCommands.UserInterface.Commands..uno:FlipVertical.Label") + return true; + if (sSourceFile == "registry/data/org/openoffice/Office/UI/WriterCommands.xcu" && sKey == "WriterCommands.UserInterface.Commands..uno:FlipHorizontal.Label") + return true; + if (sSourceFile == "registry/data/org/openoffice/Office/Common.xcu" && sKey == "Common.View.Localisation.AutoMnemonic") + return true; + if (sSourceFile == "registry/data/org/openoffice/Office/Common.xcu" && sKey == "Common.View.Localisation.DialogScale") + return true; + if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/SlideTransitions.UIName") + return true; + if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/CustomAnimations.UIName") + return true; + if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/MasterPages.UIName") + return true; + if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/Layouts.UIName") + return true; + if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/TableDesign.UIName") + return true; + } + if (msModuleName == "readlicense_oo") + { + if (sSourceFile == "docs/readme/readme.xrm") + { + if (sKey == "BDB11") + return true; + if (sKey == "BDB2a") + return true; + if (sKey == "BDB3a") + return true; + if (sKey == "BDB4a") + return true; + } + } + if (msModuleName == "scp2") + { + if (sSourceFile == "source/binfilter/module_binfilter.ulf") + return true; + if (sSourceFile == "source/binfilter/registryitem_binfilter.ulf") + return true; + } + if (msModuleName == "sdext") + { + if (sSourceFile == "source/minimizer/registry/data/org/openoffice/Office/Addons.xcu") + return true; + if (sSourceFile == "source/minimizer/registry/data/org/openoffice/Office/extension/SunPresentationMinimizer.xcu") + return true; + if (sSourceFile == "source/presenter/help/en-US/com.sun.PresenterScreen/presenter.xhp") + return true; + if (sSourceFile == "source/presenter/registry/data/org/openoffice/Office/extension/PresenterScreen.xcu") + return true; + } + if (msModuleName == "sd") + { + if (sSourceFile == "source/ui/dlg/celltempl.src") + return true; + } + if (msModuleName == "svx") + { + if (sSourceFile == "source/dialog/fontwork.src") + { + if (sKey == "RID_SVXSTR_FONTWORK_FORM1.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_FORM2.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_FORM3.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_FORM4.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_FORM5.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_FORM6.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_FORM7.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_FORM8.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_FORM9.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_FORM10.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_FORM11.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_FORM12.String.Text") + return true; + if (sKey == "RID_SVXSTR_FONTWORK_UNDOCREATE.String.Text") + return true; + } + if (sSourceFile == "source/dialog/sdstring.src") + { + if (sKey == "RID_SVXSTR_LIGHTGREY.String.Text") + return true; + if (sKey == "RID_SVXSTR_LIGHTBLUE.String.Text") + return true; + if (sKey == "RID_SVXSTR_LIGHTGREEN.String.Text") + return true; + if (sKey == "RID_SVXSTR_LIGHTCYAN.String.Text") + return true; + if (sKey == "RID_SVXSTR_LIGHTRED.String.Text") + return true; + if (sKey == "RID_SVXSTR_LIGHTMAGENTA.String.Text") + return true; + if (sKey == "RID_SVXSTR_COLOR_SUN.String.Text") + return true; + } + if (sSourceFile == "source/svdraw/svdstr.src" && sKey == "SIP_XA_FORMTXTSTDFORM.String.Text") + return true; + } + return false; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::convEntryKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + const std::string& sMsgStr, + bool bIsFuzzy) +{ + std::vector<int> ivEntryList; + std::string curFileName; + std::string curKeyUpper; + int curFileIndex, curENUSindex, i, iSize; + + + // filter out dummy messages, silently + if (convFilterWarning(sSourceFile, sKey, sMsgId)) + return; + + // check for directory names in file name + i = sSourceFile.rfind("/"); + if (i > 0) + curFileName = sSourceFile.substr(i+1); + else + curFileName = sSourceFile; + + // Find all matching file names (old system does not have directory. + // build list of potential entries + iSize = mcDb.mcFileList.size(); + for (curFileIndex = 1; curFileIndex < iSize; ++curFileIndex) + if (curFileName == mcDb.mcFileList[curFileIndex].msPureName) + { + int j = mcDb.mcFileList[curFileIndex].miStart; + int iEnd = mcDb.mcFileList[curFileIndex].miEnd; + + for (; j <= iEnd; ++j) + ivEntryList.push_back(j); + } + + // Did we find one or more files ? + iSize = ivEntryList.size(); + if (!iSize) + { + showWarning("source file(" + curFileName + ") not in template file", iLineNo); + return; + } + + // Loop through all potential en-US entries + for (curENUSindex = -1, i = 0; i < iSize; ++i) + { + l10nMem_enus_entry& curE = mcDb.mcENUSlist[ivEntryList[i]]; + + + // The entry must be unconverted if strict mode (comparing .pot files) + if (mcDb.mbStrictMode && curE.meState != l10nMem::ENTRY_DELETED) + continue; + + // msgId must match + if (sMsgId == curE.msMsgId) + { + curENUSindex = ivEntryList[i]; + if (curE.meState == l10nMem::ENTRY_DELETED) + curE.meState = l10nMem::ENTRY_NORMAL; + break; + } + } + + // do we need to do advanced find + if (curENUSindex == -1 || mcDb.mbStrictMode) + { + // make copy of key in upper case + curKeyUpper = sKey; + l10nMem_db::keyToUpper(curKeyUpper); + + // Loop through all potential en-US entries + for (i = 0; i < iSize; ++i) + { + l10nMem_enus_entry& curE = mcDb.mcENUSlist[ivEntryList[i]]; + + // compare keys, but be aware of different length + if (curKeyUpper.find(curE.msKey) != std::string::npos) + { + curENUSindex = ivEntryList[i]; + bIsFuzzy = true; + break; + } + } + } + + if (curENUSindex == -1) + { + showWarning("file(" + curFileName + ") key(" + sKey + ") msgId(" + sMsgId + ") not found in templates", iLineNo); + return; + } + + // update language text + l10nMem_enus_entry& curE = mcDb.mcENUSlist[curENUSindex]; + l10nMem_lang_entry& curL = curE.mcLangText[mcDb.miCurLangInx]; + + if (sMsgStr != curL.msMsgStr) + { + curL.msMsgStr = sMsgStr; + curL.mbFuzzy = bIsFuzzy; + curE.meState = l10nMem::ENTRY_CHANGED; + mcDb.mcLangList[mcDb.miCurLangInx].mbChanged = true; + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::convertToInetString(std::string& sText) +{ +static const char *replacingStr[] = {"&", "\'", ">", "<", "\"", NULL }; +static const int replacingLen[] = {1, 1, 1, 1, 1, 0 }; +static const char *newStr[] = {"&", "'", ">", "<", """, NULL }; +static const int newLen[] = {5, 6, 4, 4, 6, 0 }; + int i, pos; + + for (i = 0; replacingStr[i]; i++) + { + pos = 0; + while((pos = sText.find(replacingStr[i], pos)) != (int)std::string::npos) { + sText.replace(pos, replacingLen[i], newStr[i]); + pos += newLen[i]; + } + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::convertFromInetString(std::string& sText) +{ +static const char *replacingStr[] = {"&", "'", ">", "<", """, NULL }; +static const int replacingLen[] = {5, 6, 4, 4, 6, 0 }; +static const char *newStr[] = {"&", "\'", ">", "<", "\"", NULL }; +static const int newLen[] = {1, 1, 1, 1, 1, 0 }; + int i, pos; + + for (i = 0; replacingStr[i]; i++) + { + pos = 0; + while((pos = sText.find(replacingStr[i], pos)) != (int)std::string::npos) { + sText.replace(pos, replacingLen[i], newStr[i]); + pos += newLen[i]; + } + } +} diff --git a/l10ntools/source/gL10nMemDB.cxx b/l10ntools/source/gL10nMemDB.cxx new file mode 100644 index 000000000000..2055b0e5e318 --- /dev/null +++ b/l10ntools/source/gL10nMemDB.cxx @@ -0,0 +1,463 @@ +/* -*- 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 "gL10nMem.hxx" +#include <iostream> +#include <fstream> +#include <sstream> + + +/***************************************************************************** + ********************** G L 1 0 N M E M D B . C X X ********************** + ***************************************************************************** + * This is the translation memory that links between the converts (from source + * files) and to the language files. The memory contains the actual text info + ***********************d******************************************************/ + + + +/******************* G L O B A L D E F I N I T I O N *******************/ + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_lang_entry::l10nMem_lang_entry(const std::string& sMsgStr, bool bFuzzy) + : + msMsgStr(sMsgStr), + mbFuzzy(bFuzzy) +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_lang_entry::~l10nMem_lang_entry() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_enus_entry::l10nMem_enus_entry(const std::string& sKey, + const std::string& sMsgId, + int iLineNo, + int iFileInx, + int iLangSize, + l10nMem::ENTRY_STATE eState) + : + msMsgId(sMsgId), + meState(eState), + miFileInx(iFileInx), + miLineNo(iLineNo) +{ + int i; + + // add dummy language entries + for (i = 0; i < iLangSize; ++i) + mcLangText.push_back(l10nMem_lang_entry("", false)); + + // convert key to upper case + msKey = sKey; + l10nMem_db::keyToUpper(msKey); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_enus_entry::~l10nMem_enus_entry() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_file_entry::l10nMem_file_entry(const std::string& sFileName, int iStart) + : + msFileName(sFileName), + miStart(iStart), + miEnd(iStart) +{ + // Store fileName without relative path + int i = msFileName.rfind("/"); + if (i == (int)std::string::npos) + msPureName = msFileName; + else + msPureName = msFileName.substr(i+1); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_file_entry::~l10nMem_file_entry() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_lang_list_entry::l10nMem_lang_list_entry(const std::string& sName) + : + msName(sName), + mbChanged(false) +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_lang_list_entry::~l10nMem_lang_list_entry() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_db::l10nMem_db() + : + miCurFileInx(0), + miCurLangInx(0), + miCurENUSinx(0), + mbNeedWrite(false), + mbConvertMode(false), + mbStrictMode(false) +{ + mcFileList.push_back(l10nMem_file_entry("-genLang-", 0)); + mcLangList.push_back(l10nMem_lang_list_entry("-genLang-")); + mcENUSlist.push_back(l10nMem_enus_entry("-genLang-", "-genLang-", 0, 0, 0, l10nMem::ENTRY_DELETED)); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +l10nMem_db::~l10nMem_db() +{ +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_db::loadENUSkey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId) +{ + // add it to vector and update file pointer + addKey(iLineNo, sSourceFile, sKey, sMsgId, l10nMem::ENTRY_DELETED); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_db::setLanguage(const std::string& sLanguage, + bool bCreate) +{ + int i, iSize; + + // regular load or convert of old po files + miCurFileInx = 0; + + // With no languages selected only en-US is generated + if (!sLanguage.size()) + { + miCurLangInx = 0; + return; + } + + // en-US is loaded as master and cannot be loaded again + if (sLanguage == "en-US") + throw l10nMem::showError("en-US is loaded automatically"); + + // check if language is already loaded + iSize = mcLangList.size(); + for (miCurLangInx = 0; miCurLangInx < iSize && mcLangList[miCurLangInx].msName != sLanguage; ++miCurLangInx) ; + if (miCurLangInx < iSize) + { + if (bCreate) + throw l10nMem::showError("loading " + sLanguage + " twice"); + return; + } + + // language does not exist in db + if (!bCreate) + throw l10nMem::showError("language " + sLanguage + " not loaded"); + + // create language + mcLangList.push_back(sLanguage); + + // add language to all ENUS entries + iSize = mcENUSlist.size(); + for (i = 0; i < iSize; ++i) + mcENUSlist[i].mcLangText.push_back(l10nMem_lang_entry("", false)); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_db::setConvert(bool bConvert, + bool bStrict) +{ + // regular load or convert of old po files + mbConvertMode = bConvert; + mbStrictMode = bStrict; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +bool l10nMem_db::findFileName(const std::string& sSourceFile) +{ + int iSize = mcFileList.size(); + + // Check this or next file + if (mcFileList[miCurFileInx].msFileName == sSourceFile || mcFileList[miCurFileInx].msPureName == sSourceFile) + return true; + if (++miCurFileInx < iSize && mcFileList[miCurFileInx].msFileName == sSourceFile) + return true; + + for (miCurFileInx = 1; + miCurFileInx < iSize && mcFileList[miCurFileInx].msFileName != sSourceFile && + mcFileList[miCurFileInx].msPureName != sSourceFile; + ++miCurFileInx) ; + if (miCurFileInx == iSize) + { + miCurFileInx = 0; + return false; + } + else + return true; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_db::loadLangKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + const std::string& sMsgStr, + bool bFuzzy) +{ + if (!locateKey(iLineNo, sSourceFile, sKey, sMsgId, true)) + throw l10nMem::showError(".po file contains unknown filename: " + sSourceFile + " or key: " + sKey); + + l10nMem_lang_entry& xCur = mcENUSlist[miCurENUSinx].mcLangText[miCurLangInx]; + xCur.msMsgStr = sMsgStr; + xCur.mbFuzzy = bFuzzy; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_db::reorganize(bool bConvert) +{ + int iE, iEsize = mcENUSlist.size(); + int iD, iDsize; + std::vector<int> listDel, listAdd; + + + // Check number of changes + for (iE = 1; iE < iEsize; ++iE) + { + l10nMem_enus_entry& cur = mcENUSlist[iE]; + if (cur.meState == l10nMem::ENTRY_ADDED) + listAdd.push_back(iE); + if (cur.meState == l10nMem::ENTRY_DELETED) + { + if (bConvert) + cur.meState = l10nMem::ENTRY_NORMAL; + else + listDel.push_back(iE); + } + } + + if (!listDel.size() || !listAdd.size()) + return; + + // loop through added text and see if key match deleted text + iEsize = listAdd.size(); + iDsize = listDel.size(); + for (iE = 0; iE < iEsize; ++iE) + { + l10nMem_enus_entry& curAdd = mcENUSlist[listAdd[iE]]; + for (iD = 0; iD < iDsize; ++iD) + { + l10nMem_enus_entry& curE = mcENUSlist[listDel[iD]]; + + if (curE.miFileInx != curAdd.miFileInx) + continue; + if (curE.msKey == curAdd.msKey) + break; + if (curE.msMsgId == curAdd.msMsgId) + break; + } + if (iD == iDsize) + continue; + + // Update deleted entry (original), because lang is connected here + l10nMem_enus_entry& curDel = mcENUSlist[listDel[iD]]; + curDel.msMsgId = curAdd.msMsgId; + curDel.msKey = curAdd.msKey; + curDel.meState = l10nMem::ENTRY_CHANGED; + curAdd.meState = l10nMem::ENTRY_DELETED; + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +bool l10nMem_db::locateKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + bool bThrow) +{ + std::string sUpperKey(sKey); + int i, iSize = sUpperKey.size(); + char ch; + + // Position file pointer + if (!findFileName(sSourceFile)) + return false; + + // convert key to upper case + for (i = 0; i < iSize; ++i) + { + ch = sUpperKey[i]; + if (ch == ' ' || ch == '*' || ch == '+' || ch == '%') + sUpperKey[i] = '_'; + else + sUpperKey[i] = toupper(sUpperKey[i]); + } + + // Fast check, to see if next key is the one (normal with load and source without change) + if (++miCurENUSinx < (int)mcENUSlist.size()) + { + l10nMem_enus_entry& nowEntry = mcENUSlist[miCurENUSinx]; + if (nowEntry.msMsgId == sMsgId && nowEntry.msKey == sUpperKey) + return true; + } + + // Start from beginning of file and to end + l10nMem_file_entry& cCur = mcFileList[miCurFileInx]; + + // Find match with key and text + for (miCurENUSinx = cCur.miStart; miCurENUSinx <= cCur.miEnd; ++miCurENUSinx) + { + l10nMem_enus_entry& cEntry = mcENUSlist[miCurENUSinx]; + if (cEntry.msMsgId == sMsgId && cEntry.msKey == sUpperKey) + return true; + } + + if (bThrow) + throw l10nMem::showError("cannot find key(" + sUpperKey +") with text(" + sMsgId + ")", iLineNo); + return false; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_db::addKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + l10nMem::ENTRY_STATE eStat) +{ + // check file + if (!findFileName(sSourceFile)) + { + // prepare for new entry + miCurENUSinx = mcENUSlist.size(); + miCurFileInx = mcFileList.size(); + + // Create file + mcFileList.push_back(l10nMem_file_entry(sSourceFile, miCurENUSinx)); + + // and add entry at the back (no problem since it is a new file) + mcENUSlist.push_back(l10nMem_enus_entry(sKey, sMsgId, iLineNo, miCurFileInx, + mcLangList.size(), eStat)); + mcFileList[miCurFileInx].miEnd = miCurENUSinx; + } + else + { + int iFsize = mcFileList.size(); + l10nMem_file_entry& curF = mcFileList[miCurFileInx]; + std::vector<l10nMem_enus_entry>::iterator it = mcENUSlist.begin(); + + // file is registred, so we need to add the entry at the end of the file range + curF.miEnd++; + miCurENUSinx = curF.miEnd; + mcENUSlist.insert(it + curF.miEnd, + l10nMem_enus_entry(sKey, sMsgId, iLineNo, miCurFileInx, + mcLangList.size(), eStat)); + for (int i = miCurFileInx+1; i < iFsize; ++i) + { + l10nMem_file_entry& curF2 = mcFileList[i]; + if (curF2.miStart >= curF.miEnd) + curF2.miStart++; + if (curF2.miEnd >= curF.miEnd) + curF2.miEnd++; + } + } +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +int l10nMem_db::prepareMerge() +{ + miCurLangInx = 0; + return mcLangList.size(); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +bool l10nMem_db::getMergeLang(std::string& sLang, + std::string& sMsgStr) +{ + miCurLangInx++; + if (miCurLangInx >= (int)mcLangList.size()) + return false; + + // update pointers + sLang = mcLangList[miCurLangInx].msName; + if (!sMsgStr.size()) + sMsgStr = "NOT TRANSLATED"; + else + sMsgStr = mcENUSlist[miCurENUSinx].mcLangText[miCurLangInx].msMsgStr; + return true; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_db::keyToUpper(std::string& sKey) +{ + int i, iSize; + + iSize = sKey.size(); + for (i = 0; i < iSize; ++i) + { + char ch = sKey[i]; + if (ch == ' ' || ch == '*' || ch == '+' || ch == '%') + sKey[i] = '_'; + else + sKey[i] = toupper(ch); + } +} diff --git a/l10ntools/source/gLang.cxx b/l10ntools/source/gLang.cxx new file mode 100644 index 000000000000..9a3105a8a694 --- /dev/null +++ b/l10ntools/source/gLang.cxx @@ -0,0 +1,48 @@ +/* -*- 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 "gLang.hxx" + + + +/***************************************************************************** + *************************** G L A N G . C X X *************************** + ***************************************************************************** + * This is the main of the l10n localizer program, it is C based and call + * down to classes for handling. + *****************************************************************************/ + + + + +/********************** I M P L E M E N T A T I O N **********************/ +#if defined(UNX) || defined(OS2) +int main(int argc, char *argv[]) +#else +int _cdecl main(int argc, char *argv[]) +#endif +{ + handler cHandler; + + // check command line (exit if problems) + cHandler.checkCommandLine(argc, argv); + + // command line is ok, so execute it + cHandler.run(); +} diff --git a/l10ntools/source/gLexPo.l b/l10ntools/source/gLexPo.l new file mode 100644 index 000000000000..13eb4c6b7196 --- /dev/null +++ b/l10ntools/source/gLexPo.l @@ -0,0 +1,174 @@ +/* -*- 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 . + */ + + +/***************************************************************************** + ********************** L E X D E F I N I T I O N ********************** + ***************************************************************************** + * lex grammar for parsing ressource source files (*.po files) + * file is converted to gConPo_yy.cxx with "flex" + *****************************************************************************/ + +/* + white-space + # translator-comments + #. extracted-comments + #: reference... + #, fuzzy + #| msgid previous-untranslated-string + msgid untranslated-string + msgstr translated-string + + #: lib/error.c:116 + msgid "Unknown system error" + msgstr "Error desconegut del sistema" +*/ + + +/*************** O V E R W R I T I N G F U N C T I O N S ***************/ +%top{ +#include "gConvPo.hxx" + +#define IMPLptr convert_gen_impl::mcImpl +#define LOCptr ((convert_po *)convert_gen_impl::mcImpl) + +/* enlarge token buffer to tokenize whole std::strings */ +#undef YYLMAX +#define YYLMAX 64000 + +/* change reader function (input) to our own version */ +#define YY_INPUT(buf,result,max_size) {int xres; IMPLptr->lexRead(buf, &xres, max_size); result = xres;} + +#define yytext_ptr potext_ptr +#define YY_NO_UNISTD_H 1 +} + +%{ +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +%} + + +/***************************** O P T I O N S *****************************/ +/* 8bit --> allow 8bit characters in the input stream */ +/* noyywrap --> yywrap is not called (single file scan) */ +/* never-interactive --> no check for console output */ +/* prefix= --> yyFlexLexer change name */ +/* --- The following options are for future use (maybe) */ +/* yyclass= --> subClass yyFlexLexer to allow own functions */ +/* c++ --> generate C++ classes */ +%option prefix="po" 8bit noyywrap never-interactive +%array +%p 24000 +%e 1200 +%n 500 + +/*********************** H E L P E R M A C R O S ***********************/ +SPACE [ \t]* +/******************* R U L E S D E F I N I T I O N S *******************/ +%% + + +"\"" { + char c, buildValue[8000]; + int j, i, iLineCnt; + + // loop across multiple "..." and combine them, while keeping the source + for (j = -1, iLineCnt = i = 0; (c = yytext[i]) == '\"';) + { + // build current "..." + for (; (buildValue[++j] = yytext[++i] = c = yyinput()) != '\"';) + if (yytext[i] == '\\') + buildValue[++j] = yytext[++i] = yyinput(); + --j; + + if (!LOCptr->mbExpectId && !LOCptr->mbExpectStr) + break; + + // skip rest of line + for (; (c = yytext[++i] = yyinput()) == ' ' || yytext[i] == '\t' || yytext[i] == '\n';) + if (yytext[i] == '\n') + ++iLineCnt; + } + + if (LOCptr->mbExpectId || LOCptr->mbExpectStr) + { + if (yytext[i] != EOF) + { + unput(yytext[i]); + } + buildValue[j+1] = '\0'; + LOCptr->setValue(buildValue, iLineCnt); + } +} + + +"#,"{SPACE}.*[fF][uU][zZ][zZ][yY] { + LOCptr->setFuzzy(); +} + + +"#:".* { + LOCptr->setKey(yytext); +} + + +[mM][sS][gG][cC][tT][xX][tT].* | +"#*".* | +"# ".* | +"#~".* { + // special comment, just skip +} + + +[mM][sS][gG][iI][dD]{SPACE} { + LOCptr->setMsgId(); +} + + +[mM][sS][gG][sS][tT][rR]{SPACE} { + LOCptr->setMsgStr(); +} + + +\n { + LOCptr->handleNL(); + + // Just to please compiler. + if (false) + REJECT; +} + + +.|\n { +} +%% + + +void dummyJustForCompiler() +{ +// char *txt = NULL; +// yy_flex_strlen(txt); +// yyunput(0, txt); +} + diff --git a/l10ntools/source/gLexSrc.l b/l10ntools/source/gLexSrc.l new file mode 100644 index 000000000000..d68e5d07b5b5 --- /dev/null +++ b/l10ntools/source/gLexSrc.l @@ -0,0 +1,337 @@ +/* -*- 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 . + */ + + +/***************************************************************************** + ********************** L E X D E F I N I T I O N ********************** + ***************************************************************************** + * lex grammar for parsing ressource source files (*.src) + * file is converted to gConSrc_yy.cxx with "flex" + *****************************************************************************/ + + + +/*************** O V E R W R I T I N G F U N C T I O N S ***************/ +%top{ +#include "gConvSrc.hxx" + +#define IMPLptr convert_gen_impl::mcImpl +#define LOCptr ((convert_src *)convert_gen_impl::mcImpl) + +/* enlarge token buffer to tokenize whole std::strings */ +#undef YYLMAX +#define YYLMAX 64000 + +/* change reader function (input) to our own version */ +#define YY_INPUT(buf,result,max_size) {int xres; IMPLptr->lexRead(buf, &xres, max_size); result = (yy_size_t)xres;} + +#define yytext_ptr srctext_ptr +#define YY_NO_UNISTD_H 1 +} + +%{ +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +%} + + + + + +/***************************** O P T I O N S *****************************/ +/* 8bit --> allow 8bit characters in the input stream */ +/* noyywrap --> yywrap is not called (single file scan) */ +/* never-interactive --> no check for console output */ +/* prefix= --> yyFlexLexer change name */ +/* --- The following options are for future use (maybe) */ +/* yyclass= --> subClass yyFlexLexer to allow own functions */ +/* c++ --> generate C++ classes */ +%option prefix="src" 8bit noyywrap never-interactive +%array +%p 24000 +%e 1200 +%n 500 + + +/*********************** H E L P E R M A C R O S ***********************/ +%x CMD +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_-]+ + +/******************* R U L E S D E F I N I T I O N S *******************/ +%% + + + +"/*" { + int i = 1; + for (;;) + { + while (yytext[i] != '*') + yytext[++i] = yyinput(); + yytext[++i] = yyinput(); + if (yytext[i] == '/') + break; + } + yytext[i+1] = '\0'; + + IMPLptr->copySource(yytext); +} + + +"//".* { + IMPLptr->copySource(yytext); +} + + + +"\"" { + char buildValue[8000]; + int j, i; + + // loop across multiple "..." and combine them, while keeping the source + buildValue[0] = yytext[0]; + for (j = i = 0; yytext[i] != ';' ;) + { + // build current "..." + for (; (buildValue[++j] = yytext[++i] = yyinput()) != '\"';) + 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; + } + yytext[++i] = + buildValue[j+1] = '\0'; + LOCptr->setValue(yytext, &buildValue[1]); +} + + + +"{" { + LOCptr->startBlock(yytext); +} + + + +"}"{SPACE}";"* { + LOCptr->stopBlock(yytext); +} + + + +{PRE}"<"{SUF} { + yyless(strlen(yytext)-1); + LOCptr->setListItem(yytext, true); +} + + + +">"{SPACE}";"{SUF} { + yyless(strlen(yytext)-1); + LOCptr->setListItem(yytext, false); +} + + + +\n { + LOCptr->setNL(yytext, false); +} + + + +\\[\r]*\n { + LOCptr->setNL(yytext, true); +} + + + +"["{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} | +{PRE}[cC][hH][eE][cC][kK][bB][oO][xX]{SUF} | +{PRE}[cC][oO][nN][tT][rR][oO][lL]{SUF} | +{PRE}[cC][oO][mM][bB][oO][bB][oO][xX]{SUF} | +{PRE}[dD][oO][cC][kK][iI][nN][gG][wW][iI][nN][dD][oO][wW]{SUF} | +{PRE}[eE][dD][iI][tT]{SUF} | +{PRE}[eE][rR][rR][oO][rR][bB][oO][xX]{SUF} | +{PRE}[fF][iI][xX][eE][dD][tT][eE][xX][tT]{SUF} | +{PRE}[fF][iI][xX][eE][dD][lL][iI][nN][eE]{SUF} | +{PRE}[fF][lL][oO][aA][tT][iI][nN][gG][wW][iI][nN][dD][oO][wW]{SUF} | +{PRE}[gG][rR][oO][uU][pP][bB][oO][xX]{SUF} | +{PRE}[hH][eE][lL][pP][bB][uU][tT][tT][oO][nN]{SUF} | +{PRE}[iI][dD][lL][iI][sS][tT]{SUF} | +{PRE}[iI][mM][aA][gG][eE]{SUF} | +{PRE}[iI][mM][aA][gG][eE][lL][iI][sS][tT]{SUF} | +{PRE}[iI][mM][aA][gG][eE][bB][uU][tT][tT][oO][nN]{SUF} | +{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} | +{PRE}[mM][oO][dD][eE][lL][eE][sS][sS][dD][iI][aA][lL][oO][gG]{SUF} | +{PRE}[mM][oO][rR][eE][bB][uU][tT][tT][oO][nN]{SUF} | +{PRE}[mM][uU][lL][tT][iI][lL][iI][nN][eE][eE][dD][iI][tT]{SUF} | +{PRE}[nN][uU][mM][eE][rR][iI][cC][fF][iI][eE][lL][dD]{SUF} | +{PRE}[oO][kK][bB][uU][tT][tT][oO][nN]{SUF} | +{PRE}[pP][aA][gG][eE][iI][tT][eE][mM]{SUF} | +{PRE}[pP][aA][gG][eE][lL][iI][sS][tT]{SUF} | +{PRE}[pP][uU][sS][hH][bB][uU][tT][tT][oO][nN]{SUF} | +{PRE}[qQ][uU][eE][rR][yY][bB][oO][xX]{SUF} | +{PRE}[rR][aA][dD][iI][oO][bB][uU][tT][tT][oO][nN]{SUF} | +{PRE}[rR][eE][sS][oO][uU][rR][cC][eE]{SUF} | +{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} | +{PRE}[tT][aA][bB][pP][aA][gG][eE]{SUF} | +{PRE}[tT][iI][mM][eE][fF][iI][eE][lL][dD]{SUF} | +{PRE}[tT][oO][oO][lL][bB][oO][xX]{SUF} | +{PRE}[tT][oO][oO][lL][bB][oO][xX][iI][tT][eE][mM]{SUF} | +{PRE}[tT][rR][iI][sS][tT][aA][tT][eE][bB][oO][xX]{SUF} | +{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=]+ { + IMPLptr->copySource(yytext); +} + +<CMD>.|\n|\r { + yyless(0); + BEGIN(INITIAL); +} + + + +{PRE}[hH][eE][lL][pP][iI][dD]{SUF} { + yyless(strlen(yytext)-1); + LOCptr->setId(yytext, false); +} + + + +{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); +} + + + +{PRE}[cC][uU][sS][tT][oO][mM][uU][nN][iI][tT][tT][eE][xX][tT]{SUFT} | +{PRE}[hH][eE][lL][pP][tT][eE][xX][tT]{SUFT} | +{PRE}[mM][eE][sS][sS][aA][gG][eE]{SUFT} | +{PRE}[qQ][uU][iI][cC][kK][hH][eE][lL][pP][tT][eE][xX][tT]{SUFT} | +{PRE}[tT][eE][xX][tT]{SUFT} | +{PRE}[tT][iI][tT][lL][eE]{SUFT} { + yyless(strlen(yytext)-1); + LOCptr->setText(yytext); +} + + + +{PRE}[fF][iI][lL][tT][eE][rR][lL][iI][sS][tT]{SUFT} | +{PRE}[iI][tT][eE][mM][lL][iI][sS][tT]{SUFT} | +{PRE}[sS][tT][yY][lL][eE][fF][aA][mM][iI][lL][yY][lL][iI][sS][tT]{SUF} { + yyless(strlen(yytext)-1); + LOCptr->setList(yytext); +} + + + +{PRE}[pP][aA][iI][rR][eE][dD][lL][iI][sS][tT]{SUFT} | +{PRE}[sS][tT][rR][iI][nN][gG][lL][iI][sS][tT]{SUFT} { + yyless(strlen(yytext)-1); + LOCptr->setList(yytext); +} + + + +{PRE}"#define"{SUF} { + yyless(strlen(yytext)-1); + LOCptr->setMacro(yytext); + BEGIN(CMD); +} + + + +{KEYID} { + LOCptr->setName(yytext); +} + + + +. { + IMPLptr->copySource(yytext); + + // Just to please compiler. + if (false) + REJECT; +} + +%% + + + +void src_dummyJustForCompiler() +{ +// char *txt = NULL; +// yy_flex_strlen(txt); +// yyunput(0, txt); +} diff --git a/l10ntools/source/gLexTree.l b/l10ntools/source/gLexTree.l new file mode 100644 index 000000000000..c47d9c09abd9 --- /dev/null +++ b/l10ntools/source/gLexTree.l @@ -0,0 +1,165 @@ +/* -*- 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 . + */ + + +/***************************************************************************** + ********************** L E X D E F I N I T I O N ********************** + ***************************************************************************** + * lex grammar for parsing ressource source files (*.tree files) + * file is converted to gConTree_yy.cxx with "flex" + *****************************************************************************/ + + + +/*************** O V E R W R I T I N G F U N C T I O N S ***************/ +%top{ +#include "gConvTree.hxx" + +#define IMPLptr convert_gen_impl::mcImpl +#define LOCptr ((convert_tree *)convert_gen_impl::mcImpl) + +/* enlarge token buffer to tokenize whole std::strings */ +#undef YYLMAX +#define YYLMAX 64000 + +/* change reader function (input) to our own version */ +#define YY_INPUT(buf,result,max_size) {int xres; IMPLptr->lexRead(buf, &xres, max_size); result = xres;} + +#define yytext_ptr treetext_ptr +#define YY_NO_UNISTD_H 1 +} + +%{ +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +%} + + + + + +/***************************** O P T I O N S *****************************/ +/* 8bit --> allow 8bit characters in the input stream */ +/* noyywrap --> yywrap is not called (single file scan) */ +/* never-interactive --> no check for console output */ +/* prefix= --> yyFlexLexer change name */ +/* --- The following options are for future use (maybe) */ +/* yyclass= --> subClass yyFlexLexer to allow own functions */ +/* c++ --> generate C++ classes */ +%option prefix="tree" 8bit noyywrap never-interactive +%array +%p 24000 +%e 1200 +%n 500 + + + +/*********************** H E L P E R M A C R O S ***********************/ +SP [ \t]* +IDENT [\.a-zA-Z0-9_-]+ +/******************* R U L E S D E F I N I T I O N S *******************/ +%% + + +"\"" { + int j; + + // build current "..." + for (j = -1; (yytext[++j] = yyinput()) != '\"';) + if (yytext[j] == '\\') + yytext[++j] = yyinput(); + + yytext[j+1] = '\0'; + LOCptr->setString(yytext); +} + + + +\> { + LOCptr->setState(yytext, convert_tree::STATE_TAG_VALUE, convert_tree::STATE_VAL_NONE); +} + + + +"id=" { + LOCptr->setState(yytext, convert_tree::STATE_TAG_NONE, convert_tree::STATE_VAL_ID); +} + + + +"application=" { + LOCptr->setState(yytext, convert_tree::STATE_TAG_NONE, convert_tree::STATE_VAL_APPL); +} + + + +"title=" { + LOCptr->setState(yytext, convert_tree::STATE_TAG_NONE, convert_tree::STATE_VAL_TITLE); +} + + + +"<help_section " { + LOCptr->setState(yytext, convert_tree::STATE_TAG_HELPSEC, convert_tree::STATE_VAL_NONE); +} + + + +"<node " { + LOCptr->setState(yytext, convert_tree::STATE_TAG_NODE, convert_tree::STATE_VAL_NONE); +} + + + +"<topic " { + LOCptr->setState(yytext, convert_tree::STATE_TAG_TOPIC, convert_tree::STATE_VAL_NONE); +} + + + +"</topic" { + LOCptr->setValue(yytext); +} + + + +.|\n { + LOCptr->copySourceSpecial(yytext, 0); + + // Just to please compiler. + if (false) + REJECT; +} + + + +%% + + + +void tree_dummyJustForCompiler() +{ +// char *txt = NULL; +// yy_flex_strlen(txt); +// yyunput(0, txt); +} diff --git a/l10ntools/source/gLexUlf.l b/l10ntools/source/gLexUlf.l new file mode 100644 index 000000000000..34d63caa016d --- /dev/null +++ b/l10ntools/source/gLexUlf.l @@ -0,0 +1,144 @@ +/* -*- 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 . + */ + + +/***************************************************************************** + ********************** L E X D E F I N I T I O N ********************** + ***************************************************************************** + * lex grammar for parsing ressource source files (*.ulf files) + * file is converted to gConUlf_yy.cxx with "flex" + *****************************************************************************/ + + + +/*************** O V E R W R I T I N G F U N C T I O N S ***************/ +%top{ +#include "gConvUlf.hxx" + +#define IMPLptr convert_gen_impl::mcImpl +#define LOCptr ((convert_ulf *)convert_gen_impl::mcImpl) + +/* enlarge token buffer to tokenize whole std::strings */ +#undef YYLMAX +#define YYLMAX 64000 + +/* change reader function (input) to our own version */ +#define YY_INPUT(buf,result,max_size) {int xres; IMPLptr->lexRead(buf, &xres, max_size); result = xres;} + +#define yytext_ptr ulftext_ptr +#define YY_NO_UNISTD_H 1 +} + +%{ +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +%} + + + + + +/***************************** O P T I O N S *****************************/ +/* 8bit --> allow 8bit characters in the input stream */ +/* noyywrap --> yywrap is not called (single file scan) */ +/* never-interactive --> no check for console output */ +/* prefix= --> yyFlexLexer change name */ +/* --- The following options are for future use (maybe) */ +/* yyclass= --> subClass yyFlexLexer to allow own functions */ +/* c++ --> generate C++ classes */ +%option prefix="ulf" 8bit noyywrap never-interactive +%array +%p 24000 +%e 1200 +%n 500 + +/*********************** H E L P E R M A C R O S ***********************/ +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]|[0-9]) +KEYID [a-zA-Z0-9_-]+ +/******************* R U L E S D E F I N I T I O N S *******************/ +%% + + + +"/*" { + int i = 1; + for (;;) + { + while (yytext[i] != '*') + yytext[++i] = yyinput(); + yytext[++i] = yyinput(); + if (yytext[i] == '/') + break; + } + yytext[i+1] = '\0'; + + IMPLptr->copySource(yytext); +} + + + +"\"".* { + LOCptr->setValue(yytext); +} + + + +"["[^\]]+"]" { + LOCptr->setKey(yytext); +} + + + +"en-US"[ \t]*"=" { + LOCptr->setText(yytext, true); +} + + + +[a-zA-Z_\-]+[ \t]*"=" { + LOCptr->setText(yytext, false); +} + + + +.|\n { + IMPLptr->copySource(yytext); + + // Just to please compiler. + if (false) + REJECT; +} +%% + + + +void ulf_dummyJustForCompiler() +{ +// char *txt = NULL; +// yy_flex_strlen(txt); +// yyunput(0, txt); +} diff --git a/l10ntools/source/gLexXcs.l b/l10ntools/source/gLexXcs.l new file mode 100644 index 000000000000..07228b2b7f88 --- /dev/null +++ b/l10ntools/source/gLexXcs.l @@ -0,0 +1,111 @@ +/* -*- 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 . + */ + + +/***************************************************************************** + ********************** L E X D E F I N I T I O N ********************** + ***************************************************************************** + * lex grammar for parsing ressource source files (*.xrm files) + * file is converted to gConXcs_yy.cxx with "flex" + *****************************************************************************/ + + + +/*************** O V E R W R I T I N G F U N C T I O N S ***************/ +%top{ +#include "gConvXcs.hxx" + +#define IMPLptr convert_gen_impl::mcImpl +#define LOCptr ((convert_xcs *)convert_gen_impl::mcImpl) + +/* enlarge token buffer to tokenize whole std::strings */ +#undef YYLMAX +#define YYLMAX 64000 + +/* change reader function (input) to our own version */ +#define YY_INPUT(buf,result,max_size) {int xres; IMPLptr->lexRead(buf, &xres, max_size); result = xres;} +#define yytext_ptr xcstext_ptr +#define YY_NO_UNISTD_H 1 +} + +%{ +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +%} + + + + + +/***************************** O P T I O N S *****************************/ +/* 8bit --> allow 8bit characters in the input stream */ +/* noyywrap --> yywrap is not called (single file scan) */ +/* never-interactive --> no check for console output */ +/* prefix= --> yyFlexLexer change name */ +/* --- The following options are for future use (maybe) */ +/* yyclass= --> subClass yyFlexLexer to allow own functions */ +/* c++ --> generate C++ classes */ +%option prefix="xcs" 8bit noyywrap never-interactive +%array +%p 24000 +%e 1200 +%n 500 + + + +/******************* R U L E S D E F I N I T I O N S *******************/ +%% + +"<prop"[^>]*> { + LOCptr->setKey(yytext); +} + +"</prop>" { + LOCptr->unsetKey(yytext); +} + +"<value"[^>]*> { + LOCptr->startCollectData(yytext); +} + +"</value>" { + LOCptr->stopCollectData(yytext); +} + +.|\n { + IMPLptr->copySource(yytext); + + // Just to please compiler. + if (false) + REJECT; +} +%% + + + +void xcs_dummyJustForCompiler() +{ +// char *txt = NULL; +// yy_flex_strlen(txt); +// yyunput(0, txt); +} diff --git a/l10ntools/source/gLexXcu.l b/l10ntools/source/gLexXcu.l new file mode 100644 index 000000000000..c5579076dab5 --- /dev/null +++ b/l10ntools/source/gLexXcu.l @@ -0,0 +1,161 @@ +/* -*- 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 . + */ + + +/***************************************************************************** + ********************** L E X D E F I N I T I O N ********************** + ***************************************************************************** + * lex grammar for parsing ressource source files (*.xrm files) + * file is converted to gConXcu_yy.cxx with "flex" + *****************************************************************************/ + + + +/*************** O V E R W R I T I N G F U N C T I O N S ***************/ +%top{ +#include "gConvXcu.hxx" + +#define IMPLptr convert_gen_impl::mcImpl +#define LOCptr ((convert_xcu *)convert_gen_impl::mcImpl) + +/* enlarge token buffer to tokenize whole std::strings */ +#undef YYLMAX +#define YYLMAX 64000 + +/* change reader function (input) to our own version */ +#define YY_INPUT(buf,result,max_size) {int xres; IMPLptr->lexRead(buf, &xres, max_size); result = xres;} + +#define yytext_ptr xcutext_ptr +#define YY_NO_UNISTD_H 1 +} + +%{ +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +%} + + + + + +/***************************** O P T I O N S *****************************/ +/* 8bit --> allow 8bit characters in the input stream */ +/* noyywrap --> yywrap is not called (single file scan) */ +/* never-interactive --> no check for console output */ +/* prefix= --> yyFlexLexer change name */ +/* --- The following options are for future use (maybe) */ +/* yyclass= --> subClass yyFlexLexer to allow own functions */ +/* c++ --> generate C++ classes */ +%option prefix="xcu" 8bit noyywrap never-interactive +%array +%p 24000 +%e 1200 +%n 500 + + + +/*********************** H E L P E R M A C R O S ***********************/ +SPACE [ \t]* +NAME .*"oor:name="\"[^\"]+\"{SPACE} +FIN [^/>]*">" +/******************* R U L E S D E F I N I T I O N S *******************/ +%% + + + +"component-data" { + LOCptr->addLevel(); + IMPLptr->copySource(yytext, false); +} + + + +"<oor:component-data"{NAME} { + LOCptr->addLevel(); + LOCptr->pushKey(yytext); +} + + + +"<prop"{NAME}{FIN} | +"<node"{NAME}{FIN} { + LOCptr->pushKey(yytext); +} + + + +"</oor:component-data" | +"</prop" | +"</node" { + LOCptr->popKey(yytext); +} + + +"<value xml:lang="\"[^\"]+\"[^>]*">" { + LOCptr->startCollectData(yytext); +} + + + +"</value>" { + LOCptr->stopCollectData(yytext); +} + + + +"&" | +"'" | +">" | +"<" | +""" { + LOCptr->copySpecial(yytext); +} + + + +({SPACE}\n{SPACE})+ { + LOCptr->copyNL(yytext); +} + + + +. { + IMPLptr->copySource(yytext, LOCptr->mbNoCollectingData); + + // Just to please compiler. + if (false) + REJECT; +} + + + +%% + + + +void xcu_dummyJustForCompiler() +{ +// char *txt = NULL; +// yy_flex_strlen(txt); +// yyunput(0, txt); +} diff --git a/l10ntools/source/gLexXhp.l b/l10ntools/source/gLexXhp.l new file mode 100644 index 000000000000..fbcd8fa26886 --- /dev/null +++ b/l10ntools/source/gLexXhp.l @@ -0,0 +1,197 @@ +/* -*- 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 . + */ + + +/***************************************************************************** + ********************** L E X D E F I N I T I O N ********************** + ***************************************************************************** + * lex grammar for parsing ressource source files (*.xrm files) + * file is converted to gConXrm_yy.cxx with "flex" + *****************************************************************************/ + + + +/*************** O V E R W R I T I N G F U N C T I O N S ***************/ +%top{ +#include "gConvXhp.hxx" + +#define IMPLptr convert_gen_impl::mcImpl +#define LOCptr ((convert_xhp *)convert_gen_impl::mcImpl) + +/* enlarge token buffer to tokenize whole std::strings */ +#undef YYLMAX +#define YYLMAX 64000 + +/* change reader function (input) to our own version */ +#define YY_INPUT(buf,result,max_size) {int xres; IMPLptr->lexRead(buf, &xres, max_size); result = xres;} + +#define yytext_ptr xhptext_ptr +#define YY_NO_UNISTD_H 1 +} + +%{ +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +%} + + + + +/***************************** O P T I O N S *****************************/ +/* 8bit --> allow 8bit characters in the input stream */ +/* noyywrap --> yywrap is not called (single file scan) */ +/* never-interactive --> no check for console output */ +/* prefix= --> yyFlexLexer change name */ +/* --- The following options are for future use (maybe) */ +/* yyclass= --> subClass yyFlexLexer to allow own functions */ +/* c++ --> generate C++ classes */ +%option prefix="xhp" 8bit noyywrap never-interactive +%array +%p 24000 +%e 1200 +%n 500 + + + +/*********************** H E L P E R M A C R O S ***********************/ +SP [ \t]* +IDENT [\.a-zA-Z0-9_-]+ +/******************* R U L E S D E F I N I T I O N S *******************/ +%% + + + +\" { + LOCptr->setString(yytext); +} + + + +\< { + LOCptr->openTag(yytext); +} + + + +\/\> { + LOCptr->closeTagNOvalue(yytext); +} + + + +\> { + LOCptr->closeTag(yytext); +} + + + +"id="{SP}\"{SP}{IDENT}{SP}\" { + LOCptr->setId(yytext); +} + + + +"xml-lang="{SP}\"{SP}{IDENT}{SP}\" { + LOCptr->setLang(yytext); +} + + + +"oldref="{SP}\"{SP}{IDENT}{SP}\" { + LOCptr->setRef(yytext); +} + + +"<title " | +"<bookmark " | +"<paragraph " { + LOCptr->openTransTag(yytext); +} + + +"</title>" | +"</bookmark>" | +"</paragraph>" { + LOCptr->closeTransTag(yytext); +} + + + +"<comment>" { + LOCptr->startComment(yytext); +} + + + +"</comment>" { + LOCptr->stopComment(yytext); +} + + + +"localize=\"false\"" { + LOCptr->stopTransTag(yytext); +} + + + +"&" | +">" | +"<" | +""" { + LOCptr->handleSpecial(yytext); +} + + +\r*\n\t* { + LOCptr->handleDataEnd(yytext); +} + + + +\\ { + LOCptr->duplicate(yytext); +} + + + +.|\n { + LOCptr->copySourceSpecial(yytext, 0); + + // Just to please compiler. + if (false) + REJECT; +} + + + +%% + + + +void xhp_dummyJustForCompiler() +{ +// char *txt = NULL; +// yy_flex_strlen(txt); +// yyunput(0, txt); +} diff --git a/l10ntools/source/gLexXrm.l b/l10ntools/source/gLexXrm.l new file mode 100644 index 000000000000..64520c1cd326 --- /dev/null +++ b/l10ntools/source/gLexXrm.l @@ -0,0 +1,132 @@ +/* -*- 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 . + */ + + +/***************************************************************************** + ********************** L E X D E F I N I T I O N ********************** + ***************************************************************************** + * lex grammar for parsing ressource source files (*.xrm files) + * file is converted to gConXrm_yy.cxx with "flex" + *****************************************************************************/ + + + +/*************** O V E R W R I T I N G F U N C T I O N S ***************/ +%top{ +#include "gConvXrm.hxx" + +#define IMPLptr convert_gen_impl::mcImpl +#define LOCptr ((convert_xrm *)convert_gen_impl::mcImpl) + +/* enlarge token buffer to tokenize whole std::strings */ +#undef YYLMAX +#define YYLMAX 64000 + +/* change reader function (input) to our own version */ +#define YY_INPUT(buf,result,max_size) {int xres; IMPLptr->lexRead(buf, &xres, max_size); result = xres;} + +#define yytext_ptr xrmtext_ptr +#define YY_NO_UNISTD_H 1 +} + +%{ +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +%} + + + + +/***************************** O P T I O N S *****************************/ +/* 8bit --> allow 8bit characters in the input stream */ +/* noyywrap --> yywrap is not called (single file scan) */ +/* never-interactive --> no check for console output */ +/* prefix= --> yyFlexLexer change name */ +/* --- The following options are for future use (maybe) */ +/* yyclass= --> subClass yyFlexLexer to allow own functions */ +/* c++ --> generate C++ classes */ +%option prefix="xrm" 8bit noyywrap never-interactive +%array +%p 24000 +%e 1200 +%n 500 + +/*********************** H E L P E R M A C R O S ***********************/ +IDENT [a-zA-Z0-9_-]* +NAME \"{IDENT}\" +SP [ \t]* +/******************* R U L E S D E F I N I T I O N S *******************/ +%% + + + +"id"{SP}"="{SP}{NAME} { + LOCptr->setId(yytext); +} + + + +"lang"{SP}"="{SP}{NAME} { + LOCptr->setLang(yytext); +} + + +"<title " | +"<h"[0-9]" " | +"<p " { + LOCptr->setTag(yytext); +} + + + +"</title>"[ \t\r]*[\n] | +"</h"[0-9]">"[ \t\r]*[\n] | +"</p>"[ \t\r]*[\n] { + LOCptr->stopCollectData(yytext); +} + + + +">" { + LOCptr->startCollectData(yytext); +} + + + +.|\n { + IMPLptr->copySource(yytext, LOCptr->mbNoCollectingData); + + // Just to please compiler. + if (false) + REJECT; +} + + +%% + +void xrm_dummyJustForCompiler() +{ +// char *txt = NULL; +// yy_flex_strlen(txt); +// yyunput(0, txt); +} |