annotate ffstools/caltools/c1xx-calextr.c @ 296:77d561735b07

c1xx-calextr: preparations for both ASCII and binary output
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 18 Nov 2017 17:30:26 +0000
parents 1416fe200069
children b1ac1bd1dbbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program parses Compal's proprietary data structure that contains
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * the factory RF calibration values among other data, locates those RF
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * calibration records, extracts their essential content (Rx GMagic and
296
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
5 * Tx APC values), converts this distilled content into TCS211 RF calibration
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
6 * tables (Rx agcparams and Tx levels) and writes these tables out in either
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
7 * FreeCalypso ASCII or FFS binary format.
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <sys/types.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <sys/file.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <stdio.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <stdlib.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <unistd.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #define COMPAL_SECTOR_LENGTH 0x2000
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 u_char sector[COMPAL_SECTOR_LENGTH];
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 u_char endmarker[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 u_char record_magic[4] = {0xAA, 0x00, 0x00, 0x00};
296
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
23 char *ascii_output_dir, *bin_output_dir;
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct band {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 char *name;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 unsigned compal_record_id;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 unsigned record_length;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 unsigned magic2_offset;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 unsigned start_plnum;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 unsigned end_plnum;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 } bands[] = {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {"900", 0x00, 0x94, 0x54, 5, 19},
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 {"1800", 0x01, 0xC8, 0x74, 0, 15},
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {"1900", 0x02, 0xB4, 0x68, 0, 15},
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {"850", 0x18, 0x88, 0x4C, 5, 19},
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 };
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 read_binfile(filename, offset_arg)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 char *filename, *offset_arg;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 int fd, cc;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 u_long offset;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 char *endp;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fd = open(filename, O_RDONLY);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (fd < 0) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 perror(filename);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 offset = strtoul(offset_arg, &endp, 0);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (*endp) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fprintf(stderr, "error: invalid offset argument \"%s\"\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 offset_arg);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 lseek(fd, offset, SEEK_SET);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 cc = read(fd, sector, COMPAL_SECTOR_LENGTH);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (cc != COMPAL_SECTOR_LENGTH) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 fprintf(stderr,
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 "error: unable to read Compal sector of %d bytes from %s at offset %s\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 COMPAL_SECTOR_LENGTH, filename, offset_arg);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 close(fd);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 process_band_record(band, offset)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 struct band *band;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 unsigned offset;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 u_char *record;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 record = sector + offset + 8;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (bcmp(record, record_magic, 4)) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 printf("bad magic1, skipping\n");
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 return(-1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 if (bcmp(record + band->magic2_offset, record_magic, 4)) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 printf("bad magic2, skipping\n");
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return(-1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (bcmp(record + band->magic2_offset + 8, record_magic, 4)) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 printf("bad magic3, skipping\n");
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 return(-1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 /* Rx GMagic and Tx levels extraction to be filled */
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 return(0);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90
296
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
91 process_sector_data()
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 unsigned offset, next_offset;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 u_char *header;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 unsigned hdr_words[4];
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 struct band *band;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 int i;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 for (offset = 0; ; offset = next_offset) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (offset > COMPAL_SECTOR_LENGTH - 12)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 break;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 header = sector + offset;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 if (!bcmp(header, endmarker, 8))
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 break;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 for (i = 0; i < 4; i++)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 hdr_words[i] = header[i*2] | (header[i*2+1] << 8);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 if (!hdr_words[3]) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 fprintf(stderr,
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 "error at offset 0x%X: rounded record length word is 0\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 if (hdr_words[3] & 3) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 fprintf(stderr,
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 "error at offset 0x%X: rounded record length word is not aligned to 4\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 if (hdr_words[3] > COMPAL_SECTOR_LENGTH - offset - 8) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 fprintf(stderr,
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 "error at offset 0x%X: rounded record length spills past end of sector\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 if (hdr_words[2] > hdr_words[3]) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 fprintf(stderr,
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 "error at offset 0x%X: native record length is greater than rounded\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 next_offset = offset + 8 + hdr_words[3];
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 if (hdr_words[0] != 0x000C)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 continue;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 for (band = bands; band->name; band++)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 if (hdr_words[1] == band->compal_record_id)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 break;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 if (!band->name)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 continue;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 printf("Found %s MHz calibration record at offset 0x%X\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 band->name, offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 if (hdr_words[2] != band->record_length) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 printf("Oops, wrong length, skipping\n");
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 continue;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 process_band_record(band, offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 }
296
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
147 }
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
148
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
149 main(argc, argv)
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
150 char **argv;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
151 {
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
152 int c;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
153 extern char *optarg;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
154 extern int optind;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
155
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
156 while ((c = getopt(argc, argv, "a:b:")) != EOF)
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
157 switch (c) {
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
158 case 'a':
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
159 ascii_output_dir = optarg;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
160 continue;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
161 case 'b':
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
162 bin_output_dir = optarg;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
163 continue;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
164 case '?':
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
165 default:
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
166 usage: fprintf(stderr,
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
167 "usage: %s [-a ascii_outdir] [-b bin_outdir] c1xx-binfile offset\n",
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
168 argv[0]);
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
169 exit(1);
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
170 }
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
171 if (argc - optind != 2)
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
172 goto usage;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
173 read_binfile(argv[optind], argv[optind+1]);
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
174 if (ascii_output_dir)
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
175 mkdir_existok(ascii_output_dir);
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
176 if (bin_output_dir)
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
177 mkdir_existok(bin_output_dir);
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
178 process_sector_data();
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 exit(0);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 }