File huc.dif of Package huc

--- src/huc/const.c
+++ src/huc/const.c	2007/09/05 15:50:13
@@ -71,7 +71,7 @@
 		if (stor != CONST)
 			error ("can't initialize non-const arrays");
 		if(!match ("{")) {
-			error ("syntax error");
+			error ("syntax error: expected { (array initializer)");
 			return (-1);
 		}
 		if(!match ("}")) {
@@ -93,7 +93,7 @@
 				if (const_val_idx < MAX_CONST_VALUE)
 					const_val[const_val_idx++] = i;
 				if ((ch() != ',') && (ch() != '}')) {
-					error("syntax error");
+					error("syntax error: expected , or } (end of array initializer)");
 					return (-1);
 				}
 				if (match ("}"))
@@ -191,7 +191,7 @@
 		/* end */
 		else if ((c == 0) || (c == '}')) {
 			if (level)
-				error("syntax error");
+				error("syntax error: expected (, ), or ,");
 			break;
 		}
 
--- src/huc/data.c
+++ src/huc/data.c	2007/09/05 15:33:18
@@ -55,6 +55,7 @@
 	lastst,
 	overlayflag,
 	optimize,
+	kandr,
 	globals_h_in_process;
 
 FILE	*input, *input2, *output;
--- src/huc/data.h
+++ src/huc/data.h	2007/09/05 15:32:53
@@ -52,6 +52,7 @@
 		lastst,
     overlayflag,
     optimize,
+    kandr,
 		globals_h_in_process;
 
 extern	FILE	*input, *input2, *output;
--- src/huc/defs.h
+++ src/huc/defs.h	2007/09/05 15:50:35
@@ -180,6 +180,7 @@
 
 #define	CCHAR	1
 #define	CINT	2
+#define	CVOID	3
 
 /* possible entries for storage */
 
--- src/huc/function.c
+++ src/huc/function.c	2007/09/06 11:37:13
@@ -46,18 +46,15 @@
  *	modified version.  p.l. woods
  *
  */
-void newfunc (void)
+void newfunc (char* n)
 {
-	char n[NAMESIZE], *ptr;
+	char *ptr;
 	int  nbarg;
-
+	int save_lptr;
+	long save_input;
+	char save_line[LINESIZE];
 	fexitlab = getlabel();
 
-	if (!symname (n) ) {
-		error ("illegal function or declaration");
-		kill ();
-		return;
-	}
 	if ( (ptr = findglb (n)) ) {
 		if (ptr[IDENT] != FUNCTION)
 			multidef (n);
@@ -77,7 +74,25 @@
 	locptr = STARTLOC;
 	argstk = 0;
 	nbarg = 0;
+
+	if(!kandr) {
+		/* save position */
+		save_lptr = lptr;
+		save_input = ftell(input);
+		strcpy(save_line, line);
+	}
+
+	/* count arguments, add symbols */
 	while (!match (")")) {
+		if(!kandr) {
+			amatch("register",8);
+			amatch("int",3);
+			amatch("char",4);
+			if(amatch("void",4)) {
+				if(!match("*"))	error("illegal argument type void");
+			}
+			else match("*");
+		}
 		if (symname (n)) {
 			if (findloc (n))
 				multidef (n);
@@ -93,13 +108,22 @@
 		blanks ();
 		if (!streq (line + lptr, ")")) {
 			if (!match (","))
-				error ("expected comma");
+				error ("expected , or ) after argument");
 		}
 		if (endst ())
 			break;
 	}
 	stkp = 0;
 	argtop = argstk;
+
+	if(!kandr) {
+		/* restore position */
+		lptr = save_lptr;
+		strcpy(line, save_line);
+		fseek(input, save_input, SEEK_SET);
+	}
+
+	/* argument types and relocs */
 	while (argstk) {
 		if (amatch ("register", 8)) {
 			if (amatch("char", 4)) 
@@ -108,18 +132,16 @@
 				getarg(CINT);
 			else
 				getarg(CINT);
-			ns();
 		} else if (amatch ("char", 4)) {
 			getarg (CCHAR);
-			ns ();
 		} else if (amatch ("int", 3)) {
 			getarg (CINT);
-			ns ();
 		} else {
 			error ("wrong number args");
 			break;
 		}
 	}
+	if(!kandr) match(")");	/* remove closing bracket if there are no arguments */
 	if (nbarg)      /* David, arg optimization */
 		gpusharg (0);
 	statement(YES);
@@ -175,10 +197,16 @@
 				error ("expecting argument name");
 		}
 		argstk = argstk - INTSIZE;
-		if (endst ())
-			return;
+		if(kandr) {
+			if(endst()) {
+				ns();
+				return;
+			}
+		} else if(match(")")) return;
+		
 		if (!match (","))
-			error ("expected comma");
+			error ("expecting ) or , after function argument");
+		if(!kandr) return;
 	}
 }
 
--- src/huc/function.h
+++ src/huc/function.h	2007/09/05 12:13:02
@@ -6,7 +6,7 @@
 #ifndef _FUNCTION_H
 #define _FUNCTION_H
 
-void newfunc (void);
+void newfunc (char* n);
 void getarg (int t);
 void callfunction (char *ptr);
 void arg_stack(int arg);
--- src/huc/main.c
+++ src/huc/main.c	2007/09/06 11:39:56
@@ -1,7 +1,10 @@
 /*	File main.c: 2.7 (84/11/28,10:14:56)
  *
  * PC Engine C Compiler
- * Made by <unknown guy>, hacked to work on Pc Engine by David Michel
+ * written by Ron Cain
+ * additional code by James E. Hendrix, Chris Lewis, Ken Yap, and probably
+ * others
+ * hacked to work on PC Engine by David Michel
  * resumed work by Zeograd
  *
  * 00/02/22 : added oldargv variable to show real exe name in usage function
@@ -44,6 +47,7 @@
 	verboseflag = 0;
 	startup_incl = 0;
 	optimize = 2;	/* -O2 by default */
+	kandr = 1;
 	overlayflag = 0;
 	asmdefs[0] = '\0';
 
@@ -118,12 +122,16 @@
 					}
 				case 'O':
 					/* David, made -O equal to -O2
-					 * I'm too lazy to tape -O2 each time :)
+					 * I'm too lazy to type -O2 each time :)
 					 */
 					if (!p[1]) optimize = 2;
 					else       optimize = atoi(++p);
 					break;
