annotate ffstools/newcomp/tiffs-mkfile.c @ 1004:d15d337ac0a9

loadtools/scripts: remove long-deprecated -h gta02 config
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Dec 2023 18:35:30 +0000
parents f19c347d0a80
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
746
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program generates certain types of binary files that go into TIFFS.
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * It is intended for use in shell scripts that prepare input trees for
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * tiffs-mkfs.
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/file.h>
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <ctype.h>
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <unistd.h>
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #define MAX_FILE_SIZE 256
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 u_char databuf[MAX_FILE_SIZE];
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 unsigned datalen;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 void
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 write_binary_file(filename)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 char *filename;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 int fd, cc;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (fd < 0) {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 perror(filename);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 exit(1);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 cc = write(fd, databuf, datalen);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (cc != datalen) {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 perror("error writing to file");
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 exit(1);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 close(fd);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 void
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 do_filetype_ascii(str)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 char *str;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 unsigned len;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 len = strlen(str);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (len > MAX_FILE_SIZE) {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 fprintf(stderr,
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 "error: ASCII string exceeds file size limit\n");
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 exit(1);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 bcopy(str, databuf, len);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 datalen = len;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 hexdigit(c)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (isdigit(c))
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 return(c - '0');
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 else if (isupper(c))
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return(c - 'A' + 10);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 else
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return(c - 'a' + 10);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 void
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 do_filetype_hex(hexstr)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 char *hexstr;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 char *cp;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 unsigned len;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 for (cp = hexstr, len = 0; ; cp += 2) {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 while (isspace(*cp))
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 cp++;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (!*cp)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 break;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (!isxdigit(cp[0]) || !isxdigit(cp[1])) {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 fprintf(stderr, "error: invalid hex string argument\n");
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 exit(1);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (len >= MAX_FILE_SIZE) {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 fprintf(stderr,
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 "error: hex string exceeds file size limit\n");
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 exit(1);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 databuf[len++] = hexdigit(cp[0]) << 4 | hexdigit(cp[1]);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 datalen = len;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 void
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 parse_imeisv_arg(input, buf)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 char *input, *buf;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 char *cp;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 int i;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 cp = input;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (!isdigit(*cp)) {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 inv: fprintf(stderr,
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 "error: IMEISV argument must have 16 decimal digits\n");
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 exit(1);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 for (i = 0; i < 16; i++) {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if (ispunct(*cp))
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 cp++;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 if (!isdigit(*cp))
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 goto inv;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 buf[i] = *cp++ - '0';
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 if (*cp)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 goto inv;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 void
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 do_filetype_imeisv(strarg)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 char *strarg;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 char digits[16];
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 int i;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 parse_imeisv_arg(strarg, digits);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 for (i = 0; i < 8; i++)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 databuf[i] = digits[i*2] << 4 | digits[i*2+1];
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 datalen = 8;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 void
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 do_filetype_pcm_imei(strarg)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 char *strarg;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 char digits[16];
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 int i;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 parse_imeisv_arg(strarg, digits);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 for (i = 0; i < 8; i++)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 databuf[i] = digits[i*2+1] << 4 | digits[i*2];
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 datalen = 8;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 static struct band_table {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 char *keyword;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 u_char bytes[4];
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 } band_table[] = {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 {"dual-eu", {0x00, 0x0B, 0x41, 0x00}},
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 {"dual-us", {0x00, 0x14, 0x00, 0x14}},
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 {"tri900", {0x00, 0x0F, 0x41, 0x10}},
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 {"tri850", {0x00, 0x16, 0x01, 0x14}},
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 {"quad", {0x00, 0x1F, 0x41, 0x14}},
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 {0, {0x00, 0x00, 0x00, 0x00}}
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 };
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 static u_char rfcap_tail[12] = {0x00, 0x00, 0x00, 0x00,
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 0x50, 0x00, 0x00, 0xA5,
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 0x05, 0x00, 0xC0, 0x00};
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 void
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 do_filetype_rfcap(band_config_kw)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 char *band_config_kw;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 struct band_table *tp;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 for (tp = band_table; tp->keyword; tp++)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 if (!strcmp(tp->keyword, band_config_kw))
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 break;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 if (!tp->keyword) {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 fprintf(stderr, "error: band configuration \"%s\" not known\n",
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 band_config_kw);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 exit(1);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 bcopy(tp->bytes, databuf, 4);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 bcopy(rfcap_tail, databuf + 4, 12);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 datalen = 16;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 static struct file_type {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 char *keyword;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 void (*func)();
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 } file_type_table[] = {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 {"ascii", do_filetype_ascii},
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 {"hex", do_filetype_hex},
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 {"imeisv", do_filetype_imeisv},
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 {"pcm-imei", do_filetype_pcm_imei},
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 {"rfcap", do_filetype_rfcap},
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 /* table search terminator */
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 {0, 0}
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 };
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 main(argc, argv)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 char **argv;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 struct file_type *tp;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 if (argc != 4) {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 fprintf(stderr, "usage: %s dest-file file-type content-str\n",
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 argv[0]);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 exit(1);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 for (tp = file_type_table; tp->keyword; tp++)
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 if (!strcmp(tp->keyword, argv[2]))
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 break;
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 if (!tp->func) {
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 fprintf(stderr, "error: file type \"%s\" not supported\n",
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 argv[2]);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 exit(1);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 }
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 tp->func(argv[3]);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 write_binary_file(argv[1]);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 exit(0);
f19c347d0a80 tiffs-mkfile utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 }