-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmc.c
More file actions
57 lines (44 loc) · 853 Bytes
/
tmc.c
File metadata and controls
57 lines (44 loc) · 853 Bytes
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
#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
#include <turing.h>
#include <tmc-parse.h>
static int run(char **argv);
int
run(char **argv)
{
struct parse ir[1]={0};
char *fn = *argv;
uint8_t *map;
off_t len;
int fd;
fd = open(fn, O_RDONLY);
if (fd == -1) perror("open failed"), exit(EX_NOINPUT);
len = lseek(fd, SEEK_END, 0);
if (fd == -1) perror("lseek failed"), exit(EX_OSERR);
map = mmap(0x0, len, PROT_READ, MAP_PRIVATE, fd, 0);
parse(ir, map, len);
if (ir->error) {
goto finally;
}
finally:
munmap(map, len);
close(fd);
return ir->error;
}
void
usage(void)
{
fprintf(stderr, "usage: tmc <file>\n");
}
int
main(int argc, char **argv)
{
if (argc < 2) usage(), exit(EX_USAGE);
return run(argv+1);
}