annotate librftab/readfir.c @ 465:003e48f8ebe1

rvinterf/etmsync/fsnew.c: cast 0 to (char *) for execl sentinel I generally don't use NULL and use plain 0 instead, based on a "NULL considered harmful" discussion on the classiccmp mailing list many aeons ago (I couldn't find it, and I reason that it must have been 2005 or earlier), but a recent complaint by a packager sent me searching, and I found this: https://ewontfix.com/11/ While I don't give a @#$% about "modern" systems and code-nazi tools, I realized that passing a plain 0 as a pointer sentinel in execl is wrong because it will break on systems where pointers are longer than the plain int type. Again, I don't give a @#$% about the abomination of x86_64 and the like, but if anyone ever manages to port my code to something like a PDP-11 (16-bit int, 32-bit long and pointers), then passing a plain 0 as a function argument where a pointer is expected most definitely won't work: if the most natural stack slot and SP alignment unit is 16 bits, fitting an int, with longs and pointers taking up two such slots, then the call stack will be totally wrong with a plain 0 passed for a pointer. Casting the 0 to (char *) ought to be the most kosher solution for the most retro systems possible.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Feb 2019 00:00:19 +0000
parents 9178594bc283
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
315
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Reading FIR coefficient tables from formatted ASCII files, used for the
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * auw-fir command in fc-tmsh.
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <ctype.h>
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "../rvinterf/include/exitcodes.h"
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "rdcommon.c"
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static u_char *writeptr;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 static
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 process_number()
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 {
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char *field;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int rc;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 long number;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 rc = get_field(&field);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (rc < 0)
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(ERROR_USAGE);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (!rc) {
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 printf("error: %s is too short for a FIR coefficient table\n",
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 filename);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return(ERROR_USAGE);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 number = strtol(field, 0, 0);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 *writeptr++ = number;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 *writeptr++ = number >> 8;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return(0);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 read_fir_coeff_table(filename_arg, rdbuf)
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 char *filename_arg;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 u_char *rdbuf;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 char *field;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 int rc, i;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 filename = filename_arg;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 rdfile = fopen(filename, "r");
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (!rdfile) {
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 perror(filename);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return(ERROR_UNIX);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 lineno = 0;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 line_nfields = 0;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 rc = get_field(&field);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (rc <= 0) {
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 not_valid_fir_table:
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 printf("error: %s is not a valid FIR coefficient table file\n",
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 filename);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 fclose(rdfile);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(ERROR_USAGE);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (strcmp(field, "fir-coeff-table"))
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 goto not_valid_fir_table;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 writeptr = rdbuf;
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 for (i = 0; i < 31; i++) {
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 rc = process_number();
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (rc) {
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 fclose(rdfile);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return(rc);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 rc = get_field(&field);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 fclose(rdfile);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (rc < 0)
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 return(ERROR_USAGE);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (rc) {
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 printf("error: %s is too long for a FIR coefficient table\n",
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 filename);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 return(ERROR_USAGE);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return(0);
9178594bc283 librftab: implemented reading of FIR coefficient tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }