annotate librftab/rdcommon.c @ 624:7485e75d9477

srec-regions: removed unnecessary prohibition against address going backward
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 27 Feb 2020 08:12:11 +0000
parents a0f79bba0ad8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
314
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This C file is not a compilation unit in itself, but is the common piece
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * (a set of static variables and functions) included in the librftab modules
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * responsible for reading different kinds of ASCII tables.
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #define MAX_FIELDS_PER_LINE 64
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 static char *filename;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 static FILE *rdfile;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 static unsigned lineno;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static char linebuf[256], *line_fields[MAX_FIELDS_PER_LINE];
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static unsigned line_nfields, line_field_ptr;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 static int
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 read_line()
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *cp;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (!fgets(linebuf, sizeof linebuf, rdfile))
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 return(0);
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 lineno++;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 cp = linebuf;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 for (line_nfields = 0; ; ) {
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 while (isspace(*cp))
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 cp++;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (*cp == '\0' || *cp == '#')
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 break;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (line_nfields >= MAX_FIELDS_PER_LINE) {
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 printf("%s line %d: too many fields on one line\n",
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 filename, lineno);
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(-1);
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 line_fields[line_nfields++] = cp;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 while (*cp && !isspace(*cp))
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 cp++;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (*cp)
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 *cp++ = '\0';
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return(1);
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 static
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 get_field(retp)
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 char **retp;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 int rc;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (line_field_ptr < line_nfields) {
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 *retp = line_fields[line_field_ptr++];
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return(1);
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 do {
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 rc = read_line();
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (rc <= 0)
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 return(rc);
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 } while (!line_nfields);
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 *retp = line_fields[0];
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 line_field_ptr = 1;
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(1);
a0f79bba0ad8 librftab: reading of Tx ramp template files split from rftablerd module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }