1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #ifndef SOLTOOLS_GI_PARSE_HXX 28*cdf0e10cSrcweir #define SOLTOOLS_GI_PARSE_HXX 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "simstr.hxx" 31*cdf0e10cSrcweir #include "gilacces.hxx" 32*cdf0e10cSrcweir #include <fstream> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir class GenericInfoList_Builder; 35*cdf0e10cSrcweir class GenericInfoList_Browser; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir /** Reads generic information files into a simple structure in memory. 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir Information files used by this parser have the following format: 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir key [value] 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir key [value] 44*cdf0e10cSrcweir key [value] 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir key [value] 47*cdf0e10cSrcweir ... 48*cdf0e10cSrcweir ... 49*cdf0e10cSrcweir } 50*cdf0e10cSrcweir } 51*cdf0e10cSrcweir key [value] 52*cdf0e10cSrcweir ... 53*cdf0e10cSrcweir ... 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir */ 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir class GenericInfo_Parser : public GenericInfoParseTypes 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir public: 61*cdf0e10cSrcweir typedef unsigned long UINT32; 62*cdf0e10cSrcweir typedef short INT16; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir GenericInfo_Parser(); 65*cdf0e10cSrcweir ~GenericInfo_Parser(); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir /** reads a information file and stores the data in a 68*cdf0e10cSrcweir List_GenericInfo 69*cdf0e10cSrcweir */ 70*cdf0e10cSrcweir bool LoadList( 71*cdf0e10cSrcweir GenericInfoList_Builder & 72*cdf0e10cSrcweir o_rResult, 73*cdf0e10cSrcweir const Simstr & i_sSourceFileName ); 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir /** save the InformationList to rSourceFile 76*cdf0e10cSrcweir returns false on error 77*cdf0e10cSrcweir */ 78*cdf0e10cSrcweir bool SaveList( 79*cdf0e10cSrcweir const Simstr & i_rOutputFile, 80*cdf0e10cSrcweir GenericInfoList_Browser & 81*cdf0e10cSrcweir io_rListBrowser ); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir E_Error GetLastError( 84*cdf0e10cSrcweir UINT32 * o_pErrorLine = 0 ) const; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir private: 87*cdf0e10cSrcweir enum E_LineType 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir lt_empty = 0, 90*cdf0e10cSrcweir lt_key, 91*cdf0e10cSrcweir lt_open_list, 92*cdf0e10cSrcweir lt_close_list, 93*cdf0e10cSrcweir lt_comment 94*cdf0e10cSrcweir }; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir void SetError( 97*cdf0e10cSrcweir E_Error i_eError ); 98*cdf0e10cSrcweir void ResetState( 99*cdf0e10cSrcweir GenericInfoList_Builder & 100*cdf0e10cSrcweir io_rResult ); 101*cdf0e10cSrcweir void ResetState( 102*cdf0e10cSrcweir GenericInfoList_Browser & 103*cdf0e10cSrcweir io_rSrc ); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir void ReadLine(); 106*cdf0e10cSrcweir bool InterpretLine(); 107*cdf0e10cSrcweir E_LineType ClassifyLine(); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir void ReadKey(); 110*cdf0e10cSrcweir void PushLevel_Read(); /// When list is opened by '{': 111*cdf0e10cSrcweir void PopLevel_Read(); /// When list is closed by '}': 112*cdf0e10cSrcweir void AddCurLine2CurComment(); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir void WriteList( 115*cdf0e10cSrcweir std::ostream & o_rFile ); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir void PushLevel_Write(); /// When SubList is pushed in pResource 118*cdf0e10cSrcweir void PopLevel_Write(); /// When SubList is popped in pResource 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void WriteComment( 121*cdf0e10cSrcweir std::ostream & o_rFile, 122*cdf0e10cSrcweir const char * i_sStr ); 123*cdf0e10cSrcweir void WriteKey( 124*cdf0e10cSrcweir std::ostream & o_rFile, 125*cdf0e10cSrcweir const char * i_sStr ); 126*cdf0e10cSrcweir void WriteValue( 127*cdf0e10cSrcweir std::ostream & o_rFile, 128*cdf0e10cSrcweir const char * i_sStr ); 129*cdf0e10cSrcweir void WriteIndentation( 130*cdf0e10cSrcweir std::ostream & o_rFile ); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir // DATA 133*cdf0e10cSrcweir const char * sCurParsePosition; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir UINT32 nCurLine; 136*cdf0e10cSrcweir INT16 nLevel; 137*cdf0e10cSrcweir bool bGoon; 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir Simstr sCurComment; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir E_Error eErrorCode; 142*cdf0e10cSrcweir UINT32 nErrorLine; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir GenericInfoList_Builder * 145*cdf0e10cSrcweir pResult; 146*cdf0e10cSrcweir GenericInfoList_Browser * 147*cdf0e10cSrcweir pResource; 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir char * dpBuffer; 150*cdf0e10cSrcweir char * sFilePtr; 151*cdf0e10cSrcweir }; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir inline GenericInfo_Parser::E_Error 155*cdf0e10cSrcweir GenericInfo_Parser::GetLastError( UINT32 * o_pErrorLine ) const 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir if ( o_pErrorLine != 0 ) 158*cdf0e10cSrcweir *o_pErrorLine = nErrorLine; 159*cdf0e10cSrcweir return eErrorCode; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir #endif 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir 166