diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-10 15:14:32 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-10 15:14:32 +0000 |
commit | 6c74a7db80c130fe8e9dc1d0195f95db5ed8a3b9 (patch) | |
tree | 20de398cac851c74ff3bf5a143a9bbf72fc07dd8 /utils/zenutils | |
parent | b1498300211db1fec46b49a861b4b4c77c545408 (diff) | |
download | rockbox-6c74a7db80c130fe8e9dc1d0195f95db5ed8a3b9.tar.gz rockbox-6c74a7db80c130fe8e9dc1d0195f95db5ed8a3b9.zip |
Fix ZenUtils compilation
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21242 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/zenutils')
-rw-r--r-- | utils/zenutils/CMakeLists.txt | 2 | ||||
-rw-r--r-- | utils/zenutils/libraries/getpot-c++-1.1.17/getpot/getpot.hpp | 2435 | ||||
-rw-r--r-- | utils/zenutils/libraries/getpot-c++-1.1.18/getpot/GetPot (renamed from utils/zenutils/libraries/getpot-c++-1.1.17/getpot/GetPot) | 1471 | ||||
-rw-r--r-- | utils/zenutils/libraries/getpot-c++-1.1.18/getpot/LPGL.txt (renamed from utils/zenutils/libraries/getpot-c++-1.1.17/getpot/LPGL.txt) | 13 | ||||
-rw-r--r-- | utils/zenutils/libraries/getpot-c++-1.1.18/getpot/README (renamed from utils/zenutils/libraries/getpot-c++-1.1.17/getpot/README) | 9 | ||||
-rw-r--r-- | utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h | 1 | ||||
-rw-r--r-- | utils/zenutils/source/firmware_extract/main.cpp | 2 | ||||
-rw-r--r-- | utils/zenutils/source/firmware_make/main.cpp | 2 | ||||
-rw-r--r-- | utils/zenutils/source/update_extract/main.cpp | 2 | ||||
-rw-r--r-- | utils/zenutils/source/update_patch/main.cpp | 2 | ||||
-rw-r--r-- | utils/zenutils/source/zen_crypt/main.cpp | 2 |
11 files changed, 756 insertions, 3185 deletions
diff --git a/utils/zenutils/CMakeLists.txt b/utils/zenutils/CMakeLists.txt index 0983d394a7..fe2fa915df 100644 --- a/utils/zenutils/CMakeLists.txt +++ b/utils/zenutils/CMakeLists.txt | |||
@@ -6,7 +6,7 @@ SUBDIRS(source libraries) | |||
6 | 6 | ||
7 | INCLUDE_DIRECTORIES( | 7 | INCLUDE_DIRECTORIES( |
8 | ${zenutils_SOURCE_DIR}/libraries/beecrypt-4.1.2 | 8 | ${zenutils_SOURCE_DIR}/libraries/beecrypt-4.1.2 |
9 | ${zenutils_SOURCE_DIR}/libraries/getpot-c++-1.1.17 | 9 | ${zenutils_SOURCE_DIR}/libraries/getpot-c++-1.1.18 |
10 | ${zenutils_SOURCE_DIR}/libraries/pelib-0.9 | 10 | ${zenutils_SOURCE_DIR}/libraries/pelib-0.9 |
11 | ${zenutils_SOURCE_DIR}/libraries/zlib123 | 11 | ${zenutils_SOURCE_DIR}/libraries/zlib123 |
12 | ${zenutils_SOURCE_DIR}/source/shared | 12 | ${zenutils_SOURCE_DIR}/source/shared |
diff --git a/utils/zenutils/libraries/getpot-c++-1.1.17/getpot/getpot.hpp b/utils/zenutils/libraries/getpot-c++-1.1.17/getpot/getpot.hpp deleted file mode 100644 index 9986d17893..0000000000 --- a/utils/zenutils/libraries/getpot-c++-1.1.17/getpot/getpot.hpp +++ /dev/null | |||
@@ -1,2435 +0,0 @@ | |||
1 | // -*- c++ -*- | ||
2 | // GetPot Version $$Version$$ $$Date$$ | ||
3 | // | ||
4 | // WEBSITE: http://getpot.sourceforge.net | ||
5 | // | ||
6 | // NOTE: The LPGL License for this library is only valid in case that | ||
7 | // it is not used for the production or development of applications | ||
8 | // dedicated to military industry. This is what the author calls | ||
9 | // the 'unofficial peace version of the LPGL'. | ||
10 | // | ||
11 | // This library is free software; you can redistribute it and/or modify | ||
12 | // it under the terms of the GNU Lesser General Public License as | ||
13 | // published by the Free Software Foundation; either version 2.1 of the | ||
14 | // License, or (at your option) any later version. | ||
15 | // | ||
16 | // This library is distributed in the hope that it will be useful, but | ||
17 | // WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | // Lesser General Public License for more details. | ||
20 | // | ||
21 | // You should have received a copy of the GNU Lesser General Public | ||
22 | // License along with this library; if not, write to the Free Software | ||
23 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
24 | // USA | ||
25 | // | ||
26 | // (C) 2001-2005 Frank R. Schaefer <fschaef@users.sf.net> | ||
27 | //========================================================================== | ||
28 | |||
29 | #ifndef __include_guard_GETPOT_H__ | ||
30 | #define __include_guard_GETPOT_H__ | ||
31 | |||
32 | #if defined(WIN32) || defined(SOLARIS_RAW) || (__GNUC__ == 2) || defined(__HP_aCC) | ||
33 | #define strtok_r(a, b, c) strtok(a, b) | ||
34 | #endif // WINDOWS or SOLARIS or gcc 2.* or HP aCC | ||
35 | |||
36 | extern "C" { | ||
37 | // leave the 'extern C' to make it 100% sure to work - | ||
38 | // expecially with older distributions of header files. | ||
39 | #ifndef WIN32 | ||
40 | // this is necessary (depending on OS) | ||
41 | #include <ctype.h> | ||
42 | #endif | ||
43 | #include <stdio.h> | ||
44 | #include <stdarg.h> | ||
45 | #include <assert.h> | ||
46 | } | ||
47 | #include <cmath> | ||
48 | #include <string> | ||
49 | #include <vector> | ||
50 | #include <algorithm> | ||
51 | |||
52 | #include <fstream> | ||
53 | #include <iostream> // not every compiler distribution includes <iostream> | ||
54 | // // with <fstream> | ||
55 | |||
56 | typedef std::vector<std::string> STRING_VECTOR; | ||
57 | |||
58 | #define victorate(TYPE, VARIABLE, ITERATOR) \ | ||
59 | std::vector<TYPE>::const_iterator ITERATOR = (VARIABLE).begin(); \ | ||
60 | for(; (ITERATOR) != (VARIABLE).end(); (ITERATOR)++) | ||
61 | |||
62 | |||
63 | class GetPot { | ||
64 | //-------- | ||
65 | inline void __basic_initialization(); | ||
66 | public: | ||
67 | // (*) constructors, destructor, assignment operator ----------------------- | ||
68 | inline GetPot(); | ||
69 | inline GetPot(const GetPot&); | ||
70 | inline GetPot(const int argc_, char** argv_, | ||
71 | const char* FieldSeparator=0x0); | ||
72 | inline GetPot(const char* FileName, | ||
73 | const char* CommentStart=0x0, const char* CommentEnd=0x0, | ||
74 | const char* FieldSeparator=0x0); | ||
75 | inline ~GetPot(); | ||
76 | inline GetPot& operator=(const GetPot&); | ||
77 | |||
78 | |||
79 | // (*) absorbing contents of another GetPot object | ||
80 | inline void absorb(const GetPot& That); | ||
81 | // -- for ufo detection: recording requested arguments, options etc. | ||
82 | inline void clear_requests(); | ||
83 | inline void disable_request_recording() { __request_recording_f = false; } | ||
84 | inline void enable_request_recording() { __request_recording_f = true; } | ||
85 | |||
86 | // (*) direct access to command line arguments ----------------------------- | ||
87 | inline const std::string operator[](unsigned Idx) const; | ||
88 | inline int get(unsigned Idx, int Default) const; | ||
89 | inline double get(unsigned Idx, const double& Default) const; | ||
90 | inline const std::string get(unsigned Idx, const char* Default) const; | ||
91 | inline unsigned size() const; | ||
92 | |||
93 | // (*) flags --------------------------------------------------------------- | ||
94 | inline bool options_contain(const char* FlagList) const; | ||
95 | inline bool argument_contains(unsigned Idx, const char* FlagList) const; | ||
96 | |||
97 | // (*) variables ----------------------------------------------------------- | ||
98 | // -- scalar values | ||
99 | inline int operator()(const char* VarName, int Default) const; | ||
100 | inline double operator()(const char* VarName, const double& Default) const; | ||
101 | inline const std::string operator()(const char* VarName, const char* Default) const; | ||
102 | // -- vectors | ||
103 | inline int operator()(const char* VarName, int Default, unsigned Idx) const; | ||
104 | inline double operator()(const char* VarName, const double& Default, unsigned Idx) const; | ||
105 | inline const std::string operator()(const char* VarName, const char* Default, unsigned Idx) const; | ||
106 | |||
107 | // -- setting variables | ||
108 | // i) from outside of GetPot (considering prefix etc.) | ||
109 | // ii) from inside, use '__set_variable()' below | ||
110 | inline void set(const char* VarName, const char* Value, const bool Requested = true); | ||
111 | inline void set(const char* VarName, const double& Value, const bool Requested = true); | ||
112 | inline void set(const char* VarName, const int Value, const bool Requested = true); | ||
113 | |||
114 | inline unsigned vector_variable_size(const char* VarName) const; | ||
115 | inline STRING_VECTOR get_variable_names() const; | ||
116 | inline STRING_VECTOR get_section_names() const; | ||
117 | |||
118 | |||
119 | // (*) cursor oriented functions ------------------------------------------- | ||
120 | inline void set_prefix(const char* Prefix) { prefix = std::string(Prefix); } | ||
121 | inline bool search_failed() const { return search_failed_f; } | ||
122 | |||
123 | // -- enable/disable search for an option in loop | ||
124 | inline void disable_loop() { search_loop_f = false; } | ||
125 | inline void enable_loop() { search_loop_f = true; } | ||
126 | |||
127 | // -- reset cursor to position '1' | ||
128 | inline void reset_cursor(); | ||
129 | inline void init_multiple_occurrence(); | ||
130 | |||
131 | // -- search for a certain option and set cursor to position | ||
132 | inline bool search(const char* option); | ||
133 | inline bool search(unsigned No, const char* P, ...); | ||
134 | // -- get argument at cursor++ | ||
135 | inline int next(int Default); | ||
136 | inline double next(const double& Default); | ||
137 | inline const std::string next(const char* Default); | ||
138 | // -- search for option and get argument at cursor++ | ||
139 | inline int follow(int Default, const char* Option); | ||
140 | inline double follow(const double& Default, const char* Option); | ||
141 | inline const std::string follow(const char* Default, const char* Option); | ||
142 | // -- search for one of the given options and get argument that follows it | ||
143 | inline int follow(int Default, unsigned No, const char* Option, ...); | ||
144 | inline double follow(const double& Default, unsigned No, const char* Option, ...); | ||
145 | inline const std::string follow(const char* Default, unsigned No, const char* Option, ...); | ||
146 | // -- lists of nominuses following an option | ||
147 | inline std::vector<std::string> nominus_followers(const char* Option); | ||
148 | inline std::vector<std::string> nominus_followers(unsigned No, ...); | ||
149 | |||
150 | // -- directly followed arguments | ||
151 | inline int direct_follow(int Default, const char* Option); | ||
152 | inline double direct_follow(const double& Default, const char* Option); | ||
153 | inline const std::string direct_follow(const char* Default, const char* Option); | ||
154 | |||
155 | inline std::vector<std::string> string_tails(const char* StartString); | ||
156 | inline std::vector<int> int_tails(const char* StartString, const int Default = 1); | ||
157 | inline std::vector<double> double_tails(const char* StartString, const double Default = 1.0); | ||
158 | |||
159 | // (*) nominus arguments --------------------------------------------------- | ||
160 | inline STRING_VECTOR nominus_vector() const; | ||
161 | inline unsigned nominus_size() const { return static_cast<unsigned int>(idx_nominus.size()); } | ||
162 | inline std::string next_nominus(); | ||
163 | |||
164 | // (*) unidentified flying objects ----------------------------------------- | ||
165 | inline STRING_VECTOR unidentified_arguments(unsigned Number, const char* Known, ...) const; | ||
166 | inline STRING_VECTOR unidentified_arguments(const STRING_VECTOR& Knowns) const; | ||
167 | inline STRING_VECTOR unidentified_arguments() const; | ||
168 | |||
169 | inline STRING_VECTOR unidentified_options(unsigned Number, const char* Known, ...) const; | ||
170 | inline STRING_VECTOR unidentified_options(const STRING_VECTOR& Knowns) const; | ||
171 | inline STRING_VECTOR unidentified_options() const; | ||
172 | |||
173 | inline std::string unidentified_flags(const char* Known, | ||
174 | int ArgumentNumber /* =-1 */) const; | ||
175 | |||
176 | inline STRING_VECTOR unidentified_variables(unsigned Number, const char* Known, ...) const; | ||
177 | inline STRING_VECTOR unidentified_variables(const STRING_VECTOR& Knowns) const; | ||
178 | inline STRING_VECTOR unidentified_variables() const; | ||
179 | |||
180 | inline STRING_VECTOR unidentified_sections(unsigned Number, const char* Known, ...) const; | ||
181 | inline STRING_VECTOR unidentified_sections(const STRING_VECTOR& Knowns) const; | ||
182 | inline STRING_VECTOR unidentified_sections() const; | ||
183 | |||
184 | inline STRING_VECTOR unidentified_nominuses(unsigned Number, const char* Known, ...) const; | ||
185 | inline STRING_VECTOR unidentified_nominuses(const STRING_VECTOR& Knowns) const; | ||
186 | inline STRING_VECTOR unidentified_nominuses() const; | ||
187 | |||
188 | // (*) output -------------------------------------------------------------- | ||
189 | inline int print() const; | ||
190 | |||
191 | private: | ||
192 | // (*) Type Declaration ---------------------------------------------------- | ||
193 | struct variable { | ||
194 | //----------- | ||
195 | // Variable to be specified on the command line or in input files. | ||
196 | // (i.e. of the form var='12 312 341') | ||
197 | |||
198 | // -- constructors, destructors, assignment operator | ||
199 | variable(); | ||
200 | variable(const variable&); | ||
201 | variable(const char* Name, const char* Value, const char* FieldSeparator); | ||
202 | ~variable(); | ||
203 | variable& operator=(const variable& That); | ||
204 | |||
205 | void take(const char* Value, const char* FieldSeparator); | ||
206 | |||
207 | // -- get a specific element in the string vector | ||
208 | // (return 0 if not present) | ||
209 | const std::string* get_element(unsigned Idx) const; | ||
210 | |||
211 | // -- data memebers | ||
212 | std::string name; // identifier of variable | ||
213 | STRING_VECTOR value; // value of variable stored in vector | ||
214 | std::string original; // value of variable as given on command line | ||
215 | }; | ||
216 | |||
217 | // (*) member variables -------------------------------------------------------------- | ||
218 | std::string prefix; // prefix automatically added in queries | ||
219 | std::string section; // (for dollar bracket parsing) | ||
220 | STRING_VECTOR section_list; // list of all parsed sections | ||
221 | // -- argument vector | ||
222 | STRING_VECTOR argv; // vector of command line arguments stored as strings | ||
223 | unsigned cursor; // cursor for argv | ||
224 | bool search_loop_f; // shall search start at beginning after | ||
225 | // // reaching end of arg array ? | ||
226 | bool search_failed_f; // flag indicating a failed search() operation | ||
227 | // // (e.g. next() functions react with 'missed') | ||
228 | |||
229 | // -- nominus vector | ||
230 | int nominus_cursor; // cursor for nominus_pointers | ||
231 | std::vector<unsigned> idx_nominus; // indecies of 'no minus' arguments | ||
232 | |||
233 | // -- variables | ||
234 | // (arguments of the form "variable=value") | ||
235 | std::vector<variable> variables; | ||
236 | |||
237 | // -- comment delimiters | ||
238 | std::string _comment_start; | ||
239 | std::string _comment_end; | ||
240 | |||
241 | // -- field separator (separating elements of a vector) | ||
242 | std::string _field_separator; | ||
243 | |||
244 | // -- some functions return a char pointer to a temporarily existing string | ||
245 | // this container makes them 'available' until the getpot object is destroyed. | ||
246 | std::vector<char*> __internal_string_container; | ||
247 | |||
248 | // -- keeping track about arguments that are requested, so that the UFO detection | ||
249 | // can be simplified | ||
250 | STRING_VECTOR _requested_arguments; | ||
251 | STRING_VECTOR _requested_variables; | ||
252 | STRING_VECTOR _requested_sections; | ||
253 | |||
254 | bool __request_recording_f; // speed: request recording can be turned off | ||
255 | |||
256 | // -- if an argument is requested record it and the 'tag' the section branch to which | ||
257 | // it belongs. Caution: both functions mark the sections as 'tagged'. | ||
258 | void __record_argument_request(const std::string& Arg); | ||
259 | void __record_variable_request(const std::string& Arg); | ||
260 | |||
261 | // (*) helper functions ---------------------------------------------------- | ||
262 | // set variable from inside GetPot (no prefix considered) | ||
263 | inline void __set_variable(const char* VarName, const char* Value); | ||
264 | |||
265 | // -- produce three basic data vectors: | ||
266 | // - argument vector | ||
267 | // - nominus vector | ||
268 | // - variable dictionary | ||
269 | inline void __parse_argument_vector(const STRING_VECTOR& ARGV); | ||
270 | |||
271 | // -- helpers for argument list processing | ||
272 | // * search for a variable in 'variables' array | ||
273 | inline const variable* __find_variable(const char*) const; | ||
274 | // * support finding directly followed arguments | ||
275 | inline const char* __match_starting_string(const char* StartString); | ||
276 | // * support search for flags in a specific argument | ||
277 | inline bool __check_flags(const std::string& Str, const char* FlagList) const; | ||
278 | // * type conversion if possible | ||
279 | inline int __convert_to_type(const std::string& String, int Default) const; | ||
280 | inline double __convert_to_type(const std::string& String, double Default) const; | ||
281 | // * prefix extraction | ||
282 | const std::string __get_remaining_string(const std::string& String, | ||
283 | const std::string& Start) const; | ||
284 | // * search for a specific string | ||
285 | inline bool __search_string_vector(const STRING_VECTOR& Vec, | ||
286 | const std::string& Str) const; | ||
287 | |||
288 | // -- helpers to parse input file | ||
289 | // create an argument vector based on data found in an input file, i.e.: | ||
290 | // 1) delete comments (in between '_comment_start' '_comment_end') | ||
291 | // 2) contract assignment expressions, such as | ||
292 | // my-variable = '007 J. B.' | ||
293 | // into | ||
294 | // my-variable='007 J. B.' | ||
295 | // 3) interprete sections like '[../my-section]' etc. | ||
296 | inline void __skip_whitespace(std::istream& istr); | ||
297 | inline const std::string __get_next_token(std::istream& istr); | ||
298 | inline const std::string __get_string(std::istream& istr); | ||
299 | inline const std::string __get_until_closing_bracket(std::istream& istr); | ||
300 | |||
301 | inline STRING_VECTOR __read_in_stream(std::istream& istr); | ||
302 | inline STRING_VECTOR __read_in_file(const char* FileName); | ||
303 | inline std::string __process_section_label(const std::string& Section, | ||
304 | STRING_VECTOR& section_stack); | ||
305 | |||
306 | // -- dollar bracket expressions | ||
307 | std::string __DBE_expand_string(const std::string str); | ||
308 | std::string __DBE_expand(const std::string str); | ||
309 | const GetPot::variable* __DBE_get_variable(const std::string str); | ||
310 | STRING_VECTOR __DBE_get_expr_list(const std::string str, const unsigned ExpectedNumber); | ||
311 | |||
312 | std::string __double2string(const double& Value) const { | ||
313 | // -- converts a double integer into a string | ||
314 | char* tmp = new char[128]; | ||
315 | #ifndef WIN32 | ||
316 | snprintf(tmp, (int)sizeof(char)*128, "%e", Value); | ||
317 | #else | ||
318 | _snprintf(tmp, sizeof(char)*128, "%e", Value); | ||
319 | #endif | ||
320 | std::string result(tmp); | ||
321 | delete [] tmp; | ||
322 | return result; | ||
323 | } | ||
324 | |||
325 | std::string __int2string(const int& Value) const { | ||
326 | // -- converts an integer into a string | ||
327 | char* tmp = new char[128]; | ||
328 | #ifndef WIN32 | ||
329 | snprintf(tmp, (int)sizeof(char)*128, "%i", Value); | ||
330 | #else | ||
331 | _snprintf(tmp, sizeof(char)*128, "%i", Value); | ||
332 | #endif | ||
333 | std::string result(tmp); | ||
334 | delete [] tmp; | ||
335 | return result; | ||
336 | } | ||
337 | |||
338 | STRING_VECTOR __get_section_tree(const std::string& FullPath) { | ||
339 | // -- cuts a variable name into a tree of sub-sections. this is requested for recording | ||
340 | // requested sections when dealing with 'ufo' detection. | ||
341 | STRING_VECTOR result; | ||
342 | const char* Start = FullPath.c_str(); | ||
343 | |||
344 | for(char *p = (char*)Start; *p ; p++) { | ||
345 | if( *p == '/' ) { | ||
346 | *p = '\0'; // set terminating zero for convinience | ||
347 | const std::string Section = Start; | ||
348 | *p = '/'; // reset slash at place | ||
349 | result.push_back(Section); | ||
350 | } | ||
351 | } | ||
352 | |||
353 | return result; | ||
354 | } | ||
355 | }; | ||
356 | |||
357 | |||
358 | /////////////////////////////////////////////////////////////////////////////// | ||
359 | // (*) constructors, destructor, assignment operator | ||
360 | //............................................................................. | ||
361 | // | ||
362 | inline void | ||
363 | GetPot::__basic_initialization() | ||
364 | { | ||
365 | cursor = 0; nominus_cursor = -1; | ||
366 | search_failed_f = true; search_loop_f = true; | ||
367 | prefix = ""; section = ""; | ||
368 | |||
369 | // automatic request recording for later ufo detection | ||
370 | __request_recording_f = true; | ||
371 | |||
372 | // comment start and end strings | ||
373 | _comment_start = std::string("#"); | ||
374 | _comment_end = std::string("\n"); | ||
375 | |||
376 | // default: separate vector elements by whitespaces | ||
377 | _field_separator = " \t\n"; | ||
378 | } | ||
379 | |||
380 | inline | ||
381 | GetPot::GetPot() | ||
382 | { | ||
383 | __basic_initialization(); | ||
384 | |||
385 | STRING_VECTOR _apriori_argv; | ||
386 | _apriori_argv.push_back(std::string("Empty")); | ||
387 | __parse_argument_vector(_apriori_argv); | ||
388 | } | ||
389 | |||
390 | inline | ||
391 | GetPot::GetPot(const int argc_, char ** argv_, | ||
392 | const char* FieldSeparator /* =0x0 */) | ||
393 | // leave 'char**' non-const to honor less capable compilers ... | ||
394 | { | ||
395 | // TODO: Ponder over the problem when the argument list is of size = 0. | ||
396 | // This is 'sabotage', but it can still occur if the user specifies | ||
397 | // it himself. | ||
398 | assert(argc_ >= 1); | ||
399 | __basic_initialization(); | ||
400 | |||
401 | // if specified -> overwrite default string | ||
402 | if( FieldSeparator ) _field_separator = std::string(FieldSeparator); | ||
403 | |||
404 | // -- make an internal copy of the argument list: | ||
405 | STRING_VECTOR _apriori_argv; | ||
406 | // -- for the sake of clarity: we do want to include the first argument in the argument vector ! | ||
407 | // it will not be a nominus argument, though. This gives us a minimun vector size of one | ||
408 | // which facilitates error checking in many functions. Also the user will be able to | ||
409 | // retrieve the name of his application by "get[0]" | ||
410 | _apriori_argv.push_back(std::string(argv_[0])); | ||
411 | int i=1; | ||
412 | for(; i<argc_; ++i) { | ||
413 | std::string tmp(argv_[i]); // recall the problem with temporaries, | ||
414 | _apriori_argv.push_back(tmp); // reference counting in arguement lists ... | ||
415 | } | ||
416 | __parse_argument_vector(_apriori_argv); | ||
417 | } | ||
418 | |||
419 | |||
420 | inline | ||
421 | GetPot::GetPot(const char* FileName, | ||
422 | const char* CommentStart /* = 0x0 */, const char* CommentEnd /* = 0x0 */, | ||
423 | const char* FieldSeparator/* = 0x0 */) | ||
424 | { | ||
425 | __basic_initialization(); | ||
426 | |||
427 | // if specified -> overwrite default strings | ||
428 | if( CommentStart ) _comment_start = std::string(CommentStart); | ||
429 | if( CommentEnd ) _comment_end = std::string(CommentEnd); | ||
430 | if( FieldSeparator ) _field_separator = FieldSeparator; | ||
431 | |||
432 | STRING_VECTOR _apriori_argv; | ||
433 | // -- file name is element of argument vector, however, it is not parsed for | ||
434 | // variable assignments or nominuses. | ||
435 | _apriori_argv.push_back(std::string(FileName)); | ||
436 | |||
437 | STRING_VECTOR args = __read_in_file(FileName); | ||
438 | _apriori_argv.insert(_apriori_argv.begin()+1, args.begin(), args.end()); | ||
439 | __parse_argument_vector(_apriori_argv); | ||
440 | } | ||
441 | |||
442 | inline | ||
443 | GetPot::GetPot(const GetPot& That) | ||
444 | { GetPot::operator=(That); } | ||
445 | |||
446 | inline | ||
447 | GetPot::~GetPot() | ||
448 | { | ||
449 | // may be some return strings had to be created, delete now ! | ||
450 | victorate(char*, __internal_string_container, it) | ||
451 | delete [] *it; | ||
452 | } | ||
453 | |||
454 | inline GetPot& | ||
455 | GetPot::operator=(const GetPot& That) | ||
456 | { | ||
457 | if (&That == this) return *this; | ||
458 | |||
459 | _comment_start = That._comment_start; | ||
460 | _comment_end = That._comment_end; | ||
461 | argv = That.argv; | ||
462 | variables = That.variables; | ||
463 | prefix = That.prefix; | ||
464 | |||
465 | cursor = That.cursor; | ||
466 | nominus_cursor = That.nominus_cursor; | ||
467 | search_failed_f = That.search_failed_f; | ||
468 | |||
469 | idx_nominus = That.idx_nominus; | ||
470 | search_loop_f = That.search_loop_f; | ||
471 | |||
472 | return *this; | ||
473 | } | ||
474 | |||
475 | |||
476 | inline void | ||
477 | GetPot::absorb(const GetPot& That) | ||
478 | { | ||
479 | if (&That == this) return; | ||
480 | |||
481 | STRING_VECTOR __tmp(That.argv); | ||
482 | |||
483 | __tmp.erase(__tmp.begin()); | ||
484 | |||
485 | __parse_argument_vector(__tmp); | ||
486 | } | ||
487 | |||
488 | inline void | ||
489 | GetPot::clear_requests() | ||
490 | { | ||
491 | _requested_arguments.erase(_requested_arguments.begin(), _requested_arguments.end()); | ||
492 | _requested_variables.erase(_requested_variables.begin(), _requested_variables.end()); | ||
493 | _requested_sections.erase(_requested_sections.begin(), _requested_sections.end()); | ||
494 | } | ||
495 | |||
496 | inline void | ||
497 | GetPot::__parse_argument_vector(const STRING_VECTOR& ARGV) | ||
498 | { | ||
499 | if( ARGV.size() == 0 ) return; | ||
500 | |||
501 | // build internal databases: | ||
502 | // 1) array with no-minus arguments (usually used as filenames) | ||
503 | // 2) variable assignments: | ||
504 | // 'variable name' '=' number | string | ||
505 | STRING_VECTOR section_stack; | ||
506 | STRING_VECTOR::const_iterator it = ARGV.begin(); | ||
507 | |||
508 | |||
509 | section = ""; | ||
510 | |||
511 | // -- do not parse the first argument, so that it is not interpreted a s a nominus or so. | ||
512 | argv.push_back(*it); | ||
513 | ++it; | ||
514 | |||
515 | // -- loop over remaining arguments | ||
516 | unsigned i=1; | ||
517 | for(; it != ARGV.end(); ++it, ++i) { | ||
518 | std::string arg = *it; | ||
519 | |||
520 | if( arg.length() == 0 ) continue; | ||
521 | |||
522 | // -- [section] labels | ||
523 | if( arg.length() > 1 && arg[0] == '[' && arg[arg.length()-1] == ']' ) { | ||
524 | |||
525 | // (*) sections are considered 'requested arguments' | ||
526 | if( __request_recording_f ) _requested_arguments.push_back(arg); | ||
527 | |||
528 | const std::string Name = __DBE_expand_string(arg.substr(1, arg.length()-2)); | ||
529 | section = __process_section_label(Name, section_stack); | ||
530 | // new section --> append to list of sections | ||
531 | if( find(section_list.begin(), section_list.end(), section) == section_list.end() ) | ||
532 | if( section.length() != 0 ) section_list.push_back(section); | ||
533 | argv.push_back(arg); | ||
534 | } | ||
535 | else { | ||
536 | arg = section + __DBE_expand_string(arg); | ||
537 | argv.push_back(arg); | ||
538 | } | ||
539 | |||
540 | // -- separate array for nominus arguments | ||
541 | if( arg[0] != '-' ) idx_nominus.push_back(unsigned(i)); | ||
542 | |||
543 | // -- variables: does arg contain a '=' operator ? | ||
544 | const char* p = arg.c_str(); | ||
545 | for(; *p ; p++) { | ||
546 | if( *p == '=' ) { | ||
547 | // (*) record for later ufo detection | ||
548 | // arguments carriying variables are always treated as 'requested' arguments. | ||
549 | // as a whole! That is 'x=4712' is considered a requested argument. | ||
550 | // | ||
551 | // unrequested variables have to be detected with the ufo-variable | ||
552 | // detection routine. | ||
553 | if( __request_recording_f ) _requested_arguments.push_back(arg); | ||
554 | |||
555 | // set terminating 'zero' to treat first part as single string | ||
556 | // => arg (from start to 'p') = Name of variable | ||
557 | // p+1 (until terminating zero) = value of variable | ||
558 | char* o = (char*)p++; | ||
559 | *o = '\0'; // set temporary terminating zero | ||
560 | // __set_variable(...) | ||
561 | // calls __find_variable(...) which registers the search | ||
562 | // temporarily disable this | ||
563 | const bool tmp = __request_recording_f; | ||
564 | __request_recording_f = false; | ||
565 | __set_variable(arg.c_str(), p); // v-name = c_str() bis 'p', value = rest | ||
566 | __request_recording_f = tmp; | ||
567 | *o = '='; // reset the original '=' | ||
568 | break; | ||
569 | } | ||
570 | } | ||
571 | } | ||
572 | } | ||
573 | |||
574 | |||
575 | inline STRING_VECTOR | ||
576 | GetPot::__read_in_file(const char* FileName) | ||
577 | { | ||
578 | std::ifstream i(FileName); | ||
579 | if( ! i ) return STRING_VECTOR(); | ||
580 | // argv[0] == the filename of the file that was read in | ||
581 | return __read_in_stream(i); | ||
582 | } | ||
583 | |||
584 | inline STRING_VECTOR | ||
585 | GetPot::__read_in_stream(std::istream& istr) | ||
586 | { | ||
587 | STRING_VECTOR brute_tokens; | ||
588 | while(istr) { | ||
589 | __skip_whitespace(istr); | ||
590 | |||
591 | const std::string Token = __get_next_token(istr); | ||
592 | if( Token.length() == 0 || Token[0] == EOF) break; | ||
593 | brute_tokens.push_back(Token); | ||
594 | } | ||
595 | |||
596 | // -- reduce expressions of token1'='token2 to a single | ||
597 | // string 'token1=token2' | ||
598 | // -- copy everything into 'argv' | ||
599 | // -- arguments preceded by something like '[' name ']' (section) | ||
600 | // produce a second copy of each argument with a prefix '[name]argument' | ||
601 | unsigned i1 = 0; | ||
602 | unsigned i2 = 1; | ||
603 | unsigned i3 = 2; | ||
604 | |||
605 | STRING_VECTOR arglist; | ||
606 | while( i1 < brute_tokens.size() ) { | ||
607 | const std::string& SRef = brute_tokens[i1]; | ||
608 | // 1) concatinate 'abcdef' '=' 'efgasdef' to 'abcdef=efgasdef' | ||
609 | // note: java.lang.String: substring(a,b) = from a to b-1 | ||
610 | // C++ string: substr(a,b) = from a to a + b | ||
611 | if( i2 < brute_tokens.size() && brute_tokens[i2] == "=" ) { | ||
612 | if( i3 >= brute_tokens.size() ) | ||
613 | arglist.push_back(brute_tokens[i1] + brute_tokens[i2]); | ||
614 | else | ||
615 | arglist.push_back(brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3]); | ||
616 | i1 = i3+1; i2 = i3+2; i3 = i3+3; | ||
617 | continue; | ||
618 | } | ||
619 | else { | ||
620 | arglist.push_back(SRef); | ||
621 | i1=i2; i2=i3; i3++; | ||
622 | } | ||
623 | } | ||
624 | return arglist; | ||
625 | } | ||
626 | |||
627 | inline void | ||
628 | GetPot::__skip_whitespace(std::istream& istr) | ||
629 | // find next non-whitespace while deleting comments | ||
630 | { | ||
631 | int tmp = istr.get(); | ||
632 | do { | ||
633 | // -- search a non whitespace | ||
634 | while( isspace(tmp) ) { | ||
635 | tmp = istr.get(); | ||
636 | if( ! istr ) return; | ||
637 | } | ||
638 | |||
639 | // -- look if characters match the comment starter string | ||
640 | const std::istream::pos_type Pos = istr.tellg(); | ||
641 | unsigned i=0; | ||
642 | for(; i<_comment_start.length() ; ++i) { | ||
643 | if( tmp != _comment_start[i] ) { | ||
644 | // HACK: The following line throws off msvc8: | ||
645 | // istr.seekg(Pos); | ||
646 | // -- one step more backwards, since 'tmp' already at non-whitespace | ||
647 | istr.unget(); | ||
648 | return; | ||
649 | } | ||
650 | tmp = istr.get(); | ||
651 | if( ! istr ) { istr.unget(); return; } | ||
652 | } | ||
653 | // 'tmp' contains last character of _comment_starter | ||
654 | |||
655 | // -- comment starter found -> search for comment ender | ||
656 | unsigned match_no=0; | ||
657 | while(1+1 == 2) { | ||
658 | tmp = istr.get(); | ||
659 | if( ! istr ) { istr.unget(); return; } | ||
660 | |||
661 | if( tmp == _comment_end[match_no] ) { | ||
662 | match_no++; | ||
663 | if( match_no == _comment_end.length() ) { | ||
664 | istr.unget(); | ||
665 | break; // shuffle more whitespace, end of comment found | ||
666 | } | ||
667 | } | ||
668 | else | ||
669 | match_no = 0; | ||
670 | } | ||
671 | |||
672 | tmp = istr.get(); | ||
673 | |||
674 | } while( istr ); | ||
675 | istr.unget(); | ||
676 | } | ||
677 | |||
678 | inline const std::string | ||
679 | GetPot::__get_next_token(std::istream& istr) | ||
680 | // get next concatinates string token. consider quotes that embrace | ||
681 | // whitespaces | ||
682 | { | ||
683 | std::string token; | ||
684 | int tmp = 0; | ||
685 | int last_letter = 0; | ||
686 | while(1+1 == 2) { | ||
687 | last_letter = tmp; tmp = istr.get(); | ||
688 | if( tmp == EOF | ||
689 | || ((tmp == ' ' || tmp == '\t' || tmp == '\n') && last_letter != '\\') ) { | ||
690 | return token; | ||
691 | } | ||
692 | else if( tmp == '\'' && last_letter != '\\' ) { | ||
693 | // QUOTES: un-backslashed quotes => it's a string | ||
694 | token += __get_string(istr); | ||
695 | continue; | ||
696 | } | ||
697 | else if( tmp == '{' && last_letter == '$') { | ||
698 | token += '{' + __get_until_closing_bracket(istr); | ||
699 | continue; | ||
700 | } | ||
701 | else if( tmp == '$' && last_letter == '\\') { | ||
702 | token += tmp; tmp = 0; // so that last_letter will become = 0, not '$'; | ||
703 | continue; | ||
704 | } | ||
705 | else if( tmp == '\\' && last_letter != '\\') | ||
706 | continue; // don't append un-backslashed backslashes | ||
707 | token += tmp; | ||
708 | } | ||
709 | } | ||
710 | |||
711 | inline const std::string | ||
712 | GetPot::__get_string(std::istream& istr) | ||
713 | // parse input until next matching ' | ||
714 | { | ||
715 | std::string str; | ||
716 | int tmp = 0; | ||
717 | int last_letter = 0; | ||
718 | while(1 + 1 == 2) { | ||
719 | last_letter = tmp; tmp = istr.get(); | ||
720 | if( tmp == EOF) return str; | ||
721 | // un-backslashed quotes => it's the end of the string | ||
722 | else if( tmp == '\'' && last_letter != '\\') return str; | ||
723 | else if( tmp == '\\' && last_letter != '\\') continue; // don't append | ||
724 | |||
725 | str += tmp; | ||
726 | } | ||
727 | } | ||
728 | |||
729 | inline const std::string | ||
730 | GetPot::__get_until_closing_bracket(std::istream& istr) | ||
731 | // parse input until next matching } | ||
732 | { | ||
733 | std::string str = ""; | ||
734 | int tmp = 0; | ||
735 | int last_letter = 0; | ||
736 | int brackets = 1; | ||
737 | while(1 + 1 == 2) { | ||
738 | last_letter = tmp; tmp = istr.get(); | ||
739 | if( tmp == EOF) return str; | ||
740 | else if( tmp == '{' && last_letter == '$') brackets += 1; | ||
741 | else if( tmp == '}') { | ||
742 | brackets -= 1; | ||
743 | // un-backslashed brackets => it's the end of the string | ||
744 | if( brackets == 0) return str + '}'; | ||
745 | else if( tmp == '\\' && last_letter != '\\') | ||
746 | continue; // do not append an unbackslashed backslash | ||
747 | } | ||
748 | str += tmp; | ||
749 | } | ||
750 | } | ||
751 | |||
752 | inline std::string | ||
753 | GetPot::__process_section_label(const std::string& Section, | ||
754 | STRING_VECTOR& section_stack) | ||
755 | { | ||
756 | std::string sname = Section; | ||
757 | // 1) subsection of actual section ('./' prefix) | ||
758 | if( sname.length() >= 2 && sname.substr(0, 2) == "./" ) { | ||
759 | sname = sname.substr(2); | ||
760 | } | ||
761 | // 2) subsection of parent section ('../' prefix) | ||
762 | else if( sname.length() >= 3 && sname.substr(0, 3) == "../" ) { | ||
763 | do { | ||
764 | if( section_stack.end() != section_stack.begin() ) | ||
765 | section_stack.pop_back(); | ||
766 | sname = sname.substr(3); | ||
767 | } while( sname.substr(0, 3) == "../" ); | ||
768 | } | ||
769 | // 3) subsection of the root-section | ||
770 | else { | ||
771 | section_stack.erase(section_stack.begin(), section_stack.end()); | ||
772 | // [] => back to root section | ||
773 | } | ||
774 | |||
775 | if( sname != "" ) { | ||
776 | // parse section name for 'slashes' | ||
777 | unsigned i=0; | ||
778 | while( i < sname.length() ) { | ||
779 | if( sname[i] == '/' ) { | ||
780 | section_stack.push_back(sname.substr(0,i)); | ||
781 | if( i+1 < sname.length()-1 ) | ||
782 | sname = sname.substr(i+1); | ||
783 | i = 0; | ||
784 | } | ||
785 | else | ||
786 | ++i; | ||
787 | } | ||
788 | section_stack.push_back(sname); | ||
789 | } | ||
790 | std::string section = ""; | ||
791 | if( section_stack.size() != 0 ) { | ||
792 | victorate(std::string, section_stack, it) | ||
793 | section += *it + "/"; | ||
794 | } | ||
795 | return section; | ||
796 | } | ||
797 | |||
798 | |||
799 | // convert string to DOUBLE, if not possible return Default | ||
800 | inline double | ||
801 | GetPot::__convert_to_type(const std::string& String, double Default) const | ||
802 | { | ||
803 | double tmp; | ||
804 | if( sscanf(String.c_str(),"%lf", &tmp) != 1 ) return Default; | ||
805 | return tmp; | ||
806 | } | ||
807 | |||
808 | // convert string to INT, if not possible return Default | ||
809 | inline int | ||
810 | GetPot::__convert_to_type(const std::string& String, int Default) const | ||
811 | { | ||
812 | // NOTE: intermediate results may be floating points, so that the string | ||
813 | // may look like 2.0e1 (i.e. float format) => use float conversion | ||
814 | // in any case. | ||
815 | return (int)__convert_to_type(String, (double)Default); | ||
816 | } | ||
817 | |||
818 | ////////////////////////////////////////////////////////////////////////////// | ||
819 | // (*) cursor oriented functions | ||
820 | //............................................................................. | ||
821 | inline const std::string | ||
822 | GetPot::__get_remaining_string(const std::string& String, const std::string& Start) const | ||
823 | // Checks if 'String' begins with 'Start' and returns the remaining String. | ||
824 | // Returns None if String does not begin with Start. | ||
825 | { | ||
826 | if( Start == "" ) return String; | ||
827 | // note: java.lang.String: substring(a,b) = from a to b-1 | ||
828 | // C++ string: substr(a,b) = from a to a + b | ||
829 | if( String.find(Start) == 0 ) return String.substr(Start.length()); | ||
830 | else return ""; | ||
831 | } | ||
832 | |||
833 | // -- search for a certain argument and set cursor to position | ||
834 | inline bool | ||
835 | GetPot::search(const char* Option) | ||
836 | { | ||
837 | unsigned OldCursor = cursor; | ||
838 | const std::string SearchTerm = prefix + Option; | ||
839 | |||
840 | // (*) record requested arguments for later ufo detection | ||
841 | __record_argument_request(SearchTerm); | ||
842 | |||
843 | if( OldCursor >= argv.size() ) OldCursor = static_cast<unsigned int>(argv.size()) - 1; | ||
844 | search_failed_f = true; | ||
845 | |||
846 | // (*) first loop from cursor position until end | ||
847 | unsigned c = cursor; | ||
848 | for(; c < argv.size(); c++) { | ||
849 | if( argv[c] == SearchTerm ) | ||
850 | { cursor = c; search_failed_f = false; return true; } | ||
851 | } | ||
852 | if( ! search_loop_f ) return false; | ||
853 | |||
854 | // (*) second loop from 0 to old cursor position | ||
855 | for(c = 1; c < OldCursor; c++) { | ||
856 | if( argv[c] == SearchTerm ) | ||
857 | { cursor = c; search_failed_f = false; return true; } | ||
858 | } | ||
859 | // in case nothing is found the cursor stays where it was | ||
860 | return false; | ||
861 | } | ||
862 | |||
863 | |||
864 | inline bool | ||
865 | GetPot::search(unsigned No, const char* P, ...) | ||
866 | { | ||
867 | // (*) recording the requested arguments happens in subroutine 'search' | ||
868 | if( No == 0 ) return false; | ||
869 | |||
870 | // search for the first argument | ||
871 | if( search(P) == true ) return true; | ||
872 | |||
873 | // start interpreting variable argument list | ||
874 | va_list ap; | ||
875 | va_start(ap, P); | ||
876 | unsigned i = 1; | ||
877 | for(; i < No; ++i) { | ||
878 | char* Opt = va_arg(ap, char *); | ||
879 | if( search(Opt) == true ) break; | ||
880 | } | ||
881 | |||
882 | if( i < No ) { | ||
883 | ++i; | ||
884 | // loop was left before end of array --> hit but | ||
885 | // make sure that the rest of the search terms is marked | ||
886 | // as requested. | ||
887 | for(; i < No; ++i) { | ||
888 | char* Opt = va_arg(ap, char *); | ||
889 | // (*) record requested arguments for later ufo detection | ||
890 | __record_argument_request(Opt); | ||
891 | } | ||
892 | va_end(ap); | ||
893 | return true; | ||
894 | } | ||
895 | |||
896 | va_end(ap); | ||
897 | // loop was left normally --> no hit | ||
898 | return false; | ||
899 | } | ||
900 | |||
901 | inline void | ||
902 | GetPot::reset_cursor() | ||
903 | { search_failed_f = false; cursor = 0; } | ||
904 | |||
905 | inline void | ||
906 | GetPot::init_multiple_occurrence() | ||
907 | { disable_loop(); reset_cursor(); } | ||
908 | /////////////////////////////////////////////////////////////////////////////// | ||
909 | // (*) direct access to command line arguments | ||
910 | //............................................................................. | ||
911 | // | ||
912 | inline const std::string | ||
913 | GetPot::operator[](unsigned idx) const | ||
914 | { return idx < argv.size() ? argv[idx] : ""; } | ||
915 | |||
916 | inline int | ||
917 | GetPot::get(unsigned Idx, int Default) const | ||
918 | { | ||
919 | if( Idx >= argv.size() ) return Default; | ||
920 | return __convert_to_type(argv[Idx], Default); | ||
921 | } | ||
922 | |||
923 | inline double | ||
924 | GetPot::get(unsigned Idx, const double& Default) const | ||
925 | { | ||
926 | if( Idx >= argv.size() ) return Default; | ||
927 | return __convert_to_type(argv[Idx], Default); | ||
928 | } | ||
929 | |||
930 | inline const std::string | ||
931 | GetPot::get(unsigned Idx, const char* Default) const | ||
932 | { | ||
933 | if( Idx >= argv.size() ) return Default; | ||
934 | else return argv[Idx]; | ||
935 | } | ||
936 | |||
937 | inline unsigned | ||
938 | GetPot::size() const | ||
939 | { return static_cast<unsigned int>(argv.size()); } | ||
940 | |||
941 | |||
942 | // -- next() function group | ||
943 | inline int | ||
944 | GetPot::next(int Default) | ||
945 | { | ||
946 | if( search_failed_f ) return Default; | ||
947 | cursor++; | ||
948 | if( cursor >= argv.size() ) | ||
949 | { cursor = static_cast<unsigned int>(argv.size()); return Default; } | ||
950 | |||
951 | // (*) record requested argument for later ufo detection | ||
952 | __record_argument_request(argv[cursor]); | ||
953 | |||
954 | const std::string Remain = __get_remaining_string(argv[cursor], prefix); | ||
955 | |||
956 | return Remain != "" ? __convert_to_type(Remain, Default) : Default; | ||
957 | } | ||
958 | |||
959 | inline double | ||
960 | GetPot::next(const double& Default) | ||
961 | { | ||
962 | if( search_failed_f ) return Default; | ||
963 | cursor++; | ||
964 | |||
965 | if( cursor >= argv.size() ) | ||
966 | { cursor = static_cast<unsigned int>(argv.size()); return Default; } | ||
967 | |||
968 | // (*) record requested argument for later ufo detection | ||
969 | __record_argument_request(argv[cursor]); | ||
970 | |||
971 | std::string Remain = __get_remaining_string(argv[cursor], prefix); | ||
972 | |||
973 | return Remain != "" ? __convert_to_type(Remain, Default) : Default; | ||
974 | } | ||
975 | |||
976 | inline const std::string | ||
977 | GetPot::next(const char* Default) | ||
978 | { | ||
979 | if( search_failed_f ) return Default; | ||
980 | cursor++; | ||
981 | |||
982 | if( cursor >= argv.size() ) | ||
983 | { cursor = static_cast<unsigned int>(argv.size()); return Default; } | ||
984 | |||
985 | // (*) record requested argument for later ufo detection | ||
986 | __record_argument_request(argv[cursor]); | ||
987 | |||
988 | const std::string Remain = __get_remaining_string(argv[cursor], prefix); | ||
989 | |||
990 | if( Remain == "" ) return Default; | ||
991 | |||
992 | |||
993 | // (*) function returns a pointer to a char array (inside Remain) | ||
994 | // this array will be deleted, though after this function call. | ||
995 | // To ensure propper functioning, create a copy inside *this | ||
996 | // object and only delete it, when *this is deleted. | ||
997 | char* result = new char[Remain.length()+1]; | ||
998 | strncpy(result, Remain.c_str(), Remain.length()+1); | ||
999 | |||
1000 | // store the created string internally, delete if when object deleted | ||
1001 | __internal_string_container.push_back(result); | ||
1002 | |||
1003 | return result; | ||
1004 | } | ||
1005 | |||
1006 | // -- follow() function group | ||
1007 | // distinct option to be searched for | ||
1008 | inline int | ||
1009 | GetPot::follow(int Default, const char* Option) | ||
1010 | { | ||
1011 | // (*) record requested of argument is entirely handled in 'search()' and 'next()' | ||
1012 | if( search(Option) == false ) return Default; | ||
1013 | return next(Default); | ||
1014 | } | ||
1015 | |||
1016 | inline double | ||
1017 | GetPot::follow(const double& Default, const char* Option) | ||
1018 | { | ||
1019 | // (*) record requested of argument is entirely handled in 'search()' and 'next()' | ||
1020 | if( search(Option) == false ) return Default; | ||
1021 | return next(Default); | ||
1022 | } | ||
1023 | |||
1024 | inline const std::string | ||
1025 | GetPot::follow(const char* Default, const char* Option) | ||
1026 | { | ||
1027 | // (*) record requested of argument is entirely handled in 'search()' and 'next()' | ||
1028 | if( search(Option) == false ) return Default; | ||
1029 | return next(Default); | ||
1030 | } | ||
1031 | |||
1032 | // -- second follow() function group | ||
1033 | // multiple option to be searched for | ||
1034 | inline int | ||
1035 | GetPot::follow(int Default, unsigned No, const char* P, ...) | ||
1036 | { | ||
1037 | // (*) record requested of argument is entirely handled in 'search()' and 'next()' | ||
1038 | if( No == 0 ) return Default; | ||
1039 | if( search(P) == true ) return next(Default); | ||
1040 | |||
1041 | va_list ap; | ||
1042 | va_start(ap, P); | ||
1043 | unsigned i=1; | ||
1044 | for(; i<No; ++i) { | ||
1045 | char* Opt = va_arg(ap, char *); | ||
1046 | if( search(Opt) == true ) { | ||
1047 | va_end(ap); | ||
1048 | return next(Default); | ||
1049 | } | ||
1050 | } | ||
1051 | va_end(ap); | ||
1052 | return Default; | ||
1053 | } | ||
1054 | |||
1055 | inline double | ||
1056 | GetPot::follow(const double& Default, unsigned No, const char* P, ...) | ||
1057 | { | ||
1058 | // (*) record requested of argument is entirely handled in 'search()' and 'next()' | ||
1059 | if( No == 0 ) return Default; | ||
1060 | if( search(P) == true ) return next(Default); | ||
1061 | |||
1062 | va_list ap; | ||
1063 | va_start(ap, P); | ||
1064 | for(unsigned i=1; i<No; ++i) { | ||
1065 | char* Opt = va_arg(ap, char *); | ||
1066 | if( search(Opt) == true ) { | ||
1067 | va_end(ap); | ||
1068 | return next(Default); | ||
1069 | } | ||
1070 | } | ||
1071 | va_end(ap); | ||
1072 | return Default; | ||
1073 | } | ||
1074 | |||
1075 | inline const std::string | ||
1076 | GetPot::follow(const char* Default, unsigned No, const char* P, ...) | ||
1077 | { | ||
1078 | // (*) record requested of argument is entirely handled in 'search()' and 'next()' | ||
1079 | if( No == 0 ) return Default; | ||
1080 | if( search(P) == true ) return next(Default); | ||
1081 | |||
1082 | va_list ap; | ||
1083 | va_start(ap, P); | ||
1084 | unsigned i=1; | ||
1085 | for(; i<No; ++i) { | ||
1086 | char* Opt = va_arg(ap, char *); | ||
1087 | if( search(Opt) == true ) { | ||
1088 | va_end(ap); | ||
1089 | return next(Default); | ||
1090 | } | ||
1091 | } | ||
1092 | va_end(ap); | ||
1093 | return Default; | ||
1094 | } | ||
1095 | |||
1096 | |||
1097 | /////////////////////////////////////////////////////////////////////////////// | ||
1098 | // (*) lists of nominus following an option | ||
1099 | //............................................................................. | ||
1100 | // | ||
1101 | inline std::vector<std::string> | ||
1102 | GetPot::nominus_followers(const char* Option) | ||
1103 | { | ||
1104 | std::vector<std::string> result_list; | ||
1105 | if( search(Option) == false ) return result_list; | ||
1106 | while( 1 + 1 == 2 ) { | ||
1107 | ++cursor; | ||
1108 | if( cursor >= argv.size() ) { | ||
1109 | cursor = argv.size() - 1; | ||
1110 | return result_list; | ||
1111 | } | ||
1112 | if( argv[cursor].length() >= 1 ) { | ||
1113 | if( argv[cursor][0] == '-' ) { | ||
1114 | return result_list; | ||
1115 | } | ||
1116 | // -- record for later ufo-detection | ||
1117 | __record_argument_request(argv[cursor]); | ||
1118 | // -- append to the result list | ||
1119 | result_list.push_back(argv[cursor]); | ||
1120 | } | ||
1121 | } | ||
1122 | } | ||
1123 | |||
1124 | inline std::vector<std::string> | ||
1125 | GetPot::nominus_followers(unsigned No, ...) | ||
1126 | { | ||
1127 | std::vector<std::string> result_list; | ||
1128 | // (*) record requested of argument is entirely handled in 'search()' | ||
1129 | // and 'nominus_followers()' | ||
1130 | if( No == 0 ) return result_list; | ||
1131 | |||
1132 | va_list ap; | ||
1133 | va_start(ap, No); | ||
1134 | for(unsigned i=0; i<No; ++i) { | ||
1135 | char* Option = va_arg(ap, char *); | ||
1136 | std::vector<std::string> tmp = nominus_followers(Option); | ||
1137 | result_list.insert(result_list.end(), tmp.begin(), tmp.end()); | ||
1138 | |||
1139 | // std::cerr << "option = '" << Option << "'" << std::endl; | ||
1140 | // std::cerr << "length = " << tmp.size() << std::endl; | ||
1141 | // std::cerr << "new result list = <"; | ||
1142 | // for(std::vector<std::string>::const_iterator it = result_list.begin(); | ||
1143 | // it != result_list.end(); ++it) | ||
1144 | // std::cerr << *it << ", "; | ||
1145 | // std::cerr << ">\n"; | ||
1146 | } | ||
1147 | va_end(ap); | ||
1148 | return result_list; | ||
1149 | } | ||
1150 | |||
1151 | |||
1152 | /////////////////////////////////////////////////////////////////////////////// | ||
1153 | // (*) directly connected options | ||
1154 | //............................................................................. | ||
1155 | // | ||
1156 | inline int | ||
1157 | GetPot::direct_follow(int Default, const char* Option) | ||
1158 | { | ||
1159 | const char* FollowStr = __match_starting_string(Option); | ||
1160 | if( FollowStr == 0x0 ) return Default; | ||
1161 | |||
1162 | // (*) record requested of argument for later ufo-detection | ||
1163 | __record_argument_request(std::string(Option) + FollowStr); | ||
1164 | |||
1165 | if( ++cursor >= static_cast<unsigned int>(argv.size()) ) cursor = static_cast<unsigned int>(argv.size()); | ||
1166 | return __convert_to_type(FollowStr, Default); | ||
1167 | } | ||
1168 | |||
1169 | inline double | ||
1170 | GetPot::direct_follow(const double& Default, const char* Option) | ||
1171 | { | ||
1172 | const char* FollowStr = __match_starting_string(Option); | ||
1173 | if( FollowStr == 0 ) return Default; | ||
1174 | |||
1175 | // (*) record requested of argument for later ufo-detection | ||
1176 | __record_argument_request(std::string(Option) + FollowStr); | ||
1177 | |||
1178 | if( ++cursor >= static_cast<unsigned int>(argv.size()) ) cursor = static_cast<unsigned int>(argv.size()); | ||
1179 | return __convert_to_type(FollowStr, Default); | ||
1180 | } | ||
1181 | |||
1182 | inline const std::string | ||
1183 | GetPot::direct_follow(const char* Default, const char* Option) | ||
1184 | { | ||
1185 | if( search_failed_f ) return Default; | ||
1186 | const char* FollowStr = __match_starting_string(Option); | ||
1187 | if( FollowStr == 0 ) return Default; | ||
1188 | |||
1189 | // (*) record requested of argument for later ufo-detection | ||
1190 | if( FollowStr ) __record_argument_request(std::string(Option) + FollowStr); | ||
1191 | |||
1192 | if( ++cursor >= static_cast<unsigned int>(argv.size()) ) cursor = static_cast<unsigned int>(argv.size()); | ||
1193 | return std::string(FollowStr); | ||
1194 | } | ||
1195 | |||
1196 | inline std::vector<std::string> | ||
1197 | GetPot::string_tails(const char* StartString) | ||
1198 | { | ||
1199 | std::vector<std::string> result; | ||
1200 | const unsigned N = static_cast<unsigned int>(strlen(StartString)); | ||
1201 | |||
1202 | std::vector<std::string>::iterator it = argv.begin(); | ||
1203 | |||
1204 | unsigned idx = 0; | ||
1205 | while( it != argv.end() ) { | ||
1206 | // (*) does start string match the given option? | ||
1207 | // NO -> goto next option | ||
1208 | if( strncmp(StartString, (*it).c_str(), N) != 0) { ++it; ++idx; continue; } | ||
1209 | |||
1210 | // append the found tail to the result vector | ||
1211 | result.push_back((*it).substr(N)); | ||
1212 | |||
1213 | // adapt the nominus vector | ||
1214 | std::vector<unsigned>::iterator nit = idx_nominus.begin(); | ||
1215 | for(; nit != idx_nominus.end(); ++nit) { | ||
1216 | if( *nit == idx ) { | ||
1217 | idx_nominus.erase(nit); | ||
1218 | for(; nit != idx_nominus.end(); ++nit) *nit -= 1; | ||
1219 | break; | ||
1220 | } | ||
1221 | } | ||
1222 | |||
1223 | // erase the found option | ||
1224 | argv.erase(it); | ||
1225 | |||
1226 | // 100% safe solution: set iterator back to the beginning. | ||
1227 | // (normally, 'it--' would be enough, but who knows how the | ||
1228 | // iterator is implemented and .erase() definitely invalidates | ||
1229 | // the current iterator position. | ||
1230 | if( argv.empty() ) break; | ||
1231 | it = argv.begin(); | ||
1232 | } | ||
1233 | cursor = 0; | ||
1234 | nominus_cursor = -1; | ||
1235 | return result; | ||
1236 | } | ||
1237 | |||
1238 | inline std::vector<int> | ||
1239 | GetPot::int_tails(const char* StartString, const int Default /* = -1 */) | ||
1240 | { | ||
1241 | std::vector<int> result; | ||
1242 | const unsigned N = static_cast<unsigned int>(strlen(StartString)); | ||
1243 | |||
1244 | std::vector<std::string>::iterator it = argv.begin(); | ||
1245 | |||
1246 | unsigned idx = 0; | ||
1247 | while( it != argv.end() ) { | ||
1248 | // (*) does start string match the given option? | ||
1249 | // NO -> goto next option | ||
1250 | if( strncmp(StartString, (*it).c_str(), N) != 0) { ++it; ++idx; continue; } | ||
1251 | |||
1252 | // append the found tail to the result vector | ||
1253 | result.push_back(__convert_to_type((*it).substr(N), Default)); | ||
1254 | |||
1255 | // adapt the nominus vector | ||
1256 | std::vector<unsigned>::iterator nit = idx_nominus.begin(); | ||
1257 | for(; nit != idx_nominus.end(); ++nit) { | ||
1258 | if( *nit == idx ) { | ||
1259 | idx_nominus.erase(nit); | ||
1260 | for(; nit != idx_nominus.end(); ++nit) *nit -= 1; | ||
1261 | break; | ||
1262 | } | ||
1263 | } | ||
1264 | |||
1265 | // erase the found option | ||
1266 | argv.erase(it); | ||
1267 | |||
1268 | // 100% safe solution: set iterator back to the beginning. | ||
1269 | // (normally, 'it--' would be enough, but who knows how the | ||
1270 | // iterator is implemented and .erase() definitely invalidates | ||
1271 | // the current iterator position. | ||
1272 | if( argv.empty() ) break; | ||
1273 | it = argv.begin(); | ||
1274 | } | ||
1275 | cursor = 0; | ||
1276 | nominus_cursor = -1; | ||
1277 | return result; | ||
1278 | } | ||
1279 | |||
1280 | inline std::vector<double> | ||
1281 | GetPot::double_tails(const char* StartString, | ||
1282 | const double Default /* = -1.0 */) | ||
1283 | { | ||
1284 | std::vector<double> result; | ||
1285 | const unsigned N = static_cast<unsigned int>(strlen(StartString)); | ||
1286 | |||
1287 | std::vector<std::string>::iterator it = argv.begin(); | ||
1288 | unsigned idx = 0; | ||
1289 | while( it != argv.end() ) { | ||
1290 | // (*) does start string match the given option? | ||
1291 | // NO -> goto next option | ||
1292 | if( strncmp(StartString, (*it).c_str(), N) != 0) { ++it; ++idx; continue; } | ||
1293 | |||
1294 | // append the found tail to the result vector | ||
1295 | result.push_back(__convert_to_type((*it).substr(N), Default)); | ||
1296 | |||
1297 | // adapt the nominus vector | ||
1298 | std::vector<unsigned>::iterator nit = idx_nominus.begin(); | ||
1299 | for(; nit != idx_nominus.end(); ++nit) { | ||
1300 | if( *nit == idx ) { | ||
1301 | idx_nominus.erase(nit); | ||
1302 | for(; nit != idx_nominus.end(); ++nit) *nit -= 1; | ||
1303 | break; | ||
1304 | } | ||
1305 | } | ||
1306 | |||
1307 | // erase the found option | ||
1308 | argv.erase(it); | ||
1309 | |||
1310 | // 100% safe solution: set iterator back to the beginning. | ||
1311 | // (normally, 'it--' would be enough, but who knows how the | ||
1312 | // iterator is implemented and .erase() definitely invalidates | ||
1313 | // the current iterator position. | ||
1314 | if( argv.empty() ) break; | ||
1315 | it = argv.begin(); | ||
1316 | } | ||
1317 | cursor = 0; | ||
1318 | nominus_cursor = -1; | ||
1319 | return result; | ||
1320 | } | ||
1321 | |||
1322 | |||
1323 | |||
1324 | |||
1325 | |||
1326 | inline const char* | ||
1327 | GetPot::__match_starting_string(const char* StartString) | ||
1328 | // pointer to the place where the string after | ||
1329 | // the match inside the found argument starts. | ||
1330 | // 0 no argument matches the starting string. | ||
1331 | { | ||
1332 | const unsigned N = static_cast<unsigned int>(strlen(StartString)); | ||
1333 | unsigned OldCursor = cursor; | ||
1334 | |||
1335 | if( OldCursor >= static_cast<unsigned int>(argv.size()) ) OldCursor = static_cast<unsigned int>(argv.size()) - 1; | ||
1336 | search_failed_f = true; | ||
1337 | |||
1338 | // (*) first loop from cursor position until end | ||
1339 | unsigned c = cursor; | ||
1340 | for(; c < argv.size(); c++) { | ||
1341 | if( strncmp(StartString, argv[c].c_str(), N) == 0) | ||
1342 | { cursor = c; search_failed_f = false; return &(argv[c].c_str()[N]); } | ||
1343 | } | ||
1344 | |||
1345 | if( ! search_loop_f ) return false; | ||
1346 | |||
1347 | // (*) second loop from 0 to old cursor position | ||
1348 | for(c = 1; c < OldCursor; c++) { | ||
1349 | if( strncmp(StartString, argv[c].c_str(), N) == 0) | ||
1350 | { cursor = c; search_failed_f = false; return &(argv[c].c_str()[N]); } | ||
1351 | } | ||
1352 | return 0; | ||
1353 | } | ||
1354 | |||
1355 | /////////////////////////////////////////////////////////////////////////////// | ||
1356 | // (*) search for flags | ||
1357 | //............................................................................. | ||
1358 | // | ||
1359 | inline bool | ||
1360 | GetPot::options_contain(const char* FlagList) const | ||
1361 | { | ||
1362 | // go through all arguments that start with a '-' (but not '--') | ||
1363 | std::string str; | ||
1364 | STRING_VECTOR::const_iterator it = argv.begin(); | ||
1365 | for(; it != argv.end(); ++it) { | ||
1366 | str = __get_remaining_string(*it, prefix); | ||
1367 | |||
1368 | if( str.length() >= 2 && str[0] == '-' && str[1] != '-' ) | ||
1369 | if( __check_flags(str, FlagList) ) return true; | ||
1370 | } | ||
1371 | return false; | ||
1372 | } | ||
1373 | |||
1374 | inline bool | ||
1375 | GetPot::argument_contains(unsigned Idx, const char* FlagList) const | ||
1376 | { | ||
1377 | if( Idx >= argv.size() ) return false; | ||
1378 | |||
1379 | // (*) record requested of argument for later ufo-detection | ||
1380 | // an argument that is checked for flags is considered to be 'requested' | ||
1381 | ((GetPot*)this)->__record_argument_request(argv[Idx]); | ||
1382 | |||
1383 | if( prefix == "" ) | ||
1384 | // search argument for any flag in flag list | ||
1385 | return __check_flags(argv[Idx], FlagList); | ||
1386 | |||
1387 | // if a prefix is set, then the argument index is the index | ||
1388 | // inside the 'namespace' | ||
1389 | // => only check list of arguments that start with prefix | ||
1390 | unsigned no_matches = 0; | ||
1391 | unsigned i=0; | ||
1392 | for(; i<argv.size(); ++i) { | ||
1393 | const std::string Remain = __get_remaining_string(argv[i], prefix); | ||
1394 | if( Remain != "") { | ||
1395 | no_matches += 1; | ||
1396 | if( no_matches == Idx) | ||
1397 | return __check_flags(Remain, FlagList); | ||
1398 | } | ||
1399 | } | ||
1400 | // no argument in this namespace | ||
1401 | return false; | ||
1402 | } | ||
1403 | |||
1404 | inline bool | ||
1405 | GetPot::__check_flags(const std::string& Str, const char* FlagList) const | ||
1406 | { | ||
1407 | const char* p=FlagList; | ||
1408 | for(; *p != '\0' ; p++) | ||
1409 | if( Str.find(*p) != std::string::npos ) return true; // found something | ||
1410 | return false; | ||
1411 | } | ||
1412 | |||
1413 | /////////////////////////////////////////////////////////////////////////////// | ||
1414 | // (*) nominus arguments | ||
1415 | inline STRING_VECTOR | ||
1416 | GetPot::nominus_vector() const | ||
1417 | // return vector of nominus arguments | ||
1418 | { | ||
1419 | STRING_VECTOR nv; | ||
1420 | std::vector<unsigned>::const_iterator it = idx_nominus.begin(); | ||
1421 | for(; it != idx_nominus.end(); ++it) { | ||
1422 | nv.push_back(argv[*it]); | ||
1423 | |||
1424 | // (*) record for later ufo-detection | ||
1425 | // when a nominus vector is requested, the entire set of nominus arguments are | ||
1426 | // tagged as 'requested' | ||
1427 | ((GetPot*)this)->__record_argument_request(argv[*it]); | ||
1428 | } | ||
1429 | return nv; | ||
1430 | } | ||
1431 | |||
1432 | inline std::string | ||
1433 | GetPot::next_nominus() | ||
1434 | { | ||
1435 | if( nominus_cursor < int(idx_nominus.size()) - 1 ) { | ||
1436 | const std::string Tmp = argv[idx_nominus[++nominus_cursor]]; | ||
1437 | |||
1438 | // (*) record for later ufo-detection | ||
1439 | __record_argument_request(Tmp); | ||
1440 | |||
1441 | // -- cannot use the Tmp variable, since it is temporary and c_str() will return a pointer | ||
1442 | // to something that does no longer exist. | ||
1443 | return Tmp; | ||
1444 | } | ||
1445 | return std::string(""); | ||
1446 | } | ||
1447 | |||
1448 | /////////////////////////////////////////////////////////////////////////////// | ||
1449 | // (*) variables | ||
1450 | //............................................................................. | ||
1451 | // | ||
1452 | inline int | ||
1453 | GetPot::operator()(const char* VarName, int Default) const | ||
1454 | { | ||
1455 | // (*) recording of requested variables happens in '__find_variable()' | ||
1456 | const variable* sv = __find_variable(VarName); | ||
1457 | if( sv == 0 ) return Default; | ||
1458 | return __convert_to_type(sv->original, Default); | ||
1459 | } | ||
1460 | |||
1461 | inline double | ||
1462 | GetPot::operator()(const char* VarName, const double& Default) const | ||
1463 | { | ||
1464 | // (*) recording of requested variables happens in '__find_variable()' | ||
1465 | const variable* sv = __find_variable(VarName); | ||
1466 | if( sv == 0 ) return Default; | ||
1467 | return __convert_to_type(sv->original, Default); | ||
1468 | } | ||
1469 | |||
1470 | inline const std::string | ||
1471 | GetPot::operator()(const char* VarName, const char* Default) const | ||
1472 | { | ||
1473 | // (*) recording of requested variables happens in '__find_variable()' | ||
1474 | const variable* sv = __find_variable(VarName); | ||
1475 | if( sv == 0 ) return Default; | ||
1476 | // -- returning a c_str() pointer is OK here, since the variable remains existant, | ||
1477 | // while 'sv' of course is delete at the end of the function. | ||
1478 | return sv->original; | ||
1479 | } | ||
1480 | |||
1481 | inline int | ||
1482 | GetPot::operator()(const char* VarName, int Default, unsigned Idx) const | ||
1483 | { | ||
1484 | // (*) recording of requested variables happens in '__find_variable()' | ||
1485 | const variable* sv = __find_variable(VarName); | ||
1486 | if( sv == 0 ) return Default; | ||
1487 | const std::string* element = sv->get_element(Idx); | ||
1488 | if( element == 0 ) return Default; | ||
1489 | return __convert_to_type(*element, Default); | ||
1490 | } | ||
1491 | |||
1492 | inline double | ||
1493 | GetPot::operator()(const char* VarName, const double& Default, unsigned Idx) const | ||
1494 | { | ||
1495 | // (*) recording of requested variables happens in '__find_variable()' | ||
1496 | const variable* sv = __find_variable(VarName); | ||
1497 | if( sv == 0 ) return Default; | ||
1498 | const std::string* element = sv->get_element(Idx); | ||
1499 | if( element == 0 ) return Default; | ||
1500 | return __convert_to_type(*element, Default); | ||
1501 | } | ||
1502 | |||
1503 | inline const std::string | ||
1504 | GetPot::operator()(const char* VarName, const char* Default, unsigned Idx) const | ||
1505 | { | ||
1506 | // (*) recording of requested variables happens in '__find_variable()' | ||
1507 | const variable* sv = __find_variable(VarName); | ||
1508 | if( sv == 0 ) return Default; | ||
1509 | const std::string* element = sv->get_element(Idx); | ||
1510 | if( element == 0 ) return Default; | ||
1511 | return *element; | ||
1512 | } | ||
1513 | |||
1514 | inline void | ||
1515 | GetPot::__record_argument_request(const std::string& Name) | ||
1516 | { | ||
1517 | if( ! __request_recording_f ) return; | ||
1518 | |||
1519 | // (*) record requested variable for later ufo detection | ||
1520 | _requested_arguments.push_back(Name); | ||
1521 | |||
1522 | // (*) record considered section for ufo detection | ||
1523 | STRING_VECTOR STree = __get_section_tree(Name); | ||
1524 | victorate(std::string, STree, it) | ||
1525 | if( find(_requested_sections.begin(), _requested_sections.end(), *it) == _requested_sections.end() ) | ||
1526 | if( section.length() != 0 ) _requested_sections.push_back(*it); | ||
1527 | } | ||
1528 | |||
1529 | inline void | ||
1530 | GetPot::__record_variable_request(const std::string& Name) | ||
1531 | { | ||
1532 | if( ! __request_recording_f ) return; | ||
1533 | |||
1534 | // (*) record requested variable for later ufo detection | ||
1535 | _requested_variables.push_back(Name); | ||
1536 | |||
1537 | // (*) record considered section for ufo detection | ||
1538 | STRING_VECTOR STree = __get_section_tree(Name); | ||
1539 | victorate(std::string, STree, it) | ||
1540 | if( find(_requested_sections.begin(), _requested_sections.end(), *it) == _requested_sections.end() ) | ||
1541 | if( section.length() != 0 ) _requested_sections.push_back(*it); | ||
1542 | } | ||
1543 | |||
1544 | // (*) following functions are to be used from 'outside', after getpot has parsed its | ||
1545 | // arguments => append an argument in the argument vector that reflects the addition | ||
1546 | inline void | ||
1547 | GetPot::__set_variable(const char* VarName, const char* Value) | ||
1548 | { | ||
1549 | const GetPot::variable* Var = __find_variable(VarName); | ||
1550 | if( Var == 0 ) variables.push_back(variable(VarName, Value, _field_separator.c_str())); | ||
1551 | else ((GetPot::variable*)Var)->take(Value, _field_separator.c_str()); | ||
1552 | } | ||
1553 | |||
1554 | inline void | ||
1555 | GetPot::set(const char* VarName, const char* Value, const bool Requested /* = yes */) | ||
1556 | { | ||
1557 | const std::string Arg = prefix + std::string(VarName) + std::string("=") + std::string(Value); | ||
1558 | argv.push_back(Arg); | ||
1559 | __set_variable(VarName, Value); | ||
1560 | |||
1561 | // if user does not specify the variable as 'not being requested' it will be | ||
1562 | // considered amongst the requested variables | ||
1563 | if( Requested ) __record_variable_request(Arg); | ||
1564 | } | ||
1565 | |||
1566 | inline void | ||
1567 | GetPot::set(const char* VarName, const double& Value, const bool Requested /* = yes */) | ||
1568 | { __set_variable(VarName, __double2string(Value).c_str()); } | ||
1569 | |||
1570 | inline void | ||
1571 | GetPot::set(const char* VarName, const int Value, const bool Requested /* = yes */) | ||
1572 | { __set_variable(VarName, __int2string(Value).c_str()); } | ||
1573 | |||
1574 | |||
1575 | inline unsigned | ||
1576 | GetPot::vector_variable_size(const char* VarName) const | ||
1577 | { | ||
1578 | const variable* sv = __find_variable(VarName); | ||
1579 | if( sv == 0 ) return 0; | ||
1580 | return static_cast<unsigned int>(sv->value.size()); | ||
1581 | } | ||
1582 | |||
1583 | inline STRING_VECTOR | ||
1584 | GetPot::get_variable_names() const | ||
1585 | { | ||
1586 | STRING_VECTOR result; | ||
1587 | std::vector<GetPot::variable>::const_iterator it = variables.begin(); | ||
1588 | for(; it != variables.end(); ++it) { | ||
1589 | const std::string Tmp = __get_remaining_string((*it).name, prefix); | ||
1590 | if( Tmp != "" ) result.push_back(Tmp); | ||
1591 | } | ||
1592 | return result; | ||
1593 | } | ||
1594 | |||
1595 | inline STRING_VECTOR | ||
1596 | GetPot::get_section_names() const | ||
1597 | { return section_list; } | ||
1598 | |||
1599 | inline const GetPot::variable* | ||
1600 | GetPot::__find_variable(const char* VarName) const | ||
1601 | { | ||
1602 | const std::string Name = prefix + VarName; | ||
1603 | |||
1604 | // (*) record requested variable for later ufo detection | ||
1605 | ((GetPot*)this)->__record_variable_request(Name); | ||
1606 | |||
1607 | std::vector<variable>::const_iterator it = variables.begin(); | ||
1608 | for(; it != variables.end(); ++it) { | ||
1609 | if( (*it).name == Name ) return &(*it); | ||
1610 | } | ||
1611 | return 0; | ||
1612 | } | ||
1613 | |||
1614 | /////////////////////////////////////////////////////////////////////////////// | ||
1615 | // (*) ouput (basically for debugging reasons | ||
1616 | //............................................................................. | ||
1617 | // | ||
1618 | inline int | ||
1619 | GetPot::print() const | ||
1620 | { | ||
1621 | std::cout << "argc = " << static_cast<unsigned int>(argv.size()) << std::endl; | ||
1622 | STRING_VECTOR::const_iterator it = argv.begin(); | ||
1623 | for(; it != argv.end(); ++it) | ||
1624 | std::cout << *it << std::endl; | ||
1625 | std::cout << std::endl; | ||
1626 | return 1; | ||
1627 | } | ||
1628 | |||
1629 | // (*) dollar bracket expressions (DBEs) ------------------------------------ | ||
1630 | // | ||
1631 | // 1) Entry Function: __DBE_expand_string() | ||
1632 | // Takes a string such as | ||
1633 | // | ||
1634 | // "${+ ${x} ${y}} Subject-${& ${section} ${subsection}}: ${title}" | ||
1635 | // | ||
1636 | // calls __DBE_expand() for each of the expressions | ||
1637 | // | ||
1638 | // ${+ ${x} ${y}} | ||
1639 | // ${& ${section} ${subsection}} | ||
1640 | // ${Title} | ||
1641 | // | ||
1642 | // and returns the string | ||
1643 | // | ||
1644 | // "4711 Subject-1.01: Mit den Clowns kamen die Schwaene" | ||
1645 | // | ||
1646 | // assuming that | ||
1647 | // x = "4699" | ||
1648 | // y = "12" | ||
1649 | // section = "1." | ||
1650 | // subsection = "01" | ||
1651 | // title = "Mit den Clowns kamen die Schwaene" | ||
1652 | // | ||
1653 | // 2) __DBE_expand(): | ||
1654 | // | ||
1655 | // checks for the command, i.e. the 'sign' that follows '${' | ||
1656 | // divides the argument list into sub-expressions using | ||
1657 | // __DBE_get_expr_list() | ||
1658 | // | ||
1659 | // ${+ ${x} ${y}} -> "${x}" "${y}" | ||
1660 | // ${& ${section} ${subsection}} -> "${section}" "${subsection}" | ||
1661 | // ${Title} -> Nothing, variable expansion | ||
1662 | // | ||
1663 | // 3) __DBE_expression_list(): | ||
1664 | // | ||
1665 | // builds a vector of unbracketed whitespace separated strings, i.e. | ||
1666 | // | ||
1667 | // " ${Number}.a ${: Das Marmorbild} AB-${& Author= ${Eichendorf}-1870}" | ||
1668 | // | ||
1669 | // is split into a vector | ||
1670 | // | ||
1671 | // [0] ${Number}.a | ||
1672 | // [1] ${: Das Marmorbild} | ||
1673 | // [2] AB-${& Author= ${Eichendorf}}-1870 | ||
1674 | // | ||
1675 | // Each sub-expression is expanded using expand(). | ||
1676 | //--------------------------------------------------------------------------- | ||
1677 | inline std::string | ||
1678 | GetPot::__DBE_expand_string(const std::string str) | ||
1679 | { | ||
1680 | // Parses for closing operators '${ }' and expands them letting | ||
1681 | // white spaces and other letters as they are. | ||
1682 | std::string new_string = ""; | ||
1683 | unsigned open_brackets = 0; | ||
1684 | unsigned first = 0; | ||
1685 | unsigned i = 0; | ||
1686 | for(; i<str.size(); ++i) { | ||
1687 | if( i < str.size() - 2 && str.substr(i, 2) == "${" ) { | ||
1688 | if( open_brackets == 0 ) first = i+2; | ||
1689 | open_brackets++; | ||
1690 | } | ||
1691 | else if( str[i] == '}' && open_brackets > 0) { | ||
1692 | open_brackets -= 1; | ||
1693 | if( open_brackets == 0 ) { | ||
1694 | const std::string Replacement = __DBE_expand(str.substr(first, i - first)); | ||
1695 | new_string += Replacement; | ||
1696 | } | ||
1697 | } | ||
1698 | else if( open_brackets == 0 ) | ||
1699 | new_string += str[i]; | ||
1700 | } | ||
1701 | return new_string; | ||
1702 | } | ||
1703 | |||
1704 | inline STRING_VECTOR | ||
1705 | GetPot::__DBE_get_expr_list(const std::string str_, const unsigned ExpectedNumber) | ||
1706 | // ensures that the resulting vector has the expected number | ||
1707 | // of arguments, but they may contain an error message | ||
1708 | { | ||
1709 | std::string str = str_; | ||
1710 | // Separates expressions by non-bracketed whitespaces, expands them | ||
1711 | // and puts them into a list. | ||
1712 | |||
1713 | unsigned i=0; | ||
1714 | // (1) eat initial whitespaces | ||
1715 | for(; i < str.size(); ++i) | ||
1716 | if( ! isspace(str[i]) ) break; | ||
1717 | |||
1718 | STRING_VECTOR expr_list; | ||
1719 | unsigned open_brackets = 0; | ||
1720 | std::vector<unsigned> start_idx; | ||
1721 | unsigned start_new_string = i; | ||
1722 | unsigned l = static_cast<unsigned int>(str.size()); | ||
1723 | |||
1724 | // (2) search for ${ } expressions ... | ||
1725 | while( i < l ) { | ||
1726 | const char letter = str[i]; | ||
1727 | // whitespace -> end of expression | ||
1728 | if( isspace(letter) && open_brackets == 0) { | ||
1729 | expr_list.push_back(str.substr(start_new_string, i - start_new_string)); | ||
1730 | bool no_breakout_f = true; | ||
1731 | for(++i; i < l ; ++i) { | ||
1732 | if( ! isspace(str[i]) ) | ||
1733 | { no_breakout_f = false; start_new_string = i; break; } | ||
1734 | } | ||
1735 | if( no_breakout_f ) { | ||
1736 | // end of expression list | ||
1737 | if( expr_list.size() < ExpectedNumber ) { | ||
1738 | const std::string pre_tmp("<< ${ }: missing arguments>>"); | ||
1739 | STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp); | ||
1740 | expr_list.insert(expr_list.end(), tmp.begin(), tmp.end()); | ||
1741 | } | ||
1742 | return expr_list; | ||
1743 | } | ||
1744 | } | ||
1745 | |||
1746 | // dollar-bracket expression | ||
1747 | if( str.length() >= i+2 && str.substr(i, 2) == "${" ) { | ||
1748 | open_brackets++; | ||
1749 | start_idx.push_back(i+2); | ||
1750 | } | ||
1751 | else if( letter == '}' && open_brackets > 0) { | ||
1752 | int start = start_idx[start_idx.size()-1]; | ||
1753 | start_idx.pop_back(); | ||
1754 | const std::string Replacement = __DBE_expand(str.substr(start, i-start)); | ||
1755 | if( start - 3 < (int)0) | ||
1756 | str = Replacement + str.substr(i+1); | ||
1757 | else | ||
1758 | str = str.substr(0, start-2) + Replacement + str.substr(i+1); | ||
1759 | l = static_cast<unsigned int>(str.size()); | ||
1760 | i = start + static_cast<unsigned int>(Replacement.size()) - 3; | ||
1761 | open_brackets--; | ||
1762 | } | ||
1763 | ++i; | ||
1764 | } | ||
1765 | |||
1766 | // end of expression list | ||
1767 | expr_list.push_back(str.substr(start_new_string, i-start_new_string)); | ||
1768 | |||
1769 | if( expr_list.size() < ExpectedNumber ) { | ||
1770 | const std::string pre_tmp("<< ${ }: missing arguments>>"); | ||
1771 | STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp); | ||
1772 | expr_list.insert(expr_list.end(), tmp.begin(), tmp.end()); | ||
1773 | } | ||
1774 | |||
1775 | return expr_list; | ||
1776 | } | ||
1777 | |||
1778 | inline const GetPot::variable* | ||
1779 | GetPot::__DBE_get_variable(std::string VarName) | ||
1780 | { | ||
1781 | static GetPot::variable ev; | ||
1782 | std::string secure_Prefix = prefix; | ||
1783 | |||
1784 | prefix = section; | ||
1785 | // (1) first search in currently active section | ||
1786 | const GetPot::variable* var = __find_variable(VarName.c_str()); | ||
1787 | if( var != 0 ) { prefix = secure_Prefix; return var; } | ||
1788 | |||
1789 | // (2) search in root name space | ||
1790 | prefix = ""; | ||
1791 | var = __find_variable(VarName.c_str()); | ||
1792 | if( var != 0 ) { prefix = secure_Prefix; return var; } | ||
1793 | |||
1794 | prefix = secure_Prefix; | ||
1795 | |||
1796 | // error occured => variable name == "" | ||
1797 | char* tmp = new char[VarName.length() + 25]; | ||
1798 | #ifndef WIN32 | ||
1799 | snprintf(tmp, (int)sizeof(char)*(VarName.length() + 25), | ||
1800 | #else | ||
1801 | _snprintf(tmp, sizeof(char)*(VarName.length() + 25), | ||
1802 | #endif | ||
1803 | "<<${ } variable '%s' undefined>>", VarName.c_str()); | ||
1804 | ev.name = ""; | ||
1805 | ev.original = std::string(tmp); | ||
1806 | delete [] tmp; | ||
1807 | return &ev; | ||
1808 | } | ||
1809 | |||
1810 | inline std::string | ||
1811 | GetPot::__DBE_expand(const std::string expr) | ||
1812 | { | ||
1813 | // ${: } pure text | ||
1814 | if( expr[0] == ':' ) | ||
1815 | return expr.substr(1); | ||
1816 | |||
1817 | // ${& expr expr ... } text concatination | ||
1818 | else if( expr[0] == '&' ) { | ||
1819 | const STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 1); | ||
1820 | |||
1821 | STRING_VECTOR::const_iterator it = A.begin(); | ||
1822 | std::string result = *it++; | ||
1823 | for(; it != A.end(); ++it) result += *it; | ||
1824 | |||
1825 | return result; | ||
1826 | } | ||
1827 | |||
1828 | // ${<-> expr expr expr} text replacement | ||
1829 | else if( expr.length() >= 3 && expr.substr(0, 3) == "<->" ) { | ||
1830 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(3), 3); | ||
1831 | std::string::size_type tmp = 0; | ||
1832 | const std::string::size_type L = A[1].length(); | ||
1833 | while( (tmp = A[0].find(A[1])) != std::string::npos ) { | ||
1834 | A[0].replace(tmp, L, A[2]); | ||
1835 | } | ||
1836 | return A[0]; | ||
1837 | } | ||
1838 | // ${+ ...}, ${- ...}, ${* ...}, ${/ ...} expressions | ||
1839 | else if( expr[0] == '+' ) { | ||
1840 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | ||
1841 | STRING_VECTOR::const_iterator it = A.begin(); | ||
1842 | double result = __convert_to_type(*it++, 0.0); | ||
1843 | for(; it != A.end(); ++it) | ||
1844 | result += __convert_to_type(*it, 0.0); | ||
1845 | |||
1846 | return __double2string(result); | ||
1847 | } | ||
1848 | else if( expr[0] == '-' ) { | ||
1849 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | ||
1850 | STRING_VECTOR::const_iterator it = A.begin(); | ||
1851 | double result = __convert_to_type(*it++, 0.0); | ||
1852 | for(; it != A.end(); ++it) | ||
1853 | result -= __convert_to_type(*it, 0.0); | ||
1854 | |||
1855 | return __double2string(result); | ||
1856 | } | ||
1857 | else if( expr[0] == '*' ) { | ||
1858 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | ||
1859 | STRING_VECTOR::const_iterator it = A.begin(); | ||
1860 | double result = __convert_to_type(*it++, 0.0); | ||
1861 | for(; it != A.end(); ++it) | ||
1862 | result *= __convert_to_type(*it, 0.0); | ||
1863 | |||
1864 | return __double2string(result); | ||
1865 | } | ||
1866 | else if( expr[0] == '/' ) { | ||
1867 | |||
1868 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | ||
1869 | STRING_VECTOR::const_iterator it = A.begin(); | ||
1870 | double result = __convert_to_type(*it++, 0.0); | ||
1871 | if( result == 0 ) return "0.0"; | ||
1872 | for(; it != A.end(); ++it) { | ||
1873 | const double Q = __convert_to_type(*it, 0.0); | ||
1874 | if( Q == 0.0 ) return "0.0"; | ||
1875 | result /= Q; | ||
1876 | } | ||
1877 | return __double2string(result); | ||
1878 | } | ||
1879 | |||
1880 | // ${^ ... } power expressions | ||
1881 | else if( expr[0] == '^' ) { | ||
1882 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | ||
1883 | STRING_VECTOR::const_iterator it = A.begin(); | ||
1884 | double result = __convert_to_type(*it++, 0.0); | ||
1885 | for(; it != A.end(); ++it) | ||
1886 | result = pow(result, __convert_to_type(*it, 0.0)); | ||
1887 | return __double2string(result); | ||
1888 | } | ||
1889 | |||
1890 | // ${== } ${<= } ${>= } comparisons (return the number of the first 'match' | ||
1891 | else if( expr.length() >= 2 && | ||
1892 | ( expr.substr(0,2) == "==" || expr.substr(0,2) == ">=" || | ||
1893 | expr.substr(0,2) == "<=" || expr[0] == '>' || expr[0] == '<')) { | ||
1894 | // differentiate between two and one sign operators | ||
1895 | unsigned op = 0; | ||
1896 | enum { EQ, GEQ, LEQ, GT, LT }; | ||
1897 | if ( expr.substr(0, 2) == "==" ) op = EQ; | ||
1898 | else if ( expr.substr(0, 2) == ">=" ) op = GEQ; | ||
1899 | else if ( expr.substr(0, 2) == "<=" ) op = LEQ; | ||
1900 | else if ( expr[0] == '>' ) op = GT; | ||
1901 | else /* "<" */ op = LT; | ||
1902 | |||
1903 | STRING_VECTOR a; | ||
1904 | if ( op == GT || op == LT ) a = __DBE_get_expr_list(expr.substr(1), 2); | ||
1905 | else a = __DBE_get_expr_list(expr.substr(2), 2); | ||
1906 | |||
1907 | std::string x_orig = a[0]; | ||
1908 | double x = __convert_to_type(x_orig, 1e37); | ||
1909 | unsigned i = 1; | ||
1910 | |||
1911 | STRING_VECTOR::const_iterator y_orig = a.begin(); | ||
1912 | for(y_orig++; y_orig != a.end(); y_orig++) { | ||
1913 | double y = __convert_to_type(*y_orig, 1e37); | ||
1914 | |||
1915 | // set the strings as reference if one wasn't a number | ||
1916 | if ( x == 1e37 || y == 1e37 ) { | ||
1917 | // it's a string comparison | ||
1918 | if( (op == EQ && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) || | ||
1919 | (op == LEQ && x_orig <= *y_orig) || (op == GT && x_orig > *y_orig) || | ||
1920 | (op == LT && x_orig < *y_orig) ) | ||
1921 | return __int2string(i); | ||
1922 | } | ||
1923 | else { | ||
1924 | // it's a number comparison | ||
1925 | if( (op == EQ && x == y) || (op == GEQ && x >= y) || | ||
1926 | (op == LEQ && x <= y) || (op == GT && x > y) || | ||
1927 | (op == LT && x < y) ) | ||
1928 | return __int2string(i); | ||
1929 | } | ||
1930 | ++i; | ||
1931 | } | ||
1932 | |||
1933 | // nothing fulfills the condition => return 0 | ||
1934 | return "0"; | ||
1935 | } | ||
1936 | // ${?? expr expr} select | ||
1937 | else if( expr.length() >= 2 && expr.substr(0, 2) == "??" ) { | ||
1938 | STRING_VECTOR a = __DBE_get_expr_list(expr.substr(2), 2); | ||
1939 | double x = __convert_to_type(a[0], 1e37); | ||
1940 | // last element is always the default argument | ||
1941 | if( x == 1e37 || x < 0 || x >= a.size() - 1 ) return a[a.size()-1]; | ||
1942 | |||
1943 | // round x to closest integer | ||
1944 | return a[int(x+0.5)]; | ||
1945 | } | ||
1946 | // ${? expr expr expr} if then else conditions | ||
1947 | else if( expr[0] == '?' ) { | ||
1948 | STRING_VECTOR a = __DBE_get_expr_list(expr.substr(1), 2); | ||
1949 | if( __convert_to_type(a[0], 0.0) == 1.0 ) return a[1]; | ||
1950 | else if( a.size() > 2 ) return a[2]; | ||
1951 | } | ||
1952 | // ${! expr} maxro expansion | ||
1953 | else if( expr[0] == '!' ) { | ||
1954 | const GetPot::variable* Var = __DBE_get_variable(expr.substr(1)); | ||
1955 | // error | ||
1956 | if( Var->name == "" ) return std::string(Var->original); | ||
1957 | |||
1958 | const STRING_VECTOR A = __DBE_get_expr_list(Var->original, 2); | ||
1959 | return A[0]; | ||
1960 | } | ||
1961 | // ${@: } - string subscription | ||
1962 | else if( expr.length() >= 2 && expr.substr(0,2) == "@:" ) { | ||
1963 | const STRING_VECTOR A = __DBE_get_expr_list(expr.substr(2), 2); | ||
1964 | double x = __convert_to_type(A[1], 1e37); | ||
1965 | |||
1966 | // last element is always the default argument | ||
1967 | if( x == 1e37 || x < 0 || x >= A[0].size() - 1) | ||
1968 | return "<<1st index out of range>>"; | ||
1969 | |||
1970 | if( A.size() > 2 ) { | ||
1971 | double y = __convert_to_type(A[2], 1e37); | ||
1972 | if ( y != 1e37 && y > 0 && y <= A[0].size() - 1 && y > x ) | ||
1973 | return A[0].substr(int(x+0.5), int(y+1.5) - int(x+0.5)); | ||
1974 | else if( y == -1 ) | ||
1975 | return A[0].substr(int(x+0.5)); | ||
1976 | return "<<2nd index out of range>>"; | ||
1977 | } | ||
1978 | else { | ||
1979 | char* tmp = new char[2]; | ||
1980 | tmp[0] = A[0][int(x+0.5)]; tmp[1] = '\0'; | ||
1981 | std::string result(tmp); | ||
1982 | delete [] tmp; | ||
1983 | return result; | ||
1984 | } | ||
1985 | } | ||
1986 | // ${@ } - vector subscription | ||
1987 | else if( expr[0] == '@' ) { | ||
1988 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | ||
1989 | const GetPot::variable* Var = __DBE_get_variable(A[0]); | ||
1990 | // error | ||
1991 | if( Var->name == "" ) { | ||
1992 | // make a copy of the string if an error occured | ||
1993 | // (since the error variable is a static variable inside get_variable()) | ||
1994 | return std::string(Var->original); | ||
1995 | } | ||
1996 | |||
1997 | double x = __convert_to_type(A[1], 1e37); | ||
1998 | |||
1999 | // last element is always the default argument | ||
2000 | if (x == 1e37 || x < 0 || x >= Var->value.size() ) | ||
2001 | return "<<1st index out of range>>"; | ||
2002 | |||
2003 | if ( A.size() > 2) { | ||
2004 | double y = __convert_to_type(A[2], 1e37); | ||
2005 | int begin = int(x+0.5); | ||
2006 | int end = 0; | ||
2007 | if ( y != 1e37 && y > 0 && y <= Var->value.size() && y > x) | ||
2008 | end = int(y+1.5); | ||
2009 | else if( y == -1 ) | ||
2010 | end = static_cast<unsigned int>(Var->value.size()); | ||
2011 | else | ||
2012 | return "<<2nd index out of range>>"; | ||
2013 | |||
2014 | std::string result = *(Var->get_element(begin)); | ||
2015 | int i = begin+1; | ||
2016 | for(; i < end; ++i) | ||
2017 | result += std::string(" ") + *(Var->get_element(i)); | ||
2018 | return result; | ||
2019 | } | ||
2020 | else | ||
2021 | return *(Var->get_element(int(x+0.5))); | ||
2022 | } | ||
2023 | |||
2024 | const STRING_VECTOR A = __DBE_get_expr_list(expr, 1); | ||
2025 | const GetPot::variable* B = __DBE_get_variable(A[0]); | ||
2026 | |||
2027 | // make a copy of the string if an error occured | ||
2028 | // (since the error variable is a static variable inside get_variable()) | ||
2029 | if( B->name == "" ) return std::string(B->original); | ||
2030 | // (psuggs@pobox.com mentioned to me the warning MSVC++6.0 produces | ||
2031 | // with: else return B->original (thanks)) | ||
2032 | return B->original; | ||
2033 | } | ||
2034 | |||
2035 | |||
2036 | /////////////////////////////////////////////////////////////////////////////// | ||
2037 | // (*) unidentified flying objects | ||
2038 | //............................................................................. | ||
2039 | // | ||
2040 | inline bool | ||
2041 | GetPot::__search_string_vector(const STRING_VECTOR& VecStr, const std::string& Str) const | ||
2042 | { | ||
2043 | victorate(std::string, VecStr, itk) { | ||
2044 | if( *itk == Str ) return true; | ||
2045 | } | ||
2046 | return false; | ||
2047 | } | ||
2048 | |||
2049 | inline STRING_VECTOR | ||
2050 | GetPot::unidentified_arguments(unsigned Number, | ||
2051 | const char* KnownArgument1, ...) const | ||
2052 | { | ||
2053 | STRING_VECTOR known_arguments; | ||
2054 | |||
2055 | // (1) create a vector of known arguments | ||
2056 | if( Number == 0 ) return STRING_VECTOR(); | ||
2057 | |||
2058 | va_list ap; | ||
2059 | va_start(ap, KnownArgument1); | ||
2060 | known_arguments.push_back(std::string(KnownArgument1)); | ||
2061 | unsigned i=1; | ||
2062 | for(; i<Number; ++i) | ||
2063 | known_arguments.push_back(std::string(va_arg(ap, char *))); | ||
2064 | va_end(ap); | ||
2065 | |||
2066 | return unidentified_arguments(known_arguments); | ||
2067 | } | ||
2068 | |||
2069 | inline STRING_VECTOR | ||
2070 | GetPot::unidentified_arguments() const | ||
2071 | { return unidentified_arguments(_requested_arguments); } | ||
2072 | |||
2073 | inline STRING_VECTOR | ||
2074 | GetPot::unidentified_arguments(const STRING_VECTOR& Knowns) const | ||
2075 | { | ||
2076 | STRING_VECTOR ufos; | ||
2077 | STRING_VECTOR::const_iterator it = argv.begin(); | ||
2078 | ++it; // forget about argv[0] (application or filename) | ||
2079 | for(; it != argv.end(); ++it) { | ||
2080 | // -- argument belongs to prefixed section ? | ||
2081 | const std::string arg = __get_remaining_string(*it, prefix); | ||
2082 | if( arg == "" ) continue; | ||
2083 | |||
2084 | // -- check if in list | ||
2085 | if( __search_string_vector(Knowns, arg) == false) | ||
2086 | ufos.push_back(*it); | ||
2087 | } | ||
2088 | return ufos; | ||
2089 | } | ||
2090 | |||
2091 | inline STRING_VECTOR | ||
2092 | GetPot::unidentified_options(unsigned Number, | ||
2093 | const char* KnownOption1, ...) const | ||
2094 | { | ||
2095 | STRING_VECTOR known_options; | ||
2096 | |||
2097 | // (1) create a vector of known arguments | ||
2098 | if( Number == 0 ) return STRING_VECTOR(); | ||
2099 | |||
2100 | va_list ap; | ||
2101 | va_start(ap, KnownOption1); | ||
2102 | known_options.push_back(std::string(KnownOption1)); | ||
2103 | unsigned i=1; | ||
2104 | for(; i<Number; ++i) | ||
2105 | known_options.push_back(std::string(va_arg(ap, char *))); | ||
2106 | va_end(ap); | ||
2107 | |||
2108 | return unidentified_options(known_options); | ||
2109 | } | ||
2110 | |||
2111 | inline STRING_VECTOR | ||
2112 | GetPot::unidentified_options() const | ||
2113 | { | ||
2114 | // -- every option is an argument. | ||
2115 | // -- the set of requested arguments contains the set of requested options. | ||
2116 | // -- IF the set of requested arguments contains unrequested options, | ||
2117 | // THEN they were requested as 'follow' and 'next' arguments and not as real options. | ||
2118 | // | ||
2119 | // => it is not necessary to separate requested options from the list | ||
2120 | STRING_VECTOR option_list; | ||
2121 | victorate(std::string, _requested_arguments, it) { | ||
2122 | const std::string arg = *it; | ||
2123 | if( arg.length() == 0 ) continue; | ||
2124 | if( arg[0] == '-' ) option_list.push_back(arg); | ||
2125 | } | ||
2126 | return unidentified_options(option_list); | ||
2127 | } | ||
2128 | |||
2129 | inline STRING_VECTOR | ||
2130 | GetPot::unidentified_options(const STRING_VECTOR& Knowns) const | ||
2131 | { | ||
2132 | STRING_VECTOR ufos; | ||
2133 | STRING_VECTOR::const_iterator it = argv.begin(); | ||
2134 | ++it; // forget about argv[0] (application or filename) | ||
2135 | for(; it != argv.end(); ++it) { | ||
2136 | // -- argument belongs to prefixed section ? | ||
2137 | const std::string arg = __get_remaining_string(*it, prefix); | ||
2138 | if( arg == "" ) continue; | ||
2139 | |||
2140 | // is argument really an option (starting with '-') ? | ||
2141 | if( arg.length() < 1 || arg[0] != '-' ) continue; | ||
2142 | |||
2143 | if( __search_string_vector(Knowns, arg) == false) | ||
2144 | ufos.push_back(*it); | ||
2145 | } | ||
2146 | |||
2147 | return ufos; | ||
2148 | } | ||
2149 | |||
2150 | inline std::string | ||
2151 | GetPot::unidentified_flags(const char* KnownFlagList, int ArgumentNumber=-1) const | ||
2152 | // Two modes: | ||
2153 | // ArgumentNumber >= 0 check specific argument | ||
2154 | // ArgumentNumber == -1 check all options starting with one '-' | ||
2155 | // for flags | ||
2156 | { | ||
2157 | std::string ufos; | ||
2158 | STRING_VECTOR known_arguments; | ||
2159 | std::string KFL(KnownFlagList); | ||
2160 | |||
2161 | // (2) iteration over '-' arguments (options) | ||
2162 | if( ArgumentNumber == -1 ) { | ||
2163 | STRING_VECTOR::const_iterator it = argv.begin(); | ||
2164 | ++it; // forget about argv[0] (application or filename) | ||
2165 | for(; it != argv.end(); ++it) { | ||
2166 | // -- argument belongs to prefixed section ? | ||
2167 | const std::string arg = __get_remaining_string(*it, prefix); | ||
2168 | if( arg == "" ) continue; | ||
2169 | |||
2170 | // -- does arguments start with '-' (but not '--') | ||
2171 | if ( arg.length() < 2 ) continue; | ||
2172 | else if( arg[0] != '-' ) continue; | ||
2173 | else if( arg[1] == '-' ) continue; | ||
2174 | |||
2175 | // -- check out if flags inside option are contained in KnownFlagList | ||
2176 | const char* p=arg.c_str(); | ||
2177 | p++; // skip starting minus | ||
2178 | for(; *p != '\0' ; p++) | ||
2179 | if( KFL.find(*p) == std::string::npos ) ufos += *p; | ||
2180 | } | ||
2181 | } | ||
2182 | // (1) check specific argument | ||
2183 | else { | ||
2184 | // -- only check arguments that start with prefix | ||
2185 | int no_matches = 0; | ||
2186 | unsigned i=1; | ||
2187 | for(; i<argv.size(); ++i) { | ||
2188 | const std::string Remain = __get_remaining_string(argv[i], prefix); | ||
2189 | if( Remain != "") { | ||
2190 | no_matches++; | ||
2191 | if( no_matches == ArgumentNumber) { | ||
2192 | // -- the right argument number inside the section is found | ||
2193 | // => check it for flags | ||
2194 | const char* p = Remain.c_str(); | ||
2195 | p++; // skip starting minus | ||
2196 | for(; *p != '\0' ; p++) | ||
2197 | if( KFL.find(*p) == std::string::npos ) ufos += *p; | ||
2198 | return ufos; | ||
2199 | } | ||
2200 | } | ||
2201 | } | ||
2202 | } | ||
2203 | return ufos; | ||
2204 | } | ||
2205 | |||
2206 | inline STRING_VECTOR | ||
2207 | GetPot::unidentified_variables(unsigned Number, | ||
2208 | const char* KnownVariable1, ...) const | ||
2209 | { | ||
2210 | STRING_VECTOR known_variables; | ||
2211 | |||
2212 | // create vector of known arguments | ||
2213 | if( Number == 0 ) return STRING_VECTOR(); | ||
2214 | |||
2215 | va_list ap; | ||
2216 | va_start(ap, KnownVariable1); | ||
2217 | known_variables.push_back(std::string(KnownVariable1)); | ||
2218 | unsigned i=1; | ||
2219 | for(; i<Number; ++i) | ||
2220 | known_variables.push_back(std::string(va_arg(ap, char *))); | ||
2221 | va_end(ap); | ||
2222 | |||
2223 | return unidentified_variables(known_variables); | ||
2224 | } | ||
2225 | |||
2226 | inline STRING_VECTOR | ||
2227 | GetPot::unidentified_variables(const STRING_VECTOR& Knowns) const | ||
2228 | { | ||
2229 | STRING_VECTOR ufos; | ||
2230 | |||
2231 | victorate(GetPot::variable, variables, it) { | ||
2232 | // -- check if variable has specific prefix | ||
2233 | const std::string var_name = __get_remaining_string((*it).name, prefix); | ||
2234 | if( var_name == "" ) continue; | ||
2235 | |||
2236 | // -- check if variable is known | ||
2237 | if( __search_string_vector(Knowns, var_name) == false) | ||
2238 | ufos.push_back((*it).name); | ||
2239 | } | ||
2240 | return ufos; | ||
2241 | } | ||
2242 | |||
2243 | inline STRING_VECTOR | ||
2244 | GetPot::unidentified_variables() const | ||
2245 | { return unidentified_variables(_requested_variables); } | ||
2246 | |||
2247 | |||
2248 | inline STRING_VECTOR | ||
2249 | GetPot::unidentified_sections(unsigned Number, | ||
2250 | const char* KnownSection1, ...) const | ||
2251 | { | ||
2252 | STRING_VECTOR known_sections; | ||
2253 | |||
2254 | // (1) create a vector of known arguments | ||
2255 | if( Number == 0 ) return STRING_VECTOR(); | ||
2256 | |||
2257 | va_list ap; | ||
2258 | va_start(ap, KnownSection1); | ||
2259 | known_sections.push_back(std::string(KnownSection1)); | ||
2260 | unsigned i=1; | ||
2261 | for(; i<Number; ++i) { | ||
2262 | std::string tmp = std::string(va_arg(ap, char *)); | ||
2263 | if( tmp.length() == 0 ) continue; | ||
2264 | if( tmp[tmp.length()-1] != '/' ) tmp += '/'; | ||
2265 | known_sections.push_back(tmp); | ||
2266 | } | ||
2267 | va_end(ap); | ||
2268 | |||
2269 | return unidentified_sections(known_sections); | ||
2270 | } | ||
2271 | |||
2272 | inline STRING_VECTOR | ||
2273 | GetPot::unidentified_sections() const | ||
2274 | { return unidentified_sections(_requested_sections); } | ||
2275 | |||
2276 | inline STRING_VECTOR | ||
2277 | GetPot::unidentified_sections(const STRING_VECTOR& Knowns) const | ||
2278 | { | ||
2279 | STRING_VECTOR ufos; | ||
2280 | |||
2281 | victorate(std::string, section_list, it) { | ||
2282 | // -- check if section conform to prefix | ||
2283 | const std::string sec_name = __get_remaining_string(*it, prefix); | ||
2284 | if( sec_name == "" ) continue; | ||
2285 | |||
2286 | // -- check if section is known | ||
2287 | if( __search_string_vector(Knowns, sec_name) == false ) | ||
2288 | ufos.push_back(*it); | ||
2289 | } | ||
2290 | |||
2291 | return ufos; | ||
2292 | } | ||
2293 | |||
2294 | |||
2295 | inline STRING_VECTOR | ||
2296 | GetPot::unidentified_nominuses(unsigned Number, const char* Known, ...) const | ||
2297 | { | ||
2298 | STRING_VECTOR known_nominuses; | ||
2299 | |||
2300 | // create vector of known arguments | ||
2301 | if( Number == 0 ) return STRING_VECTOR(); | ||
2302 | |||
2303 | va_list ap; | ||
2304 | va_start(ap, Known); | ||
2305 | known_nominuses.push_back(std::string(Known)); | ||
2306 | unsigned i=1; | ||
2307 | for(; i<Number; ++i) { | ||
2308 | std::string tmp = std::string(va_arg(ap, char *)); | ||
2309 | if( tmp.length() == 0 ) continue; | ||
2310 | known_nominuses.push_back(tmp); | ||
2311 | } | ||
2312 | va_end(ap); | ||
2313 | |||
2314 | return unidentified_nominuses(known_nominuses); | ||
2315 | } | ||
2316 | |||
2317 | inline STRING_VECTOR | ||
2318 | GetPot::unidentified_nominuses() const { | ||
2319 | // -- every nominus is an argument. | ||
2320 | // -- the set of requested arguments contains the set of requested nominuss. | ||
2321 | // -- IF the set of requested arguments contains unrequested nominuss, | ||
2322 | // THEN they were requested as 'follow' and 'next' arguments and not as real nominuses. | ||
2323 | // | ||
2324 | // => it is not necessary to separate requested nominus from the list | ||
2325 | |||
2326 | return unidentified_nominuses(_requested_arguments); | ||
2327 | } | ||
2328 | |||
2329 | inline STRING_VECTOR | ||
2330 | GetPot::unidentified_nominuses(const STRING_VECTOR& Knowns) const | ||
2331 | { | ||
2332 | STRING_VECTOR ufos; | ||
2333 | |||
2334 | // (2) iterate over all arguments | ||
2335 | STRING_VECTOR::const_iterator it = argv.begin(); | ||
2336 | ++it; // forget about argv[0] (application or filename) | ||
2337 | for(; it != argv.end(); ++it) { | ||
2338 | // -- check if nominus part of prefix | ||
2339 | const std::string arg = __get_remaining_string(*it, prefix); | ||
2340 | if( arg == "" ) continue; | ||
2341 | |||
2342 | if( arg.length() < 1 ) continue; | ||
2343 | // option ? --> not a nomius | ||
2344 | if( arg[0] == '-' ) continue; | ||
2345 | // section ? --> not a real nominus | ||
2346 | if( arg[0] == '[' && arg[arg.length()-1] == ']' ) continue; | ||
2347 | // variable definition ? --> not a real nominus | ||
2348 | bool continue_f = false; | ||
2349 | unsigned i=0; | ||
2350 | for(; i<arg.length() ; ++i) | ||
2351 | if( arg[i] == '=' ) { continue_f = true; break; } | ||
2352 | if( continue_f ) continue; | ||
2353 | |||
2354 | // real nominuses are compared with the given list | ||
2355 | if( __search_string_vector(Knowns, arg) == false ) | ||
2356 | ufos.push_back(*it); | ||
2357 | } | ||
2358 | return ufos; | ||
2359 | } | ||
2360 | |||
2361 | |||
2362 | /////////////////////////////////////////////////////////////////////////////// | ||
2363 | // (*) variable class | ||
2364 | //............................................................................. | ||
2365 | // | ||
2366 | inline | ||
2367 | GetPot::variable::variable() | ||
2368 | {} | ||
2369 | |||
2370 | inline | ||
2371 | GetPot::variable::variable(const variable& That) | ||
2372 | { | ||
2373 | #ifdef WIN32 | ||
2374 | operator=(That); | ||
2375 | #else | ||
2376 | GetPot::variable::operator=(That); | ||
2377 | #endif | ||
2378 | } | ||
2379 | |||
2380 | |||
2381 | inline | ||
2382 | GetPot::variable::variable(const char* Name, const char* Value, const char* FieldSeparator) | ||
2383 | : name(Name) | ||
2384 | { | ||
2385 | // make a copy of the 'Value' | ||
2386 | take(Value, FieldSeparator); | ||
2387 | } | ||
2388 | |||
2389 | inline const std::string* | ||
2390 | GetPot::variable::get_element(unsigned Idx) const | ||
2391 | { if( Idx >= value.size() ) return 0; else return &(value[Idx]); } | ||
2392 | |||
2393 | inline void | ||
2394 | GetPot::variable::take(const char* Value, const char* FieldSeparator) | ||
2395 | { | ||
2396 | original = std::string(Value); | ||
2397 | |||
2398 | // separate string by white space delimiters using 'strtok' | ||
2399 | // thread safe usage of strtok (no static members) | ||
2400 | char* spt = 0; | ||
2401 | // make a copy of the 'Value' | ||
2402 | char* copy = new char[strlen(Value)+1]; | ||
2403 | strcpy(copy, Value); | ||
2404 | char* follow_token = strtok_r(copy, FieldSeparator, &spt); | ||
2405 | if( value.size() != 0 ) value.erase(value.begin(), value.end()); | ||
2406 | while(follow_token != 0) { | ||
2407 | value.push_back(std::string(follow_token)); | ||
2408 | follow_token = strtok_r(NULL, FieldSeparator, &spt); | ||
2409 | } | ||
2410 | |||
2411 | delete [] copy; | ||
2412 | } | ||
2413 | |||
2414 | inline | ||
2415 | GetPot::variable::~variable() | ||
2416 | {} | ||
2417 | |||
2418 | inline GetPot::variable& | ||
2419 | GetPot::variable::operator=(const GetPot::variable& That) | ||
2420 | { | ||
2421 | if( &That != this) { | ||
2422 | name = That.name; | ||
2423 | value = That.value; | ||
2424 | original = That.original; | ||
2425 | } | ||
2426 | return *this; | ||
2427 | } | ||
2428 | |||
2429 | #undef victorate | ||
2430 | |||
2431 | |||
2432 | #endif // __include_guard_GETPOT_H__ | ||
2433 | |||
2434 | |||
2435 | |||
diff --git a/utils/zenutils/libraries/getpot-c++-1.1.17/getpot/GetPot b/utils/zenutils/libraries/getpot-c++-1.1.18/getpot/GetPot index 0663880990..4c305f6532 100644 --- a/utils/zenutils/libraries/getpot-c++-1.1.17/getpot/GetPot +++ b/utils/zenutils/libraries/getpot-c++-1.1.18/getpot/GetPot | |||
@@ -1,4 +1,4 @@ | |||
1 | // -*- c++ -*- | 1 | // -*- c++ -*- vim: set syntax=cpp: |
2 | // GetPot Version $$Version$$ $$Date$$ | 2 | // GetPot Version $$Version$$ $$Date$$ |
3 | // | 3 | // |
4 | // WEBSITE: http://getpot.sourceforge.net | 4 | // WEBSITE: http://getpot.sourceforge.net |
@@ -23,7 +23,7 @@ | |||
23 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | 23 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
24 | // USA | 24 | // USA |
25 | // | 25 | // |
26 | // (C) 2001-2005 Frank R. Schaefer <fschaef@users.sf.net> | 26 | // (C) 2001-2007 Frank R. Schaefer <fschaef@users.sf.net> |
27 | //========================================================================== | 27 | //========================================================================== |
28 | 28 | ||
29 | #ifndef __include_guard_GETPOT_H__ | 29 | #ifndef __include_guard_GETPOT_H__ |
@@ -43,6 +43,7 @@ extern "C" { | |||
43 | #include <stdio.h> | 43 | #include <stdio.h> |
44 | #include <stdarg.h> | 44 | #include <stdarg.h> |
45 | #include <assert.h> | 45 | #include <assert.h> |
46 | #include <string.h> | ||
46 | } | 47 | } |
47 | #include <cmath> | 48 | #include <cmath> |
48 | #include <string> | 49 | #include <string> |
@@ -68,10 +69,10 @@ public: | |||
68 | inline GetPot(); | 69 | inline GetPot(); |
69 | inline GetPot(const GetPot&); | 70 | inline GetPot(const GetPot&); |
70 | inline GetPot(const int argc_, char** argv_, | 71 | inline GetPot(const int argc_, char** argv_, |
71 | const char* FieldSeparator=0x0); | 72 | const char* FieldSeparator=0x0); |
72 | inline GetPot(const char* FileName, | 73 | inline GetPot(const char* FileName, |
73 | const char* CommentStart=0x0, const char* CommentEnd=0x0, | 74 | const char* CommentStart=0x0, const char* CommentEnd=0x0, |
74 | const char* FieldSeparator=0x0); | 75 | const char* FieldSeparator=0x0); |
75 | inline ~GetPot(); | 76 | inline ~GetPot(); |
76 | inline GetPot& operator=(const GetPot&); | 77 | inline GetPot& operator=(const GetPot&); |
77 | 78 | ||
@@ -171,7 +172,7 @@ public: | |||
171 | inline STRING_VECTOR unidentified_options() const; | 172 | inline STRING_VECTOR unidentified_options() const; |
172 | 173 | ||
173 | inline std::string unidentified_flags(const char* Known, | 174 | inline std::string unidentified_flags(const char* Known, |
174 | int ArgumentNumber /* =-1 */) const; | 175 | int ArgumentNumber /* =-1 */) const; |
175 | 176 | ||
176 | inline STRING_VECTOR unidentified_variables(unsigned Number, const char* Known, ...) const; | 177 | inline STRING_VECTOR unidentified_variables(unsigned Number, const char* Known, ...) const; |
177 | inline STRING_VECTOR unidentified_variables(const STRING_VECTOR& Knowns) const; | 178 | inline STRING_VECTOR unidentified_variables(const STRING_VECTOR& Knowns) const; |
@@ -191,27 +192,27 @@ public: | |||
191 | private: | 192 | private: |
192 | // (*) Type Declaration ---------------------------------------------------- | 193 | // (*) Type Declaration ---------------------------------------------------- |
193 | struct variable { | 194 | struct variable { |
194 | //----------- | 195 | //----------- |
195 | // Variable to be specified on the command line or in input files. | 196 | // Variable to be specified on the command line or in input files. |
196 | // (i.e. of the form var='12 312 341') | 197 | // (i.e. of the form var='12 312 341') |
197 | 198 | ||
198 | // -- constructors, destructors, assignment operator | 199 | // -- constructors, destructors, assignment operator |
199 | variable(); | 200 | variable(); |
200 | variable(const variable&); | 201 | variable(const variable&); |
201 | variable(const char* Name, const char* Value, const char* FieldSeparator); | 202 | variable(const char* Name, const char* Value, const char* FieldSeparator); |
202 | ~variable(); | 203 | ~variable(); |
203 | variable& operator=(const variable& That); | 204 | variable& operator=(const variable& That); |
204 | 205 | ||
205 | void take(const char* Value, const char* FieldSeparator); | 206 | void take(const char* Value, const char* FieldSeparator); |
206 | 207 | ||
207 | // -- get a specific element in the string vector | 208 | // -- get a specific element in the string vector |
208 | // (return 0 if not present) | 209 | // (return 0 if not present) |
209 | const std::string* get_element(unsigned Idx) const; | 210 | const std::string* get_element(unsigned Idx) const; |
210 | 211 | ||
211 | // -- data memebers | 212 | // -- data memebers |
212 | std::string name; // identifier of variable | 213 | std::string name; // identifier of variable |
213 | STRING_VECTOR value; // value of variable stored in vector | 214 | STRING_VECTOR value; // value of variable stored in vector |
214 | std::string original; // value of variable as given on command line | 215 | std::string original; // value of variable as given on command line |
215 | }; | 216 | }; |
216 | 217 | ||
217 | // (*) member variables -------------------------------------------------------------- | 218 | // (*) member variables -------------------------------------------------------------- |
@@ -280,10 +281,10 @@ private: | |||
280 | inline double __convert_to_type(const std::string& String, double Default) const; | 281 | inline double __convert_to_type(const std::string& String, double Default) const; |
281 | // * prefix extraction | 282 | // * prefix extraction |
282 | const std::string __get_remaining_string(const std::string& String, | 283 | const std::string __get_remaining_string(const std::string& String, |
283 | const std::string& Start) const; | 284 | const std::string& Start) const; |
284 | // * search for a specific string | 285 | // * search for a specific string |
285 | inline bool __search_string_vector(const STRING_VECTOR& Vec, | 286 | inline bool __search_string_vector(const STRING_VECTOR& Vec, |
286 | const std::string& Str) const; | 287 | const std::string& Str) const; |
287 | 288 | ||
288 | // -- helpers to parse input file | 289 | // -- helpers to parse input file |
289 | // create an argument vector based on data found in an input file, i.e.: | 290 | // create an argument vector based on data found in an input file, i.e.: |
@@ -301,7 +302,7 @@ private: | |||
301 | inline STRING_VECTOR __read_in_stream(std::istream& istr); | 302 | inline STRING_VECTOR __read_in_stream(std::istream& istr); |
302 | inline STRING_VECTOR __read_in_file(const char* FileName); | 303 | inline STRING_VECTOR __read_in_file(const char* FileName); |
303 | inline std::string __process_section_label(const std::string& Section, | 304 | inline std::string __process_section_label(const std::string& Section, |
304 | STRING_VECTOR& section_stack); | 305 | STRING_VECTOR& section_stack); |
305 | 306 | ||
306 | // -- dollar bracket expressions | 307 | // -- dollar bracket expressions |
307 | std::string __DBE_expand_string(const std::string str); | 308 | std::string __DBE_expand_string(const std::string str); |
@@ -310,47 +311,47 @@ private: | |||
310 | STRING_VECTOR __DBE_get_expr_list(const std::string str, const unsigned ExpectedNumber); | 311 | STRING_VECTOR __DBE_get_expr_list(const std::string str, const unsigned ExpectedNumber); |
311 | 312 | ||
312 | std::string __double2string(const double& Value) const { | 313 | std::string __double2string(const double& Value) const { |
313 | // -- converts a double integer into a string | 314 | // -- converts a double integer into a string |
314 | char* tmp = new char[128]; | 315 | char* tmp = new char[128]; |
315 | #ifndef WIN32 | 316 | #ifndef WIN32 |
316 | snprintf(tmp, (int)sizeof(char)*128, "%e", Value); | 317 | snprintf(tmp, (int)sizeof(char)*128, "%e", Value); |
317 | #else | 318 | #else |
318 | _snprintf(tmp, sizeof(char)*128, "%e", Value); | 319 | _snprintf(tmp, sizeof(char)*128, "%e", Value); |
319 | #endif | 320 | #endif |
320 | std::string result(tmp); | 321 | std::string result(tmp); |
321 | delete [] tmp; | 322 | delete [] tmp; |
322 | return result; | 323 | return result; |
323 | } | 324 | } |
324 | 325 | ||
325 | std::string __int2string(const int& Value) const { | 326 | std::string __int2string(const int& Value) const { |
326 | // -- converts an integer into a string | 327 | // -- converts an integer into a string |
327 | char* tmp = new char[128]; | 328 | char* tmp = new char[128]; |
328 | #ifndef WIN32 | 329 | #ifndef WIN32 |
329 | snprintf(tmp, (int)sizeof(char)*128, "%i", Value); | 330 | snprintf(tmp, (int)sizeof(char)*128, "%i", Value); |
330 | #else | 331 | #else |
331 | _snprintf(tmp, sizeof(char)*128, "%i", Value); | 332 | _snprintf(tmp, sizeof(char)*128, "%i", Value); |
332 | #endif | 333 | #endif |
333 | std::string result(tmp); | 334 | std::string result(tmp); |
334 | delete [] tmp; | 335 | delete [] tmp; |
335 | return result; | 336 | return result; |
336 | } | 337 | } |
337 | 338 | ||
338 | STRING_VECTOR __get_section_tree(const std::string& FullPath) { | 339 | STRING_VECTOR __get_section_tree(const std::string& FullPath) { |
339 | // -- cuts a variable name into a tree of sub-sections. this is requested for recording | 340 | // -- cuts a variable name into a tree of sub-sections. this is requested for recording |
340 | // requested sections when dealing with 'ufo' detection. | 341 | // requested sections when dealing with 'ufo' detection. |
341 | STRING_VECTOR result; | 342 | STRING_VECTOR result; |
342 | const char* Start = FullPath.c_str(); | 343 | const char* Start = FullPath.c_str(); |
343 | 344 | ||
344 | for(char *p = (char*)Start; *p ; p++) { | 345 | for(char *p = (char*)Start; *p ; p++) { |
345 | if( *p == '/' ) { | 346 | if( *p == '/' ) { |
346 | *p = '\0'; // set terminating zero for convinience | 347 | *p = '\0'; // set terminating zero for convinience |
347 | const std::string Section = Start; | 348 | const std::string Section = Start; |
348 | *p = '/'; // reset slash at place | 349 | *p = '/'; // reset slash at place |
349 | result.push_back(Section); | 350 | result.push_back(Section); |
350 | } | 351 | } |
351 | } | 352 | } |
352 | 353 | ||
353 | return result; | 354 | return result; |
354 | } | 355 | } |
355 | }; | 356 | }; |
356 | 357 | ||
@@ -389,7 +390,7 @@ GetPot::GetPot() | |||
389 | 390 | ||
390 | inline | 391 | inline |
391 | GetPot::GetPot(const int argc_, char ** argv_, | 392 | GetPot::GetPot(const int argc_, char ** argv_, |
392 | const char* FieldSeparator /* =0x0 */) | 393 | const char* FieldSeparator /* =0x0 */) |
393 | // leave 'char**' non-const to honor less capable compilers ... | 394 | // leave 'char**' non-const to honor less capable compilers ... |
394 | { | 395 | { |
395 | // TODO: Ponder over the problem when the argument list is of size = 0. | 396 | // TODO: Ponder over the problem when the argument list is of size = 0. |
@@ -410,8 +411,8 @@ GetPot::GetPot(const int argc_, char ** argv_, | |||
410 | _apriori_argv.push_back(std::string(argv_[0])); | 411 | _apriori_argv.push_back(std::string(argv_[0])); |
411 | int i=1; | 412 | int i=1; |
412 | for(; i<argc_; ++i) { | 413 | for(; i<argc_; ++i) { |
413 | std::string tmp(argv_[i]); // recall the problem with temporaries, | 414 | std::string tmp(argv_[i]); // recall the problem with temporaries, |
414 | _apriori_argv.push_back(tmp); // reference counting in arguement lists ... | 415 | _apriori_argv.push_back(tmp); // reference counting in arguement lists ... |
415 | } | 416 | } |
416 | __parse_argument_vector(_apriori_argv); | 417 | __parse_argument_vector(_apriori_argv); |
417 | } | 418 | } |
@@ -419,8 +420,8 @@ GetPot::GetPot(const int argc_, char ** argv_, | |||
419 | 420 | ||
420 | inline | 421 | inline |
421 | GetPot::GetPot(const char* FileName, | 422 | GetPot::GetPot(const char* FileName, |
422 | const char* CommentStart /* = 0x0 */, const char* CommentEnd /* = 0x0 */, | 423 | const char* CommentStart /* = 0x0 */, const char* CommentEnd /* = 0x0 */, |
423 | const char* FieldSeparator/* = 0x0 */) | 424 | const char* FieldSeparator/* = 0x0 */) |
424 | { | 425 | { |
425 | __basic_initialization(); | 426 | __basic_initialization(); |
426 | 427 | ||
@@ -448,7 +449,7 @@ GetPot::~GetPot() | |||
448 | { | 449 | { |
449 | // may be some return strings had to be created, delete now ! | 450 | // may be some return strings had to be created, delete now ! |
450 | victorate(char*, __internal_string_container, it) | 451 | victorate(char*, __internal_string_container, it) |
451 | delete [] *it; | 452 | delete [] *it; |
452 | } | 453 | } |
453 | 454 | ||
454 | inline GetPot& | 455 | inline GetPot& |
@@ -515,59 +516,59 @@ GetPot::__parse_argument_vector(const STRING_VECTOR& ARGV) | |||
515 | // -- loop over remaining arguments | 516 | // -- loop over remaining arguments |
516 | unsigned i=1; | 517 | unsigned i=1; |
517 | for(; it != ARGV.end(); ++it, ++i) { | 518 | for(; it != ARGV.end(); ++it, ++i) { |
518 | std::string arg = *it; | 519 | std::string arg = *it; |
519 | 520 | ||
520 | if( arg.length() == 0 ) continue; | 521 | if( arg.length() == 0 ) continue; |
521 | 522 | ||
522 | // -- [section] labels | 523 | // -- [section] labels |
523 | if( arg.length() > 1 && arg[0] == '[' && arg[arg.length()-1] == ']' ) { | 524 | if( arg.length() > 1 && arg[0] == '[' && arg[arg.length()-1] == ']' ) { |
524 | 525 | ||
525 | // (*) sections are considered 'requested arguments' | 526 | // (*) sections are considered 'requested arguments' |
526 | if( __request_recording_f ) _requested_arguments.push_back(arg); | 527 | if( __request_recording_f ) _requested_arguments.push_back(arg); |
527 | 528 | ||
528 | const std::string Name = __DBE_expand_string(arg.substr(1, arg.length()-2)); | 529 | const std::string Name = __DBE_expand_string(arg.substr(1, arg.length()-2)); |
529 | section = __process_section_label(Name, section_stack); | 530 | section = __process_section_label(Name, section_stack); |
530 | // new section --> append to list of sections | 531 | // new section --> append to list of sections |
531 | if( find(section_list.begin(), section_list.end(), section) == section_list.end() ) | 532 | if( find(section_list.begin(), section_list.end(), section) == section_list.end() ) |
532 | if( section.length() != 0 ) section_list.push_back(section); | 533 | if( section.length() != 0 ) section_list.push_back(section); |
533 | argv.push_back(arg); | 534 | argv.push_back(arg); |
534 | } | 535 | } |
535 | else { | 536 | else { |
536 | arg = section + __DBE_expand_string(arg); | 537 | arg = section + __DBE_expand_string(arg); |
537 | argv.push_back(arg); | 538 | argv.push_back(arg); |
538 | } | 539 | } |
539 | 540 | ||
540 | // -- separate array for nominus arguments | 541 | // -- separate array for nominus arguments |
541 | if( arg[0] != '-' ) idx_nominus.push_back(unsigned(i)); | 542 | if( arg[0] != '-' ) idx_nominus.push_back(unsigned(i)); |
542 | 543 | ||
543 | // -- variables: does arg contain a '=' operator ? | 544 | // -- variables: does arg contain a '=' operator ? |
544 | const char* p = arg.c_str(); | 545 | const char* p = arg.c_str(); |
545 | for(; *p ; p++) { | 546 | for(; *p ; p++) { |
546 | if( *p == '=' ) { | 547 | if( *p == '=' ) { |
547 | // (*) record for later ufo detection | 548 | // (*) record for later ufo detection |
548 | // arguments carriying variables are always treated as 'requested' arguments. | 549 | // arguments carriying variables are always treated as 'requested' arguments. |
549 | // as a whole! That is 'x=4712' is considered a requested argument. | 550 | // as a whole! That is 'x=4712' is considered a requested argument. |
550 | // | 551 | // |
551 | // unrequested variables have to be detected with the ufo-variable | 552 | // unrequested variables have to be detected with the ufo-variable |
552 | // detection routine. | 553 | // detection routine. |
553 | if( __request_recording_f ) _requested_arguments.push_back(arg); | 554 | if( __request_recording_f ) _requested_arguments.push_back(arg); |
554 | 555 | ||
555 | // set terminating 'zero' to treat first part as single string | 556 | // set terminating 'zero' to treat first part as single string |
556 | // => arg (from start to 'p') = Name of variable | 557 | // => arg (from start to 'p') = Name of variable |
557 | // p+1 (until terminating zero) = value of variable | 558 | // p+1 (until terminating zero) = value of variable |
558 | char* o = (char*)p++; | 559 | char* o = (char*)p++; |
559 | *o = '\0'; // set temporary terminating zero | 560 | *o = '\0'; // set temporary terminating zero |
560 | // __set_variable(...) | 561 | // __set_variable(...) |
561 | // calls __find_variable(...) which registers the search | 562 | // calls __find_variable(...) which registers the search |
562 | // temporarily disable this | 563 | // temporarily disable this |
563 | const bool tmp = __request_recording_f; | 564 | const bool tmp = __request_recording_f; |
564 | __request_recording_f = false; | 565 | __request_recording_f = false; |
565 | __set_variable(arg.c_str(), p); // v-name = c_str() bis 'p', value = rest | 566 | __set_variable(arg.c_str(), p); // v-name = c_str() bis 'p', value = rest |
566 | __request_recording_f = tmp; | 567 | __request_recording_f = tmp; |
567 | *o = '='; // reset the original '=' | 568 | *o = '='; // reset the original '=' |
568 | break; | 569 | break; |
569 | } | 570 | } |
570 | } | 571 | } |
571 | } | 572 | } |
572 | } | 573 | } |
573 | 574 | ||
@@ -586,10 +587,10 @@ GetPot::__read_in_stream(std::istream& istr) | |||
586 | { | 587 | { |
587 | STRING_VECTOR brute_tokens; | 588 | STRING_VECTOR brute_tokens; |
588 | while(istr) { | 589 | while(istr) { |
589 | __skip_whitespace(istr); | 590 | __skip_whitespace(istr); |
590 | const std::string Token = __get_next_token(istr); | 591 | const std::string Token = __get_next_token(istr); |
591 | if( Token.length() == 0 || Token[0] == EOF) break; | 592 | if( Token.length() == 0 || Token[0] == EOF) break; |
592 | brute_tokens.push_back(Token); | 593 | brute_tokens.push_back(Token); |
593 | } | 594 | } |
594 | 595 | ||
595 | // -- reduce expressions of token1'='token2 to a single | 596 | // -- reduce expressions of token1'='token2 to a single |
@@ -603,22 +604,22 @@ GetPot::__read_in_stream(std::istream& istr) | |||
603 | 604 | ||
604 | STRING_VECTOR arglist; | 605 | STRING_VECTOR arglist; |
605 | while( i1 < brute_tokens.size() ) { | 606 | while( i1 < brute_tokens.size() ) { |
606 | const std::string& SRef = brute_tokens[i1]; | 607 | const std::string& SRef = brute_tokens[i1]; |
607 | // 1) concatinate 'abcdef' '=' 'efgasdef' to 'abcdef=efgasdef' | 608 | // 1) concatinate 'abcdef' '=' 'efgasdef' to 'abcdef=efgasdef' |
608 | // note: java.lang.String: substring(a,b) = from a to b-1 | 609 | // note: java.lang.String: substring(a,b) = from a to b-1 |
609 | // C++ string: substr(a,b) = from a to a + b | 610 | // C++ string: substr(a,b) = from a to a + b |
610 | if( i2 < brute_tokens.size() && brute_tokens[i2] == "=" ) { | 611 | if( i2 < brute_tokens.size() && brute_tokens[i2] == "=" ) { |
611 | if( i3 >= brute_tokens.size() ) | 612 | if( i3 >= brute_tokens.size() ) |
612 | arglist.push_back(brute_tokens[i1] + brute_tokens[i2]); | 613 | arglist.push_back(brute_tokens[i1] + brute_tokens[i2]); |
613 | else | 614 | else |
614 | arglist.push_back(brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3]); | 615 | arglist.push_back(brute_tokens[i1] + brute_tokens[i2] + brute_tokens[i3]); |
615 | i1 = i3+1; i2 = i3+2; i3 = i3+3; | 616 | i1 = i3+1; i2 = i3+2; i3 = i3+3; |
616 | continue; | 617 | continue; |
617 | } | 618 | } |
618 | else { | 619 | else { |
619 | arglist.push_back(SRef); | 620 | arglist.push_back(SRef); |
620 | i1=i2; i2=i3; i3++; | 621 | i1=i2; i2=i3; i3++; |
621 | } | 622 | } |
622 | } | 623 | } |
623 | return arglist; | 624 | return arglist; |
624 | } | 625 | } |
@@ -629,45 +630,48 @@ GetPot::__skip_whitespace(std::istream& istr) | |||
629 | { | 630 | { |
630 | int tmp = istr.get(); | 631 | int tmp = istr.get(); |
631 | do { | 632 | do { |
632 | // -- search a non whitespace | 633 | // -- search a non whitespace |
633 | while( isspace(tmp) ) { | 634 | while( isspace(tmp) ) { |
634 | tmp = istr.get(); | 635 | tmp = istr.get(); |
635 | if( ! istr ) return; | 636 | if( ! istr ) return; |
636 | } | 637 | } |
637 | 638 | ||
638 | // -- look if characters match the comment starter string | 639 | // -- look if characters match the comment starter string |
639 | const std::istream::pos_type Pos = istr.tellg(); | 640 | unsigned i=0; |
640 | unsigned i=0; | 641 | for(; i<_comment_start.length() ; ++i) { |
641 | for(; i<_comment_start.length() ; ++i) { | 642 | if( tmp != _comment_start[i] ) { |
642 | if( tmp != _comment_start[i] ) { | 643 | // NOTE: Due to a 'strange behavior' in Microsoft's streaming lib we do |
643 | istr.seekg(Pos); | 644 | // a series of unget()s instead a quick seek. See |
644 | // -- one step more backwards, since 'tmp' already at non-whitespace | 645 | // http://sourceforge.net/tracker/index.php?func=detail&aid=1545239&group_id=31994&atid=403915 |
645 | istr.unget(); | 646 | // for a detailed discussion. |
646 | return; | 647 | |
647 | } | 648 | // -- one step more backwards, since 'tmp' already at non-whitespace |
648 | tmp = istr.get(); | 649 | do istr.unget(); while( i-- != 0 ); |
649 | if( ! istr ) { istr.unget(); return; } | 650 | return; |
650 | } | 651 | } |
651 | // 'tmp' contains last character of _comment_starter | 652 | tmp = istr.get(); |
652 | 653 | if( ! istr ) { istr.unget(); return; } | |
653 | // -- comment starter found -> search for comment ender | 654 | } |
654 | unsigned match_no=0; | 655 | // 'tmp' contains last character of _comment_starter |
655 | while(1+1 == 2) { | 656 | |
656 | tmp = istr.get(); | 657 | // -- comment starter found -> search for comment ender |
657 | if( ! istr ) { istr.unget(); return; } | 658 | unsigned match_no=0; |
658 | 659 | while(1+1 == 2) { | |
659 | if( tmp == _comment_end[match_no] ) { | 660 | tmp = istr.get(); |
660 | match_no++; | 661 | if( ! istr ) { istr.unget(); return; } |
661 | if( match_no == _comment_end.length() ) { | 662 | |
662 | istr.unget(); | 663 | if( tmp == _comment_end[match_no] ) { |
663 | break; // shuffle more whitespace, end of comment found | 664 | match_no++; |
664 | } | 665 | if( match_no == _comment_end.length() ) { |
665 | } | 666 | istr.unget(); |
666 | else | 667 | break; // shuffle more whitespace, end of comment found |
667 | match_no = 0; | 668 | } |
668 | } | 669 | } |
669 | 670 | else | |
670 | tmp = istr.get(); | 671 | match_no = 0; |
672 | } | ||
673 | |||
674 | tmp = istr.get(); | ||
671 | 675 | ||
672 | } while( istr ); | 676 | } while( istr ); |
673 | istr.unget(); | 677 | istr.unget(); |
@@ -682,27 +686,27 @@ GetPot::__get_next_token(std::istream& istr) | |||
682 | int tmp = 0; | 686 | int tmp = 0; |
683 | int last_letter = 0; | 687 | int last_letter = 0; |
684 | while(1+1 == 2) { | 688 | while(1+1 == 2) { |
685 | last_letter = tmp; tmp = istr.get(); | 689 | last_letter = tmp; tmp = istr.get(); |
686 | if( tmp == EOF | 690 | if( tmp == EOF |
687 | || ((tmp == ' ' || tmp == '\t' || tmp == '\n') && last_letter != '\\') ) { | 691 | || ((tmp == ' ' || tmp == '\t' || tmp == '\n') && last_letter != '\\') ) { |
688 | return token; | 692 | return token; |
689 | } | 693 | } |
690 | else if( tmp == '\'' && last_letter != '\\' ) { | 694 | else if( tmp == '\'' && last_letter != '\\' ) { |
691 | // QUOTES: un-backslashed quotes => it's a string | 695 | // QUOTES: un-backslashed quotes => it's a string |
692 | token += __get_string(istr); | 696 | token += __get_string(istr); |
693 | continue; | 697 | continue; |
694 | } | 698 | } |
695 | else if( tmp == '{' && last_letter == '$') { | 699 | else if( tmp == '{' && last_letter == '$') { |
696 | token += '{' + __get_until_closing_bracket(istr); | 700 | token += '{' + __get_until_closing_bracket(istr); |
697 | continue; | 701 | continue; |
698 | } | 702 | } |
699 | else if( tmp == '$' && last_letter == '\\') { | 703 | else if( tmp == '$' && last_letter == '\\') { |
700 | token += tmp; tmp = 0; // so that last_letter will become = 0, not '$'; | 704 | token += tmp; tmp = 0; // so that last_letter will become = 0, not '$'; |
701 | continue; | 705 | continue; |
702 | } | 706 | } |
703 | else if( tmp == '\\' && last_letter != '\\') | 707 | else if( tmp == '\\' && last_letter != '\\') |
704 | continue; // don't append un-backslashed backslashes | 708 | continue; // don't append un-backslashed backslashes |
705 | token += tmp; | 709 | token += tmp; |
706 | } | 710 | } |
707 | } | 711 | } |
708 | 712 | ||
@@ -714,13 +718,13 @@ GetPot::__get_string(std::istream& istr) | |||
714 | int tmp = 0; | 718 | int tmp = 0; |
715 | int last_letter = 0; | 719 | int last_letter = 0; |
716 | while(1 + 1 == 2) { | 720 | while(1 + 1 == 2) { |
717 | last_letter = tmp; tmp = istr.get(); | 721 | last_letter = tmp; tmp = istr.get(); |
718 | if( tmp == EOF) return str; | 722 | if( tmp == EOF) return str; |
719 | // un-backslashed quotes => it's the end of the string | 723 | // un-backslashed quotes => it's the end of the string |
720 | else if( tmp == '\'' && last_letter != '\\') return str; | 724 | else if( tmp == '\'' && last_letter != '\\') return str; |
721 | else if( tmp == '\\' && last_letter != '\\') continue; // don't append | 725 | else if( tmp == '\\' && last_letter != '\\') continue; // don't append |
722 | 726 | ||
723 | str += tmp; | 727 | str += tmp; |
724 | } | 728 | } |
725 | } | 729 | } |
726 | 730 | ||
@@ -733,62 +737,62 @@ GetPot::__get_until_closing_bracket(std::istream& istr) | |||
733 | int last_letter = 0; | 737 | int last_letter = 0; |
734 | int brackets = 1; | 738 | int brackets = 1; |
735 | while(1 + 1 == 2) { | 739 | while(1 + 1 == 2) { |
736 | last_letter = tmp; tmp = istr.get(); | 740 | last_letter = tmp; tmp = istr.get(); |
737 | if( tmp == EOF) return str; | 741 | if( tmp == EOF) return str; |
738 | else if( tmp == '{' && last_letter == '$') brackets += 1; | 742 | else if( tmp == '{' && last_letter == '$') brackets += 1; |
739 | else if( tmp == '}') { | 743 | else if( tmp == '}') { |
740 | brackets -= 1; | 744 | brackets -= 1; |
741 | // un-backslashed brackets => it's the end of the string | 745 | // un-backslashed brackets => it's the end of the string |
742 | if( brackets == 0) return str + '}'; | 746 | if( brackets == 0) return str + '}'; |
743 | else if( tmp == '\\' && last_letter != '\\') | 747 | else if( tmp == '\\' && last_letter != '\\') |
744 | continue; // do not append an unbackslashed backslash | 748 | continue; // do not append an unbackslashed backslash |
745 | } | 749 | } |
746 | str += tmp; | 750 | str += tmp; |
747 | } | 751 | } |
748 | } | 752 | } |
749 | 753 | ||
750 | inline std::string | 754 | inline std::string |
751 | GetPot::__process_section_label(const std::string& Section, | 755 | GetPot::__process_section_label(const std::string& Section, |
752 | STRING_VECTOR& section_stack) | 756 | STRING_VECTOR& section_stack) |
753 | { | 757 | { |
754 | std::string sname = Section; | 758 | std::string sname = Section; |
755 | // 1) subsection of actual section ('./' prefix) | 759 | // 1) subsection of actual section ('./' prefix) |
756 | if( sname.length() >= 2 && sname.substr(0, 2) == "./" ) { | 760 | if( sname.length() >= 2 && sname.substr(0, 2) == "./" ) { |
757 | sname = sname.substr(2); | 761 | sname = sname.substr(2); |
758 | } | 762 | } |
759 | // 2) subsection of parent section ('../' prefix) | 763 | // 2) subsection of parent section ('../' prefix) |
760 | else if( sname.length() >= 3 && sname.substr(0, 3) == "../" ) { | 764 | else if( sname.length() >= 3 && sname.substr(0, 3) == "../" ) { |
761 | do { | 765 | do { |
762 | if( section_stack.end() != section_stack.begin() ) | 766 | if( section_stack.end() != section_stack.begin() ) |
763 | section_stack.pop_back(); | 767 | section_stack.pop_back(); |
764 | sname = sname.substr(3); | 768 | sname = sname.substr(3); |
765 | } while( sname.substr(0, 3) == "../" ); | 769 | } while( sname.substr(0, 3) == "../" ); |
766 | } | 770 | } |
767 | // 3) subsection of the root-section | 771 | // 3) subsection of the root-section |
768 | else { | 772 | else { |
769 | section_stack.erase(section_stack.begin(), section_stack.end()); | 773 | section_stack.erase(section_stack.begin(), section_stack.end()); |
770 | // [] => back to root section | 774 | // [] => back to root section |
771 | } | 775 | } |
772 | 776 | ||
773 | if( sname != "" ) { | 777 | if( sname != "" ) { |
774 | // parse section name for 'slashes' | 778 | // parse section name for 'slashes' |
775 | unsigned i=0; | 779 | unsigned i=0; |
776 | while( i < sname.length() ) { | 780 | while( i < sname.length() ) { |
777 | if( sname[i] == '/' ) { | 781 | if( sname[i] == '/' ) { |
778 | section_stack.push_back(sname.substr(0,i)); | 782 | section_stack.push_back(sname.substr(0,i)); |
779 | if( i+1 < sname.length()-1 ) | 783 | if( i+1 < sname.length() ) |
780 | sname = sname.substr(i+1); | 784 | sname = sname.substr(i+1); |
781 | i = 0; | 785 | i = 0; |
782 | } | 786 | } |
783 | else | 787 | else |
784 | ++i; | 788 | ++i; |
785 | } | 789 | } |
786 | section_stack.push_back(sname); | 790 | section_stack.push_back(sname); |
787 | } | 791 | } |
788 | std::string section = ""; | 792 | std::string section = ""; |
789 | if( section_stack.size() != 0 ) { | 793 | if( section_stack.size() != 0 ) { |
790 | victorate(std::string, section_stack, it) | 794 | victorate(std::string, section_stack, it) |
791 | section += *it + "/"; | 795 | section += *it + "/"; |
792 | } | 796 | } |
793 | return section; | 797 | return section; |
794 | } | 798 | } |
@@ -836,7 +840,7 @@ GetPot::search(const char* Option) | |||
836 | const std::string SearchTerm = prefix + Option; | 840 | const std::string SearchTerm = prefix + Option; |
837 | 841 | ||
838 | // (*) record requested arguments for later ufo detection | 842 | // (*) record requested arguments for later ufo detection |
839 | __record_argument_request(SearchTerm); | 843 | __record_argument_request(SearchTerm); |
840 | 844 | ||
841 | if( OldCursor >= argv.size() ) OldCursor = static_cast<unsigned int>(argv.size()) - 1; | 845 | if( OldCursor >= argv.size() ) OldCursor = static_cast<unsigned int>(argv.size()) - 1; |
842 | search_failed_f = true; | 846 | search_failed_f = true; |
@@ -844,15 +848,15 @@ GetPot::search(const char* Option) | |||
844 | // (*) first loop from cursor position until end | 848 | // (*) first loop from cursor position until end |
845 | unsigned c = cursor; | 849 | unsigned c = cursor; |
846 | for(; c < argv.size(); c++) { | 850 | for(; c < argv.size(); c++) { |
847 | if( argv[c] == SearchTerm ) | 851 | if( argv[c] == SearchTerm ) |
848 | { cursor = c; search_failed_f = false; return true; } | 852 | { cursor = c; search_failed_f = false; return true; } |
849 | } | 853 | } |
850 | if( ! search_loop_f ) return false; | 854 | if( ! search_loop_f ) return false; |
851 | 855 | ||
852 | // (*) second loop from 0 to old cursor position | 856 | // (*) second loop from 0 to old cursor position |
853 | for(c = 1; c < OldCursor; c++) { | 857 | for(c = 1; c < OldCursor; c++) { |
854 | if( argv[c] == SearchTerm ) | 858 | if( argv[c] == SearchTerm ) |
855 | { cursor = c; search_failed_f = false; return true; } | 859 | { cursor = c; search_failed_f = false; return true; } |
856 | } | 860 | } |
857 | // in case nothing is found the cursor stays where it was | 861 | // in case nothing is found the cursor stays where it was |
858 | return false; | 862 | return false; |
@@ -873,22 +877,22 @@ GetPot::search(unsigned No, const char* P, ...) | |||
873 | va_start(ap, P); | 877 | va_start(ap, P); |
874 | unsigned i = 1; | 878 | unsigned i = 1; |
875 | for(; i < No; ++i) { | 879 | for(; i < No; ++i) { |
876 | char* Opt = va_arg(ap, char *); | 880 | char* Opt = va_arg(ap, char *); |
877 | if( search(Opt) == true ) break; | 881 | if( search(Opt) == true ) break; |
878 | } | 882 | } |
879 | 883 | ||
880 | if( i < No ) { | 884 | if( i < No ) { |
881 | ++i; | 885 | ++i; |
882 | // loop was left before end of array --> hit but | 886 | // loop was left before end of array --> hit but |
883 | // make sure that the rest of the search terms is marked | 887 | // make sure that the rest of the search terms is marked |
884 | // as requested. | 888 | // as requested. |
885 | for(; i < No; ++i) { | 889 | for(; i < No; ++i) { |
886 | char* Opt = va_arg(ap, char *); | 890 | char* Opt = va_arg(ap, char *); |
887 | // (*) record requested arguments for later ufo detection | 891 | // (*) record requested arguments for later ufo detection |
888 | __record_argument_request(Opt); | 892 | __record_argument_request(Opt); |
889 | } | 893 | } |
890 | va_end(ap); | 894 | va_end(ap); |
891 | return true; | 895 | return true; |
892 | } | 896 | } |
893 | 897 | ||
894 | va_end(ap); | 898 | va_end(ap); |
@@ -974,6 +978,8 @@ GetPot::next(const double& Default) | |||
974 | inline const std::string | 978 | inline const std::string |
975 | GetPot::next(const char* Default) | 979 | GetPot::next(const char* Default) |
976 | { | 980 | { |
981 | using namespace std; | ||
982 | |||
977 | if( search_failed_f ) return Default; | 983 | if( search_failed_f ) return Default; |
978 | cursor++; | 984 | cursor++; |
979 | 985 | ||
@@ -1040,11 +1046,11 @@ GetPot::follow(int Default, unsigned No, const char* P, ...) | |||
1040 | va_start(ap, P); | 1046 | va_start(ap, P); |
1041 | unsigned i=1; | 1047 | unsigned i=1; |
1042 | for(; i<No; ++i) { | 1048 | for(; i<No; ++i) { |
1043 | char* Opt = va_arg(ap, char *); | 1049 | char* Opt = va_arg(ap, char *); |
1044 | if( search(Opt) == true ) { | 1050 | if( search(Opt) == true ) { |
1045 | va_end(ap); | 1051 | va_end(ap); |
1046 | return next(Default); | 1052 | return next(Default); |
1047 | } | 1053 | } |
1048 | } | 1054 | } |
1049 | va_end(ap); | 1055 | va_end(ap); |
1050 | return Default; | 1056 | return Default; |
@@ -1060,11 +1066,11 @@ GetPot::follow(const double& Default, unsigned No, const char* P, ...) | |||
1060 | va_list ap; | 1066 | va_list ap; |
1061 | va_start(ap, P); | 1067 | va_start(ap, P); |
1062 | for(unsigned i=1; i<No; ++i) { | 1068 | for(unsigned i=1; i<No; ++i) { |
1063 | char* Opt = va_arg(ap, char *); | 1069 | char* Opt = va_arg(ap, char *); |
1064 | if( search(Opt) == true ) { | 1070 | if( search(Opt) == true ) { |
1065 | va_end(ap); | 1071 | va_end(ap); |
1066 | return next(Default); | 1072 | return next(Default); |
1067 | } | 1073 | } |
1068 | } | 1074 | } |
1069 | va_end(ap); | 1075 | va_end(ap); |
1070 | return Default; | 1076 | return Default; |
@@ -1081,11 +1087,11 @@ GetPot::follow(const char* Default, unsigned No, const char* P, ...) | |||
1081 | va_start(ap, P); | 1087 | va_start(ap, P); |
1082 | unsigned i=1; | 1088 | unsigned i=1; |
1083 | for(; i<No; ++i) { | 1089 | for(; i<No; ++i) { |
1084 | char* Opt = va_arg(ap, char *); | 1090 | char* Opt = va_arg(ap, char *); |
1085 | if( search(Opt) == true ) { | 1091 | if( search(Opt) == true ) { |
1086 | va_end(ap); | 1092 | va_end(ap); |
1087 | return next(Default); | 1093 | return next(Default); |
1088 | } | 1094 | } |
1089 | } | 1095 | } |
1090 | va_end(ap); | 1096 | va_end(ap); |
1091 | return Default; | 1097 | return Default; |
@@ -1102,20 +1108,20 @@ GetPot::nominus_followers(const char* Option) | |||
1102 | std::vector<std::string> result_list; | 1108 | std::vector<std::string> result_list; |
1103 | if( search(Option) == false ) return result_list; | 1109 | if( search(Option) == false ) return result_list; |
1104 | while( 1 + 1 == 2 ) { | 1110 | while( 1 + 1 == 2 ) { |
1105 | ++cursor; | 1111 | ++cursor; |
1106 | if( cursor >= argv.size() ) { | 1112 | if( cursor >= argv.size() ) { |
1107 | cursor = argv.size() - 1; | 1113 | cursor = argv.size() - 1; |
1108 | return result_list; | 1114 | return result_list; |
1109 | } | 1115 | } |
1110 | if( argv[cursor].length() >= 1 ) { | 1116 | if( argv[cursor].length() >= 1 ) { |
1111 | if( argv[cursor][0] == '-' ) { | 1117 | if( argv[cursor][0] == '-' ) { |
1112 | return result_list; | 1118 | return result_list; |
1113 | } | 1119 | } |
1114 | // -- record for later ufo-detection | 1120 | // -- record for later ufo-detection |
1115 | __record_argument_request(argv[cursor]); | 1121 | __record_argument_request(argv[cursor]); |
1116 | // -- append to the result list | 1122 | // -- append to the result list |
1117 | result_list.push_back(argv[cursor]); | 1123 | result_list.push_back(argv[cursor]); |
1118 | } | 1124 | } |
1119 | } | 1125 | } |
1120 | } | 1126 | } |
1121 | 1127 | ||
@@ -1130,17 +1136,17 @@ GetPot::nominus_followers(unsigned No, ...) | |||
1130 | va_list ap; | 1136 | va_list ap; |
1131 | va_start(ap, No); | 1137 | va_start(ap, No); |
1132 | for(unsigned i=0; i<No; ++i) { | 1138 | for(unsigned i=0; i<No; ++i) { |
1133 | char* Option = va_arg(ap, char *); | 1139 | char* Option = va_arg(ap, char *); |
1134 | std::vector<std::string> tmp = nominus_followers(Option); | 1140 | std::vector<std::string> tmp = nominus_followers(Option); |
1135 | result_list.insert(result_list.end(), tmp.begin(), tmp.end()); | 1141 | result_list.insert(result_list.end(), tmp.begin(), tmp.end()); |
1136 | 1142 | ||
1137 | // std::cerr << "option = '" << Option << "'" << std::endl; | 1143 | // std::cerr << "option = '" << Option << "'" << std::endl; |
1138 | // std::cerr << "length = " << tmp.size() << std::endl; | 1144 | // std::cerr << "length = " << tmp.size() << std::endl; |
1139 | // std::cerr << "new result list = <"; | 1145 | // std::cerr << "new result list = <"; |
1140 | // for(std::vector<std::string>::const_iterator it = result_list.begin(); | 1146 | // for(std::vector<std::string>::const_iterator it = result_list.begin(); |
1141 | // it != result_list.end(); ++it) | 1147 | // it != result_list.end(); ++it) |
1142 | // std::cerr << *it << ", "; | 1148 | // std::cerr << *it << ", "; |
1143 | // std::cerr << ">\n"; | 1149 | // std::cerr << ">\n"; |
1144 | } | 1150 | } |
1145 | va_end(ap); | 1151 | va_end(ap); |
1146 | return result_list; | 1152 | return result_list; |
@@ -1201,32 +1207,32 @@ GetPot::string_tails(const char* StartString) | |||
1201 | 1207 | ||
1202 | unsigned idx = 0; | 1208 | unsigned idx = 0; |
1203 | while( it != argv.end() ) { | 1209 | while( it != argv.end() ) { |
1204 | // (*) does start string match the given option? | 1210 | // (*) does start string match the given option? |
1205 | // NO -> goto next option | 1211 | // NO -> goto next option |
1206 | if( strncmp(StartString, (*it).c_str(), N) != 0) { ++it; ++idx; continue; } | 1212 | if( strncmp(StartString, (*it).c_str(), N) != 0) { ++it; ++idx; continue; } |
1207 | 1213 | ||
1208 | // append the found tail to the result vector | 1214 | // append the found tail to the result vector |
1209 | result.push_back((*it).substr(N)); | 1215 | result.push_back((*it).substr(N)); |
1210 | 1216 | ||
1211 | // adapt the nominus vector | 1217 | // adapt the nominus vector |
1212 | std::vector<unsigned>::iterator nit = idx_nominus.begin(); | 1218 | std::vector<unsigned>::iterator nit = idx_nominus.begin(); |
1213 | for(; nit != idx_nominus.end(); ++nit) { | 1219 | for(; nit != idx_nominus.end(); ++nit) { |
1214 | if( *nit == idx ) { | 1220 | if( *nit == idx ) { |
1215 | idx_nominus.erase(nit); | 1221 | idx_nominus.erase(nit); |
1216 | for(; nit != idx_nominus.end(); ++nit) *nit -= 1; | 1222 | for(; nit != idx_nominus.end(); ++nit) *nit -= 1; |
1217 | break; | 1223 | break; |
1218 | } | 1224 | } |
1219 | } | 1225 | } |
1220 | 1226 | ||
1221 | // erase the found option | 1227 | // erase the found option |
1222 | argv.erase(it); | 1228 | argv.erase(it); |
1223 | 1229 | ||
1224 | // 100% safe solution: set iterator back to the beginning. | 1230 | // 100% safe solution: set iterator back to the beginning. |
1225 | // (normally, 'it--' would be enough, but who knows how the | 1231 | // (normally, 'it--' would be enough, but who knows how the |
1226 | // iterator is implemented and .erase() definitely invalidates | 1232 | // iterator is implemented and .erase() definitely invalidates |
1227 | // the current iterator position. | 1233 | // the current iterator position. |
1228 | if( argv.empty() ) break; | 1234 | if( argv.empty() ) break; |
1229 | it = argv.begin(); | 1235 | it = argv.begin(); |
1230 | } | 1236 | } |
1231 | cursor = 0; | 1237 | cursor = 0; |
1232 | nominus_cursor = -1; | 1238 | nominus_cursor = -1; |
@@ -1243,32 +1249,32 @@ GetPot::int_tails(const char* StartString, const int Default /* = -1 */) | |||
1243 | 1249 | ||
1244 | unsigned idx = 0; | 1250 | unsigned idx = 0; |
1245 | while( it != argv.end() ) { | 1251 | while( it != argv.end() ) { |
1246 | // (*) does start string match the given option? | 1252 | // (*) does start string match the given option? |
1247 | // NO -> goto next option | 1253 | // NO -> goto next option |
1248 | if( strncmp(StartString, (*it).c_str(), N) != 0) { ++it; ++idx; continue; } | 1254 | if( strncmp(StartString, (*it).c_str(), N) != 0) { ++it; ++idx; continue; } |
1249 | 1255 | ||
1250 | // append the found tail to the result vector | 1256 | // append the found tail to the result vector |
1251 | result.push_back(__convert_to_type((*it).substr(N), Default)); | 1257 | result.push_back(__convert_to_type((*it).substr(N), Default)); |
1252 | 1258 | ||
1253 | // adapt the nominus vector | 1259 | // adapt the nominus vector |
1254 | std::vector<unsigned>::iterator nit = idx_nominus.begin(); | 1260 | std::vector<unsigned>::iterator nit = idx_nominus.begin(); |
1255 | for(; nit != idx_nominus.end(); ++nit) { | 1261 | for(; nit != idx_nominus.end(); ++nit) { |
1256 | if( *nit == idx ) { | 1262 | if( *nit == idx ) { |
1257 | idx_nominus.erase(nit); | 1263 | idx_nominus.erase(nit); |
1258 | for(; nit != idx_nominus.end(); ++nit) *nit -= 1; | 1264 | for(; nit != idx_nominus.end(); ++nit) *nit -= 1; |
1259 | break; | 1265 | break; |
1260 | } | 1266 | } |
1261 | } | 1267 | } |
1262 | 1268 | ||
1263 | // erase the found option | 1269 | // erase the found option |
1264 | argv.erase(it); | 1270 | argv.erase(it); |
1265 | 1271 | ||
1266 | // 100% safe solution: set iterator back to the beginning. | 1272 | // 100% safe solution: set iterator back to the beginning. |
1267 | // (normally, 'it--' would be enough, but who knows how the | 1273 | // (normally, 'it--' would be enough, but who knows how the |
1268 | // iterator is implemented and .erase() definitely invalidates | 1274 | // iterator is implemented and .erase() definitely invalidates |
1269 | // the current iterator position. | 1275 | // the current iterator position. |
1270 | if( argv.empty() ) break; | 1276 | if( argv.empty() ) break; |
1271 | it = argv.begin(); | 1277 | it = argv.begin(); |
1272 | } | 1278 | } |
1273 | cursor = 0; | 1279 | cursor = 0; |
1274 | nominus_cursor = -1; | 1280 | nominus_cursor = -1; |
@@ -1277,7 +1283,7 @@ GetPot::int_tails(const char* StartString, const int Default /* = -1 */) | |||
1277 | 1283 | ||
1278 | inline std::vector<double> | 1284 | inline std::vector<double> |
1279 | GetPot::double_tails(const char* StartString, | 1285 | GetPot::double_tails(const char* StartString, |
1280 | const double Default /* = -1.0 */) | 1286 | const double Default /* = -1.0 */) |
1281 | { | 1287 | { |
1282 | std::vector<double> result; | 1288 | std::vector<double> result; |
1283 | const unsigned N = static_cast<unsigned int>(strlen(StartString)); | 1289 | const unsigned N = static_cast<unsigned int>(strlen(StartString)); |
@@ -1285,32 +1291,32 @@ GetPot::double_tails(const char* StartString, | |||
1285 | std::vector<std::string>::iterator it = argv.begin(); | 1291 | std::vector<std::string>::iterator it = argv.begin(); |
1286 | unsigned idx = 0; | 1292 | unsigned idx = 0; |
1287 | while( it != argv.end() ) { | 1293 | while( it != argv.end() ) { |
1288 | // (*) does start string match the given option? | 1294 | // (*) does start string match the given option? |
1289 | // NO -> goto next option | 1295 | // NO -> goto next option |
1290 | if( strncmp(StartString, (*it).c_str(), N) != 0) { ++it; ++idx; continue; } | 1296 | if( strncmp(StartString, (*it).c_str(), N) != 0) { ++it; ++idx; continue; } |
1291 | 1297 | ||
1292 | // append the found tail to the result vector | 1298 | // append the found tail to the result vector |
1293 | result.push_back(__convert_to_type((*it).substr(N), Default)); | 1299 | result.push_back(__convert_to_type((*it).substr(N), Default)); |
1294 | 1300 | ||
1295 | // adapt the nominus vector | 1301 | // adapt the nominus vector |
1296 | std::vector<unsigned>::iterator nit = idx_nominus.begin(); | 1302 | std::vector<unsigned>::iterator nit = idx_nominus.begin(); |
1297 | for(; nit != idx_nominus.end(); ++nit) { | 1303 | for(; nit != idx_nominus.end(); ++nit) { |
1298 | if( *nit == idx ) { | 1304 | if( *nit == idx ) { |
1299 | idx_nominus.erase(nit); | 1305 | idx_nominus.erase(nit); |
1300 | for(; nit != idx_nominus.end(); ++nit) *nit -= 1; | 1306 | for(; nit != idx_nominus.end(); ++nit) *nit -= 1; |
1301 | break; | 1307 | break; |
1302 | } | 1308 | } |
1303 | } | 1309 | } |
1304 | 1310 | ||
1305 | // erase the found option | 1311 | // erase the found option |
1306 | argv.erase(it); | 1312 | argv.erase(it); |
1307 | 1313 | ||
1308 | // 100% safe solution: set iterator back to the beginning. | 1314 | // 100% safe solution: set iterator back to the beginning. |
1309 | // (normally, 'it--' would be enough, but who knows how the | 1315 | // (normally, 'it--' would be enough, but who knows how the |
1310 | // iterator is implemented and .erase() definitely invalidates | 1316 | // iterator is implemented and .erase() definitely invalidates |
1311 | // the current iterator position. | 1317 | // the current iterator position. |
1312 | if( argv.empty() ) break; | 1318 | if( argv.empty() ) break; |
1313 | it = argv.begin(); | 1319 | it = argv.begin(); |
1314 | } | 1320 | } |
1315 | cursor = 0; | 1321 | cursor = 0; |
1316 | nominus_cursor = -1; | 1322 | nominus_cursor = -1; |
@@ -1336,16 +1342,16 @@ GetPot::__match_starting_string(const char* StartString) | |||
1336 | // (*) first loop from cursor position until end | 1342 | // (*) first loop from cursor position until end |
1337 | unsigned c = cursor; | 1343 | unsigned c = cursor; |
1338 | for(; c < argv.size(); c++) { | 1344 | for(; c < argv.size(); c++) { |
1339 | if( strncmp(StartString, argv[c].c_str(), N) == 0) | 1345 | if( strncmp(StartString, argv[c].c_str(), N) == 0) |
1340 | { cursor = c; search_failed_f = false; return &(argv[c].c_str()[N]); } | 1346 | { cursor = c; search_failed_f = false; return &(argv[c].c_str()[N]); } |
1341 | } | 1347 | } |
1342 | 1348 | ||
1343 | if( ! search_loop_f ) return false; | 1349 | if( ! search_loop_f ) return false; |
1344 | 1350 | ||
1345 | // (*) second loop from 0 to old cursor position | 1351 | // (*) second loop from 0 to old cursor position |
1346 | for(c = 1; c < OldCursor; c++) { | 1352 | for(c = 1; c < OldCursor; c++) { |
1347 | if( strncmp(StartString, argv[c].c_str(), N) == 0) | 1353 | if( strncmp(StartString, argv[c].c_str(), N) == 0) |
1348 | { cursor = c; search_failed_f = false; return &(argv[c].c_str()[N]); } | 1354 | { cursor = c; search_failed_f = false; return &(argv[c].c_str()[N]); } |
1349 | } | 1355 | } |
1350 | return 0; | 1356 | return 0; |
1351 | } | 1357 | } |
@@ -1361,10 +1367,10 @@ GetPot::options_contain(const char* FlagList) const | |||
1361 | std::string str; | 1367 | std::string str; |
1362 | STRING_VECTOR::const_iterator it = argv.begin(); | 1368 | STRING_VECTOR::const_iterator it = argv.begin(); |
1363 | for(; it != argv.end(); ++it) { | 1369 | for(; it != argv.end(); ++it) { |
1364 | str = __get_remaining_string(*it, prefix); | 1370 | str = __get_remaining_string(*it, prefix); |
1365 | 1371 | ||
1366 | if( str.length() >= 2 && str[0] == '-' && str[1] != '-' ) | 1372 | if( str.length() >= 2 && str[0] == '-' && str[1] != '-' ) |
1367 | if( __check_flags(str, FlagList) ) return true; | 1373 | if( __check_flags(str, FlagList) ) return true; |
1368 | } | 1374 | } |
1369 | return false; | 1375 | return false; |
1370 | } | 1376 | } |
@@ -1379,8 +1385,8 @@ GetPot::argument_contains(unsigned Idx, const char* FlagList) const | |||
1379 | ((GetPot*)this)->__record_argument_request(argv[Idx]); | 1385 | ((GetPot*)this)->__record_argument_request(argv[Idx]); |
1380 | 1386 | ||
1381 | if( prefix == "" ) | 1387 | if( prefix == "" ) |
1382 | // search argument for any flag in flag list | 1388 | // search argument for any flag in flag list |
1383 | return __check_flags(argv[Idx], FlagList); | 1389 | return __check_flags(argv[Idx], FlagList); |
1384 | 1390 | ||
1385 | // if a prefix is set, then the argument index is the index | 1391 | // if a prefix is set, then the argument index is the index |
1386 | // inside the 'namespace' | 1392 | // inside the 'namespace' |
@@ -1388,12 +1394,12 @@ GetPot::argument_contains(unsigned Idx, const char* FlagList) const | |||
1388 | unsigned no_matches = 0; | 1394 | unsigned no_matches = 0; |
1389 | unsigned i=0; | 1395 | unsigned i=0; |
1390 | for(; i<argv.size(); ++i) { | 1396 | for(; i<argv.size(); ++i) { |
1391 | const std::string Remain = __get_remaining_string(argv[i], prefix); | 1397 | const std::string Remain = __get_remaining_string(argv[i], prefix); |
1392 | if( Remain != "") { | 1398 | if( Remain != "") { |
1393 | no_matches += 1; | 1399 | no_matches += 1; |
1394 | if( no_matches == Idx) | 1400 | if( no_matches == Idx) |
1395 | return __check_flags(Remain, FlagList); | 1401 | return __check_flags(Remain, FlagList); |
1396 | } | 1402 | } |
1397 | } | 1403 | } |
1398 | // no argument in this namespace | 1404 | // no argument in this namespace |
1399 | return false; | 1405 | return false; |
@@ -1404,7 +1410,7 @@ GetPot::__check_flags(const std::string& Str, const char* FlagList) const | |||
1404 | { | 1410 | { |
1405 | const char* p=FlagList; | 1411 | const char* p=FlagList; |
1406 | for(; *p != '\0' ; p++) | 1412 | for(; *p != '\0' ; p++) |
1407 | if( Str.find(*p) != std::string::npos ) return true; // found something | 1413 | if( Str.find(*p) != std::string::npos ) return true; // found something |
1408 | return false; | 1414 | return false; |
1409 | } | 1415 | } |
1410 | 1416 | ||
@@ -1417,12 +1423,12 @@ GetPot::nominus_vector() const | |||
1417 | STRING_VECTOR nv; | 1423 | STRING_VECTOR nv; |
1418 | std::vector<unsigned>::const_iterator it = idx_nominus.begin(); | 1424 | std::vector<unsigned>::const_iterator it = idx_nominus.begin(); |
1419 | for(; it != idx_nominus.end(); ++it) { | 1425 | for(; it != idx_nominus.end(); ++it) { |
1420 | nv.push_back(argv[*it]); | 1426 | nv.push_back(argv[*it]); |
1421 | 1427 | ||
1422 | // (*) record for later ufo-detection | 1428 | // (*) record for later ufo-detection |
1423 | // when a nominus vector is requested, the entire set of nominus arguments are | 1429 | // when a nominus vector is requested, the entire set of nominus arguments are |
1424 | // tagged as 'requested' | 1430 | // tagged as 'requested' |
1425 | ((GetPot*)this)->__record_argument_request(argv[*it]); | 1431 | ((GetPot*)this)->__record_argument_request(argv[*it]); |
1426 | } | 1432 | } |
1427 | return nv; | 1433 | return nv; |
1428 | } | 1434 | } |
@@ -1431,14 +1437,14 @@ inline std::string | |||
1431 | GetPot::next_nominus() | 1437 | GetPot::next_nominus() |
1432 | { | 1438 | { |
1433 | if( nominus_cursor < int(idx_nominus.size()) - 1 ) { | 1439 | if( nominus_cursor < int(idx_nominus.size()) - 1 ) { |
1434 | const std::string Tmp = argv[idx_nominus[++nominus_cursor]]; | 1440 | const std::string Tmp = argv[idx_nominus[++nominus_cursor]]; |
1435 | 1441 | ||
1436 | // (*) record for later ufo-detection | 1442 | // (*) record for later ufo-detection |
1437 | __record_argument_request(Tmp); | 1443 | __record_argument_request(Tmp); |
1438 | 1444 | ||
1439 | // -- cannot use the Tmp variable, since it is temporary and c_str() will return a pointer | 1445 | // -- cannot use the Tmp variable, since it is temporary and c_str() will return a pointer |
1440 | // to something that does no longer exist. | 1446 | // to something that does no longer exist. |
1441 | return Tmp; | 1447 | return Tmp; |
1442 | } | 1448 | } |
1443 | return std::string(""); | 1449 | return std::string(""); |
1444 | } | 1450 | } |
@@ -1520,8 +1526,8 @@ GetPot::__record_argument_request(const std::string& Name) | |||
1520 | // (*) record considered section for ufo detection | 1526 | // (*) record considered section for ufo detection |
1521 | STRING_VECTOR STree = __get_section_tree(Name); | 1527 | STRING_VECTOR STree = __get_section_tree(Name); |
1522 | victorate(std::string, STree, it) | 1528 | victorate(std::string, STree, it) |
1523 | if( find(_requested_sections.begin(), _requested_sections.end(), *it) == _requested_sections.end() ) | 1529 | if( find(_requested_sections.begin(), _requested_sections.end(), *it) == _requested_sections.end() ) |
1524 | if( section.length() != 0 ) _requested_sections.push_back(*it); | 1530 | if( section.length() != 0 ) _requested_sections.push_back(*it); |
1525 | } | 1531 | } |
1526 | 1532 | ||
1527 | inline void | 1533 | inline void |
@@ -1535,8 +1541,8 @@ GetPot::__record_variable_request(const std::string& Name) | |||
1535 | // (*) record considered section for ufo detection | 1541 | // (*) record considered section for ufo detection |
1536 | STRING_VECTOR STree = __get_section_tree(Name); | 1542 | STRING_VECTOR STree = __get_section_tree(Name); |
1537 | victorate(std::string, STree, it) | 1543 | victorate(std::string, STree, it) |
1538 | if( find(_requested_sections.begin(), _requested_sections.end(), *it) == _requested_sections.end() ) | 1544 | if( find(_requested_sections.begin(), _requested_sections.end(), *it) == _requested_sections.end() ) |
1539 | if( section.length() != 0 ) _requested_sections.push_back(*it); | 1545 | if( section.length() != 0 ) _requested_sections.push_back(*it); |
1540 | } | 1546 | } |
1541 | 1547 | ||
1542 | // (*) following functions are to be used from 'outside', after getpot has parsed its | 1548 | // (*) following functions are to be used from 'outside', after getpot has parsed its |
@@ -1584,8 +1590,8 @@ GetPot::get_variable_names() const | |||
1584 | STRING_VECTOR result; | 1590 | STRING_VECTOR result; |
1585 | std::vector<GetPot::variable>::const_iterator it = variables.begin(); | 1591 | std::vector<GetPot::variable>::const_iterator it = variables.begin(); |
1586 | for(; it != variables.end(); ++it) { | 1592 | for(; it != variables.end(); ++it) { |
1587 | const std::string Tmp = __get_remaining_string((*it).name, prefix); | 1593 | const std::string Tmp = __get_remaining_string((*it).name, prefix); |
1588 | if( Tmp != "" ) result.push_back(Tmp); | 1594 | if( Tmp != "" ) result.push_back(Tmp); |
1589 | } | 1595 | } |
1590 | return result; | 1596 | return result; |
1591 | } | 1597 | } |
@@ -1604,7 +1610,7 @@ GetPot::__find_variable(const char* VarName) const | |||
1604 | 1610 | ||
1605 | std::vector<variable>::const_iterator it = variables.begin(); | 1611 | std::vector<variable>::const_iterator it = variables.begin(); |
1606 | for(; it != variables.end(); ++it) { | 1612 | for(; it != variables.end(); ++it) { |
1607 | if( (*it).name == Name ) return &(*it); | 1613 | if( (*it).name == Name ) return &(*it); |
1608 | } | 1614 | } |
1609 | return 0; | 1615 | return 0; |
1610 | } | 1616 | } |
@@ -1619,7 +1625,7 @@ GetPot::print() const | |||
1619 | std::cout << "argc = " << static_cast<unsigned int>(argv.size()) << std::endl; | 1625 | std::cout << "argc = " << static_cast<unsigned int>(argv.size()) << std::endl; |
1620 | STRING_VECTOR::const_iterator it = argv.begin(); | 1626 | STRING_VECTOR::const_iterator it = argv.begin(); |
1621 | for(; it != argv.end(); ++it) | 1627 | for(; it != argv.end(); ++it) |
1622 | std::cout << *it << std::endl; | 1628 | std::cout << *it << std::endl; |
1623 | std::cout << std::endl; | 1629 | std::cout << std::endl; |
1624 | return 1; | 1630 | return 1; |
1625 | } | 1631 | } |
@@ -1682,19 +1688,19 @@ GetPot::__DBE_expand_string(const std::string str) | |||
1682 | unsigned first = 0; | 1688 | unsigned first = 0; |
1683 | unsigned i = 0; | 1689 | unsigned i = 0; |
1684 | for(; i<str.size(); ++i) { | 1690 | for(; i<str.size(); ++i) { |
1685 | if( i < str.size() - 2 && str.substr(i, 2) == "${" ) { | 1691 | if( i < str.size() - 2 && str.substr(i, 2) == "${" ) { |
1686 | if( open_brackets == 0 ) first = i+2; | 1692 | if( open_brackets == 0 ) first = i+2; |
1687 | open_brackets++; | 1693 | open_brackets++; |
1688 | } | 1694 | } |
1689 | else if( str[i] == '}' && open_brackets > 0) { | 1695 | else if( str[i] == '}' && open_brackets > 0) { |
1690 | open_brackets -= 1; | 1696 | open_brackets -= 1; |
1691 | if( open_brackets == 0 ) { | 1697 | if( open_brackets == 0 ) { |
1692 | const std::string Replacement = __DBE_expand(str.substr(first, i - first)); | 1698 | const std::string Replacement = __DBE_expand(str.substr(first, i - first)); |
1693 | new_string += Replacement; | 1699 | new_string += Replacement; |
1694 | } | 1700 | } |
1695 | } | 1701 | } |
1696 | else if( open_brackets == 0 ) | 1702 | else if( open_brackets == 0 ) |
1697 | new_string += str[i]; | 1703 | new_string += str[i]; |
1698 | } | 1704 | } |
1699 | return new_string; | 1705 | return new_string; |
1700 | } | 1706 | } |
@@ -1711,7 +1717,7 @@ GetPot::__DBE_get_expr_list(const std::string str_, const unsigned ExpectedNumbe | |||
1711 | unsigned i=0; | 1717 | unsigned i=0; |
1712 | // (1) eat initial whitespaces | 1718 | // (1) eat initial whitespaces |
1713 | for(; i < str.size(); ++i) | 1719 | for(; i < str.size(); ++i) |
1714 | if( ! isspace(str[i]) ) break; | 1720 | if( ! isspace(str[i]) ) break; |
1715 | 1721 | ||
1716 | STRING_VECTOR expr_list; | 1722 | STRING_VECTOR expr_list; |
1717 | unsigned open_brackets = 0; | 1723 | unsigned open_brackets = 0; |
@@ -1721,53 +1727,53 @@ GetPot::__DBE_get_expr_list(const std::string str_, const unsigned ExpectedNumbe | |||
1721 | 1727 | ||
1722 | // (2) search for ${ } expressions ... | 1728 | // (2) search for ${ } expressions ... |
1723 | while( i < l ) { | 1729 | while( i < l ) { |
1724 | const char letter = str[i]; | 1730 | const char letter = str[i]; |
1725 | // whitespace -> end of expression | 1731 | // whitespace -> end of expression |
1726 | if( isspace(letter) && open_brackets == 0) { | 1732 | if( isspace(letter) && open_brackets == 0) { |
1727 | expr_list.push_back(str.substr(start_new_string, i - start_new_string)); | 1733 | expr_list.push_back(str.substr(start_new_string, i - start_new_string)); |
1728 | bool no_breakout_f = true; | 1734 | bool no_breakout_f = true; |
1729 | for(++i; i < l ; ++i) { | 1735 | for(++i; i < l ; ++i) { |
1730 | if( ! isspace(str[i]) ) | 1736 | if( ! isspace(str[i]) ) |
1731 | { no_breakout_f = false; start_new_string = i; break; } | 1737 | { no_breakout_f = false; start_new_string = i; break; } |
1732 | } | 1738 | } |
1733 | if( no_breakout_f ) { | 1739 | if( no_breakout_f ) { |
1734 | // end of expression list | 1740 | // end of expression list |
1735 | if( expr_list.size() < ExpectedNumber ) { | 1741 | if( expr_list.size() < ExpectedNumber ) { |
1736 | const std::string pre_tmp("<< ${ }: missing arguments>>"); | 1742 | const std::string pre_tmp("<< ${ }: missing arguments>>"); |
1737 | STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp); | 1743 | STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp); |
1738 | expr_list.insert(expr_list.end(), tmp.begin(), tmp.end()); | 1744 | expr_list.insert(expr_list.end(), tmp.begin(), tmp.end()); |
1739 | } | 1745 | } |
1740 | return expr_list; | 1746 | return expr_list; |
1741 | } | 1747 | } |
1742 | } | 1748 | } |
1743 | 1749 | ||
1744 | // dollar-bracket expression | 1750 | // dollar-bracket expression |
1745 | if( str.length() >= i+2 && str.substr(i, 2) == "${" ) { | 1751 | if( str.length() >= i+2 && str.substr(i, 2) == "${" ) { |
1746 | open_brackets++; | 1752 | open_brackets++; |
1747 | start_idx.push_back(i+2); | 1753 | start_idx.push_back(i+2); |
1748 | } | 1754 | } |
1749 | else if( letter == '}' && open_brackets > 0) { | 1755 | else if( letter == '}' && open_brackets > 0) { |
1750 | int start = start_idx[start_idx.size()-1]; | 1756 | int start = start_idx[start_idx.size()-1]; |
1751 | start_idx.pop_back(); | 1757 | start_idx.pop_back(); |
1752 | const std::string Replacement = __DBE_expand(str.substr(start, i-start)); | 1758 | const std::string Replacement = __DBE_expand(str.substr(start, i-start)); |
1753 | if( start - 3 < (int)0) | 1759 | if( start - 3 < (int)0) |
1754 | str = Replacement + str.substr(i+1); | 1760 | str = Replacement + str.substr(i+1); |
1755 | else | 1761 | else |
1756 | str = str.substr(0, start-2) + Replacement + str.substr(i+1); | 1762 | str = str.substr(0, start-2) + Replacement + str.substr(i+1); |
1757 | l = static_cast<unsigned int>(str.size()); | 1763 | l = static_cast<unsigned int>(str.size()); |
1758 | i = start + static_cast<unsigned int>(Replacement.size()) - 3; | 1764 | i = start + static_cast<unsigned int>(Replacement.size()) - 3; |
1759 | open_brackets--; | 1765 | open_brackets--; |
1760 | } | 1766 | } |
1761 | ++i; | 1767 | ++i; |
1762 | } | 1768 | } |
1763 | 1769 | ||
1764 | // end of expression list | 1770 | // end of expression list |
1765 | expr_list.push_back(str.substr(start_new_string, i-start_new_string)); | 1771 | expr_list.push_back(str.substr(start_new_string, i-start_new_string)); |
1766 | 1772 | ||
1767 | if( expr_list.size() < ExpectedNumber ) { | 1773 | if( expr_list.size() < ExpectedNumber ) { |
1768 | const std::string pre_tmp("<< ${ }: missing arguments>>"); | 1774 | const std::string pre_tmp("<< ${ }: missing arguments>>"); |
1769 | STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp); | 1775 | STRING_VECTOR tmp(ExpectedNumber - expr_list.size(), pre_tmp); |
1770 | expr_list.insert(expr_list.end(), tmp.begin(), tmp.end()); | 1776 | expr_list.insert(expr_list.end(), tmp.begin(), tmp.end()); |
1771 | } | 1777 | } |
1772 | 1778 | ||
1773 | return expr_list; | 1779 | return expr_list; |
@@ -1798,7 +1804,7 @@ GetPot::__DBE_get_variable(std::string VarName) | |||
1798 | #else | 1804 | #else |
1799 | _snprintf(tmp, sizeof(char)*(VarName.length() + 25), | 1805 | _snprintf(tmp, sizeof(char)*(VarName.length() + 25), |
1800 | #endif | 1806 | #endif |
1801 | "<<${ } variable '%s' undefined>>", VarName.c_str()); | 1807 | "<<${ } variable '%s' undefined>>", VarName.c_str()); |
1802 | ev.name = ""; | 1808 | ev.name = ""; |
1803 | ev.original = std::string(tmp); | 1809 | ev.original = std::string(tmp); |
1804 | delete [] tmp; | 1810 | delete [] tmp; |
@@ -1810,213 +1816,213 @@ GetPot::__DBE_expand(const std::string expr) | |||
1810 | { | 1816 | { |
1811 | // ${: } pure text | 1817 | // ${: } pure text |
1812 | if( expr[0] == ':' ) | 1818 | if( expr[0] == ':' ) |
1813 | return expr.substr(1); | 1819 | return expr.substr(1); |
1814 | 1820 | ||
1815 | // ${& expr expr ... } text concatination | 1821 | // ${& expr expr ... } text concatination |
1816 | else if( expr[0] == '&' ) { | 1822 | else if( expr[0] == '&' ) { |
1817 | const STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 1); | 1823 | const STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 1); |
1818 | 1824 | ||
1819 | STRING_VECTOR::const_iterator it = A.begin(); | 1825 | STRING_VECTOR::const_iterator it = A.begin(); |
1820 | std::string result = *it++; | 1826 | std::string result = *it++; |
1821 | for(; it != A.end(); ++it) result += *it; | 1827 | for(; it != A.end(); ++it) result += *it; |
1822 | 1828 | ||
1823 | return result; | 1829 | return result; |
1824 | } | 1830 | } |
1825 | 1831 | ||
1826 | // ${<-> expr expr expr} text replacement | 1832 | // ${<-> expr expr expr} text replacement |
1827 | else if( expr.length() >= 3 && expr.substr(0, 3) == "<->" ) { | 1833 | else if( expr.length() >= 3 && expr.substr(0, 3) == "<->" ) { |
1828 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(3), 3); | 1834 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(3), 3); |
1829 | std::string::size_type tmp = 0; | 1835 | std::string::size_type tmp = 0; |
1830 | const std::string::size_type L = A[1].length(); | 1836 | const std::string::size_type L = A[1].length(); |
1831 | while( (tmp = A[0].find(A[1])) != std::string::npos ) { | 1837 | while( (tmp = A[0].find(A[1])) != std::string::npos ) { |
1832 | A[0].replace(tmp, L, A[2]); | 1838 | A[0].replace(tmp, L, A[2]); |
1833 | } | 1839 | } |
1834 | return A[0]; | 1840 | return A[0]; |
1835 | } | 1841 | } |
1836 | // ${+ ...}, ${- ...}, ${* ...}, ${/ ...} expressions | 1842 | // ${+ ...}, ${- ...}, ${* ...}, ${/ ...} expressions |
1837 | else if( expr[0] == '+' ) { | 1843 | else if( expr[0] == '+' ) { |
1838 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | 1844 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); |
1839 | STRING_VECTOR::const_iterator it = A.begin(); | 1845 | STRING_VECTOR::const_iterator it = A.begin(); |
1840 | double result = __convert_to_type(*it++, 0.0); | 1846 | double result = __convert_to_type(*it++, 0.0); |
1841 | for(; it != A.end(); ++it) | 1847 | for(; it != A.end(); ++it) |
1842 | result += __convert_to_type(*it, 0.0); | 1848 | result += __convert_to_type(*it, 0.0); |
1843 | 1849 | ||
1844 | return __double2string(result); | 1850 | return __double2string(result); |
1845 | } | 1851 | } |
1846 | else if( expr[0] == '-' ) { | 1852 | else if( expr[0] == '-' ) { |
1847 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | 1853 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); |
1848 | STRING_VECTOR::const_iterator it = A.begin(); | 1854 | STRING_VECTOR::const_iterator it = A.begin(); |
1849 | double result = __convert_to_type(*it++, 0.0); | 1855 | double result = __convert_to_type(*it++, 0.0); |
1850 | for(; it != A.end(); ++it) | 1856 | for(; it != A.end(); ++it) |
1851 | result -= __convert_to_type(*it, 0.0); | 1857 | result -= __convert_to_type(*it, 0.0); |
1852 | 1858 | ||
1853 | return __double2string(result); | 1859 | return __double2string(result); |
1854 | } | 1860 | } |
1855 | else if( expr[0] == '*' ) { | 1861 | else if( expr[0] == '*' ) { |
1856 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | 1862 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); |
1857 | STRING_VECTOR::const_iterator it = A.begin(); | 1863 | STRING_VECTOR::const_iterator it = A.begin(); |
1858 | double result = __convert_to_type(*it++, 0.0); | 1864 | double result = __convert_to_type(*it++, 0.0); |
1859 | for(; it != A.end(); ++it) | 1865 | for(; it != A.end(); ++it) |
1860 | result *= __convert_to_type(*it, 0.0); | 1866 | result *= __convert_to_type(*it, 0.0); |
1861 | 1867 | ||
1862 | return __double2string(result); | 1868 | return __double2string(result); |
1863 | } | 1869 | } |
1864 | else if( expr[0] == '/' ) { | 1870 | else if( expr[0] == '/' ) { |
1865 | 1871 | ||
1866 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | 1872 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); |
1867 | STRING_VECTOR::const_iterator it = A.begin(); | 1873 | STRING_VECTOR::const_iterator it = A.begin(); |
1868 | double result = __convert_to_type(*it++, 0.0); | 1874 | double result = __convert_to_type(*it++, 0.0); |
1869 | if( result == 0 ) return "0.0"; | 1875 | if( result == 0 ) return "0.0"; |
1870 | for(; it != A.end(); ++it) { | 1876 | for(; it != A.end(); ++it) { |
1871 | const double Q = __convert_to_type(*it, 0.0); | 1877 | const double Q = __convert_to_type(*it, 0.0); |
1872 | if( Q == 0.0 ) return "0.0"; | 1878 | if( Q == 0.0 ) return "0.0"; |
1873 | result /= Q; | 1879 | result /= Q; |
1874 | } | 1880 | } |
1875 | return __double2string(result); | 1881 | return __double2string(result); |
1876 | } | 1882 | } |
1877 | 1883 | ||
1878 | // ${^ ... } power expressions | 1884 | // ${^ ... } power expressions |
1879 | else if( expr[0] == '^' ) { | 1885 | else if( expr[0] == '^' ) { |
1880 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | 1886 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); |
1881 | STRING_VECTOR::const_iterator it = A.begin(); | 1887 | STRING_VECTOR::const_iterator it = A.begin(); |
1882 | double result = __convert_to_type(*it++, 0.0); | 1888 | double result = __convert_to_type(*it++, 0.0); |
1883 | for(; it != A.end(); ++it) | 1889 | for(; it != A.end(); ++it) |
1884 | result = pow(result, __convert_to_type(*it, 0.0)); | 1890 | result = pow(result, __convert_to_type(*it, 0.0)); |
1885 | return __double2string(result); | 1891 | return __double2string(result); |
1886 | } | 1892 | } |
1887 | 1893 | ||
1888 | // ${== } ${<= } ${>= } comparisons (return the number of the first 'match' | 1894 | // ${== } ${<= } ${>= } comparisons (return the number of the first 'match' |
1889 | else if( expr.length() >= 2 && | 1895 | else if( expr.length() >= 2 && |
1890 | ( expr.substr(0,2) == "==" || expr.substr(0,2) == ">=" || | 1896 | ( expr.substr(0,2) == "==" || expr.substr(0,2) == ">=" || |
1891 | expr.substr(0,2) == "<=" || expr[0] == '>' || expr[0] == '<')) { | 1897 | expr.substr(0,2) == "<=" || expr[0] == '>' || expr[0] == '<')) { |
1892 | // differentiate between two and one sign operators | 1898 | // differentiate between two and one sign operators |
1893 | unsigned op = 0; | 1899 | unsigned op = 0; |
1894 | enum { EQ, GEQ, LEQ, GT, LT }; | 1900 | enum { EQ, GEQ, LEQ, GT, LT }; |
1895 | if ( expr.substr(0, 2) == "==" ) op = EQ; | 1901 | if ( expr.substr(0, 2) == "==" ) op = EQ; |
1896 | else if ( expr.substr(0, 2) == ">=" ) op = GEQ; | 1902 | else if ( expr.substr(0, 2) == ">=" ) op = GEQ; |
1897 | else if ( expr.substr(0, 2) == "<=" ) op = LEQ; | 1903 | else if ( expr.substr(0, 2) == "<=" ) op = LEQ; |
1898 | else if ( expr[0] == '>' ) op = GT; | 1904 | else if ( expr[0] == '>' ) op = GT; |
1899 | else /* "<" */ op = LT; | 1905 | else /* "<" */ op = LT; |
1900 | 1906 | ||
1901 | STRING_VECTOR a; | 1907 | STRING_VECTOR a; |
1902 | if ( op == GT || op == LT ) a = __DBE_get_expr_list(expr.substr(1), 2); | 1908 | if ( op == GT || op == LT ) a = __DBE_get_expr_list(expr.substr(1), 2); |
1903 | else a = __DBE_get_expr_list(expr.substr(2), 2); | 1909 | else a = __DBE_get_expr_list(expr.substr(2), 2); |
1904 | 1910 | ||
1905 | std::string x_orig = a[0]; | 1911 | std::string x_orig = a[0]; |
1906 | double x = __convert_to_type(x_orig, 1e37); | 1912 | double x = __convert_to_type(x_orig, 1e37); |
1907 | unsigned i = 1; | 1913 | unsigned i = 1; |
1908 | 1914 | ||
1909 | STRING_VECTOR::const_iterator y_orig = a.begin(); | 1915 | STRING_VECTOR::const_iterator y_orig = a.begin(); |
1910 | for(y_orig++; y_orig != a.end(); y_orig++) { | 1916 | for(y_orig++; y_orig != a.end(); y_orig++) { |
1911 | double y = __convert_to_type(*y_orig, 1e37); | 1917 | double y = __convert_to_type(*y_orig, 1e37); |
1912 | 1918 | ||
1913 | // set the strings as reference if one wasn't a number | 1919 | // set the strings as reference if one wasn't a number |
1914 | if ( x == 1e37 || y == 1e37 ) { | 1920 | if ( x == 1e37 || y == 1e37 ) { |
1915 | // it's a string comparison | 1921 | // it's a string comparison |
1916 | if( (op == EQ && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) || | 1922 | if( (op == EQ && x_orig == *y_orig) || (op == GEQ && x_orig >= *y_orig) || |
1917 | (op == LEQ && x_orig <= *y_orig) || (op == GT && x_orig > *y_orig) || | 1923 | (op == LEQ && x_orig <= *y_orig) || (op == GT && x_orig > *y_orig) || |
1918 | (op == LT && x_orig < *y_orig) ) | 1924 | (op == LT && x_orig < *y_orig) ) |
1919 | return __int2string(i); | 1925 | return __int2string(i); |
1920 | } | 1926 | } |
1921 | else { | 1927 | else { |
1922 | // it's a number comparison | 1928 | // it's a number comparison |
1923 | if( (op == EQ && x == y) || (op == GEQ && x >= y) || | 1929 | if( (op == EQ && x == y) || (op == GEQ && x >= y) || |
1924 | (op == LEQ && x <= y) || (op == GT && x > y) || | 1930 | (op == LEQ && x <= y) || (op == GT && x > y) || |
1925 | (op == LT && x < y) ) | 1931 | (op == LT && x < y) ) |
1926 | return __int2string(i); | 1932 | return __int2string(i); |
1927 | } | 1933 | } |
1928 | ++i; | 1934 | ++i; |
1929 | } | 1935 | } |
1930 | 1936 | ||
1931 | // nothing fulfills the condition => return 0 | 1937 | // nothing fulfills the condition => return 0 |
1932 | return "0"; | 1938 | return "0"; |
1933 | } | 1939 | } |
1934 | // ${?? expr expr} select | 1940 | // ${?? expr expr} select |
1935 | else if( expr.length() >= 2 && expr.substr(0, 2) == "??" ) { | 1941 | else if( expr.length() >= 2 && expr.substr(0, 2) == "??" ) { |
1936 | STRING_VECTOR a = __DBE_get_expr_list(expr.substr(2), 2); | 1942 | STRING_VECTOR a = __DBE_get_expr_list(expr.substr(2), 2); |
1937 | double x = __convert_to_type(a[0], 1e37); | 1943 | double x = __convert_to_type(a[0], 1e37); |
1938 | // last element is always the default argument | 1944 | // last element is always the default argument |
1939 | if( x == 1e37 || x < 0 || x >= a.size() - 1 ) return a[a.size()-1]; | 1945 | if( x == 1e37 || x < 0 || x >= a.size() - 1 ) return a[a.size()-1]; |
1940 | 1946 | ||
1941 | // round x to closest integer | 1947 | // round x to closest integer |
1942 | return a[int(x+0.5)]; | 1948 | return a[int(x+0.5)]; |
1943 | } | 1949 | } |
1944 | // ${? expr expr expr} if then else conditions | 1950 | // ${? expr expr expr} if then else conditions |
1945 | else if( expr[0] == '?' ) { | 1951 | else if( expr[0] == '?' ) { |
1946 | STRING_VECTOR a = __DBE_get_expr_list(expr.substr(1), 2); | 1952 | STRING_VECTOR a = __DBE_get_expr_list(expr.substr(1), 2); |
1947 | if( __convert_to_type(a[0], 0.0) == 1.0 ) return a[1]; | 1953 | if( __convert_to_type(a[0], 0.0) == 1.0 ) return a[1]; |
1948 | else if( a.size() > 2 ) return a[2]; | 1954 | else if( a.size() > 2 ) return a[2]; |
1949 | } | 1955 | } |
1950 | // ${! expr} maxro expansion | 1956 | // ${! expr} maxro expansion |
1951 | else if( expr[0] == '!' ) { | 1957 | else if( expr[0] == '!' ) { |
1952 | const GetPot::variable* Var = __DBE_get_variable(expr.substr(1)); | 1958 | const GetPot::variable* Var = __DBE_get_variable(expr.substr(1)); |
1953 | // error | 1959 | // error |
1954 | if( Var->name == "" ) return std::string(Var->original); | 1960 | if( Var->name == "" ) return std::string(Var->original); |
1955 | 1961 | ||
1956 | const STRING_VECTOR A = __DBE_get_expr_list(Var->original, 2); | 1962 | const STRING_VECTOR A = __DBE_get_expr_list(Var->original, 2); |
1957 | return A[0]; | 1963 | return A[0]; |
1958 | } | 1964 | } |
1959 | // ${@: } - string subscription | 1965 | // ${@: } - string subscription |
1960 | else if( expr.length() >= 2 && expr.substr(0,2) == "@:" ) { | 1966 | else if( expr.length() >= 2 && expr.substr(0,2) == "@:" ) { |
1961 | const STRING_VECTOR A = __DBE_get_expr_list(expr.substr(2), 2); | 1967 | const STRING_VECTOR A = __DBE_get_expr_list(expr.substr(2), 2); |
1962 | double x = __convert_to_type(A[1], 1e37); | 1968 | double x = __convert_to_type(A[1], 1e37); |
1963 | 1969 | ||
1964 | // last element is always the default argument | 1970 | // last element is always the default argument |
1965 | if( x == 1e37 || x < 0 || x >= A[0].size() - 1) | 1971 | if( x == 1e37 || x < 0 || x >= A[0].size() - 1) |
1966 | return "<<1st index out of range>>"; | 1972 | return "<<1st index out of range>>"; |
1967 | 1973 | ||
1968 | if( A.size() > 2 ) { | 1974 | if( A.size() > 2 ) { |
1969 | double y = __convert_to_type(A[2], 1e37); | 1975 | double y = __convert_to_type(A[2], 1e37); |
1970 | if ( y != 1e37 && y > 0 && y <= A[0].size() - 1 && y > x ) | 1976 | if ( y != 1e37 && y > 0 && y <= A[0].size() - 1 && y > x ) |
1971 | return A[0].substr(int(x+0.5), int(y+1.5) - int(x+0.5)); | 1977 | return A[0].substr(int(x+0.5), int(y+1.5) - int(x+0.5)); |
1972 | else if( y == -1 ) | 1978 | else if( y == -1 ) |
1973 | return A[0].substr(int(x+0.5)); | 1979 | return A[0].substr(int(x+0.5)); |
1974 | return "<<2nd index out of range>>"; | 1980 | return "<<2nd index out of range>>"; |
1975 | } | 1981 | } |
1976 | else { | 1982 | else { |
1977 | char* tmp = new char[2]; | 1983 | char* tmp = new char[2]; |
1978 | tmp[0] = A[0][int(x+0.5)]; tmp[1] = '\0'; | 1984 | tmp[0] = A[0][int(x+0.5)]; tmp[1] = '\0'; |
1979 | std::string result(tmp); | 1985 | std::string result(tmp); |
1980 | delete [] tmp; | 1986 | delete [] tmp; |
1981 | return result; | 1987 | return result; |
1982 | } | 1988 | } |
1983 | } | 1989 | } |
1984 | // ${@ } - vector subscription | 1990 | // ${@ } - vector subscription |
1985 | else if( expr[0] == '@' ) { | 1991 | else if( expr[0] == '@' ) { |
1986 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); | 1992 | STRING_VECTOR A = __DBE_get_expr_list(expr.substr(1), 2); |
1987 | const GetPot::variable* Var = __DBE_get_variable(A[0]); | 1993 | const GetPot::variable* Var = __DBE_get_variable(A[0]); |
1988 | // error | 1994 | // error |
1989 | if( Var->name == "" ) { | 1995 | if( Var->name == "" ) { |
1990 | // make a copy of the string if an error occured | 1996 | // make a copy of the string if an error occured |
1991 | // (since the error variable is a static variable inside get_variable()) | 1997 | // (since the error variable is a static variable inside get_variable()) |
1992 | return std::string(Var->original); | 1998 | return std::string(Var->original); |
1993 | } | 1999 | } |
1994 | 2000 | ||
1995 | double x = __convert_to_type(A[1], 1e37); | 2001 | double x = __convert_to_type(A[1], 1e37); |
1996 | 2002 | ||
1997 | // last element is always the default argument | 2003 | // last element is always the default argument |
1998 | if (x == 1e37 || x < 0 || x >= Var->value.size() ) | 2004 | if (x == 1e37 || x < 0 || x >= Var->value.size() ) |
1999 | return "<<1st index out of range>>"; | 2005 | return "<<1st index out of range>>"; |
2000 | 2006 | ||
2001 | if ( A.size() > 2) { | 2007 | if ( A.size() > 2) { |
2002 | double y = __convert_to_type(A[2], 1e37); | 2008 | double y = __convert_to_type(A[2], 1e37); |
2003 | int begin = int(x+0.5); | 2009 | int begin = int(x+0.5); |
2004 | int end = 0; | 2010 | int end = 0; |
2005 | if ( y != 1e37 && y > 0 && y <= Var->value.size() && y > x) | 2011 | if ( y != 1e37 && y > 0 && y <= Var->value.size() && y > x) |
2006 | end = int(y+1.5); | 2012 | end = int(y+1.5); |
2007 | else if( y == -1 ) | 2013 | else if( y == -1 ) |
2008 | end = static_cast<unsigned int>(Var->value.size()); | 2014 | end = static_cast<unsigned int>(Var->value.size()); |
2009 | else | 2015 | else |
2010 | return "<<2nd index out of range>>"; | 2016 | return "<<2nd index out of range>>"; |
2011 | 2017 | ||
2012 | std::string result = *(Var->get_element(begin)); | 2018 | std::string result = *(Var->get_element(begin)); |
2013 | int i = begin+1; | 2019 | int i = begin+1; |
2014 | for(; i < end; ++i) | 2020 | for(; i < end; ++i) |
2015 | result += std::string(" ") + *(Var->get_element(i)); | 2021 | result += std::string(" ") + *(Var->get_element(i)); |
2016 | return result; | 2022 | return result; |
2017 | } | 2023 | } |
2018 | else | 2024 | else |
2019 | return *(Var->get_element(int(x+0.5))); | 2025 | return *(Var->get_element(int(x+0.5))); |
2020 | } | 2026 | } |
2021 | 2027 | ||
2022 | const STRING_VECTOR A = __DBE_get_expr_list(expr, 1); | 2028 | const STRING_VECTOR A = __DBE_get_expr_list(expr, 1); |
@@ -2039,14 +2045,14 @@ inline bool | |||
2039 | GetPot::__search_string_vector(const STRING_VECTOR& VecStr, const std::string& Str) const | 2045 | GetPot::__search_string_vector(const STRING_VECTOR& VecStr, const std::string& Str) const |
2040 | { | 2046 | { |
2041 | victorate(std::string, VecStr, itk) { | 2047 | victorate(std::string, VecStr, itk) { |
2042 | if( *itk == Str ) return true; | 2048 | if( *itk == Str ) return true; |
2043 | } | 2049 | } |
2044 | return false; | 2050 | return false; |
2045 | } | 2051 | } |
2046 | 2052 | ||
2047 | inline STRING_VECTOR | 2053 | inline STRING_VECTOR |
2048 | GetPot::unidentified_arguments(unsigned Number, | 2054 | GetPot::unidentified_arguments(unsigned Number, |
2049 | const char* KnownArgument1, ...) const | 2055 | const char* KnownArgument1, ...) const |
2050 | { | 2056 | { |
2051 | STRING_VECTOR known_arguments; | 2057 | STRING_VECTOR known_arguments; |
2052 | 2058 | ||
@@ -2058,7 +2064,7 @@ GetPot::unidentified_arguments(unsigned Number, | |||
2058 | known_arguments.push_back(std::string(KnownArgument1)); | 2064 | known_arguments.push_back(std::string(KnownArgument1)); |
2059 | unsigned i=1; | 2065 | unsigned i=1; |
2060 | for(; i<Number; ++i) | 2066 | for(; i<Number; ++i) |
2061 | known_arguments.push_back(std::string(va_arg(ap, char *))); | 2067 | known_arguments.push_back(std::string(va_arg(ap, char *))); |
2062 | va_end(ap); | 2068 | va_end(ap); |
2063 | 2069 | ||
2064 | return unidentified_arguments(known_arguments); | 2070 | return unidentified_arguments(known_arguments); |
@@ -2075,20 +2081,20 @@ GetPot::unidentified_arguments(const STRING_VECTOR& Knowns) const | |||
2075 | STRING_VECTOR::const_iterator it = argv.begin(); | 2081 | STRING_VECTOR::const_iterator it = argv.begin(); |
2076 | ++it; // forget about argv[0] (application or filename) | 2082 | ++it; // forget about argv[0] (application or filename) |
2077 | for(; it != argv.end(); ++it) { | 2083 | for(; it != argv.end(); ++it) { |
2078 | // -- argument belongs to prefixed section ? | 2084 | // -- argument belongs to prefixed section ? |
2079 | const std::string arg = __get_remaining_string(*it, prefix); | 2085 | const std::string arg = __get_remaining_string(*it, prefix); |
2080 | if( arg == "" ) continue; | 2086 | if( arg == "" ) continue; |
2081 | 2087 | ||
2082 | // -- check if in list | 2088 | // -- check if in list |
2083 | if( __search_string_vector(Knowns, arg) == false) | 2089 | if( __search_string_vector(Knowns, arg) == false) |
2084 | ufos.push_back(*it); | 2090 | ufos.push_back(*it); |
2085 | } | 2091 | } |
2086 | return ufos; | 2092 | return ufos; |
2087 | } | 2093 | } |
2088 | 2094 | ||
2089 | inline STRING_VECTOR | 2095 | inline STRING_VECTOR |
2090 | GetPot::unidentified_options(unsigned Number, | 2096 | GetPot::unidentified_options(unsigned Number, |
2091 | const char* KnownOption1, ...) const | 2097 | const char* KnownOption1, ...) const |
2092 | { | 2098 | { |
2093 | STRING_VECTOR known_options; | 2099 | STRING_VECTOR known_options; |
2094 | 2100 | ||
@@ -2100,7 +2106,7 @@ GetPot::unidentified_options(unsigned Number, | |||
2100 | known_options.push_back(std::string(KnownOption1)); | 2106 | known_options.push_back(std::string(KnownOption1)); |
2101 | unsigned i=1; | 2107 | unsigned i=1; |
2102 | for(; i<Number; ++i) | 2108 | for(; i<Number; ++i) |
2103 | known_options.push_back(std::string(va_arg(ap, char *))); | 2109 | known_options.push_back(std::string(va_arg(ap, char *))); |
2104 | va_end(ap); | 2110 | va_end(ap); |
2105 | 2111 | ||
2106 | return unidentified_options(known_options); | 2112 | return unidentified_options(known_options); |
@@ -2117,10 +2123,10 @@ GetPot::unidentified_options() const | |||
2117 | // => it is not necessary to separate requested options from the list | 2123 | // => it is not necessary to separate requested options from the list |
2118 | STRING_VECTOR option_list; | 2124 | STRING_VECTOR option_list; |
2119 | victorate(std::string, _requested_arguments, it) { | 2125 | victorate(std::string, _requested_arguments, it) { |
2120 | const std::string arg = *it; | 2126 | const std::string arg = *it; |
2121 | if( arg.length() == 0 ) continue; | 2127 | if( arg.length() == 0 ) continue; |
2122 | if( arg[0] == '-' ) option_list.push_back(arg); | 2128 | if( arg[0] == '-' ) option_list.push_back(arg); |
2123 | } | 2129 | } |
2124 | return unidentified_options(option_list); | 2130 | return unidentified_options(option_list); |
2125 | } | 2131 | } |
2126 | 2132 | ||
@@ -2131,15 +2137,15 @@ GetPot::unidentified_options(const STRING_VECTOR& Knowns) const | |||
2131 | STRING_VECTOR::const_iterator it = argv.begin(); | 2137 | STRING_VECTOR::const_iterator it = argv.begin(); |
2132 | ++it; // forget about argv[0] (application or filename) | 2138 | ++it; // forget about argv[0] (application or filename) |
2133 | for(; it != argv.end(); ++it) { | 2139 | for(; it != argv.end(); ++it) { |
2134 | // -- argument belongs to prefixed section ? | 2140 | // -- argument belongs to prefixed section ? |
2135 | const std::string arg = __get_remaining_string(*it, prefix); | 2141 | const std::string arg = __get_remaining_string(*it, prefix); |
2136 | if( arg == "" ) continue; | 2142 | if( arg == "" ) continue; |
2137 | 2143 | ||
2138 | // is argument really an option (starting with '-') ? | 2144 | // is argument really an option (starting with '-') ? |
2139 | if( arg.length() < 1 || arg[0] != '-' ) continue; | 2145 | if( arg.length() < 1 || arg[0] != '-' ) continue; |
2140 | 2146 | ||
2141 | if( __search_string_vector(Knowns, arg) == false) | 2147 | if( __search_string_vector(Knowns, arg) == false) |
2142 | ufos.push_back(*it); | 2148 | ufos.push_back(*it); |
2143 | } | 2149 | } |
2144 | 2150 | ||
2145 | return ufos; | 2151 | return ufos; |
@@ -2158,52 +2164,52 @@ GetPot::unidentified_flags(const char* KnownFlagList, int ArgumentNumber=-1) con | |||
2158 | 2164 | ||
2159 | // (2) iteration over '-' arguments (options) | 2165 | // (2) iteration over '-' arguments (options) |
2160 | if( ArgumentNumber == -1 ) { | 2166 | if( ArgumentNumber == -1 ) { |
2161 | STRING_VECTOR::const_iterator it = argv.begin(); | 2167 | STRING_VECTOR::const_iterator it = argv.begin(); |
2162 | ++it; // forget about argv[0] (application or filename) | 2168 | ++it; // forget about argv[0] (application or filename) |
2163 | for(; it != argv.end(); ++it) { | 2169 | for(; it != argv.end(); ++it) { |
2164 | // -- argument belongs to prefixed section ? | 2170 | // -- argument belongs to prefixed section ? |
2165 | const std::string arg = __get_remaining_string(*it, prefix); | 2171 | const std::string arg = __get_remaining_string(*it, prefix); |
2166 | if( arg == "" ) continue; | 2172 | if( arg == "" ) continue; |
2167 | 2173 | ||
2168 | // -- does arguments start with '-' (but not '--') | 2174 | // -- does arguments start with '-' (but not '--') |
2169 | if ( arg.length() < 2 ) continue; | 2175 | if ( arg.length() < 2 ) continue; |
2170 | else if( arg[0] != '-' ) continue; | 2176 | else if( arg[0] != '-' ) continue; |
2171 | else if( arg[1] == '-' ) continue; | 2177 | else if( arg[1] == '-' ) continue; |
2172 | 2178 | ||
2173 | // -- check out if flags inside option are contained in KnownFlagList | 2179 | // -- check out if flags inside option are contained in KnownFlagList |
2174 | const char* p=arg.c_str(); | 2180 | const char* p=arg.c_str(); |
2175 | p++; // skip starting minus | 2181 | p++; // skip starting minus |
2176 | for(; *p != '\0' ; p++) | 2182 | for(; *p != '\0' ; p++) |
2177 | if( KFL.find(*p) == std::string::npos ) ufos += *p; | 2183 | if( KFL.find(*p) == std::string::npos ) ufos += *p; |
2178 | } | 2184 | } |
2179 | } | 2185 | } |
2180 | // (1) check specific argument | 2186 | // (1) check specific argument |
2181 | else { | 2187 | else { |
2182 | // -- only check arguments that start with prefix | 2188 | // -- only check arguments that start with prefix |
2183 | int no_matches = 0; | 2189 | int no_matches = 0; |
2184 | unsigned i=1; | 2190 | unsigned i=1; |
2185 | for(; i<argv.size(); ++i) { | 2191 | for(; i<argv.size(); ++i) { |
2186 | const std::string Remain = __get_remaining_string(argv[i], prefix); | 2192 | const std::string Remain = __get_remaining_string(argv[i], prefix); |
2187 | if( Remain != "") { | 2193 | if( Remain != "") { |
2188 | no_matches++; | 2194 | no_matches++; |
2189 | if( no_matches == ArgumentNumber) { | 2195 | if( no_matches == ArgumentNumber) { |
2190 | // -- the right argument number inside the section is found | 2196 | // -- the right argument number inside the section is found |
2191 | // => check it for flags | 2197 | // => check it for flags |
2192 | const char* p = Remain.c_str(); | 2198 | const char* p = Remain.c_str(); |
2193 | p++; // skip starting minus | 2199 | p++; // skip starting minus |
2194 | for(; *p != '\0' ; p++) | 2200 | for(; *p != '\0' ; p++) |
2195 | if( KFL.find(*p) == std::string::npos ) ufos += *p; | 2201 | if( KFL.find(*p) == std::string::npos ) ufos += *p; |
2196 | return ufos; | 2202 | return ufos; |
2197 | } | 2203 | } |
2198 | } | 2204 | } |
2199 | } | 2205 | } |
2200 | } | 2206 | } |
2201 | return ufos; | 2207 | return ufos; |
2202 | } | 2208 | } |
2203 | 2209 | ||
2204 | inline STRING_VECTOR | 2210 | inline STRING_VECTOR |
2205 | GetPot::unidentified_variables(unsigned Number, | 2211 | GetPot::unidentified_variables(unsigned Number, |
2206 | const char* KnownVariable1, ...) const | 2212 | const char* KnownVariable1, ...) const |
2207 | { | 2213 | { |
2208 | STRING_VECTOR known_variables; | 2214 | STRING_VECTOR known_variables; |
2209 | 2215 | ||
@@ -2215,7 +2221,7 @@ GetPot::unidentified_variables(unsigned Number, | |||
2215 | known_variables.push_back(std::string(KnownVariable1)); | 2221 | known_variables.push_back(std::string(KnownVariable1)); |
2216 | unsigned i=1; | 2222 | unsigned i=1; |
2217 | for(; i<Number; ++i) | 2223 | for(; i<Number; ++i) |
2218 | known_variables.push_back(std::string(va_arg(ap, char *))); | 2224 | known_variables.push_back(std::string(va_arg(ap, char *))); |
2219 | va_end(ap); | 2225 | va_end(ap); |
2220 | 2226 | ||
2221 | return unidentified_variables(known_variables); | 2227 | return unidentified_variables(known_variables); |
@@ -2227,13 +2233,13 @@ GetPot::unidentified_variables(const STRING_VECTOR& Knowns) const | |||
2227 | STRING_VECTOR ufos; | 2233 | STRING_VECTOR ufos; |
2228 | 2234 | ||
2229 | victorate(GetPot::variable, variables, it) { | 2235 | victorate(GetPot::variable, variables, it) { |
2230 | // -- check if variable has specific prefix | 2236 | // -- check if variable has specific prefix |
2231 | const std::string var_name = __get_remaining_string((*it).name, prefix); | 2237 | const std::string var_name = __get_remaining_string((*it).name, prefix); |
2232 | if( var_name == "" ) continue; | 2238 | if( var_name == "" ) continue; |
2233 | 2239 | ||
2234 | // -- check if variable is known | 2240 | // -- check if variable is known |
2235 | if( __search_string_vector(Knowns, var_name) == false) | 2241 | if( __search_string_vector(Knowns, var_name) == false) |
2236 | ufos.push_back((*it).name); | 2242 | ufos.push_back((*it).name); |
2237 | } | 2243 | } |
2238 | return ufos; | 2244 | return ufos; |
2239 | } | 2245 | } |
@@ -2245,7 +2251,7 @@ GetPot::unidentified_variables() const | |||
2245 | 2251 | ||
2246 | inline STRING_VECTOR | 2252 | inline STRING_VECTOR |
2247 | GetPot::unidentified_sections(unsigned Number, | 2253 | GetPot::unidentified_sections(unsigned Number, |
2248 | const char* KnownSection1, ...) const | 2254 | const char* KnownSection1, ...) const |
2249 | { | 2255 | { |
2250 | STRING_VECTOR known_sections; | 2256 | STRING_VECTOR known_sections; |
2251 | 2257 | ||
@@ -2257,10 +2263,10 @@ GetPot::unidentified_sections(unsigned Number, | |||
2257 | known_sections.push_back(std::string(KnownSection1)); | 2263 | known_sections.push_back(std::string(KnownSection1)); |
2258 | unsigned i=1; | 2264 | unsigned i=1; |
2259 | for(; i<Number; ++i) { | 2265 | for(; i<Number; ++i) { |
2260 | std::string tmp = std::string(va_arg(ap, char *)); | 2266 | std::string tmp = std::string(va_arg(ap, char *)); |
2261 | if( tmp.length() == 0 ) continue; | 2267 | if( tmp.length() == 0 ) continue; |
2262 | if( tmp[tmp.length()-1] != '/' ) tmp += '/'; | 2268 | if( tmp[tmp.length()-1] != '/' ) tmp += '/'; |
2263 | known_sections.push_back(tmp); | 2269 | known_sections.push_back(tmp); |
2264 | } | 2270 | } |
2265 | va_end(ap); | 2271 | va_end(ap); |
2266 | 2272 | ||
@@ -2277,13 +2283,13 @@ GetPot::unidentified_sections(const STRING_VECTOR& Knowns) const | |||
2277 | STRING_VECTOR ufos; | 2283 | STRING_VECTOR ufos; |
2278 | 2284 | ||
2279 | victorate(std::string, section_list, it) { | 2285 | victorate(std::string, section_list, it) { |
2280 | // -- check if section conform to prefix | 2286 | // -- check if section conform to prefix |
2281 | const std::string sec_name = __get_remaining_string(*it, prefix); | 2287 | const std::string sec_name = __get_remaining_string(*it, prefix); |
2282 | if( sec_name == "" ) continue; | 2288 | if( sec_name == "" ) continue; |
2283 | 2289 | ||
2284 | // -- check if section is known | 2290 | // -- check if section is known |
2285 | if( __search_string_vector(Knowns, sec_name) == false ) | 2291 | if( __search_string_vector(Knowns, sec_name) == false ) |
2286 | ufos.push_back(*it); | 2292 | ufos.push_back(*it); |
2287 | } | 2293 | } |
2288 | 2294 | ||
2289 | return ufos; | 2295 | return ufos; |
@@ -2303,9 +2309,9 @@ GetPot::unidentified_nominuses(unsigned Number, const char* Known, ...) const | |||
2303 | known_nominuses.push_back(std::string(Known)); | 2309 | known_nominuses.push_back(std::string(Known)); |
2304 | unsigned i=1; | 2310 | unsigned i=1; |
2305 | for(; i<Number; ++i) { | 2311 | for(; i<Number; ++i) { |
2306 | std::string tmp = std::string(va_arg(ap, char *)); | 2312 | std::string tmp = std::string(va_arg(ap, char *)); |
2307 | if( tmp.length() == 0 ) continue; | 2313 | if( tmp.length() == 0 ) continue; |
2308 | known_nominuses.push_back(tmp); | 2314 | known_nominuses.push_back(tmp); |
2309 | } | 2315 | } |
2310 | va_end(ap); | 2316 | va_end(ap); |
2311 | 2317 | ||
@@ -2333,25 +2339,25 @@ GetPot::unidentified_nominuses(const STRING_VECTOR& Knowns) const | |||
2333 | STRING_VECTOR::const_iterator it = argv.begin(); | 2339 | STRING_VECTOR::const_iterator it = argv.begin(); |
2334 | ++it; // forget about argv[0] (application or filename) | 2340 | ++it; // forget about argv[0] (application or filename) |
2335 | for(; it != argv.end(); ++it) { | 2341 | for(; it != argv.end(); ++it) { |
2336 | // -- check if nominus part of prefix | 2342 | // -- check if nominus part of prefix |
2337 | const std::string arg = __get_remaining_string(*it, prefix); | 2343 | const std::string arg = __get_remaining_string(*it, prefix); |
2338 | if( arg == "" ) continue; | 2344 | if( arg == "" ) continue; |
2339 | 2345 | ||
2340 | if( arg.length() < 1 ) continue; | 2346 | if( arg.length() < 1 ) continue; |
2341 | // option ? --> not a nomius | 2347 | // option ? --> not a nomius |
2342 | if( arg[0] == '-' ) continue; | 2348 | if( arg[0] == '-' ) continue; |
2343 | // section ? --> not a real nominus | 2349 | // section ? --> not a real nominus |
2344 | if( arg[0] == '[' && arg[arg.length()-1] == ']' ) continue; | 2350 | if( arg[0] == '[' && arg[arg.length()-1] == ']' ) continue; |
2345 | // variable definition ? --> not a real nominus | 2351 | // variable definition ? --> not a real nominus |
2346 | bool continue_f = false; | 2352 | bool continue_f = false; |
2347 | unsigned i=0; | 2353 | unsigned i=0; |
2348 | for(; i<arg.length() ; ++i) | 2354 | for(; i<arg.length() ; ++i) |
2349 | if( arg[i] == '=' ) { continue_f = true; break; } | 2355 | if( arg[i] == '=' ) { continue_f = true; break; } |
2350 | if( continue_f ) continue; | 2356 | if( continue_f ) continue; |
2351 | 2357 | ||
2352 | // real nominuses are compared with the given list | 2358 | // real nominuses are compared with the given list |
2353 | if( __search_string_vector(Knowns, arg) == false ) | 2359 | if( __search_string_vector(Knowns, arg) == false ) |
2354 | ufos.push_back(*it); | 2360 | ufos.push_back(*it); |
2355 | } | 2361 | } |
2356 | return ufos; | 2362 | return ufos; |
2357 | } | 2363 | } |
@@ -2391,6 +2397,8 @@ GetPot::variable::get_element(unsigned Idx) const | |||
2391 | inline void | 2397 | inline void |
2392 | GetPot::variable::take(const char* Value, const char* FieldSeparator) | 2398 | GetPot::variable::take(const char* Value, const char* FieldSeparator) |
2393 | { | 2399 | { |
2400 | using namespace std; | ||
2401 | |||
2394 | original = std::string(Value); | 2402 | original = std::string(Value); |
2395 | 2403 | ||
2396 | // separate string by white space delimiters using 'strtok' | 2404 | // separate string by white space delimiters using 'strtok' |
@@ -2402,8 +2410,8 @@ GetPot::variable::take(const char* Value, const char* FieldSeparator) | |||
2402 | char* follow_token = strtok_r(copy, FieldSeparator, &spt); | 2410 | char* follow_token = strtok_r(copy, FieldSeparator, &spt); |
2403 | if( value.size() != 0 ) value.erase(value.begin(), value.end()); | 2411 | if( value.size() != 0 ) value.erase(value.begin(), value.end()); |
2404 | while(follow_token != 0) { | 2412 | while(follow_token != 0) { |
2405 | value.push_back(std::string(follow_token)); | 2413 | value.push_back(std::string(follow_token)); |
2406 | follow_token = strtok_r(NULL, FieldSeparator, &spt); | 2414 | follow_token = strtok_r(NULL, FieldSeparator, &spt); |
2407 | } | 2415 | } |
2408 | 2416 | ||
2409 | delete [] copy; | 2417 | delete [] copy; |
@@ -2417,9 +2425,9 @@ inline GetPot::variable& | |||
2417 | GetPot::variable::operator=(const GetPot::variable& That) | 2425 | GetPot::variable::operator=(const GetPot::variable& That) |
2418 | { | 2426 | { |
2419 | if( &That != this) { | 2427 | if( &That != this) { |
2420 | name = That.name; | 2428 | name = That.name; |
2421 | value = That.value; | 2429 | value = That.value; |
2422 | original = That.original; | 2430 | original = That.original; |
2423 | } | 2431 | } |
2424 | return *this; | 2432 | return *this; |
2425 | } | 2433 | } |
@@ -2430,4 +2438,3 @@ GetPot::variable::operator=(const GetPot::variable& That) | |||
2430 | #endif // __include_guard_GETPOT_H__ | 2438 | #endif // __include_guard_GETPOT_H__ |
2431 | 2439 | ||
2432 | 2440 | ||
2433 | |||
diff --git a/utils/zenutils/libraries/getpot-c++-1.1.17/getpot/LPGL.txt b/utils/zenutils/libraries/getpot-c++-1.1.18/getpot/LPGL.txt index b1e3f5a263..81cab28495 100644 --- a/utils/zenutils/libraries/getpot-c++-1.1.17/getpot/LPGL.txt +++ b/utils/zenutils/libraries/getpot-c++-1.1.18/getpot/LPGL.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | GNU LESSER GENERAL PUBLIC LICENSE | 1 | GNU LESSER GENERAL PUBLIC LICENSE |
2 | Version 2.1, February 1999 | 2 | Version 2.1, February 1999 |
3 | 3 | ||
4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. |
5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
@@ -10,7 +10,7 @@ | |||
10 | as the successor of the GNU Library Public License, version 2, hence | 10 | as the successor of the GNU Library Public License, version 2, hence |
11 | the version number 2.1.] | 11 | the version number 2.1.] |
12 | 12 | ||
13 | Preamble | 13 | Preamble |
14 | 14 | ||
15 | The licenses for most software are designed to take away your | 15 | The licenses for most software are designed to take away your |
16 | freedom to share and change it. By contrast, the GNU General Public | 16 | freedom to share and change it. By contrast, the GNU General Public |
@@ -112,7 +112,7 @@ modification follow. Pay close attention to the difference between a | |||
112 | former contains code derived from the library, whereas the latter must | 112 | former contains code derived from the library, whereas the latter must |
113 | be combined with the library in order to run. | 113 | be combined with the library in order to run. |
114 | 114 | ||
115 | GNU LESSER GENERAL PUBLIC LICENSE | 115 | GNU LESSER GENERAL PUBLIC LICENSE |
116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
117 | 117 | ||
118 | 0. This License Agreement applies to any software library or other | 118 | 0. This License Agreement applies to any software library or other |
@@ -432,7 +432,7 @@ decision will be guided by the two goals of preserving the free status | |||
432 | of all derivatives of our free software and of promoting the sharing | 432 | of all derivatives of our free software and of promoting the sharing |
433 | and reuse of software generally. | 433 | and reuse of software generally. |
434 | 434 | ||
435 | NO WARRANTY | 435 | NO WARRANTY |
436 | 436 | ||
437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO |
438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. | 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. |
@@ -455,7 +455,7 @@ FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF | |||
455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH | 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
456 | DAMAGES. | 456 | DAMAGES. |
457 | 457 | ||
458 | END OF TERMS AND CONDITIONS | 458 | END OF TERMS AND CONDITIONS |
459 | 459 | ||
460 | How to Apply These Terms to Your New Libraries | 460 | How to Apply These Terms to Your New Libraries |
461 | 461 | ||
@@ -501,4 +501,3 @@ necessary. Here is a sample; alter the names: | |||
501 | 501 | ||
502 | That's all there is to it! | 502 | That's all there is to it! |
503 | 503 | ||
504 | |||
diff --git a/utils/zenutils/libraries/getpot-c++-1.1.17/getpot/README b/utils/zenutils/libraries/getpot-c++-1.1.18/getpot/README index 3d55352a6b..b80a0cc060 100644 --- a/utils/zenutils/libraries/getpot-c++-1.1.17/getpot/README +++ b/utils/zenutils/libraries/getpot-c++-1.1.18/getpot/README | |||
@@ -5,10 +5,10 @@ Attention: This version contains a couple of beautiful | |||
5 | ---------- new features, that are not documented yet. | 5 | ---------- new features, that are not documented yet. |
6 | 6 | ||
7 | E.g.: -- automated ufo detection | 7 | E.g.: -- automated ufo detection |
8 | -- arbitrary comment delimiters | 8 | -- arbitrary comment delimiters |
9 | -- arbitrary vector field separators | 9 | -- arbitrary vector field separators |
10 | -- tails, i.e. easy access to all tails | 10 | -- tails, i.e. easy access to all tails |
11 | of options such as '-L' or '-I'. | 11 | of options such as '-L' or '-I'. |
12 | 12 | ||
13 | Please, refere to the example/ directory | 13 | Please, refere to the example/ directory |
14 | for usage descriptions. | 14 | for usage descriptions. |
@@ -47,4 +47,3 @@ Enjoy ! | |||
47 | 47 | ||
48 | Juli 2005, | 48 | Juli 2005, |
49 | Frank R. Schaefer | 49 | Frank R. Schaefer |
50 | |||
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h b/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h index d5c1748233..22c4133a2d 100644 --- a/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h +++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h | |||
@@ -14,6 +14,7 @@ | |||
14 | #define PEHEADER_H | 14 | #define PEHEADER_H |
15 | 15 | ||
16 | #include "PeLibAux.h" | 16 | #include "PeLibAux.h" |
17 | #include <string.h> | ||
17 | 18 | ||
18 | namespace PeLib | 19 | namespace PeLib |
19 | { | 20 | { |
diff --git a/utils/zenutils/source/firmware_extract/main.cpp b/utils/zenutils/source/firmware_extract/main.cpp index bcd77afdfc..1f31cc86eb 100644 --- a/utils/zenutils/source/firmware_extract/main.cpp +++ b/utils/zenutils/source/firmware_extract/main.cpp | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | #include <iostream> | 19 | #include <iostream> |
20 | #include <ctime> | 20 | #include <ctime> |
21 | #include <getpot/getpot.hpp> | 21 | #include <getpot/GetPot> |
22 | #include <utils.h> | 22 | #include <utils.h> |
23 | #include <firmware.h> | 23 | #include <firmware.h> |
24 | 24 | ||
diff --git a/utils/zenutils/source/firmware_make/main.cpp b/utils/zenutils/source/firmware_make/main.cpp index 35d036e601..29d0d20d83 100644 --- a/utils/zenutils/source/firmware_make/main.cpp +++ b/utils/zenutils/source/firmware_make/main.cpp | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | #include <iostream> | 19 | #include <iostream> |
20 | #include <sstream> | 20 | #include <sstream> |
21 | #include <getpot/getpot.hpp> | 21 | #include <getpot/GetPot> |
22 | #include <file.h> | 22 | #include <file.h> |
23 | #include <firmware.h> | 23 | #include <firmware.h> |
24 | #include <utils.h> | 24 | #include <utils.h> |
diff --git a/utils/zenutils/source/update_extract/main.cpp b/utils/zenutils/source/update_extract/main.cpp index 4891329397..6c7b5b1a4c 100644 --- a/utils/zenutils/source/update_extract/main.cpp +++ b/utils/zenutils/source/update_extract/main.cpp | |||
@@ -19,7 +19,7 @@ | |||
19 | #include <iostream> | 19 | #include <iostream> |
20 | #include <iomanip> | 20 | #include <iomanip> |
21 | #include <ctime> | 21 | #include <ctime> |
22 | #include <getpot/getpot.hpp> | 22 | #include <getpot/GetPot> |
23 | #include <file.h> | 23 | #include <file.h> |
24 | #include <updater.h> | 24 | #include <updater.h> |
25 | #include <utils.h> | 25 | #include <utils.h> |
diff --git a/utils/zenutils/source/update_patch/main.cpp b/utils/zenutils/source/update_patch/main.cpp index 5467694728..8e8d1ac03e 100644 --- a/utils/zenutils/source/update_patch/main.cpp +++ b/utils/zenutils/source/update_patch/main.cpp | |||
@@ -19,7 +19,7 @@ | |||
19 | #include <iostream> | 19 | #include <iostream> |
20 | #include <iomanip> | 20 | #include <iomanip> |
21 | #include <cstdio> | 21 | #include <cstdio> |
22 | #include <getpot/getpot.hpp> | 22 | #include <getpot/GetPot> |
23 | #include <file.h> | 23 | #include <file.h> |
24 | #include <updater.h> | 24 | #include <updater.h> |
25 | #include <utils.h> | 25 | #include <utils.h> |
diff --git a/utils/zenutils/source/zen_crypt/main.cpp b/utils/zenutils/source/zen_crypt/main.cpp index 29f0a843ae..f379c8e9a1 100644 --- a/utils/zenutils/source/zen_crypt/main.cpp +++ b/utils/zenutils/source/zen_crypt/main.cpp | |||
@@ -17,7 +17,7 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <iostream> | 19 | #include <iostream> |
20 | #include <getpot/getpot.hpp> | 20 | #include <getpot/GetPot> |
21 | #include <cenc.h> | 21 | #include <cenc.h> |
22 | #include <crypt.h> | 22 | #include <crypt.h> |
23 | #include <file.h> | 23 | #include <file.h> |