Isis_Fit_Engine_Type *isis_find_fit_engine (char *name) /*{{{*/ { Isis_Option_Type *opts; Isis_Fit_Engine_Type *e; if (name == NULL) name = Fit_Default_Fit_Method; if (NULL == (opts = isis_parse_option_string (name))) return NULL; name = opts->subsystem; if (NULL == (e = find_fit_engine (name))) { fprintf (stderr, "fit method %s does not exist\n", name); isis_free_options (opts); return NULL; } if (e->set_options != NULL) { if (-1 == e->set_options (e, opts)) { isis_free_options (opts); return NULL; } } isis_free_options (opts); return e; }
Isis_Fit_Statistic_Type *isis_find_fit_statistic (char *name) /*{{{*/ { Isis_Option_Type *opts; Isis_Fit_Statistic_Type *s; if (name == NULL) name = Fit_Default_Fit_Method; if (NULL == (opts = isis_parse_option_string (name))) return NULL; name = opts->subsystem; if (NULL == (s = find_statistic (name))) { fprintf (stderr, "fit statistic %s does not exist\n", name); isis_free_options (opts); return NULL; } s->message_string = NULL; if (s->set_options != NULL) { if (-1 == s->set_options (s, opts)) { isis_free_options (opts); return NULL; } } isis_free_options (opts); return s; }
static int parse_options (Isis_Rmf_t *rmf, char *options) /*{{{*/ { Isis_Option_Type *opts; if (NULL == (opts = isis_parse_option_string (options))) return -1; if (-1 == set_options (rmf, opts)) { isis_free_options (opts); return -1; } isis_free_options (opts); return 0; }
static int process_options (Isis_Kernel_t *k, char *options) /*{{{*/ { Isis_Option_Type *o; int status; if (options == NULL) return 0; if (NULL == (o = isis_parse_option_string (options))) return -1; status = isis_process_options (o, Std_Option_Table, (void *)k, 1); isis_free_options (o); return status; }
int isis_is_option_present (char *options, char *option, char **value) { unsigned int i, num; Isis_Option_Type *opt; int status; char **option_names; if (options == NULL) return 0; if (option == NULL) return 0; opt = isis_parse_option_string (options); if (opt == NULL) return -1; option_names = opt->option_names; num = opt->num_options; status = 0; for (i = 0; i < num; i++) { if (0 != isis_strcasecmp (option, option_names[i])) continue; status = 1; if (value != NULL) { char *val = opt->option_values[i]; if (val != NULL) { if (NULL == (val = isis_make_string (val))) status = -1; } *value = val; } break; } isis_free_options (opt); return status; }
Isis_Option_Type *isis_parse_option_string (char *str) { unsigned int num; Isis_Option_Type *t; char *estr; if (NULL == (t = (Isis_Option_Type *) ISIS_MALLOC (sizeof(Isis_Option_Type)))) return NULL; memset ((char *) t, 0, sizeof (Isis_Option_Type)); if (str == NULL) str = ""; str = isis_skip_whitespace (str); if (NULL == (str = isis_make_string (str))) { ISIS_FREE (t); return NULL; } t->subsystem = str; /* Now skip to the first field */ str = skip_and_truncate_field (str, FIELD_SEP_CHAR); unescape_and_trim_string (t->subsystem); /* Count the number of commas as an estimate on the number of fields */ /* Allow for a final NULL. */ num = 2; estr = str; while (NULL != (estr = strchr (estr, FIELD_SEP_CHAR))) { num++; estr++; } if (NULL == (t->option_names = (char **) ISIS_MALLOC (num * sizeof(char *)))) { isis_free_options (t); return NULL; } if (NULL == (t->option_values = (char **) ISIS_MALLOC (num * sizeof(char *)))) { isis_free_options (t); return NULL; } /* Ok, now get the options */ num = 0; while (1) { str = isis_skip_whitespace (str); if (*str == 0) break; t->option_names[num] = str; estr = skip_and_truncate_field (str, FIELD_SEP_CHAR); /* Now look for = form */ str = skip_and_truncate_field (str, '='); str = isis_skip_whitespace (str); if (*str == 0) t->option_values[num] = NULL; else t->option_values[num] = str; unescape_and_trim_string (t->option_names[num]); unescape_and_trim_string (t->option_values[num]); str = estr; num++; } t->option_values [num] = NULL; t->option_names [num] = NULL; t->num_options = num; return t; }