58 read_size = fread ( data, 1, size, fp);
110read_variable (
const char *fname,
const char *var_name,
char *fmt,
void *varp)
113 char *seek, *pos, *bol;
125 if ( (pos = strstr(seek, var_name)) == NULL)
127 seek = pos + strlen (var_name);
135 after = *(pos+strlen(var_name));
137 if ( isalnum(before) || isalnum(after) || (before ==
'_') || (after ==
'_') )
141 bol = (pos > data) ? pos - 1 : data;
142 while ( (bol > data) && (*bol !=
'\n') )
144 if ( *bol ==
'\n' ) bol++;
148 if ( strspn(bol,
" \t") !=
static_cast<size_t>(pos - bol) )
156 cout <<
"ERROR: variable " << var_name <<
" was not found in config-file!\n";
160 found += strlen (var_name);
163 found += strspn(found,
" \t=:");
168 if ( !strcmp(fmt, FMT_STRING) )
172 if ( (pos = strchr(found+1,
'"')) == NULL )
174 cout <<
"ERROR: no closing quotes found \n";
181 if ( (pos = strchr (found,
'\n')) == NULL)
182 pos = data + strlen(data);
186 char **cstr =
static_cast<char**
>(varp);
187 len = int(pos - found);
188 (*cstr) =
static_cast<char*
>(
MyMalloc(len+1));
189 strncpy ((*cstr), found, len);
194 ret = sscanf (found, fmt, varp);
197 if ( (ret == 0) || (ret == EOF) )
199 cout <<
"WARNING: Variable " << var_name <<
" was not readable using the format '"<<fmt<<
"'\n";