static int gettextfile(FILE *in, struct textfile *txt) { struct textline buf; memset(txt, 0, sizeof(*txt)); while (gettextline(in, &buf) >= 0) { if (!txt->a) { txt->a = 16; XCALLOC(txt->v, txt->a); } else if (txt->u >= txt->a) { txt->a *= 2; XREALLOC(txt->v, txt->a); } txt->v[txt->u++] = buf; } return txt->u; }
void readandcalcspline(FILE *infile, const char *inname, int d, double xstep, double llimit, double ulimit, int calclimit, int verbose, int *s) /* s is the dataset number */ { int n, l; char *line; if (infile != stdin) { infile=fopen(inname, "r"); if (infile == NULL) { fprintf(stderr, "%s: can't open \"%s\": %s.\n", progname, inname, strerror(errno)); return; } } if (verbose) printf("# %s\n", inname); /* Read the points and build an array with the samples (using insertpoint()). */ n=0; l=0; x=NULL; y=NULL; line=NULL; do { char *il; if (line != NULL) free(line); line=gettextline(infile); il=line; l++; if (il != NULL) while (isspace(*il)) il++; if ((line == NULL) || (il[0] == '\0')) { if (n > 0) { if (*s > 0) printf("\n"); calcspline(n, d, xstep, llimit, ulimit, calclimit); (*s)++; free(x); free(y); x=y=NULL; n=0; } } else if (il[0] != '#') { int k; /* number of values */ double f1, f2; /* doubleing point numbers */ /* read point */ k=sscanf(line, "%lf %lf", &f1, &f2); if (k < 1) fprintf(stderr, "%s:%s:%d: parse error at '%s'\n", progname, inname, l, line); else if (k==1) insertpoint(inname, llimit+n*xstep,f1,&n); /* Auto xscale */ else insertpoint(inname,f1,f2,&n); } } while (line != NULL); if (infile != stdin) fclose(infile); }