-
+				
+				case 'C':
+					kandr = 0;
+					break;
+					
 				default:
 					usage(oldargv[0]);
 			}
@@ -244,6 +252,7 @@
 	fprintf(stderr,"-t/-T       : include text of 'C' in asm output/listings\n");
 	fprintf(stderr,"-Dsym[=val] : define symbol 'sym' when compiling\n");
 	fprintf(stderr,"-O[val]     : invoke optimization (level <value>)\n");
+	fprintf(stderr,"-C          : expect C89-style function declarations\n");
 	fprintf(stderr,"-cd/-scd    : create CDROM output\n");
 	fprintf(stderr,"-over(lay)  : create CDROM overlay section\n\n");
 	fprintf(stderr,"Options to assembler step:\n");
@@ -261,6 +270,7 @@
  */
 void parse (void )
 {
+	char n[NAMESIZE];
 	while (!feof (input)) {
 
 // Note:
@@ -306,7 +316,7 @@
 				dodcls(CONST);
 			}
 		}
-		else if (dodcls(PUBLIC)) ;
+		else if (dodcls(PUBLIC)) ;	/* globals and function declarations with return type */
 		else if (match ("#asmdef"))
 			doasmdef ();
 		else if (match ("#asm"))
@@ -355,14 +365,15 @@
 				dopsddef();
 			}
 		}
-		else
+		else	/* function declaration without type */
 		{
 			if (!startup_incl) {
 				inc_startup();
 				unget_line();
 				incl_globals();
 			} else {
-				newfunc ();
+				if(!symname(n)) illname();
+				newfunc (n);
 			}
 		}
 		blanks ();
