1. Cat's Eye Technologies
  2. Kangaroo Iceberg

Commits

Cat's Eye Technologies  committed ec571e6

Import version 0.5 revision 2011.0509.

  • Participants
  • Parent commits 1cd993d
  • Branches default
  • Tags rel_0_5_2011_0509

Comments (0)

Files changed (5)

File src/Makefile

View file
-# BSD Makefile for kiceberg.
+# Makefile for kiceberg.
 # $Id$
 
-CC=	gcc
-CFLAGS=	-Wall -ansi -pedantic
-LIBS=	
+CC?=gcc
+LIBS?=
 
-CFLAGS+= ${EXTRA_CFLAGS}
+WARNS=	-Werror -W -Wall -Wstrict-prototypes -Wmissing-prototypes \
+	-Wpointer-arith	-Wno-uninitialized -Wreturn-type -Wcast-qual \
+	-Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wchar-subscripts \
+	-Winline -Wnested-externs -Wredundant-decls
+
+# Won't compile under ANSI, but for consistency with other Makefiles:
+ifdef ANSI
+  CFLAGS+= -ansi -pedantic
+else
+  CFLAGS+= -std=c99 -D_POSIX_C_SOURCE=200112L
+endif
+
+CFLAGS+= ${WARNS} ${EXTRA_CFLAGS}
 
 OBJS=	graph.o rule.o \
 	symbol.o \

File src/main.c

View file
 
 struct symbol_table	*gstab;	/* general symbol table */
 struct legislature	*glaw;	/* all rules */
-	
+
 /* PROTOTYPES */
 
 void			 usage(void);
 main(int argc, char **argv)
 {
 	struct scan_st *sc;
-	int ch;
 	int do_dump = 0;
 	struct node *global;
+	int argn;
+	char *global_ident;
 
 	/* Initialize / allocate globals. */
-	
+
 	gstab = symbol_table_new();
-	global = node_new(symbol_define(gstab, "__GLOBAL__", SYM_TYPE_NODE));
+	global_ident = malloc(20 * sizeof(char));
+	strcpy(global_ident, "__GLOBAL__");
+	global = node_new(symbol_define(gstab, global_ident, SYM_TYPE_NODE));
 	glaw = legislature_new();
 
 	/* Parse arguments. */
 
-	while ((ch = getopt(argc, argv, "d")) != -1) {
-		switch(ch) {
-		case 'd':
-			do_dump = 1;
+	for (argn = 1; argn < argc; argn++) {
+		if (argv[argn][0] == '-') {
+			switch(argv[argn][1]) {
+			case 'd':
+				do_dump = 1;
+				break;
+			default:
+				usage();
+			}
+		} else {
 			break;
-		case '?':
-		default:
-			usage();
 		}
 	}
-	argc -= optind;
-	argv += optind;
 	
 	/* Parse the input file. */
 
-	while (argc > 0) {
+	while (argn < argc) {
 		sc = scan_open(argv[0]);
 		kangaroo_iceberg(sc, global);
 		scan_close(sc);
-		argc--;
-		argv++;
+		argn++;
 	}
 
 	if (do_dump) {

File src/scan.c

View file
 }
 
 void
-scan_error(struct scan_st *sc, char *fmt, ...)
+scan_error(struct scan_st *sc, const char *fmt, ...)
 {
 	va_list args;
-	char err[256];
+	char error[256];
 
 	va_start(args, fmt);
-	vsnprintf(err, 255, fmt, args);
+	vsnprintf(error, 255, fmt, args);
 
 	fprintf(stderr, "Error (line %d, column %d, token '%s'): %s.\n",
-	    sc->lino, sc->columno, sc->token, err);
+	    sc->lino, sc->columno, sc->token, error);
 }
 
-int
+static int
 scan_char(struct scan_st *sc, char *x)
 {	
 	*x = (char)getc(sc->in); sc->columno++;
 }
 
 void
-scan_expect(struct scan_st *sc, char *x)
+scan_expect(struct scan_st *sc, const char *x)
 {
 	if (!strcmp(sc->token, x)) {
 		scan(sc);

File src/scan.h

View file
 
 extern struct scan_st *scan_open(char *);
 extern void scan_close(struct scan_st *);
-extern void scan_error(struct scan_st *, char *, ...);
+extern void scan_error(struct scan_st *, const char *, ...);
 extern void scan(struct scan_st *);
-extern void scan_expect(struct scan_st *, char *);
+extern void scan_expect(struct scan_st *, const char *);
 
 #endif /* !__SCAN_H */

File src/symbol.c

View file
 	struct symbol *new_sym;
 
 	MALLOC(new_sym, symbol, "symbol");
-	if ((new_sym->token = strdup(token)) == NULL)
+	if ((new_sym->token = malloc(strlen(token)+1)) == NULL)
 		perror("Could not allocate symbol lexeme");
+        strcpy(new_sym->token, token);
 	new_sym->type = type;
 	new_sym->dest = NULL;
 	new_sym->next = stab->head;
 void
 symbol_dump(int indent, struct symbol *sym)
 {
-	char *ty;
+	const char *ty;
 	int i;
 
 	for (i = 0; i < indent; i++)