diff options
| author | 2026-11-11 22:28:13 +0000 | |
|---|---|---|
| committer | 2026-11-11 22:47:34 +0000 | |
| commit | cb070b2d3f2b6e241e3be1b7e0eeb90fc755255f (patch) | |
| tree | c7d90c0abe9533c87d51b5196871846855efa1ba /src/skywrite.c | |
| download | thesis-cb070b2d3f2b6e241e3be1b7e0eeb90fc755255f.tar.gz | |
Diffstat (limited to 'src/skywrite.c')
| -rw-r--r-- | src/skywrite.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/skywrite.c b/src/skywrite.c new file mode 100644 index 0000000..196ac78 --- /dev/null +++ b/src/skywrite.c | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | /// src/skywrite.h | ||
| 2 | // | ||
| 3 | // Copyright (C) 2026 by Martin Michalec <martin@michalec.dev> | ||
| 4 | // | ||
| 5 | // SPDX-License-Identifier: MIT | ||
| 6 | // | ||
| 7 | /// Commentary: | ||
| 8 | // | ||
| 9 | /// Code: | ||
| 10 | |||
| 11 | #include <stdlib.h> | ||
| 12 | #include <stdio.h> | ||
| 13 | #include <fcntl.h> | ||
| 14 | #include <unistd.h> | ||
| 15 | |||
| 16 | #include "utils.h" | ||
| 17 | #include "da.h" | ||
| 18 | #include "rs274ngc_lexer.h" | ||
| 19 | #include "rs274ngc_cst.h" | ||
| 20 | #include "path.h" | ||
| 21 | #include "critical_points.h" | ||
| 22 | #include "compensations.h" | ||
| 23 | #include "generator.h" | ||
| 24 | |||
| 25 | void | ||
| 26 | print_arena (const struct arena *a) | ||
| 27 | { | ||
| 28 | for (struct arena_chunk *ch = a->head; ch; ch = ch->next) | ||
| 29 | printf ("%p %lu\n", ch, (void *) ch - ch->begin); | ||
| 30 | } | ||
| 31 | |||
| 32 | void | ||
| 33 | print_path (struct path path) | ||
| 34 | { | ||
| 35 | DA_FOR_EACH (pe, path) { | ||
| 36 | printf ("%04b | %10.4lf | %10.4lf | %10.4lf | %10.4lf | %10.4lf | %.*s\n", | ||
| 37 | pe->flags, pe->x, pe->y, pe->f, pe->i, pe->j, SV_FMTA (pe->line)); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | int | ||
| 42 | main (int argc, char *argv[]) | ||
| 43 | { | ||
| 44 | progname = argv[0]; | ||
| 45 | |||
| 46 | const char *filename; | ||
| 47 | int fd = 0; | ||
| 48 | if (argc == 1) { | ||
| 49 | filename = "-"; | ||
| 50 | } else if (argc == 2) { | ||
| 51 | filename = argv[1]; | ||
| 52 | fd = open (filename, O_RDONLY); | ||
| 53 | } else { | ||
| 54 | DIE ("too many arguments provided"); | ||
| 55 | } | ||
| 56 | |||
| 57 | struct arena a = {0}; | ||
| 58 | struct arena t = {0}; | ||
| 59 | |||
| 60 | struct sv rs274ngc = read_until_eof (&a, fd); | ||
| 61 | if (fd) close (fd); | ||
| 62 | |||
| 63 | rs274ngc_lexer_compile_regexes (); | ||
| 64 | struct rs274ngc_lexer lexer = rs274ngc_lexer_from_sv (rs274ngc, filename); | ||
| 65 | |||
| 66 | struct rs274ngc_cst_parser parser = { | ||
| 67 | .lexer = &lexer, | ||
| 68 | .output = &a, | ||
| 69 | .temporary = &t, | ||
| 70 | }; | ||
| 71 | |||
| 72 | struct path path = build_path (parser); | ||
| 73 | struct critical_points cps = find_critical_points (&path); | ||
| 74 | struct compensations comps = synthesize_compensations (&cps); | ||
| 75 | struct replacements reps = generate_replacements (&a, &comps); | ||
| 76 | write_code_with_replacements (0, rs274ngc, &reps); | ||
| 77 | |||
| 78 | return EXIT_SUCCESS; | ||
| 79 | } | ||
| 80 | |||
| 81 | /// src/skywrite.h ends here | ||