@@ -377,17 +388,38 @@
 
 int dodcls(int stclass)
 {
-	int err;
-
+	int err = 0;
+	char sname[NAMESIZE];
+	
 	blanks();
-	if (amatch("char", 4))
-		err = declglb(CCHAR, stclass);
-	else if (amatch("int", 3))
-		err = declglb(CINT, stclass);
-	else if (stclass == PUBLIC)
-		return(0);
-	else
-		err = declglb(CINT, stclass);
+	int matched = -1;
+	if(amatch("char", 4))
+		matched = CCHAR;
+	else if(amatch("int", 3))
+		matched = CINT;
+	else if(amatch("void", 4))
+		matched = CVOID;
+	else if(stclass == PUBLIC)
+		return 0;
+	else matched = CINT;
+	
+	if(!symname(sname)) illname();
+	blanks();
+	if(ch() == '(') {	/* function declaration */
+		if (!startup_incl) {
+			inc_startup();
+			unget_line();
+			incl_globals();
+			return(1);
+		}
+		else {
+			newfunc(sname);
+			return 1;
+		}
+	}
+	if(matched == -1) error("internal error");
+	err = declglb(matched, stclass, sname);
+	
 	if (err)
 		kill ();
 	else
@@ -578,6 +610,10 @@
 #if defined(WIN32)
 	return (execvp(exe, (const char* const*)opts));
 #else
-	return(execvp(exe, (char* const*)opts));
+	if(execvp(exe, (char* const*)opts) == -1) {
+		perror("unable to invoke assembler");
+		return -1;
+	}
+	return 0;
 #endif
 }
--- src/huc/preproc.c
+++ src/huc/preproc.c	2007/09/06 09:44:17
@@ -383,6 +383,9 @@
 				}
 			inchar ();
 			inchar ();
