rename symbol directory to match datasheet directory
[hw/altusmetrum] / nickle / fix-quantity
1 #!/usr/bin/nickle
2
3 string[] read_line(file f) {
4         string line = File::fgets(f);
5
6         return String::parse_csv(line);
7 }
8
9 void
10 print_line(file f, string[] bits) {
11         for (int i = 0; i < dim(bits); i++) {
12                 string end = i == dim(bits) - 1 ? "\n" : ",";
13                 printf ("%s%s", bits[i], end);
14         }
15 }
16
17 typedef struct {
18         string  pattern;
19         int     count;
20 } fix_t;
21
22 fix_t[] fixes = {
23         { .pattern = "RESISTOR", .count = 250 },
24         { .pattern = "CAPACITOR", .count = 100 },
25         { .pattern = "INDUCTOR", .count = 100 },
26         { .pattern = "LED", .count = 100 },
27 };
28
29 string[]
30 fix_em(string[] elts) {
31         for (int f = 0; f < dim(fixes); f++) {
32                 if (String::index(elts[2], fixes[f].pattern) >= 0) {
33                         elts[0] = sprintf ("%d", fixes[f].count);
34                         break;
35                 }
36         }
37         return elts;
38 }
39
40 void
41 main() {
42         while (!File::end(stdin)) {
43                 string[] elts = read_line(stdin);
44                 elts = fix_em(elts);
45                 print_line(stdout, elts);
46         }
47 }
48
49 main();