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