43 #include "Parser_dh.h"
62 static void init_from_default_settings_private (
Parser_dh p);
66 #define __FUNC__ "Parser_dhCreate"
83 ptr->name = (
char *) MALLOC_DH (6 *
sizeof (
char));
85 ptr->value = (
char *) MALLOC_DH (6 *
sizeof (
char));
87 strcpy (ptr->name,
"JUNK");
88 strcpy (ptr->value,
"JUNK");
92 #define __FUNC__ "Parser_dhDestroy"
96 START_FUNC_DH
OptionsNode * ptr2 = p->head, *ptr1 = ptr2;
102 FREE_DH (ptr1->name);
103 FREE_DH (ptr1->value);
107 while (ptr1 != NULL);
114 #define __FUNC__ "Parser_dhUpdateFromFile"
116 Parser_dhUpdateFromFile (
Parser_dh p,
char *filename)
118 START_FUNC_DH_2
char line[80], name[80], value[80];
121 if ((fp = fopen (filename,
"r")) == NULL)
123 sprintf (msgBuf_dh,
"can't open >>%s<< for reading", filename);
124 SET_INFO (msgBuf_dh);
128 sprintf (msgBuf_dh,
"updating parser from file: >>%s<<", filename);
129 SET_INFO (msgBuf_dh);
132 if (fgets (line, 80, fp) == NULL)
136 if (sscanf (line,
"%s %s", name, value) != 2)
138 Parser_dhInsert (p, name, value);
146 #define __FUNC__ "Parser_dhInit"
148 Parser_dhInit (
Parser_dh p,
int argc,
char *argv[])
150 START_FUNC_DH_2
int j;
155 init_from_default_settings_private (p);
159 Parser_dhUpdateFromFile (p,
"./database");
163 for (j = 1; j < argc; ++j)
165 if (strcmp (argv[j],
"-db_filename") == 0)
170 Parser_dhUpdateFromFile (p, argv[j]);
181 if (argv[i][0] ==
'-')
183 char value[] = {
"1" };
185 if (i + 1 < argc && argv[i + 1][0] ==
'-'
186 && argv[i + 1][1] ==
'-')
191 if ((i + 1 == argc || argv[i + 1][0] ==
'-') && !flag)
193 Parser_dhInsert (p, argv[i], value);
197 Parser_dhInsert (p, argv[i], argv[i + 1] + 1);
201 Parser_dhInsert (p, argv[i], argv[i + 1]);
211 #define __FUNC__ "Parser_dhHasSwitch"
213 Parser_dhHasSwitch (
Parser_dh p,
char *s)
215 START_FUNC_DH_2
bool has_switch =
false;
218 if (p != NULL && find (p, s, &node))
220 if (!strcmp (node->value,
"0"))
224 else if (!strcmp (node->value,
"false"))
228 else if (!strcmp (node->value,
"False"))
232 else if (!strcmp (node->value,
"FALSE"))
241 END_FUNC_VAL_2 (has_switch)}
247 #define __FUNC__ "Parser_dhReadInt"
249 Parser_dhReadInt (
Parser_dh p,
char *in,
int *out)
251 START_FUNC_DH_2
bool has_switch =
false;
254 if (p != NULL && find (p, in, &node))
256 *out = atoi (node->value);
257 if (!strcmp (node->value,
"0"))
266 END_FUNC_VAL_2 (has_switch)}
270 #define __FUNC__ "Parser_dhReadDouble"
272 Parser_dhReadDouble (
Parser_dh p,
char *in,
double *out)
274 START_FUNC_DH_2
bool optionExists =
false;
277 if (p != NULL && find (p, in, &node))
279 *out = atof (node->value);
282 END_FUNC_VAL_2 (optionExists)}
285 #define __FUNC__ "Parser_dhReadString"
287 Parser_dhReadString (
Parser_dh p,
char *in,
char **out)
289 START_FUNC_DH_2
bool optionExists =
false;
292 if (p != NULL && find (p, in, &node))
297 END_FUNC_VAL_2 (optionExists)}
301 #define __FUNC__ "Parser_dhPrint"
303 Parser_dhPrint (
Parser_dh p, FILE * fp,
bool allPrint)
308 SET_V_ERROR (
"fp == NULL");
310 if (myid_dh == 0 || allPrint)
312 fprintf (fp,
"------------------------ registered options:\n");
315 fprintf (fp,
"Parser object is invalid; nothing to print!\n");
322 fprintf (fp,
" %s %s\n", ptr->name, ptr->value);
333 #define __FUNC__ "Parser_dhInsert"
335 Parser_dhInsert (
Parser_dh p,
char *option,
char *value)
341 goto PARSER_NOT_INITED;
344 if (find (p, option, &node))
346 int length2 = strlen (node->value) + 1;
347 length = strlen (value) + 1;
348 if (length2 < length)
350 FREE_DH (node->value);
351 node->value = (
char *) MALLOC_DH (length *
sizeof (
char));
354 strcpy (node->value, value);
363 length = strlen (option) + 1;
364 node->name = (
char *) MALLOC_DH (length *
sizeof (
char));
366 strcpy (node->name, option);
367 length = strlen (value) + 1;
368 node->value = (
char *) MALLOC_DH (length *
sizeof (
char));
370 strcpy (node->value, value);
380 #define __FUNC__ "find"
385 bool foundit =
false;
386 while (tmpPtr != NULL)
388 if (strcmp (tmpPtr->name, option) == 0)
394 tmpPtr = tmpPtr->next;
396 END_FUNC_VAL_2 (foundit)}
400 #define __FUNC__ "init_from_default_settings_private"
402 init_from_default_settings_private (
Parser_dh p)
408 Parser_dhInsert (p,
"-sig_dh",
"1");
412 Parser_dhInsert (p,
"-px",
"1");
414 Parser_dhInsert (p,
"-py",
"1");
416 Parser_dhInsert (p,
"-pz",
"0");
418 Parser_dhInsert (p,
"-m",
"4");
421 Parser_dhInsert (p,
"-xx_coeff",
"-1.0");
423 Parser_dhInsert (p,
"-yy_coeff",
"-1.0");
425 Parser_dhInsert (p,
"-zz_coeff",
"-1.0");
428 Parser_dhInsert (p,
"-level",
"1");
431 Parser_dhInsert (p,
"-printStats",
"0");