FreeCalypso > hg > freecalypso-reveng
comparison fir/readfir.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 * Reading FIR coefficient tables from formatted ASCII files, | |
3 * modified version for host processing. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <ctype.h> | |
8 #include <stdio.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include <stdlib.h> | |
12 | |
13 #include "rdcommon.c" | |
14 | |
15 static int *writeptr; | |
16 | |
17 static | |
18 process_number() | |
19 { | |
20 char *field; | |
21 int rc, number; | |
22 | |
23 rc = get_field(&field); | |
24 if (rc < 0) | |
25 return(rc); | |
26 if (!rc) { | |
27 printf("error: %s is too short for a FIR coefficient table\n", | |
28 filename); | |
29 return(-1); | |
30 } | |
31 number = strtol(field, 0, 0); | |
32 if (number >= 32768) | |
33 number -= 65536; | |
34 *writeptr++ = number; | |
35 return(0); | |
36 } | |
37 | |
38 read_fir_coeff_table_int(filename_arg, rdbuf) | |
39 char *filename_arg; | |
40 int *rdbuf; | |
41 { | |
42 char *field; | |
43 int rc, i; | |
44 | |
45 filename = filename_arg; | |
46 rdfile = fopen(filename, "r"); | |
47 if (!rdfile) { | |
48 perror(filename); | |
49 return(-1); | |
50 } | |
51 lineno = 0; | |
52 line_nfields = 0; | |
53 rc = get_field(&field); | |
54 if (rc <= 0) { | |
55 not_valid_fir_table: | |
56 fprintf(stderr, | |
57 "error: %s is not a valid FIR coefficient table file\n", | |
58 filename); | |
59 fclose(rdfile); | |
60 return(-1); | |
61 } | |
62 if (strcmp(field, "fir-coeff-table")) | |
63 goto not_valid_fir_table; | |
64 writeptr = rdbuf; | |
65 for (i = 0; i < 31; i++) { | |
66 rc = process_number(); | |
67 if (rc < 0) { | |
68 fclose(rdfile); | |
69 return(rc); | |
70 } | |
71 } | |
72 rc = get_field(&field); | |
73 fclose(rdfile); | |
74 if (rc < 0) | |
75 return(rc); | |
76 if (rc) { | |
77 fprintf(stderr, | |
78 "error: %s is too long for a FIR coefficient table\n", | |
79 filename); | |
80 return(-1); | |
81 } | |
82 return(0); | |
83 } |