summaryrefslogtreecommitdiff
path: root/src/util/ao-make-product.5c
diff options
context:
space:
mode:
authorBdale Garbee <bdale@gag.com>2012-09-12 20:01:22 -0600
committerBdale Garbee <bdale@gag.com>2012-09-12 20:01:22 -0600
commit3b612efcd1dddc6a3d59012f7ed57754b1f798c2 (patch)
tree18d50713491ef96c5c127a309f870efb6c33f98d /src/util/ao-make-product.5c
parente076773c1693e2a62bb828dee71c04c20dbab0a5 (diff)
parent01eb36408d7e0e826b431fcc1d3b2deb23607e0b (diff)
Merge branch 'new-debian' into debian
Conflicts: ChangeLog debian/altos.install debian/changelog debian/control debian/copyright debian/dirs debian/docs debian/menu debian/rules src/Makefile
Diffstat (limited to 'src/util/ao-make-product.5c')
-rw-r--r--src/util/ao-make-product.5c103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/util/ao-make-product.5c b/src/util/ao-make-product.5c
new file mode 100644
index 00000000..5f2eb8e8
--- /dev/null
+++ b/src/util/ao-make-product.5c
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+autoimport ParseArgs;
+
+void
+write_ucs2(string a, string description)
+{
+ int len = String::length(a);
+
+ printf("/* %s */\n", description);
+ printf("#define AO_%s_LEN 0x%02x\n", description, len * 2 + 2);
+ printf("#define AO_%s_STRING \"%s\"\n", description, a);
+ printf("#define AO_%s_UCS2", description);
+ for (int i = 0; i < len; i++) {
+ int c = a[i];
+ if (i > 0)
+ printf(",");
+ if (0x20 <= c && c < 128)
+ printf(" '%c', 0", c);
+ else
+ printf(" LE_WORD(0x%04x),", c);
+ }
+ printf("\n\n");
+}
+
+void
+write_string(string a, string description)
+{
+ printf ("/* %s */\n", description);
+ printf ("#define AO_%s_STRING \"%s\"\n", description, a);
+}
+
+void
+write_int(int a, string description)
+{
+ printf ("/* %s */\n", description);
+ printf ("#define AO_%s_NUMBER %d\n\n", description, a);
+}
+
+void
+write_hex(int a, string description)
+{
+ printf ("/* %s */\n", description);
+ printf ("#define AO_%s_NUMBER 0x%04x\n\n", description, a);
+}
+
+string manufacturer = "altusmetrum.org";
+string product = "TeleMetrum";
+string version = "0.0";
+int serial = 1;
+int user_argind = 0;
+int id_product = 0x000a;
+
+argdesc argd = {
+ .args = {
+ {
+ .var = { .arg_string = &manufacturer },
+ .abbr = 'm',
+ .name = "manufacturer",
+ .expr_name = "manf",
+ .desc = "Manufacturer name." },
+ {
+ .var = { .arg_string = &product },
+ .abbr = 'p',
+ .name = "product",
+ .expr_name = "prod",
+ .desc = "Product name." },
+ {
+ .var = { .arg_int = &id_product },
+ .abbr = 'i',
+ .name = "id_product",
+ .expr_name = "id_p",
+ .desc = "Product ID." },
+ {
+ .var = { .arg_int = &serial },
+ .abbr = 's',
+ .name = "serial",
+ .expr_name = "number",
+ .desc = "Serial number." },
+ {
+ .var = { .arg_string = &version },
+ .abbr = 'v',
+ .name = "version",
+ .expr_name = "string",
+ .desc = "Program version." },
+ },
+ .prog_name = "usb descriptors",
+};
+
+void
+main()
+{
+ string[dim(argv)-1] nargv = {[n] = argv[n+1]};
+ parseargs(&argd, &nargv);
+ write_ucs2(manufacturer, "iManufacturer");
+ write_ucs2(product, "iProduct");
+ write_ucs2(sprintf("%06d", serial), "iSerial");
+ write_int(serial, "iSerial");
+ write_hex(id_product, "idProduct");
+ write_string(version, "iVersion");
+}
+
+main();