annotate ffstools/newcomp/compile-fc-chg.c @ 389:2a47a8ef860a

CHANGES: User Phone Tools addition documented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 11 Mar 2018 17:04:10 +0000
parents 0937521ec2f4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
320
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This utility compiles a FreeCalypso battery charging configuration file
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * from ASCII source into the binary form suitable for uploading into
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * /etc/charging on a FreeCalypso device.
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <ctype.h>
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "../../rvinterf/include/exitcodes.h"
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char *infname;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 FILE *inf;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char linebuf[256];
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int lineno;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 struct setting {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char *kw;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int allow_always;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int allow_never;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int mandatory;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 unsigned default_value;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 unsigned set_value;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 int is_set;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 } settings[] = {
324
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
28 {"start-delay", 0, 0, 0, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
29 {"start-threshold", 1, 1, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
30 {"restart-threshold", 0, 1, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
31 {"ci2cv-threshold", 0, 0, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
32 {"cv-initial-setpoint", 0, 0, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
33 {"cv-ctrl-loop-high", 0, 0, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
34 {"cv-ctrl-loop-low", 0, 0, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
35 {"cv-dac-max-incr", 0, 0, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
36 {"cv-dac-max-decr", 0, 0, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
37 {"cv-ctrl-loop-sample-count", 0, 0, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
38 {"overvoltage", 0, 0, 0, 0xFFFF, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
39 {"ci-current", 0, 0, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
40 {"end-current", 0, 0, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
41 {"ichg-max-spike", 0, 0, 0, 0x400, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
42 {"ichg-low-samples-needed", 0, 0, 1, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
43 {"charging-time-limit", 0, 0, 0, 0xFFFF, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
44 {"restart-delay", 0, 0, 0, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
45 {"i2v-offset", 0, 0, 0, 0, 0, 0},
0937521ec2f4 compile-fc-chg: changes for FCHG v2
Mychaela Falconia <falcon@freecalypso.org>
parents: 320
diff changeset
46 {0, 0, 0, 0, 0, 0, 0}
320
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 };
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 static void
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 do_setting(tp, arg)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 struct setting *tp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 char *arg;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 char *endp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (tp->allow_always && !strcmp(arg, "always")) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 tp->set_value = 0xFFFF;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 return;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (tp->allow_never && !strcmp(arg, "never")) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 tp->set_value = 0;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 tp->set_value = strtoul(arg, &endp, 0);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (*endp || tp->set_value > 0xFFFF) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 fprintf(stderr, "%s line %d: invalid argument to %s\n",
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 infname, lineno, tp->kw);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 exit(ERROR_USAGE);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 process_line()
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 char *cp, *kw, *arg;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 struct setting *tp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 for (cp = linebuf; isspace(*cp); cp++)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 ;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 if (*cp == '\0' || *cp == '#')
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 return(0);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 kw = cp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 while (*cp && !isspace(*cp))
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 cp++;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if (!*cp) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 inv: fprintf(stderr, "%s line %d: invalid syntax\n", infname,
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 lineno);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 exit(ERROR_USAGE);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 *cp++ = '\0';
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 while (isspace(*cp))
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 cp++;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (*cp == '\0' || *cp == '#')
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 goto inv;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 arg = cp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 while (*cp && !isspace(*cp))
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 cp++;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 if (*cp)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 *cp++ = '\0';
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 while (isspace(*cp))
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 cp++;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 if (*cp != '\0' && *cp != '#')
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 goto inv;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 for (tp = settings; tp->kw; tp++)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 if (!strcmp(tp->kw, kw))
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 break;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if (!tp->kw) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 fprintf(stderr, "%s line %d: setting \"%s\" not known\n",
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 infname, lineno, kw);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 exit(ERROR_USAGE);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 if (tp->is_set) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 fprintf(stderr, "%s line %d: %s set more than once\n", infname,
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 lineno, kw);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 exit(ERROR_USAGE);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 do_setting(tp, arg);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 tp->is_set = 1;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 return(1);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 set_defaults()
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 struct setting *tp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 for (tp = settings; tp->kw; tp++) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 if (tp->is_set)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 continue;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 if (tp->mandatory) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 fprintf(stderr,
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 "error: required setting %s is not set\n",
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 tp->kw);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 exit(ERROR_USAGE);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 tp->set_value = tp->default_value;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 write_output(filename)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 char *filename;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 FILE *of;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 struct setting *tp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 of = fopen(filename, "w");
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 if (!of) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 perror(filename);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 exit(ERROR_UNIX);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 for (tp = settings; tp->kw; tp++) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 putc(tp->set_value, of);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 putc(tp->set_value >> 8, of);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 fclose(of);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 main(argc, argv)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 char **argv;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 if (argc != 3) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 fprintf(stderr, "usage: %s srcfile output-binfile\n", argv[0]);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 exit(ERROR_USAGE);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 infname = argv[1];
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 inf = fopen(infname, "r");
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 if (!inf) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 perror(infname);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 exit(ERROR_UNIX);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 process_line();
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 fclose(inf);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 set_defaults();
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 write_output(argv[2]);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 exit(0);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 }