Browse Source

use stdarg when compiling with ANSI C compiler, and some other minor changes

ceriel 29 years ago
parent
commit
acdb874527
3 changed files with 59 additions and 1 deletions
  1. 57 0
      util/cpp/error.c
  2. 1 0
      util/cpp/input.c
  3. 1 1
      util/cpp/main.c

+ 57 - 0
util/cpp/error.c

@@ -6,7 +6,11 @@
 /*	E R R O R   A N D  D I A G N O S T I C   R O U T I N E S	*/
 
 #include	<system.h>
+#if __STDC__
+#include	<stdarg.h>
+#else
 #include	<varargs.h>
+#endif
 
 #include	"errout.h"
 #include	"LLlex.h"
@@ -27,6 +31,58 @@ err_hdr(s)
 	else	fprint(ERROUT, s);
 }
 
+#if __STDC__
+/*VARARGS1*/
+error(char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	err_hdr("");
+	err_occurred = 1;
+	doprnt(ERROUT, fmt, ap);
+	fprint(ERROUT, "\n");
+	va_end(ap);
+}
+
+/*VARARGS1*/
+warning(char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	err_hdr("(warning) ");
+	doprnt(ERROUT, fmt, ap);
+	fprint(ERROUT, "\n");
+	va_end(ap);
+}
+
+/*VARARGS1*/
+crash(char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	err_hdr("CRASH\007 ");
+	doprnt(ERROUT, fmt, ap);
+	fprint(ERROUT, "\n");
+	va_end(ap);
+	sys_stop(S_ABORT);
+}
+
+/*VARARGS1*/
+fatal(char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	err_hdr("fatal error -- ");
+	doprnt(ERROUT, fmt, ap);
+	fprint(ERROUT, "\n");
+	va_end(ap);
+	sys_stop(S_EXIT);
+}
+#else /* __STDC__ */
 /*VARARGS1*/
 error(va_alist)
 	va_dcl
@@ -89,3 +145,4 @@ fatal(va_alist)
 	va_end(ap);
 	sys_stop(S_EXIT);
 }
+#endif

+ 1 - 0
util/cpp/input.c

@@ -9,6 +9,7 @@
 #define INP_VAR		finfo
 struct file_info	finfo;
 #include <inp_pkg.body>
+#include <alloc.h>
 
 char *
 getwdir(fn)

+ 1 - 1
util/cpp/main.c

@@ -84,7 +84,7 @@ compile(argc, argv)
 	}
 
 	if (!InsertFile(source, (char **) 0, &dummy)) /* read the source file	*/
-		fatal("%s: no source file %s\n", prog_name, 
+		fatal("%s: no source file %s", prog_name, 
 			source ? source : "stdin");
 	if (source) WorkingDir = getwdir(dummy);
 	preprocess(source);