static int get_einp(int *ninp, t_inpfile **inp, const char *name) { int i; int notfound = FALSE; i = search_einp(*ninp, *inp, name); if (i == -1) { notfound = TRUE; i = (*ninp)++; srenew(*inp, (*ninp)); (*inp)[i].name = gmx_strdup(name); (*inp)[i].bSet = TRUE; } (*inp)[i].count = (*inp)[0].inp_count++; (*inp)[i].bSet = TRUE; if (debug) { fprintf(debug, "Inp %d = %s\n", (*inp)[i].count, (*inp)[i].name); } /*if (i == (*ninp)-1)*/ if (notfound) { return -1; } else { return i; } }
static int get_einp(int *ninp,t_inpfile **inp,const char *name) { int i; int notfound=FALSE; char warn_buf[STRLEN]; /* if (inp==NULL) return -1; for(i=0; (i<(*ninp)); i++) if (gmx_strcasecmp_min(name,(*inp)[i].name) == 0) break; if (i == (*ninp)) {*/ i=search_einp(*ninp, *inp, name); if (i == -1) { notfound=TRUE; i=(*ninp)++; srenew(*inp,(*ninp)); (*inp)[i].name=strdup(name); (*inp)[i].bSet=TRUE; } (*inp)[i].count = (*inp)[0].inp_count++; (*inp)[i].bSet = TRUE; if (debug) fprintf(debug,"Inp %d = %s\n",(*inp)[i].count,(*inp)[i].name); /*if (i == (*ninp)-1)*/ if (notfound) return -1; else return i; }
void mark_einp_set(int ninp, t_inpfile *inp, const char *name) { int i = search_einp(ninp, inp, name); if (i != -1) { inp[i].count = inp[0].inp_count++; inp[i].bSet = TRUE; } }
t_inpfile *read_inpfile(const char *fn, int *ninp, char **cppopts, warninp_t wi) { FILE *in; char buf[STRLEN], lbuf[STRLEN], rbuf[STRLEN], warn_buf[STRLEN]; char *ptr, *cptr; t_inpfile *inp = NULL; int nin, lc, i, j, k; /* setting cppopts from command-line options would be cooler */ gmx_bool allow_override = FALSE; if (debug) { fprintf(debug, "Reading MDP file %s\n", fn); } in = ffopen(fn, "r"); nin = lc = 0; do { ptr = fgets2(buf, STRLEN-1, in); lc++; set_warning_line(wi, fn, lc); if (ptr) { /* Strip comment */ if ((cptr = strchr(buf, COMMENTSIGN)) != NULL) { *cptr = '\0'; } /* Strip spaces */ trim(buf); for (j = 0; (buf[j] != '=') && (buf[j] != '\0'); j++) { ; } if (buf[j] == '\0') { if (j > 0) { if (debug) { fprintf(debug, "No = on line %d in file %s, ignored\n", lc, fn); } } } else { for (i = 0; (i < j); i++) { lbuf[i] = buf[i]; } lbuf[i] = '\0'; trim(lbuf); if (lbuf[0] == '\0') { if (debug) { fprintf(debug, "Empty left hand side on line %d in file %s, ignored\n", lc, fn); } } else { for (i = j+1, k = 0; (buf[i] != '\0'); i++, k++) { rbuf[k] = buf[i]; } rbuf[k] = '\0'; trim(rbuf); if (rbuf[0] == '\0') { if (debug) { fprintf(debug, "Empty right hand side on line %d in file %s, ignored\n", lc, fn); } } else { /* Now finally something sensible */ int found_index; /* first check whether we hit the 'multiple_entries' option */ if (gmx_strcasecmp_min(eMultentOpt_names[eMultentOptName], lbuf) == 0) { /* we now check whether to allow overrides from here or not */ if (gmx_strcasecmp_min(eMultentOpt_names[eMultentOptNo], rbuf) == 0) { allow_override = FALSE; } else if (gmx_strcasecmp_min(eMultentOpt_names[eMultentOptLast], rbuf) == 0) { allow_override = TRUE; } else { sprintf(warn_buf, "Parameter \"%s\" should either be %s or %s\n", lbuf, eMultentOpt_names[eMultentOptNo], eMultentOpt_names[eMultentOptLast]); warning_error(wi, warn_buf); } } else { /* it is a regular option; check for duplicates */ found_index = search_einp(nin, inp, lbuf); if (found_index == -1) { /* add a new item */ srenew(inp, ++nin); inp[nin-1].inp_count = 1; inp[nin-1].count = 0; inp[nin-1].bObsolete = FALSE; inp[nin-1].bSet = FALSE; inp[nin-1].name = strdup(lbuf); inp[nin-1].value = strdup(rbuf); } else { if (!allow_override) { sprintf(warn_buf, "Parameter \"%s\" doubly defined (and multiple assignments not allowed)\n", lbuf); warning_error(wi, warn_buf); } else { /* override */ sfree(inp[found_index].value); inp[found_index].value = strdup(rbuf); sprintf(warn_buf, "Overriding existing parameter \"%s\" with value \"%s\"\n", lbuf, rbuf); warning_note(wi, warn_buf); } } } } } } } } while (ptr); ffclose(in); if (debug) { fprintf(debug, "Done reading MDP file, there were %d entries in there\n", nin); } *ninp = nin; return inp; }