]> git.gag.com Git - hw/altusmetrum/commitdiff
Add a tool to round BOM amounts to reasonable quantities
authorKeith Packard <keithp@keithp.com>
Mon, 12 Aug 2013 09:12:33 +0000 (11:12 +0200)
committerKeith Packard <keithp@keithp.com>
Mon, 12 Aug 2013 09:12:33 +0000 (11:12 +0200)
Signed-off-by: Keith Packard <keithp@keithp.com>
nickle/fix-quantity [new file with mode: 0644]

diff --git a/nickle/fix-quantity b/nickle/fix-quantity
new file mode 100644 (file)
index 0000000..3fa31ae
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/nickle
+
+string[] read_line(file f) {
+       string line = File::fgets(f);
+
+       return String::parse_csv(line);
+}
+
+void
+print_line(file f, string[] bits) {
+       for (int i = 0; i < dim(bits); i++) {
+               string end = i == dim(bits) - 1 ? "\n" : ",";
+               printf ("%s%s", bits[i], end);
+       }
+}
+
+typedef struct {
+       string  pattern;
+       int     count;
+} fix_t;
+
+fix_t[] fixes = {
+       { .pattern = "RESISTOR", .count = 250 },
+       { .pattern = "CAPACITOR", .count = 100 },
+       { .pattern = "INDUCTOR", .count = 100 },
+       { .pattern = "LED", .count = 100 },
+};
+
+string[]
+fix_em(string[] elts) {
+       for (int f = 0; f < dim(fixes); f++) {
+               if (String::index(elts[2], fixes[f].pattern) >= 0) {
+                       elts[0] = sprintf ("%d", fixes[f].count);
+                       break;
+               }
+       }
+       return elts;
+}
+
+void
+main() {
+       while (!File::end(stdin)) {
+               string[] elts = read_line(stdin);
+               elts = fix_em(elts);
+               print_line(stdout, elts);
+       }
+}
+
+main();