annotate ffstools/newcomp/compile-fc-chg.c @ 320:7572c35a768a

compile-fc-chg tool written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 17 Dec 2017 02:25:05 +0000
parents
children 0937521ec2f4
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[] = {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 {"start-delay", 0, 0, 0, 0, 0, 0},
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {"start-threshold", 1, 1, 1, 0, 0, 0},
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {"restart-threshold", 0, 1, 1, 0, 0, 0},
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {"charge-to-voltage", 0, 0, 1, 0, 0, 0},
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {"overvoltage", 0, 0, 0, 0xFFFF, 0, 0},
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {"ci-current", 0, 0, 1, 0, 0, 0},
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 {"end-current", 0, 0, 1, 0, 0, 0},
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {"i2v-offset", 0, 0, 0, 0, 0, 0},
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {0, 0, 0, 0, 0, 0, 0}
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 };
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 static void
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 do_setting(tp, arg)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 struct setting *tp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 char *arg;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 char *endp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (tp->allow_always && !strcmp(arg, "always")) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 tp->set_value = 0xFFFF;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (tp->allow_never && !strcmp(arg, "never")) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 tp->set_value = 0;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 return;
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 tp->set_value = strtoul(arg, &endp, 0);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (*endp || tp->set_value > 0xFFFF) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 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
57 infname, lineno, tp->kw);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(ERROR_USAGE);
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 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 process_line()
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 char *cp, *kw, *arg;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 struct setting *tp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 for (cp = linebuf; isspace(*cp); cp++)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 ;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (*cp == '\0' || *cp == '#')
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 return(0);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 kw = cp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 while (*cp && !isspace(*cp))
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 cp++;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (!*cp) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 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
76 lineno);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 exit(ERROR_USAGE);
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 *cp++ = '\0';
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 while (isspace(*cp))
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 cp++;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (*cp == '\0' || *cp == '#')
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 goto inv;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 arg = cp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 while (*cp && !isspace(*cp))
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 cp++;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (*cp)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 *cp++ = '\0';
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 while (isspace(*cp))
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 cp++;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 if (*cp != '\0' && *cp != '#')
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 goto inv;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 for (tp = settings; tp->kw; tp++)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 if (!strcmp(tp->kw, kw))
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 break;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (!tp->kw) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 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
98 infname, lineno, kw);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 exit(ERROR_USAGE);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 if (tp->is_set) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 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
103 lineno, kw);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 exit(ERROR_USAGE);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 do_setting(tp, arg);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 tp->is_set = 1;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 return(1);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
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 set_defaults()
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 struct setting *tp;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 for (tp = settings; tp->kw; tp++) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 if (tp->is_set)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 continue;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 if (tp->mandatory) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 fprintf(stderr,
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 "error: required setting %s is not set\n",
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 tp->kw);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 exit(ERROR_USAGE);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 tp->set_value = tp->default_value;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 write_output(filename)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 char *filename;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 FILE *of;
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 struct setting *tp;
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 of = fopen(filename, "w");
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 if (!of) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 perror(filename);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 exit(ERROR_UNIX);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 for (tp = settings; tp->kw; tp++) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 putc(tp->set_value, of);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 putc(tp->set_value >> 8, of);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 fclose(of);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 }
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 main(argc, argv)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 char **argv;
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 if (argc != 3) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 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
151 exit(ERROR_USAGE);
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 infname = argv[1];
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 inf = fopen(infname, "r");
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 if (!inf) {
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 perror(infname);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 exit(ERROR_UNIX);
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 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++)
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 process_line();
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 fclose(inf);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 set_defaults();
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 write_output(argv[2]);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 exit(0);
7572c35a768a compile-fc-chg tool written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 }