From: Keith Packard Date: Mon, 12 Aug 2013 09:12:33 +0000 (+0200) Subject: Add a tool to round BOM amounts to reasonable quantities X-Git-Tag: telelco-v3.0~857 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=46b04c26ad92e2e7db7606b88083213c4e944c0d;p=hw%2Faltusmetrum Add a tool to round BOM amounts to reasonable quantities Signed-off-by: Keith Packard --- diff --git a/nickle/fix-quantity b/nickle/fix-quantity new file mode 100644 index 0000000..3fa31ae --- /dev/null +++ b/nickle/fix-quantity @@ -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();