Flow123d
release_3.0.0-968-gc87a28e79
|
Go to the documentation of this file.
37 #include <boost/tokenizer.hpp>
38 #include "boost/lexical_cast.hpp"
39 #include <boost/algorithm/string.hpp>
43 #define FOR_INI_ITEMS(i) for((i)=read_ini->ini_item;(i)!=NULL;(i)=(i)->next)
64 const char *
const whitespace_delim=
" \t\r\n";
66 rc =
xstrtok( s, whitespace_delim, position);
79 char *
xstrtok(
char *s1,
const char *delim,
int position )
82 static char * full_string = NULL;
83 static int token_count;
85 OLD_ASSERT(!( delim == NULL ),
"NULL pointer as delimiter in xstrtok()\n");
91 full_string = (
char *)xmalloc(
LINE_SIZE );
99 INPUT_CHECK( token_count == position || position < 0,
"Requested position %d dosn't match token position %d", position, token_count);
100 rc = strtok( s1, delim );
103 INPUT_CHECK(!( rc == NULL ),
"Missing token no. %d: original string '%s' with delimiters '%s'\n", token_count, full_string, delim );
129 ASSERT(ini)(fname).error(
"Failed to open the ini file");
133 sscanf( line,
"%s",
string );
136 if (strlen(
string)==0)
142 strcpy(section,section_ptr);
146 if(strchr(line,
'=') == NULL)
150 tmp = strstr(line,
"#");
153 if(strlen(line) == 0)
159 sscanf(tmp,
"%s",
string);
160 if(strlen(
string) == 0)
163 key = xstrcpy(
string);
169 if(strlen(tmp) == 0){
174 value = xstrcpy(tmp);
193 while((
string[0] ==
' ') || (
string[0] ==
'\t')){
196 i = strlen(
string) - 1;
197 while((
string[i] ==
' ') || (
string[i] ==
'\t') || (
string[i] ==
'\n') || (
string[i] ==
'\r')){
214 ini_item->
prev = NULL;
218 ini_item->
next = NULL;
223 ini_item->
key = xstrcpy(
key);
236 if(line == NULL)
return NULL;
238 if( (line[0] ==
'[') && (line[strlen(line)-1] ==
']') && (strlen(line) > 2))
253 xprintf(
Err,
"OptGetXXX input interface is not supported anymore.\n");
256 const char *rc = NULL;
261 rc = ini_item->
value;
294 if (sscanf(str,
"%ld",&res) == 0) {
312 if (sscanf(str,
"%lg",&res) == 0) {
314 if (sscanf(defval,
"%lg",&res) == 0)
331 if ( boost::iequals(str,
"yes") || boost::iequals(str,
"true") || boost::iequals(str,
"1") ) res=
true;
332 else if ( boost::iequals(str,
"no") || boost::iequals(str,
"false") || boost::iequals(str,
"0") ) res=
false;
337 if ( boost::iequals(str,
"yes") || boost::iequals(str,
"true") || boost::iequals(str,
"1") ) res=
true;
338 else if ( boost::iequals(str,
"no") || boost::iequals(str,
"false") || boost::iequals(str,
"0") ) res=
false;
352 ASSERT(fname).error(
"NULL file name.\n");
383 std::string str = tmp_str;
385 boost::tokenizer<boost::char_separator<char> > line_tokenizer(str, boost::char_separator<char>(
"\t "));
386 boost::tokenizer<boost::char_separator<char> >::iterator tok;
390 for( tok = line_tokenizer.begin();
391 tok != line_tokenizer.end();
393 value = boost::lexical_cast<double> (*tok);
394 array.push_back(
value);
396 }
catch (boost::bad_lexical_cast &) {
397 xprintf(
UsrErr,
"INI file: Can not convert token `%s` of key `[%s] %s` to double.\n", (*tok).c_str(),
section,
key);
412 for(i = 1; i < ArrSize; i++){
413 if (sscanf(str,
"%d",&res) == 0) {
414 if (defval == NULL)
xprintf(
UsrErr,
"Can not convert %d. ini-file entry to integer parameter: [%s] %s.\n",i,
section,
key);
415 if (sscanf(defval,
"%d",&res) == 0)
418 *(Array + (i-1)*
sizeof(
double)) = res;
static void make_ini_item_list(const char *fname)
I/O functions with filename storing, able to track current line in opened file. All standard stdio fu...
char * xfgets(char *s, int n, FILE *in)
FGETS WITH ERROR HANDLING and line count.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
FILE * xfopen(const std::string &fname, const char *mode)
static constexpr bool value
std::string sprintf(CStringRef format, ArgList args)
static struct Ini_item * new_item(struct Ini_item *prev, char *section, char *key, char *value)
char * xstrtok(char *s, int position)
STRTOK WITH ERROR HANDLING and whitespace delimiters.
void OptGetIntArray(const char *section, const char *key, const char *defval, int ArrSize, int *Array)
char * OptGetFileName(const char *section, const char *key, const char *defval)
static char * section_test(char *section)
double OptGetDbl(const char *section, const char *key, const char *defval)
void OptGetDblArray(const char *section, const char *key, const char *defval, std::vector< double > &array)
void OptionsInit(const char *fname)
Load options file.
char * OptGetStr(const char *section, const char *key, const char *defval)
Create new string from selected variable from ini file.
struct Ini_item * ini_item
#define INPUT_CHECK(i,...)
Debugging macros.
long int OptGetInt(const char *section, const char *key, const char *defval)
static struct Read_ini * read_ini
static char * strip_spaces(char *string)
bool OptGetBool(const char *section, const char *key, const char *defval)