static lwres_result_t lwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp) { char word[LWRES_CONFMAXLINELEN]; int res, i; lwres_conf_t *confdata; confdata = &ctx->confdata; res = getword(fp, word, sizeof(word)); if (strlen(word) == 0U) return (LWRES_R_FAILURE); /* Nothing else on line. */ else if (res == ' ' || res == '\t') res = eatwhite(fp); if (res != EOF && res != '\n') return (LWRES_R_FAILURE); /* Extra junk on line. */ if (confdata->domainname != NULL) CTXFREE(confdata->domainname, strlen(confdata->domainname) + 1); /* */ /* * Search and domain are mutually exclusive. */ for (i = 0; i < LWRES_CONFMAXSEARCH; i++) { if (confdata->search[i] != NULL) { CTXFREE(confdata->search[i], strlen(confdata->search[i])+1); confdata->search[i] = NULL; } } confdata->searchnxt = 0; confdata->domainname = lwres_strdup(ctx, word); if (confdata->domainname == NULL) return (LWRES_R_FAILURE); return (LWRES_R_SUCCESS); }
int parsetop(char* topin, FILE* outpsf, PsfResList* knownRes) { char line[101]; //char temp[20]; //char type[5]; //char element[3]; PsfRes* currRes; FILE* psfin; psfin = fopen(topin, "r"); if (psfin == NULL) { fputs("Warning: Couldn't open input file ", stderr); fputs(topin, stderr); fputs("\n",stderr); // stderr << "Warning: Couldn't open input file " << topin << endl; return 1; } while(fgets(line,100,psfin)) { // // Read the list of atomtypes // if (strncmp(line, "MASS", 4) == 0) { // int index=0; // float mass=0; // sscanf(line, "%s %i %s %f %s", temp, &index, type, &mass, element); // PsfType* currType = new PsfType(type,mass,element); // knownType->addtype(currType); // } //Check if we've gotten to the residue part yet if (strncmp(line, "RESI", 4) == 0) { //If so, parse and add the residue fprintf(outpsf,"%s",line); // char* comment='!'; currRes = addTopRes(line, psfin, outpsf); knownRes->addres(currRes); } else if (strncasecmp(eatwhite(line),"END",3)) { fprintf(outpsf,"%s",line); } } fclose(psfin); return 0; }
double Expression::readToken(std::map<char, double>& substitutions, std::istream& in) { char ch; eatwhite(in); // Skip whitespace in.get(ch); if ( isalpha(ch) ) return substitutions[ch]; // Substitute a variable else if ( ch == '$' ) { // Evaluate a subexpression Expression sub = local_subs.front(); local_subs.pop_front(); return sub.evaluate(substitutions); } else if ( isdigit(ch) || ch == '.' ) { // Read a number in.putback(ch); double num; in >> num; return num; }
static int yylex2(void) { int ch; int chkcomment = FALSE; yuk_a_goto: eatwhite(); if ((ch = GETC(fname)) == EOF) { if (firstsemi == 1) { firstsemi = 0; fclose(fname); fname = fnamesave; goto yuk_a_goto; } else { return(TENDOFFILE); } } do { if (ch == '/') if ((ch = GETC(fname)) == '*') { eatcomment(); eatwhite(); chkcomment = TRUE; if ((ch = GETC(fname)) == EOF) return(TENDOFFILE); } else { UNGETC(ch, fname); ch = '/'; chkcomment = FALSE; } else if (ch == '-') /* -- is a comment in our language */ { if ((ch = GETC(fname)) == '-') { eatline(); /* ignore rest of line */ if (firstsemi != 1) yylineno++; eatwhite(); chkcomment = TRUE; if ((ch = GETC(fname)) == EOF) return(TENDOFFILE); } else { UNGETC(ch, fname); ch = '-'; chkcomment = FALSE; } } else chkcomment = FALSE; } while (chkcomment); if (isalpha(ch) || ch == '_') return(eatident(ch)); if (isdigit(ch)) return(eatnumber(ch)); if (ch == '"') return(eatstring()); if (ch == '\'') { char ch2; char ch3; char chat; int ate; ch2 = GETC(fname); ch3 = GETC(fname); UNGETC(ch3,fname); UNGETC(ch2,fname); if (ch2 != ' ' || ch3 != '\'') { /* can't eat whitespace if char contains whitespace */ ate = eatwhite(); chat = GETC(fname); UNGETC(chat,fname); if (chat == '@') { if (ate || (ch2 != '@' && ch3 != '\'')) { return TPRIME; } } } return eatcharacter(); } if (ch == '.') { if (isdigit(ch = GETC(fname))) { UNGETC(ch, fname); ch = '.'; return(eatnumber(ch)); } else { UNGETC(ch, fname); ch = '.'; } } if (ch == '#') { char ch2; eatwhite(); /* remove "line" if it exists - some vers of cpp have this */ if ((ch2 = GETC(fname)) == '[') { UNGETC(ch2, fname); return eatleftovers(ch); } else { UNGETC(ch2, fname); } if (!isdigit(ch = GETC(fname))) { UNGETC(ch, fname); yylex2(); if (!strcmp(buffer,"pragma")) { for (ch = GETC(fname); ch != '\n'; ch = GETC(fname)) ; goto yuk_a_goto; } if (strcmp(buffer,"line")) { USR_FATALX(yylineno, in_file, "syntax error (appears to be a cpp directive: try -cpp)"); } eatwhite(); } else { UNGETC(ch, fname); } if (!isdigit(ch = GETC(fname))) { UNGETC(ch, fname); USR_FATALX(yylineno, in_file, "syntax error (appears to be a cpp directive: use -cpp)"); } else UNGETC(ch, fname); yylex2(); yylineno = atoi(buffer); for (ch = GETC(fname); ch != '"' && ch != '\n'; ch = GETC(fname)) ; if (ch != '"') { goto yuk_a_goto; } else UNGETC(ch, fname); yylex2(); in_file = (char *)PMALLOC((strlen(buffer) + 1)*sizeof(char)); strcpy(in_file, buffer); base_in_file = strrchr(in_file,'/'); if (base_in_file == NULL) { base_in_file = in_file; } else { base_in_file++; } for (ch = GETC(fname); ch != '\n'; ch = GETC(fname)) ; goto yuk_a_goto; } if (ispunct(ch)) return(eatleftovers(ch)); buffer[0] = ch; buffer[1] = '\0'; if (firstsemi == 1) { firstsemi = 0; fclose(fname); fname = fnamesave; goto yuk_a_goto; } return(-1); }
static void read_curves_and_surfaces(int argc, char *argv[]) { xscale=yscale=zscale=1.0; int ref=DEFAULT_REF; // Number of new knots between old ones. int maxref=DEFAULT_MAX_REF; // Maximal number of coeffs in any given direction. // (n, n) makes sure new knots are inserted close to max limit = n... int i; // // This must be reset every time we change control vertices, since // the discretization is done in the drawing routine. // for (i=0; i<curves; i++) { if (discr_curve[i]!=NULL) { delete discr_curve[i]; discr_curve[i]=NULL; } } // @HH@ // @HH@ Use the following optional command line options: // @HH@ surfaces=0; curves=0; for (i=1; i<argc; i++) { switch (argv[i][0]) { case 's': { // Next string is filename for surface. (One surface.) puts("Reading surfaces"); // surface[surfaces-1]=read_nurbs_sf(argv[i+1]); // old format std::vector<SISLSurf*> tmp; std::ifstream is(argv[i+1]); if (!is) { CRIT_ERR(printf("Could not open file: '%s'.\n", argv[i+1])); } try { eatwhite(is); while (!is.eof()) { //surface[surfaces-1] = readGoSurface(is); tmp.push_back(readGoSurface(is)); eatwhite(is); } } catch (std::exception& e) { CRIT_ERR(printf("Error occured while reading surface: %s\n", e.what())); } is.close(); int num_surfaces = tmp.size(); if (surfaces + num_surfaces > MAX_SURFACES) { CRIT_ERR(puts("Increase MAX_SURFACES.")); } for (int k = 0; k < num_surfaces; ++k) { // // 010116: This should be a quick fix for periodic // surfaces... // if (tmp[k] == NULL) { CRIT_ERR(printf("Couldn't read SISLSurf '%s'.\n", argv[i+1])); } if ((tmp[k]->cuopen_1 == SISL_CRV_PERIODIC || tmp[k]->cuopen_2 == SISL_CRV_PERIODIC)) { int kstat; SISLSurf *tmp_surf; make_sf_kreg(tmp[k], &tmp_surf, &kstat); if (kstat < 0) { CRIT_ERR(printf("make_sf_kreg failed!\n")); } freeSurf(tmp[k]); tmp[k] = tmp_surf; } if (tmp[k]->idim != 3) { CRIT_ERR(printf("Dimension of surface is %d and not 3!\n", tmp[k]->idim)); } if (surface[surfaces]) { // deleting old surface freeSurf(surface[surfaces]); } surface[surfaces] = tmp[k]; surface_name[surfaces] = argv[i+1]; surf_enabled[surfaces] = 1; // Generating an approximating polygon. lower_degree_and_subdivide(surface + surfaces, ref, maxref); // evaluating normals (normalized) delete normal[surfaces]; compute_surface_normals(surface[surfaces], normal + surfaces); ++surfaces; } } i++; break; case 'c': { // Next string is filename for file containing 1 curve. printf("Reading a single curve into slot %d.\n", curves); std::vector<SISLCurve*> tmp; //n=get_curve_set(argv[i+1], &tmp, &stat); //get_single_curve(argv[i+1], &tmp, &stat); // old format std::ifstream is(argv[i+1]); if (!is) { CRIT_ERR(printf("Could not open file: '%s'.\n", argv[i+1])); } try { eatwhite(is); while (!is.eof()) { tmp.push_back(readGoCurve(is)); eatwhite(is); } } catch (std::exception& e) { CRIT_ERR(printf("Error occured while reading curve: %s\n", e.what())); } is.close(); int num_curves = tmp.size(); if (curves + num_curves > MAX_CURVES) { CRIT_ERR(puts("Increase MAX_CURVES.")); } for(int k = 0; k < num_curves; ++k) { if (curve[curves + k] != NULL) { freeCurve(curve[curves + k]); } curve[curves + k] = tmp[k]; // // 001206: If the dimension is 2, we set up a // new curve, filling in zeros. // if (curve[curves + k]->idim==2) { double *new_coeffs= new double[3*curve[curves + k]->in]; if (new_coeffs==NULL) CRIT_ERR(puts("Couldn't allocate memory.")); int j; for (j=0; j<curve[curves + k]->in; j++) { new_coeffs[3*j+0]= curve[curves + k]->ecoef[2*j+0]; new_coeffs[3*j+1]= curve[curves + k]->ecoef[2*j+1]; new_coeffs[3*j+2]=0.0; } SISLCurve *tmp2=curve[curves + k]; curve[curves + k]= newCurve(tmp2->in, tmp2->ik, tmp2->et, new_coeffs, tmp2->ikind, 3, 1); freeCurve(tmp2); } if (curve[curves + k]->idim!=3) { CRIT_ERR(printf("Dimension of curve is %d and not 3?!\n", curve[curves + k]->idim)); } curve_name[curves + k]=argv[i+1]; curve_enabled[curves + k]=1; } curves+=num_curves; } i++; break; case 'p': { // Next string is filename for file containing a point cloud. printf("Reading a point cloud.\n"); std::ifstream is(argv[i+1]); if (!is) { CRIT_ERR(printf("Could not open file: '%s'.\n", argv[i+1])); } try { vector<double> coords; readGoPoints(coords, is); int num_points = int(coords.size()) / 3; printf("Number of vertices: %d\n", num_points); for (int i = 0; i < num_points; ++i) { pcloud.push_back(vector3t<float>(coords[3 * i], coords[3 * i + 1], coords[3 * i + 2])); } // eatwhite(is); // int tmp; // is >> tmp; // is >> tmp; // is >> tmp; // is >> tmp; // is >> tmp; // is >> tmp; // is >> tmp; // is >> tmp; // eatwhite(is); // is >> tmp; // printf("Number of vertices: %d\n", tmp); // while (!is.eof()) { // double x, y, z; // is >> x; // is >> y; // is >> z; // //printf("point: %f %f %f\n", x, y, z); // pcloud.push_back(vector3t<float>(x, y, z)); // eatwhite(is); // } } catch (std::exception& e) { CRIT_ERR(printf("Error occured while reading curve: %s\n", e.what())); } is.close(); printf("pcloud size is now %d\n", pcloud.size()); } i++; break; // case 'r': // // Set refinement factor. Default value is ???. // puts("Reading surface refinement factor"); // ref=atoi(argv[i+1]); // i++; // break; // case 'R': case 'r': // Set max refinement factor. Default value is ???. puts("Reading upper bound for surface refinement."); maxref=atoi(argv[i+1]); i++; break; case 'e': // String with keypresses to execute follows. Not // everything will work! printf("Executing '%s'.\n", argv[i+1]); strncpy(init_key_string, argv[i+1], 1000); i++; break; default: puts("Huh?! Unknown option."); exit(0); } } }
static aqwin_param *parse_cfg(const char *cfg) { char *cp; aqwin_param *param; aqwin_tuple *last; if ((param = malloc(sizeof *param)) == NULL) { complain("aqwin_open: nomem param\n"); goto e0_nomem_param; } memset(param, 0, sizeof *param); if ((param->buf = malloc(strlen(cfg))) == NULL) { complain("aqwin_open: nomem param buf\n"); goto e1_nomem_parambuf; } strcpy(param->buf, cfg); if ((param->attr = malloc(sizeof *(param->attr))) == NULL) { complain("aqwin_open: nomem param attr\n"); goto e2_nomem_paramattr; } memset(param->attr, 0, sizeof *(param->attr)); last = param->attr; cp = param->buf; for(eatwhite(&cp); *cp; cp++) { skip_inc: if(*cp == '=' && last->key == NULL) { complain("aqwin_open: keys cannot begin with '='\n"); goto e3_parse_error; } else if(*cp == '=') { *cp = '\0'; last->val = cp + 1; } else if(*cp == '\'') { *cp++ = '\0'; if (last->val) { last->val = cp; } else { complain("aqwin_open: quoted key\n"); goto e3_parse_error; } if (charff(&cp, '\'')) { *cp++ = '\0'; } else { complain("aqwin_open: unterminated string\n"); goto e3_parse_error; } eatwhite(&cp); if((last->next = malloc(sizeof *last)) == NULL) { complain("aqwin_open: nomem next param\n"); goto e3_nomem_paramnext; } last = last->next; memset(last, 0, sizeof *last); goto skip_inc; } else if(isws(*cp)) { *cp = '\0'; last->val = last->val ? last->val : cp; if (parse_attr(last)) { goto e3_parse_error; } cp++; eatwhite(&cp); if((last->next = malloc(sizeof *last)) == NULL) { complain("aqwin_open: nomem next param\n"); goto e3_nomem_paramnext; } last = last->next; memset(last, 0, sizeof *last); goto skip_inc; } else if(last->key == NULL) { last->key = cp; } } return param; e3_nomem_paramnext: e3_parse_error: aqwin_tuple_free(param->attr); e2_nomem_paramattr: free(param->buf); e1_nomem_parambuf: free(param); e0_nomem_param: return NULL; }
char *nextword(char *str) { return eatwhite(eatword(str)); }
/* board and category are initially empty strings */ static int parse_match_string(int p, int* wt,int* bt,int* winc,int* binc, int* white,int* rated,char* category, char* board, char* mstring) { int numba; int confused = 0; char parsebuf[100]; while (!confused && (sscanf(mstring, " %99s", parsebuf) == 1)) { mstring = eatword(eatwhite(mstring)); if (isdigit(*parsebuf)) { if ((numba = atoi(parsebuf)) < 0) { pprintf(p, "You can't specify negative time controls.\n"); return 0; } else if (numba > 999) { pprintf(p, "You can't specify time or inc above 999.\n"); return 0; } else if (*wt == -1) { *wt = numba; } else if (*winc == -1) { *winc = numba; } else if (*bt == -1) { *bt = numba; } else if (*binc == -1) { *binc = numba; } else confused = 1; } else if ((!strcmp("rated", parsebuf)) || (!strcmp("r",parsebuf))) { if (*rated == -1) *rated = 1; else confused = 1; } else if ((!strcmp("unrated", parsebuf)) || (!strcmp("u",parsebuf))) { if (*rated == -1) *rated = 0; else confused = 1; } else if (!strcmp("white", parsebuf) || !strcmp ("w", parsebuf)) { if (*white == -1) *white = 1; else confused = 1; } else if (!strcmp("black", parsebuf) || !strcmp ("b", parsebuf)) { if (*white == -1) *white = 0; else confused = 1; } else if (!strcmp("bughouse", parsebuf) || !strcmp ("bug", parsebuf)) { strcpy(category, "bughouse"); } else if (!strcmp("zh", parsebuf)) { strcpy(category,parsebuf); } else if (category[0] && !board[0]) { if (!strcmp("fr", parsebuf)) strcpy (board, "FR"); else if ((parsebuf[0] == 'w') && (isdigit(*(parsebuf + 1)))) strcpy (board, parsebuf+1); else strcpy(board, parsebuf); } else confused = 1; } if (confused) { pprintf(p, "Can't interpret %s in match command.\n", parsebuf); return 0; } return 1; }