annotate librftab/readfir.c @ 926:6a0aa8d36d06

rvinterf backslash escape: introduce libprint The new helper function library named libprint is meant to replace the badly misnamed libg23, and will soon contain functions for printing all of the same kinds of GPF TST packets that are now handled in libg23. However, we are also moving safe_print_trace() from libasync to this new library, and changing it to emit our new backslash escape format.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 23 May 2023 03:47:46 +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 }