Files
libreoffice/l10ntools/inc/export.hxx

390 lines
10 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-09-27 13:52:10 +01:00
/*
* This file is part of the LibreOffice project.
2001-06-26 11:56:08 +00:00
*
2012-09-27 13:52:10 +01:00
* 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/.
2001-06-26 11:56:08 +00:00
*
2012-09-27 13:52:10 +01:00
* This file incorporates work covered by the following license notice:
2001-06-26 11:56:08 +00:00
*
2012-09-27 13:52:10 +01:00
* 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 .
*/
2001-06-26 11:56:08 +00:00
#ifndef _EXPORT_HXX
#define _EXPORT_HXX
#include "sal/config.h"
#include "po.hxx"
2012-02-08 22:07:23 +01:00
#include <cstddef>
#include <fstream>
#include <osl/file.hxx>
#include <osl/file.h>
2001-06-26 11:56:08 +00:00
2011-02-06 15:20:31 +01:00
#include <boost/unordered_map.hpp>
#include <iterator> /* std::iterator*/
#include <set> /* std::set*/
#include <vector> /* std::vector*/
#include <queue>
#include <string>
2001-06-26 11:56:08 +00:00
#include <unistd.h>
#ifdef WNT
#include <direct.h>
#endif
#define NO_TRANSLATE_ISO "x-no-translate"
2001-06-26 11:56:08 +00:00
class MergeEntrys;
class MergeData;
typedef boost::unordered_map<OString, OString, OStringHash>
OStringHashMap;
2002-11-18 10:49:56 +00:00
typedef boost::unordered_map<OString, bool, OStringHash>
OStringBoolHashMap;
typedef boost::unordered_map<OString, MergeData*, OStringHash>
2012-01-25 21:01:10 +00:00
MergeDataHashMap;
2001-06-26 11:56:08 +00:00
#define SOURCE_LANGUAGE "en-US"
#define X_COMMENT "x-comment"
#define LIST_REFID "LIST_REFID"
2001-06-26 11:56:08 +00:00
typedef OStringHashMap ExportListEntry;
typedef ::std::vector< ExportListEntry* > ExportListBase;
2001-06-26 11:56:08 +00:00
//
// class ExportList
//
class ExportList
{
private:
ExportListBase maList;
2012-02-08 22:07:23 +01:00
std::size_t nSourceLanguageListEntryCount;
public:
ExportList() { nSourceLanguageListEntryCount = 0; }
2012-02-08 22:07:23 +01:00
std::size_t GetSourceLanguageListEntryCount() { return nSourceLanguageListEntryCount; }
void NewSourceLanguageListEntry() { nSourceLanguageListEntryCount++; }
size_t size() const { return maList.size(); }
void push_back( ExportListEntry* item ) { maList.push_back( item ); }
ExportListEntry* operator [] ( size_t i )
{
return ( i < maList.size() ) ? maList[ i ] : NULL;
}
};
2001-06-26 11:56:08 +00:00
#define REFID_NONE 0xFFFF
//
// struct ResData
//
/******************************************************************************
* Purpose: holds mandatory data to export a single res (used with ResStack)
******************************************************************************/
#define ID_LEVEL_NULL 0x0000
#define ID_LEVEL_AUTOID 0x0001
#define ID_LEVEL_TEXT 0x0002
#define ID_LEVEL_FIELDNAME 0x0003
#define ID_LEVEL_ACCESSPATH 0x0004
#define ID_LEVEL_IDENTIFIER 0x0005
#define ID_LEVEL_LISTINDEX 0x0006
class ResData
{
public:
ResData( const OString &rGId );
ResData( const OString &rGId , const OString &rFilename );
2001-06-26 11:56:08 +00:00
~ResData();
sal_Bool SetId(const OString &rId, sal_uInt16 nLevel);
2001-06-26 11:56:08 +00:00
sal_uInt16 nIdLevel;
sal_Bool bChild;
sal_Bool bChildWithText;
2001-06-26 11:56:08 +00:00
sal_Bool bText;
sal_Bool bHelpText;
sal_Bool bQuickHelpText;
sal_Bool bTitle;
sal_Bool bList;
2001-06-26 11:56:08 +00:00
OString sResTyp;
OString sId;
OString sGId;
OString sHelpId;
OString sFilename;
2001-06-26 11:56:08 +00:00
OStringHashMap sText;
2001-06-26 11:56:08 +00:00
OStringHashMap sHelpText;
2001-06-26 11:56:08 +00:00
OStringHashMap sQuickHelpText;
2001-06-26 11:56:08 +00:00
OStringHashMap sTitle;
2001-06-26 11:56:08 +00:00
OString sTextTyp;
2001-06-26 11:56:08 +00:00
ExportList *pStringList;
ExportList *pUIEntries;
ExportList *pItemList;
ExportList *pFilterList;
ExportList *pPairedList;
2001-06-26 11:56:08 +00:00
};
//
// class Export
//
/******************************************************************************
* Purpose: syntax check and export of *.src, called from lexer
******************************************************************************/
#define LIST_NON 0x0000
#define LIST_STRING 0x0001
#define LIST_FILTER 0x0002
#define LIST_ITEM 0x0004
#define LIST_PAIRED 0x0005
2001-06-26 11:56:08 +00:00
#define LIST_UIENTRIES 0x0008
#define STRING_TYP_TEXT 0x0010
#define STRING_TYP_HELPTEXT 0x0020
#define STRING_TYP_QUICKHELPTEXT 0x0040
#define STRING_TYP_TITLE 0x0080
#define MERGE_MODE_NORMAL 0x0000
#define MERGE_MODE_LIST 0x0001
typedef ::std::vector< ResData* > ResStack;
2001-06-26 11:56:08 +00:00
// forwards
class ParserQueue;
2001-06-26 11:56:08 +00:00
class Export
{
private:
union
{
std::ofstream* mSimple;
PoOfstream* mPo;
} aOutput;
2001-06-26 11:56:08 +00:00
ResStack aResStack; // stack for parsing recursive
sal_Bool bDefine; // cur. res. in a define?
sal_Bool bNextMustBeDefineEOL; // define but no \ at lineend
2012-02-08 22:07:23 +01:00
std::size_t nLevel; // res. recursiv? how deep?
sal_uInt16 nList; // cur. res. is String- or FilterList
OString m_sListLang;
2012-02-08 22:07:23 +01:00
std::size_t nListIndex;
std::size_t nListLevel;
bool bSkipFile;
sal_Bool bMergeMode;
OString sMergeSrc;
OString sLastListLine;
sal_Bool bError; // any errors while export?
sal_Bool bReadOver;
sal_Bool bDontWriteOutput;
OString sLastTextTyp;
OString sFilename;
OString sLanguages;
std::vector<OString> aLanguages;
2001-06-26 11:56:08 +00:00
sal_Bool WriteData( ResData *pResData, sal_Bool bCreateNew = sal_False );// called befor dest. cur ResData
sal_Bool WriteExportList( ResData *pResData, ExportList *pExportList,
const OString &rTyp, sal_Bool bCreateNew = sal_False );
2001-06-26 11:56:08 +00:00
OString MergePairedList( OString const & sLine , OString const & sText );
OString FullId(); // creates cur. GID
2001-06-26 11:56:08 +00:00
OString GetPairedListID(const OString & rText);
OString GetPairedListString(const OString& rText);
OString StripList(const OString& rText);
void InsertListEntry(const OString &rText, const OString &rLine);
void CleanValue( OString &rValue );
OString GetText(const OString &rSource, int nToken);
2001-06-26 11:56:08 +00:00
sal_Bool PrepareTextToMerge(OString &rText, sal_uInt16 nTyp,
OString &rLangIndex, ResData *pResData);
void ResData2Output( MergeEntrys *pEntry, sal_uInt16 nType, const OString& rTextType );
void MergeRest( ResData *pResData, sal_uInt16 nMode = MERGE_MODE_NORMAL );
void ConvertMergeContent( OString &rText );
void ConvertExportContent( OString &rText );
2001-06-26 11:56:08 +00:00
void WriteToMerged(const OString &rText , bool bSDFContent);
2001-06-26 11:56:08 +00:00
void SetChildWithText();
void CutComment( OString &rText );
2001-06-26 11:56:08 +00:00
public:
Export( const OString &rOutput );
Export(const OString &rMergeSource, const OString &rOutput, const OString &rLanguage);
2001-06-26 11:56:08 +00:00
~Export();
void Init();
int Execute( int nToken, const char * pToken ); // called from lexer
void SetError() { bError = sal_True; }
sal_Bool GetError() { return bError; }
ParserQueue* pParseQueue; // public!!
2001-06-26 11:56:08 +00:00
};
//
// class MergeEntrys
2001-06-26 11:56:08 +00:00
//
/**
* Purpose: holds information of data to merge
*/
2001-06-26 11:56:08 +00:00
class MergeEntrys
2001-06-26 11:56:08 +00:00
{
friend class MergeDataFile;
private:
OStringHashMap sText;
OStringBoolHashMap bTextFirst;
OStringHashMap sQuickHelpText;
OStringBoolHashMap bQuickHelpTextFirst;
OStringHashMap sTitle;
OStringBoolHashMap bTitleFirst;
2001-06-26 11:56:08 +00:00
public:
MergeEntrys(){};
void InsertEntry(const OString &rId, const OString &rText,
const OString &rQuickHelpText, const OString &rTitle)
2012-01-30 20:44:22 +00:00
{
2012-01-30 20:44:22 +00:00
sText[ rId ] = rText;
bTextFirst[ rId ] = true;
sQuickHelpText[ rId ] = rQuickHelpText;
bQuickHelpTextFirst[ rId ] = true;
sTitle[ rId ] = rTitle;
bTitleFirst[ rId ] = true;
}
sal_Bool GetText( OString &rReturn, sal_uInt16 nTyp, const OString &nLangIndex, sal_Bool bDel = sal_False );
static OString GetQTZText(const ResData& rResData, const OString& rOrigText);
2001-06-26 11:56:08 +00:00
};
//
// class MergeData
//
/******************************************************************************
* Purpose: holds information of data to merge (one resource)
2001-06-26 11:56:08 +00:00
******************************************************************************/
class MergeDataFile;
class MergeData
2001-06-26 11:56:08 +00:00
{
public:
OString sTyp;
OString sGID;
OString sLID;
OString sFilename;
MergeEntrys* pMergeEntrys;
2001-06-26 11:56:08 +00:00
public:
MergeData( const OString &rTyp, const OString &rGID, const OString &rLID , const OString &rFilename );
2001-06-26 11:56:08 +00:00
~MergeData();
MergeEntrys* GetMergeEntries();
2001-06-26 11:56:08 +00:00
sal_Bool operator==( ResData *pData );
2001-06-26 11:56:08 +00:00
};
//
// class MergeDataFile
//
/******************************************************************************
* Purpose: holds information of data to merge
******************************************************************************/
class MergeDataFile
2001-06-26 11:56:08 +00:00
{
private:
2012-01-25 07:58:34 +00:00
MergeDataHashMap aMap;
std::set<OString> aLanguageSet;
MergeData *GetMergeData( ResData *pResData , bool bCaseSensitve = false );
void InsertEntry(const OString &rTYP, const OString &rGID,
const OString &rLID, const OString &nLang,
const OString &rTEXT, const OString &rQHTEXT,
const OString &rTITLE, const OString &sFilename,
bool bCaseSensitive);
public:
explicit MergeDataFile(
const OString &rFileName, const OString& rFile,
bool bCaseSensitive, bool bWithQtz = true );
~MergeDataFile();
std::vector<OString> GetLanguages() const;
const MergeDataHashMap& getMap() const { return aMap; }
MergeEntrys *GetMergeEntrys( ResData *pResData );
MergeEntrys *GetMergeEntrysCaseSensitive( ResData *pResData );
static OString CreateKey(const OString& rTYP, const OString& rGID,
const OString& rLID, const OString& rFilename , bool bCaseSensitive = false);
2001-06-26 11:56:08 +00:00
};
class QueueEntry
{
public:
QueueEntry(int nTypVal, const OString &rLineVal)
2012-01-30 20:44:22 +00:00
: nTyp(nTypVal), sLine(rLineVal)
{
}
int nTyp;
OString sLine;
};
class ParserQueue
{
public:
ParserQueue( Export& aExportObj );
~ParserQueue();
inline void Push( const QueueEntry& aEntry );
bool bCurrentIsM; // public ?
bool bNextIsM; // public ?
bool bLastWasM; // public ?
bool bMflag; // public ?
void Close();
private:
// Future / Next
std::queue<QueueEntry>* aQueueNext;
// Current
std::queue<QueueEntry>* aQueueCur;
// Ref
std::queue<QueueEntry>* aQref;
Export& aExport;
bool bStart;
inline void Pop( std::queue<QueueEntry>& aQueue );
};
2001-06-26 11:56:08 +00:00
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */