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
|
#include "cccl.h"
#include <assert.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int verbose = 0;
int interactive = 0;
int dump = 0;
int main(int argc, char **argv)
{
const char *name = *argv;
int ch;
while ((ch = getopt(argc, argv, "vid")) >= 0)
{
switch (ch)
{
case 'v':
{
verbose = 1;
} break;
case 'i':
{
interactive = 1;
} break;
case 'd':
{
dump = 1;
} break;
default:
{
fprintf(stderr, "usage: %s [-vid] file\n", name);
exit(1);
} break;
}
}
argc -= optind;
argv += optind;
if (!*argv)
{
fprintf(stderr, "usage: %s [-vid] file\n", name);
exit(1);
}
struct cccl_File file;
int error = cccl_allocfile(*argv, &file);
if (error)
err(1, "cccl_readfile()");
FILE *f = fopen(*argv, "r");
if (!f)
err(1, "fopen()");
int bytes_read = fread(file.buffer, 1, file.size, f);
if (ferror(f) || bytes_read != file.size)
errx(1, "couldn't read %s", *argv);
fclose(f);
cccl(file);
}
|