initial design for TirePyro rear panel insert
[hw/altusmetrum] / bin / partslist-vendor
index d8ce957b0130d7ec71da47f7068d2e28f6b68e76..423796eb74ac7660b4a453fcbc7ca8bd9aeadac5 100755 (executable)
@@ -26,7 +26,11 @@ string[*] read_line(file f) {
        lineno++;
        string  line = fgets(f);
 
-       return String::parse_csv(line);
+       string[*] elts = String::parse_csv(line);
+       for (int i = 0; i < dim(elts); i++)
+               if (String::length(elts[i]) > 0 && elts[i][0] == '"')
+                       elts[i] = String::dequote(elts[i]);
+       return elts;
 }
 
 string[*] header;
@@ -39,6 +43,7 @@ string[*] required_elements = {
        "device",
        "value",
        "refdes",
+       "loadstatus"
 };
 
 bool has_header_member(string member) {
@@ -87,10 +92,29 @@ string part_number(string[string] entry)
                return entry["vendor_part_number"];
 }
 
-void process_seeed(string[string] entry)
+string quoted(string v)
 {
+       if (String::index(v, "\"") >= 0 || String::index(v, ",") >= 0) {
+               if (String::index(v, "\"") >= 0) {
+                       string ret = "\"";
+                       for (int i = 0; i < String::length(v); i++) {
+                               if (v[i] == '"')
+                                       ret = ret + "\"";
+                               ret = ret + String::new(v[i]);
+                       }
+                       ret = ret + "\"";
+                       return ret;
+               } else {
+                       return "\"" + v + "\"";
+               }
+       } else {
+               return v;
+       }
+}
 
-       if (entry["loadstatus"] != "smt")
+void process_seeed(string[string] entry)
+{
+       if (entry["loadstatus"] == "noload")
                return;
 
        static bool start = true;
@@ -109,24 +133,92 @@ void process_seeed(string[string] entry)
        }
        if (dim(refdes) > 1)
                printf ("\"");
-       printf(",%s,%s\n", entry["mfg_part_number"], entry["quantity"]);
+       printf(",%s,%s\n", quoted(entry["mfg_part_number"]), entry["quantity"]);
+}
+
+void process_goldphoenix(string[string] entry)
+{
+       int units = 1000;
+
+       if (entry["loadstatus"] == "noload")
+               return;
+
+       static int item = 1;
+       static bool start = true;
+       if (start) {
+               printf("#Item,Description,Designator,Package,Manufacturer,Manufacturer Part Number#,Supplier,Supplier Part #,QTY/BOARD,Order QTY,Unit Price, Subtotal \n");
+               start = false;
+       }
+
+       string[*] refdes = String::wordsplit(entry["refdes"], " \t");
+       printf("%d,", item);
+
+       /* description */
+       printf("%s %s,",
+              quoted(entry["device"]),
+              quoted(entry["value"]));
+
+       /* designators */
+       if (dim(refdes) > 1)
+               printf ("\"");
+       for (int i = 0; i < dim(refdes); i++) {
+               printf("%s", refdes[i]);
+               if (i < dim(refdes) - 1)
+                       printf (",");
+       }
+       if (dim(refdes) > 1)
+               printf ("\"");
+
+       /* rest */
+       printf(",%s,%s,%s,%s,%s,%s,%d\n",
+              quoted(entry["footprint"]),
+              quoted(entry["mfg"]),
+              quoted(entry["mfg_part_number"]),
+              quoted(entry["vendor"]),
+              quoted(entry["vendor_part_number"]),
+              entry["quantity"],
+              dim(refdes) * units);
+       item++;
 }
 
 void process_digikey(string[string] entry)
 {
+       if (entry["loadstatus"] == "noload")
+               return;
        printf("%s,%s,%s %s\n",
               entry["quantity"],
-              part_number(entry),
-              entry["device"],
-              entry["value"]);
+              quoted(part_number(entry)),
+              quoted(entry["device"]),
+              quoted(entry["value"]));
+}
+
+void process_mouser(string[string] entry)
+{
+       if (entry["loadstatus"] == "noload")
+               return;
+/*     printf("%s|%s\n", part_number(entry), entry["quantity"]); */
+
+       static bool start = true;
+
+       if (start) {
+               printf("Mouser Part Number,Manufacturer Part Number,Quantity\n");
+               start = false;
+       }
+
+       printf("%s,%s,%s\n",
+              quoted(entry["vendor_part_number"]),
+              quoted(entry["mfg_part_number"]),
+              entry["quantity"]);
 }
 
 void process_other(string[string] entry) {
+       if (entry["loadstatus"] == "noload")
+               return;
        printf("%s,%s,%s,%s %s\n",
               entry["vendor"],
               entry["quantity"],
-              part_number(entry),
-              entry["device"],
+              quoted(part_number(entry)),
+              quoted(entry["device"]),
               entry["value"]);
 }
 
@@ -137,12 +229,17 @@ void process_file(file f) {
                string vendor = entry["vendor"];
                if (!is_uninit(&vendors) && has_vendor(vendors, "seeed")) {
                        process_seeed(entry);
+               } else if (!is_uninit(&vendors) && has_vendor(vendors, "goldphoenix")) {
+                       process_goldphoenix(entry);
                } else if ((!is_uninit(&vendors) && has_vendor(vendors, vendor)) ||
                           (!is_uninit(&not_vendors) && !has_vendor(not_vendors, vendor))) {
                        switch (entry["vendor"]) {
                        case "digikey":
                                process_digikey(entry);
                                break;
+                       case "mouser":
+                               process_mouser(entry);
+                               break;
                        default:
                                process_other(entry);
                                break;