comparison fir/rdcommon.c @ 376:9b3e5be96bab

fir2freq: a tool for analyzing captured FIR coefficient sets
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 02 Aug 2021 04:59:46 +0000
parents
children
comparison
equal deleted inserted replaced
375:6057c98d11a9 376:9b3e5be96bab
1 /*
2 * This C file is not a compilation unit in itself, but is the common piece
3 * (a set of static variables and functions) included in the librftab modules
4 * responsible for reading different kinds of ASCII tables.
5 */
6
7 #define MAX_FIELDS_PER_LINE 64
8
9 static char *filename;
10 static FILE *rdfile;
11 static unsigned lineno;
12 static char linebuf[256], *line_fields[MAX_FIELDS_PER_LINE];
13 static unsigned line_nfields, line_field_ptr;
14
15 static int
16 read_line()
17 {
18 char *cp;
19
20 if (!fgets(linebuf, sizeof linebuf, rdfile))
21 return(0);
22 lineno++;
23 cp = linebuf;
24 for (line_nfields = 0; ; ) {
25 while (isspace(*cp))
26 cp++;
27 if (*cp == '\0' || *cp == '#')
28 break;
29 if (line_nfields >= MAX_FIELDS_PER_LINE) {
30 fprintf(stderr,
31 "%s line %d: too many fields on one line\n",
32 filename, lineno);
33 return(-1);
34 }
35 line_fields[line_nfields++] = cp;
36 while (*cp && !isspace(*cp))
37 cp++;
38 if (*cp)
39 *cp++ = '\0';
40 }
41 return(1);
42 }
43
44 static
45 get_field(retp)
46 char **retp;
47 {
48 int rc;
49
50 if (line_field_ptr < line_nfields) {
51 *retp = line_fields[line_field_ptr++];
52 return(1);
53 }
54 do {
55 rc = read_line();
56 if (rc <= 0)
57 return(rc);
58 } while (!line_nfields);
59 *retp = line_fields[0];
60 line_field_ptr = 1;
61 return(1);
62 }