annotate ffstools/newcomp/compile-fc-batt2.c @ 794:1a084d7512dc

CHANGES: document fc-simint
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 19 Mar 2021 05:10:57 +0000
parents cae22bec3cba
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
753
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This utility compiles a table of battery thresholds for the 2020-10 version
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * of FreeCalypso battery management code from ASCII source into the binary
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * form suitable for uploading into /etc/batterytab2 on a FreeCalypso device.
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <ctype.h>
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "../../rvinterf/include/exitcodes.h"
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #define MIN_PERCENT_THRESH 5
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #define MAX_PERCENT_THRESH 21 /* allowing 5% steps */
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #define NB_BARS_THRESH 4
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 char *infname;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 FILE *inf;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char linebuf[256];
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int lineno;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 unsigned main_array_mv[MAX_PERCENT_THRESH];
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 unsigned main_array_percent[MAX_PERCENT_THRESH];
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 unsigned main_array_count;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 u_char bars_thresh_array[NB_BARS_THRESH];
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 unsigned expect_bars = NB_BARS_THRESH, bars_index;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 process_line()
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 char *cp;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 unsigned mv, percent, bars;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 int bars_set;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 for (cp = linebuf; isspace(*cp); cp++)
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 ;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (*cp == '\0' || *cp == '#')
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return(0);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (!isdigit(*cp)) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 inv: fprintf(stderr, "%s line %d: invalid syntax\n", infname,
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 lineno);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 exit(ERROR_USAGE);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 mv = strtoul(cp, 0, 10);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 while (isdigit(*cp))
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 cp++;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (!isspace(*cp))
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 goto inv;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 while (isspace(*cp))
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 cp++;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (!isdigit(*cp))
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 goto inv;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 percent = strtoul(cp, 0, 10);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 while (isdigit(*cp))
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 cp++;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 while (isspace(*cp))
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 cp++;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (*cp && *cp != '#') {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (!isdigit(*cp))
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 goto inv;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 bars = strtoul(cp, 0, 10);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 while (isdigit(*cp))
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 cp++;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 while (isspace(*cp))
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 cp++;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (*cp && *cp != '#')
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 goto inv;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 bars_set = 1;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 } else
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 bars_set = 0;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (mv > 0xFFFF) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 fprintf(stderr, "%s line %d: the millivolt value is invalid\n",
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 infname, lineno);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 exit(ERROR_USAGE);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (percent > 100) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 fprintf(stderr, "%s line %d: the percent value is invalid\n",
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 infname, lineno);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 exit(ERROR_USAGE);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (bars_set && (bars < 1 || bars > NB_BARS_THRESH)) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 fprintf(stderr, "%s line %d: the bars number is invalid\n",
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 infname, lineno);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 exit(ERROR_USAGE);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (main_array_count >= MAX_PERCENT_THRESH) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 fprintf(stderr, "%s line %d: too many table entries\n",
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 infname, lineno);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 exit(ERROR_USAGE);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 if (main_array_count) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 if (mv >= main_array_mv[main_array_count-1]) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 fprintf(stderr,
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 "%s line %d: millivolt numbers must be decreasing\n",
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 infname, lineno);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 exit(ERROR_USAGE);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (percent >= main_array_percent[main_array_count-1]) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 fprintf(stderr,
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 "%s line %d: percent numbers must be decreasing\n",
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 infname, lineno);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 exit(ERROR_USAGE);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 main_array_mv[main_array_count] = mv;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 main_array_percent[main_array_count] = percent;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 if (bars_set) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 if (bars != expect_bars) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 fprintf(stderr,
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 "%s line %d: bars threshold out of order\n",
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 infname, lineno);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 exit(1);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 bars_thresh_array[bars_index++] = main_array_count;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 expect_bars--;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 main_array_count++;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 return(1);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 write_output(filename)
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 char *filename;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 FILE *of;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 unsigned n, mv, percent;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 of = fopen(filename, "w");
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 if (!of) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 perror(filename);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 exit(ERROR_UNIX);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 fwrite(bars_thresh_array, 1, NB_BARS_THRESH, of);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 for (n = 0; n < main_array_count; n++) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 mv = main_array_mv[n];
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 percent = main_array_percent[n];
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 putc(mv, of);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 putc(mv >> 8, of);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 putc(percent, of);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 putc(0, of);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 fclose(of);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 main(argc, argv)
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 char **argv;
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 if (argc != 3) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 fprintf(stderr, "usage: %s srcfile output-binfile\n", argv[0]);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 exit(ERROR_USAGE);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 infname = argv[1];
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 inf = fopen(infname, "r");
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 if (!inf) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 perror(infname);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 exit(ERROR_UNIX);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++)
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 process_line();
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 fclose(inf);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 if (main_array_count < MIN_PERCENT_THRESH) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 fprintf(stderr, "error: %s is too short\n", infname);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 exit(ERROR_USAGE);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 if (expect_bars) {
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 fprintf(stderr, "error: %s did not specify bars thresholds\n",
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 infname);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 exit(ERROR_USAGE);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 }
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 write_output(argv[2]);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 exit(0);
cae22bec3cba compile-fc-batt2 utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 }