Import version 0.5 revision 2011.0509.
Cat's Eye Technologies
11 years ago
0 | |
# BSD Makefile for kiceberg.
|
|
0 |
# Makefile for kiceberg.
|
1 | 1 |
# $Id$
|
2 | 2 |
|
3 | |
CC= gcc
|
4 | |
CFLAGS= -Wall -ansi -pedantic
|
5 | |
LIBS=
|
|
3 |
CC?=gcc
|
|
4 |
LIBS?=
|
6 | 5 |
|
7 | |
CFLAGS+= ${EXTRA_CFLAGS}
|
|
6 |
WARNS= -Werror -W -Wall -Wstrict-prototypes -Wmissing-prototypes \
|
|
7 |
-Wpointer-arith -Wno-uninitialized -Wreturn-type -Wcast-qual \
|
|
8 |
-Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wchar-subscripts \
|
|
9 |
-Winline -Wnested-externs -Wredundant-decls
|
|
10 |
|
|
11 |
# Won't compile under ANSI, but for consistency with other Makefiles:
|
|
12 |
ifdef ANSI
|
|
13 |
CFLAGS+= -ansi -pedantic
|
|
14 |
else
|
|
15 |
CFLAGS+= -std=c99 -D_POSIX_C_SOURCE=200112L
|
|
16 |
endif
|
|
17 |
|
|
18 |
CFLAGS+= ${WARNS} ${EXTRA_CFLAGS}
|
8 | 19 |
|
9 | 20 |
OBJS= graph.o rule.o \
|
10 | 21 |
symbol.o \
|
52 | 52 |
|
53 | 53 |
struct symbol_table *gstab; /* general symbol table */
|
54 | 54 |
struct legislature *glaw; /* all rules */
|
55 | |
|
|
55 |
|
56 | 56 |
/* PROTOTYPES */
|
57 | 57 |
|
58 | 58 |
void usage(void);
|
|
63 | 63 |
main(int argc, char **argv)
|
64 | 64 |
{
|
65 | 65 |
struct scan_st *sc;
|
66 | |
int ch;
|
67 | 66 |
int do_dump = 0;
|
68 | 67 |
struct node *global;
|
|
68 |
int argn;
|
|
69 |
char *global_ident;
|
69 | 70 |
|
70 | 71 |
/* Initialize / allocate globals. */
|
71 | |
|
|
72 |
|
72 | 73 |
gstab = symbol_table_new();
|
73 | |
global = node_new(symbol_define(gstab, "__GLOBAL__", SYM_TYPE_NODE));
|
|
74 |
global_ident = malloc(20 * sizeof(char));
|
|
75 |
strcpy(global_ident, "__GLOBAL__");
|
|
76 |
global = node_new(symbol_define(gstab, global_ident, SYM_TYPE_NODE));
|
74 | 77 |
glaw = legislature_new();
|
75 | 78 |
|
76 | 79 |
/* Parse arguments. */
|
77 | 80 |
|
78 | |
while ((ch = getopt(argc, argv, "d")) != -1) {
|
79 | |
switch(ch) {
|
80 | |
case 'd':
|
81 | |
do_dump = 1;
|
|
81 |
for (argn = 1; argn < argc; argn++) {
|
|
82 |
if (argv[argn][0] == '-') {
|
|
83 |
switch(argv[argn][1]) {
|
|
84 |
case 'd':
|
|
85 |
do_dump = 1;
|
|
86 |
break;
|
|
87 |
default:
|
|
88 |
usage();
|
|
89 |
}
|
|
90 |
} else {
|
82 | 91 |
break;
|
83 | |
case '?':
|
84 | |
default:
|
85 | |
usage();
|
86 | 92 |
}
|
87 | 93 |
}
|
88 | |
argc -= optind;
|
89 | |
argv += optind;
|
90 | 94 |
|
91 | 95 |
/* Parse the input file. */
|
92 | 96 |
|
93 | |
while (argc > 0) {
|
|
97 |
while (argn < argc) {
|
94 | 98 |
sc = scan_open(argv[0]);
|
95 | 99 |
kangaroo_iceberg(sc, global);
|
96 | 100 |
scan_close(sc);
|
97 | |
argc--;
|
98 | |
argv++;
|
|
101 |
argn++;
|
99 | 102 |
}
|
100 | 103 |
|
101 | 104 |
if (do_dump) {
|
75 | 75 |
}
|
76 | 76 |
|
77 | 77 |
void
|
78 | |
scan_error(struct scan_st *sc, char *fmt, ...)
|
|
78 |
scan_error(struct scan_st *sc, const char *fmt, ...)
|
79 | 79 |
{
|
80 | 80 |
va_list args;
|
81 | |
char err[256];
|
|
81 |
char error[256];
|
82 | 82 |
|
83 | 83 |
va_start(args, fmt);
|
84 | |
vsnprintf(err, 255, fmt, args);
|
|
84 |
vsnprintf(error, 255, fmt, args);
|
85 | 85 |
|
86 | 86 |
fprintf(stderr, "Error (line %d, column %d, token '%s'): %s.\n",
|
87 | |
sc->lino, sc->columno, sc->token, err);
|
|
87 |
sc->lino, sc->columno, sc->token, error);
|
88 | 88 |
}
|
89 | 89 |
|
90 | |
int
|
|
90 |
static int
|
91 | 91 |
scan_char(struct scan_st *sc, char *x)
|
92 | 92 |
{
|
93 | 93 |
*x = (char)getc(sc->in); sc->columno++;
|
|
188 | 188 |
}
|
189 | 189 |
|
190 | 190 |
void
|
191 | |
scan_expect(struct scan_st *sc, char *x)
|
|
191 |
scan_expect(struct scan_st *sc, const char *x)
|
192 | 192 |
{
|
193 | 193 |
if (!strcmp(sc->token, x)) {
|
194 | 194 |
scan(sc);
|
30 | 30 |
|
31 | 31 |
extern struct scan_st *scan_open(char *);
|
32 | 32 |
extern void scan_close(struct scan_st *);
|
33 | |
extern void scan_error(struct scan_st *, char *, ...);
|
|
33 |
extern void scan_error(struct scan_st *, const char *, ...);
|
34 | 34 |
extern void scan(struct scan_st *);
|
35 | |
extern void scan_expect(struct scan_st *, char *);
|
|
35 |
extern void scan_expect(struct scan_st *, const char *);
|
36 | 36 |
|
37 | 37 |
#endif /* !__SCAN_H */
|
72 | 72 |
struct symbol *new_sym;
|
73 | 73 |
|
74 | 74 |
MALLOC(new_sym, symbol, "symbol");
|
75 | |
if ((new_sym->token = strdup(token)) == NULL)
|
|
75 |
if ((new_sym->token = malloc(strlen(token)+1)) == NULL)
|
76 | 76 |
perror("Could not allocate symbol lexeme");
|
|
77 |
strcpy(new_sym->token, token);
|
77 | 78 |
new_sym->type = type;
|
78 | 79 |
new_sym->dest = NULL;
|
79 | 80 |
new_sym->next = stab->head;
|
|
113 | 114 |
void
|
114 | 115 |
symbol_dump(int indent, struct symbol *sym)
|
115 | 116 |
{
|
116 | |
char *ty;
|
|
117 |
const char *ty;
|
117 | 118 |
int i;
|
118 | 119 |
|
119 | 120 |
for (i = 0; i < indent; i++)
|