summaryrefslogtreecommitdiffstats
path: root/code/hpgl.c
diff options
context:
space:
mode:
Diffstat (limited to 'code/hpgl.c')
-rw-r--r--code/hpgl.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/code/hpgl.c b/code/hpgl.c
new file mode 100644
index 0000000..f9436b4
--- /dev/null
+++ b/code/hpgl.c
@@ -0,0 +1,129 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+
+void
+pos (int x, int y, int b)
+{
+ int16_t lr[2];
+ int i;
+
+
+ lr[0] = 3 * y + 10000;
+ lr[1] = 15000 - x * 3;
+
+ lr[0] &= ~1;
+ lr[1] &= ~1;
+
+ if (!b)
+ lr[1] |= 1;
+
+
+ fprintf (stderr, "%6d %6d %d\n", x, y, b);
+
+ for (i = 0; i < 15; ++i)
+ {
+ fwrite (lr, sizeof (lr), 1, stdout);
+ }
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ char c;
+ char buf[1024];
+ int ic, len;
+ int commas;
+ int beam = 0, oldbeam = 0;
+ int x, y;
+
+ buf[0] = 0;
+ len = 0;
+ commas = 0;
+
+ while ((ic = getchar ()) != EOF)
+ {
+ c = ic;
+ if ((c == ' ') || (c == '\t'))
+ continue;
+
+ buf[len++] = c;
+ buf[len] = 0;
+
+// fprintf(stderr,"A>%s<A\n",buf);
+
+ if (!strcmp (buf, "PA"))
+ {
+ len = 0;
+ commas = 0;
+ continue;
+ }
+
+ if (!strcmp (buf, "PU"))
+ {
+ len = 0;
+ commas = 0;
+ beam = 0;
+ continue;
+ }
+
+ if (!strcmp (buf, "PD"))
+ {
+ len = 0;
+ commas = 0;
+ beam = 1;
+ continue;
+ }
+
+ if (!strncmp (buf, "SP", 2))
+ {
+ commas = 0;
+ if (c == ';')
+ len = 0;
+ continue;
+ }
+
+ if (c == ',')
+ commas++;
+
+
+ if (((commas) && ((c == ';') || (c == '\n'))) || (commas == 2))
+ {
+
+
+ if (sscanf (buf, "%d,%d", &x, &y) == 2)
+ {
+ if (beam)
+ {
+ if (!oldbeam)
+ {
+
+ pos (x, y, 0);
+
+ }
+ pos (x, y, beam);
+
+
+ }
+ oldbeam = beam;
+ }
+
+
+ len = 0;
+ commas = 0;
+
+ }
+
+
+ if ((c == ';') || (c == '\n'))
+ {
+ commas = 0;
+ len = 0;
+ }
+
+ }
+
+ return 0;
+}