+		} else if ((ch() == '/') && (nch() == '/')) {
+			while(ch() != 0) inchar();
+			if(feof(input)) break;
 		} else if (an (ch ())) {
 			k = 0;
 			while (an (ch ())) {
--- src/huc/stmt.c
+++ src/huc/stmt.c	2007/09/05 13:32:59
@@ -73,6 +73,8 @@
 		declloc(CCHAR, stclass);
 	else if (amatch("int", 3))
 		declloc(CINT, stclass);
+	else if (amatch("void", 4))
+		declloc(CVOID, stclass);
 	else if (stclass == LSTATIC || stclass == DEFAUTO)
 		declloc(CINT, stclass);
 	else
--- src/huc/sym.c
+++ src/huc/sym.c	2007/09/05 16:34:22
@@ -15,6 +15,7 @@
 #include "primary.h"
 #include "pragma.h"
 #include "sym.h"
+#include <string.h>
 
 
 /*
@@ -24,20 +25,29 @@
  *
  */
 int
-declglb (int typ, int stor)
+declglb (int typ, int stor, char* snam)
 {
 	int	 k, id;
+	int firstsym = 1;
 	char sname[NAMESIZE];
+	strcpy(sname, snam);
 
 	for (;;) {
 		for (;;) {
 			k = 1;
-			if (match ("*"))
+			if (match ("*")) {
+				if(typ == CVOID) typ = CCHAR;
 				id = POINTER;
-			else
+			}
+			else {
+				if(typ == CVOID) error("illegal global variable type void");
 				id = VARIABLE;
-			if(!symname (sname))
-				illname ();
+			}
+			if(!firstsym) {
+				if(!symname(sname)) illname();
+			}
+			else firstsym = 0;
+			
 			if (findglb (sname))
 				multidef (sname);
 			if (match ("[")) {
@@ -77,7 +87,7 @@
 		if (endst ())
 			return (0);
 		if (!match (",")) {
-			error ("syntax error");
+			error ("syntax error: expected ,");
 			return (1);
 		}
 	}
@@ -105,10 +115,14 @@
 				stkp = modstk (stkp - totalk);
 				return;
 			}
-			if (match ("*"))
+			if (match ("*")) {
+				if(typ == CVOID) typ = CCHAR;
 				j = POINTER;
-			else
+			}
+			else {
+				if(typ == CVOID) error("illegal local variable type void");
 				j = VARIABLE;
+			}
 			if (!symname (sname))
 				illname ();
 			if (findloc (sname))
--- src/huc/sym.h
+++ src/huc/sym.h	2007/09/05 12:09:33
@@ -1,7 +1,7 @@
 #ifndef _SYM_H
 #define _SYM_H
 
-int declglb (int typ, int stor);
+int declglb (int typ, int stor, char* sname);
 void declloc (int typ, int stclass);
 int needsub (void);
 char* findglb (char *sname);
--- src/mkit/as/command.c
+++ src/mkit/as/command.c	2007/09/05 11:03:55
@@ -1024,7 +1024,7 @@
 {
 	unsigned char buffer[32];
 	unsigned int i, j;
-	unsigned int x, y, w, h;
+	int x, y, w, h;
 	unsigned int tx, ty;
 	int total = 0;
 	int size;
--- src/mkit/as/expr.h
+++ src/mkit/as/expr.h	2007/09/05 11:02:37
@@ -53,8 +53,8 @@
 unsigned int val_stack[64];	/* value stack */
 int op_idx, val_idx;	/* index in the operator and value stacks */
 int need_operator;		/* when set await an operator, else await a value */
-unsigned char *expr;	/* pointer to the expression string */
-unsigned char *expr_stack[16];	/* expression stack */
+char *expr;	/* pointer to the expression string */
+char *expr_stack[16];	/* expression stack */
 struct t_symbol *expr_lablptr;	/* pointer to the lastest label */
 int expr_lablcnt;		/* number of label seen in an expression */
 char *keyword[8] = {	/* predefined functions */
--- src/mkit/as/externs.h
+++ src/mkit/as/externs.h	2007/09/05 11:03:09
@@ -29,7 +29,7 @@
 extern unsigned int   pcx_arg[8];	/* PCX args array */
 extern unsigned char *pcx_buf;	/* pointer to the PCX buffer */
 extern unsigned char  pcx_pal[256][3];	/* palette */
-extern unsigned char *expr;	/* expression string pointer */
+extern char *expr;	/* expression string pointer */
 extern int  mopt;
 extern int  in_macro;
 extern int  expand_macro;
--- src/mkit/as/map.c
+++ src/mkit/as/map.c	2007/09/05 11:05:37
@@ -18,7 +18,7 @@
 pce_load_map(char *fname, int mode)
 {
 	FILE *fp;
-	unsigned char header[16];
+	char header[16];
 	int fsize;
 	int size;
 	int nb;
--- src/mkit/as/pce.c
+++ src/mkit/as/pce.c	2007/09/05 11:05:19
@@ -529,7 +529,8 @@
 pce_incbat(int *ip)
 {
 	unsigned char *ptr, ref;
-	unsigned int i, j, k, l, x, y, w, h;
+	unsigned int i, j, k, l;
+	int x, y, w, h;
 	unsigned int base, index, flag;
 	unsigned int temp;
 
@@ -662,7 +663,7 @@
 pce_incspr(int *ip)
 {
 	unsigned int i, j;
-	unsigned int x, y, w, h;
+	int x, y, w, h;
 	unsigned int sx, sy;
 	unsigned int size;
 
@@ -710,7 +711,7 @@
 pce_inctile(int *ip)
 {
 	unsigned int i, j;
-	unsigned int x, y, w, h;
+	int x, y, w, h;
 	unsigned int tx, ty;
 	int nb_tile = 0;
 	int size = 0;
@@ -769,7 +770,7 @@
 pce_incmap(int *ip)
 {
 	unsigned int i, j;
-	unsigned int x, y, w, h;
+	int x, y, w, h;
 	unsigned int tx, ty;
 	int tile, size;
 	int err = 0;
openSUSE Build Service is sponsored by