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