Debian Codegraph @

Kernel/configure.cpp

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "configure.h"cxx . . $ `<file>/Kernel/configure.h`/
21
22 #include <fstream>
23
24 #undef USE_DEBUG
25
26 Configurationcxx . . $ Configuration# :: ~cxx . . $ Configuration#`~Configuration`(49f6e7a06ebc5aa8).Configurationcxx . . $ Configuration#()
27 {
28 for ( auto* elem : Basecxx . . $ Configuration#Base. )
29 delete elem;
30 }
31
32 ConfSectioncxx . . $ ConfSection# :: ~cxx . . $ ConfSection#`~ConfSection`(49f6e7a06ebc5aa8).ConfSectioncxx . . $ ConfSection#()
33 {
34 for ( auto* elem : Basecxx . . $ ConfSection#Base. )
35 delete elem;
36 }
37
38 ConfSectioncxx . . $ ConfSection#* Configurationcxx . . $ Configuration# :: FindSectioncxx . . $ Configuration#FindSection(3eefb06bfae2ad5f). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& pc ) const
39 {
40 for ( ConfSectioncxx . . $ ConfSection#* section : Basecxx . . $ Configuration#Base. )
41 if ( *section ==cxx . . $ ConfSection#`operator==`(13a55b95a0133754). pc )
42 return section;
43
44 // can not find section
45 return nullptr;
46 }
47
48 ConfElemcxx . . $ ConfElem#* ConfSectioncxx . . $ ConfSection# :: FindByNamecxx . . $ ConfSection#FindByName(b61d646b7f8a015a). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name ) const
49 {
50 for ( ConfElemcxx . . $ ConfElem#* elem : Basecxx . . $ ConfSection#Base. )
51 if ( elem->Namecxx . . $ ConfElem#Name. ==cxx . . $ std/`operator==`(2965e344aacb545b). name )
52 return elem;
53
54 // can not find element in section
55 return nullptr;
56 }
57
58
59 // add section; set Section to new pointer. Ret 1 if couldn't.
60 void Configurationcxx . . $ Configuration# :: createSectioncxx . . $ Configuration#createSection(9c546c94e5fcce4e). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name )
61 {
62 // if section already exists -- nothing to do
63 if ( !useSectioncxx . . $ Configuration#useSection(7c222eea44a24d43). ( name ) )
64 return;
65
66 Sectioncxx . . $ Configuration#Section. = new ConfSectioncxx . . $ ConfSection# ( name );
67 Basecxx . . $ Configuration#Base..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(Sectioncxx . . $ Configuration#Section.);
68 isSavedcxx . . $ Configuration#isSaved. = false;
69 }
70
71 // add Field.value to current Section; sets Element to new p.
72 bool Configurationcxx . . $ Configuration# :: setValuecxx . . $ Configuration#setValue(1667653f663d0d88). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& Field, const stdcxx . . $ std/::stringcxx . . $ std/string#& Value )
73 {
74 if ( !Sectioncxx . . $ Configuration#Section. )
75 return true;
76
77 //changing things
78 isSavedcxx . . $ Configuration#isSaved. = false;
79
80 // check for existing field
81 if ( (Elementcxx . . $ Configuration#Element. = Sectioncxx . . $ Configuration#Section.->FindByNamecxx . . $ ConfSection#FindByName(b61d646b7f8a015a).(Field)) )
82 {
83 Elementcxx . . $ Configuration#Element.->Valuecxx . . $ ConfElem#Value. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). Value;
84 return false;
85 }
86 else
87 {
88 Sectioncxx . . $ Configuration#Section. -> addEntrycxx . . $ ConfSection#addEntry(c3ca1c130ce09c52). ( Field, Value );
89 return !(Elementcxx . . $ Configuration#Element. = Sectioncxx . . $ Configuration#Section.->FindByNamecxx . . $ ConfSection#FindByName(b61d646b7f8a015a).(Field));
90 }
91 }
92
93 // check if Field exists if Section is set;
94 bool Configurationcxx . . $ Configuration# :: checkValuecxx . . $ Configuration#checkValue(7c222eea44a24d43). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& Field )
95 {
96 if ( !Sectioncxx . . $ Configuration#Section. )
97 return true;
98
99 Elementcxx . . $ Configuration#Element. = Sectioncxx . . $ Configuration#Section.->FindByNamecxx . . $ ConfSection#FindByName(b61d646b7f8a015a).(Field);
100 return Elementcxx . . $ Configuration#Element. == nullptr;
101 }
102
103 // check if Section:Field exists;
104 bool Configurationcxx . . $ Configuration# :: checkValuecxx . . $ Configuration#checkValue(1667653f663d0d88). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& Sect, const stdcxx . . $ std/::stringcxx . . $ std/string#& Field )
105 {
106 if ( useSectioncxx . . $ Configuration#useSection(7c222eea44a24d43).(Sect) )
107 return true;
108
109 Elementcxx . . $ Configuration#Element. = Sectioncxx . . $ Configuration#Section.->FindByNamecxx . . $ ConfSection#FindByName(b61d646b7f8a015a).(Field);
110 return Elementcxx . . $ Configuration#Element. == nullptr;
111 }
112
113 // Manipulation part
114 void ConfSectioncxx . . $ ConfSection# :: addEntrycxx . . $ ConfSection#addEntry(c3ca1c130ce09c52). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name, const stdcxx . . $ std/::stringcxx . . $ std/string#& value )
115 {
116 #ifdef USE_DEBUG
117 std::cerr << "\nadd pair \'" << name << "\',\'" << value << "\' to section \'" << Name << "\'";
118 #endif
119 Basecxx . . $ ConfSection#Base..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70). ( new ConfElemcxx . . $ ConfElem# ( name, value ) );
120 }
121
122 // Load part
123 int Configurationcxx . . $ Configuration# :: SplitLinecxx . . $ Configuration#SplitLine(c31b88f480a969c1). ( char*& pName, char*& pValue )
124 {
125 char* p = Linecxx . . $ Configuration#Line.;
126
127 while ( *p && isspace (*p) ) ++p; // skip leading spaces
128 pName = p;
129 // skip the property name
130 for ( ; *p && *p != '='; ++p )
131 ;
132 if (!*p) return 1;
133
134 // we found '='
135 pValue = p+1; // the next char after '='
136 // skip last spaces
137 for ( *p=0, --p; p!=Linecxx . . $ Configuration#Line. && isspace (*p); --p ) *p=0;
138 if ( p == Linecxx . . $ Configuration#Line. && isspace (*p) ) return 2;
139
140 // here we have name
141 for ( p=pValue; *p && isspace (*p); ++p )
142 ; // skip leading spaces
143 if (!*p) return 3;
144 pValue = p;
145
146 // skip last spaces
147 for ( p=pValue+strlen(pValue)-1; isspace (*p) && p!=pValue; --p ) *p=0;
148 if ( p == pValue && isspace (*p) ) return 4;
149
150 #ifdef USE_DEBUG
151 std::cerr << "\nfound string \'" << pName << "\'=\'" << pValue << "\'";
152 #endif
153 // all right!
154 return 0;
155 }
156
157 void Configurationcxx . . $ Configuration# :: loadStringcxx . . $ Configuration#loadString(21eaf1e8e1bd68f5). ( stdcxx . . $ std/::istreamcxx . . $ std/istream#& i )
158 {
159 do
160 i.getlinecxx . . $ std/basic_istream#getline(ec7d6f01d31dcb96). ( Linecxx . . $ Configuration#Line., MaxConfLineLencxx . . $ MaxConfLineLen. );
161 while ( i && isCommentcxx . . $ Configuration#isComment(50ce9a9e25b4a850). () );
162
163 #ifdef USE_DEBUG
164 cerr << "\nload string \'" << Line << "\'";
165 #endif
166 }
167
168 bool Configurationcxx . . $ Configuration# :: isCommentcxx . . $ Configuration#isComment(50ce9a9e25b4a850). ( void ) const
169 {
170 size_t n = strlen (Linecxx . . $ Configuration#Line.);
171
172 if ( n == 0 )
173 return true;
174
175 if ( Linecxx . . $ Configuration#Line. [0] == ';' || Linecxx . . $ Configuration#Line. [0] == '#' || ( Linecxx . . $ Configuration#Line. [0] == '/' && Linecxx . . $ Configuration#Line. [1] == '/' ) )
176 return true;
177
178 for ( size_t i = 0; i < n; i++ )
179 if ( !isspace (Linecxx . . $ Configuration#Line. [i]) )
180 return false;
181
182 return true;
183 }
184
185 bool Configurationcxx . . $ Configuration# :: Loadcxx . . $ Configuration#Load(c5f7da30cbc0f4e9). ( const char* Filename )
186 {
187 stdcxx . . $ std/::ifstreamcxx . . $ std/ifstream# incxx . . $ std/basic_ifstream#basic_ifstream(b8cd37071ce335df). ( Filename );
188 char *pName, *pValue;
189
190 isLoadedcxx . . $ Configuration#isLoaded. = false;
191 if ( !cxx . . $ std/basic_ios#`operator!`(50ce9a9e25b4a850).in ) return true;
192
193 loadStringcxx . . $ Configuration#loadString(21eaf1e8e1bd68f5). (in);
194 while ( !in.eofcxx . . $ std/basic_ios#eof(50ce9a9e25b4a850). () )
195 {
196 if ( isSectioncxx . . $ Configuration#isSection(50ce9a9e25b4a850). () )
197 loadSectioncxx . . $ Configuration#loadSection(49f6e7a06ebc5aa8). ();
198 else
199 return true;
200
201 do
202 {
203 loadStringcxx . . $ Configuration#loadString(21eaf1e8e1bd68f5). (in);
204 if ( in.eofcxx . . $ std/basic_ios#eof(50ce9a9e25b4a850). () )
205 break;
206
207 if ( isSectioncxx . . $ Configuration#isSection(50ce9a9e25b4a850). () )
208 break;
209
210 if ( SplitLinecxx . . $ Configuration#SplitLine(c31b88f480a969c1). ( pName, pValue ) )
211 return true;
212
213 if ( setValuecxx . . $ Configuration#setValue(1667653f663d0d88). ( pNamecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., pValuecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d). ) )
214 return true;
215 } while ( !in.eofcxx . . $ std/basic_ios#eof(50ce9a9e25b4a850). () );
216 }
217
218 isLoadedcxx . . $ Configuration#isLoaded. = isSavedcxx . . $ Configuration#isSaved. = true;
219 fileNamecxx . . $ Configuration#fileName. =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). Filename;
220 return false;
221 }
222
223 void Configurationcxx . . $ Configuration# :: loadSectioncxx . . $ Configuration#loadSection(49f6e7a06ebc5aa8). ( void )
224 {
225 Linecxx . . $ Configuration#Line. [strlen(Linecxx . . $ Configuration#Line.)-1] = (char) 0; // kill ']' of section
226 #ifdef USE_DEBUG
227 std::cerr << "\nfound section \'" << Line+1 << "\'";
228 #endif
229 createSectioncxx . . $ Configuration#createSection(9c546c94e5fcce4e). ( Linecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).+1 ); // skip '['
230 }
231
232 // Save part
233 void ConfElemcxx . . $ ConfElem# :: Savecxx . . $ ConfElem#Save(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const
234 {
235 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(88df5bef833f7f83). Namecxx . . $ ConfElem#Name. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " = " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). Valuecxx . . $ ConfElem#Value. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
236 }
237
238 void ConfSectioncxx . . $ ConfSection# :: Savecxx . . $ ConfSection#Save(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const
239 {
240 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "[" <<cxx . . $ std/`operator<<`(88df5bef833f7f83). Namecxx . . $ ConfSection#Name. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "]\n";
241
242 for ( const ConfElemcxx . . $ ConfElem#* elem : Basecxx . . $ ConfSection#Base. )
243 elem->Savecxx . . $ ConfElem#Save(490063bd7e6d8d5d).(o);
244
245 o <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
246 }
247
248 bool Configurationcxx . . $ Configuration# :: Savecxx . . $ Configuration#Save(c5f7da30cbc0f4e9). ( const char* Filename )
249 {
250 stdcxx . . $ std/::ofstreamcxx . . $ std/ofstream# ocxx . . $ std/basic_ofstream#basic_ofstream(b8cd37071ce335df). ( Filename );
251 if ( o.badcxx . . $ std/basic_ios#bad(50ce9a9e25b4a850). () )
252 return true;
253
254 for ( ConfSectioncxx . . $ ConfSection#* section : Basecxx . . $ Configuration#Base. )
255 section->Savecxx . . $ ConfSection#Save(490063bd7e6d8d5d).(o);
256
257 isLoadedcxx . . $ Configuration#isLoaded. = isSavedcxx . . $ Configuration#isSaved. = true;
258 return false;
259 }