|
| 1 | +/* Copyright (C) 2025 Lars Brinkhoff <lars@nocrew.org> |
| 2 | +
|
| 3 | + This program is free software: you can redistribute it and/or modify |
| 4 | + it under the terms of the GNU General Public License as published by |
| 5 | + the Free Software Foundation, either version 2 of the License, or |
| 6 | + (at your option) any later version. |
| 7 | +
|
| 8 | + This program is distributed in the hope that it will be useful, |
| 9 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | + GNU General Public License for more details. |
| 12 | +
|
| 13 | + You should have received a copy of the GNU General Public License |
| 14 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 15 | + |
| 16 | +#include <stdio.h> |
| 17 | +//#include <unistd.h> |
| 18 | +#include "dis.h" |
| 19 | +#include "svg.h" |
| 20 | + |
| 21 | +static int x, y; |
| 22 | +static void (*plot)(FILE *f, int x, int y); |
| 23 | + |
| 24 | +static void fatal(const char *message) |
| 25 | +{ |
| 26 | + fputs(message, stderr); |
| 27 | + exit(1); |
| 28 | +} |
| 29 | + |
| 30 | +static void just_move(FILE *f, int x, int y) |
| 31 | +{ |
| 32 | + (void)f; |
| 33 | + (void)x; |
| 34 | + (void)y; |
| 35 | +} |
| 36 | + |
| 37 | +static void process(int data) |
| 38 | +{ |
| 39 | + if ((data & 060) == 060) |
| 40 | + fatal ("Pen both up and down."); |
| 41 | + if (data & 040) { |
| 42 | + if (plot != just_move) |
| 43 | + svg_polyline_end(stdout); |
| 44 | + plot = just_move; |
| 45 | + } |
| 46 | + if (data & 020) { |
| 47 | + if (plot == just_move) |
| 48 | + plot = svg_polyline_begin; |
| 49 | + } |
| 50 | + if (data & 010) |
| 51 | + y--; |
| 52 | + if (data & 004) |
| 53 | + y++; |
| 54 | + if (data & 002) |
| 55 | + x--; |
| 56 | + if (data & 001) |
| 57 | + x++; |
| 58 | + plot (stdout, x, y); |
| 59 | + if (plot == svg_polyline_begin) |
| 60 | + plot = svg_polyline_point; |
| 61 | +} |
| 62 | + |
| 63 | +static void calcomp(FILE *f) |
| 64 | +{ |
| 65 | + word_t data; |
| 66 | + int i; |
| 67 | + |
| 68 | + for (;;) { |
| 69 | + data = get_word(f); |
| 70 | + if (data == -1) |
| 71 | + return; |
| 72 | + for (i = 0; i < 6; i++, data <<= 6) |
| 73 | + process((data >> 30) & 077); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +int main(void) |
| 78 | +{ |
| 79 | + input_word_format = &aa_word_format; |
| 80 | + x = y = 0; |
| 81 | + plot = just_move; |
| 82 | + svg_file_begin(stdout); |
| 83 | + calcomp(stdin); |
| 84 | + svg_file_end(stdout); |
| 85 | + return 0; |
| 86 | +} |
0 commit comments