shithub: scc

Download patch

ref: aaf5ff88b71d5e589da7245c942c4a7fa83ff983
parent: 9751bfd656a98f47f301db6265f28937d3857590
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Mar 14 07:28:22 EDT 2018

Add name of the tool in die() messages

--- a/as/parser.c
+++ b/as/parser.c
@@ -1,6 +1,7 @@
 static char sccsid[] = "@(#) ./as/parser.c";
 #include <assert.h>
 #include <ctype.h>
+#include <errno.h>
 #include <limits.h>
 #include <setjmp.h>
 #include <stdarg.h>
@@ -455,7 +456,7 @@
 	}
 	n = getline(ip->fp, buff);
 	if (++ip->lineno == 0)
-		die("as: file too long");
+		die("as: %s: file too long", infile);
 	if (n == 0)
 		goto repeat;
 	if (extract(buff, n, lp) == 0)
@@ -469,9 +470,9 @@
 	FILE *fp;
 
 	if (isp == &inputs[NR_INPUTS])
-		die("too many included files");
+		die("as: too many included files");
 	if ((fp = fopen(fname, "r")) == NULL)
-		die("error opening input file '%s'", fname);
+		die("as: %s: %s", fname, strerror(errno));
 	isp->fname = xstrdup(fname);
 	isp->fp = fp;
 	isp->lineno = 0;
@@ -485,7 +486,7 @@
 		return EOF;
 	--isp;
 	if (fclose(isp->fp) == EOF)
-		die("error closing file '%s'", isp->fname);
+		die("as: %s: %s", isp->fname, strerror(errno));
 	free(isp->fname);
 	return 0;
 }
--- a/as/symbol.c
+++ b/as/symbol.c
@@ -147,7 +147,7 @@
 	    curpc > cursec->curpc ||
 	    cursec->curpc > maxaddr ||
 	    cursec->pc > maxaddr) {
-		die("address overflow");
+		die("as: address overflow in section '%s'");
 	}
 }
 
@@ -238,7 +238,7 @@
 
 		siz = sec->max - sec->base;
 		if (siz > SIZE_MAX)
-			die("out of memory");
+			die("as: out of memory");
 		sec->mem = xmalloc(sec->max - sec->base);
 	}
 	cursec = stext;
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -416,7 +416,7 @@
 incdir(char *dir)
 {
 	if (!dir || *dir == '\0')
-		die("incorrect -I flag");
+		die("cc1: incorrect -I flag");
 	newitem(&dirinclude, dir);
 }
 
@@ -454,7 +454,7 @@
 	if ((p = strrchr(s, '/')) == NULL)
 		return NULL;
 	if ((len = p - s) >= FILENAME_MAX)
-		die("current work directory too long");
+		die("cc1: current work directory too long");
 	memcpy(buf, s, len);
 	buf[len] = '\0';
 	return buf;
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -75,7 +75,7 @@
 	size_t len;
 
 	if ((len = strlen(fname)) >= FILENAME_MAX)
-		die("file name too long: '%s'", fname);
+		die("cc1: %s: file name too long", fname);
 	memmove(filenam, fname, len);
 	filenam[len] = '\0';
 
@@ -97,7 +97,7 @@
 		/* this is a macro expansion */
 		fp = NULL;
 		if (hide->hide == UCHAR_MAX)
-			die("Too many macro expansions");
+			die("cc1: too many macro expansions");
 		++hide->hide;
 		flags = IMACRO;
 	} else  if (fname) {
@@ -150,8 +150,7 @@
 	switch (ip->flags & ITYPE) {
 	case IFILE:
 		if (fclose(ip->fp))
-			die("error: failed to read from input file '%s'",
-			    ip->filenam);
+			die("cc1: %s: %s", ip->filenam, strerror(errno));
 		break;
 	case IMACRO:
 		assert(hide->hide == 1);
@@ -171,7 +170,7 @@
 newline(void)
 {
 	if (++lineno == 0)
-		die("error: input file '%s' too long", filenam);
+		die("cc1: %s: file too long", filenam);
 }
 
 /*
--- a/cc1/main.c
+++ b/cc1/main.c
@@ -1,5 +1,6 @@
 static char sccsid[] = "@(#) ./cc1/main.c";
 #include <setjmp.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -35,8 +36,9 @@
 static void
 usage(void)
 {
-	die("usage: cc1 [-Ewd] [-D def[=val]]... [-U def]... "
-	    "[-I dir]... [-o output] [input]");
+	fputs("usage: cc1 [-Ewd] [-D def[=val]]... [-U def]... "
+	      "[-I dir]... [-o output] [input]\n", stderr);
+	exit(1);
 }
 
 int
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -198,7 +198,7 @@
 		return 0;
 	id = ++counterid;
 	if (id == 0) {
-		die("Overflow in %s identifiers",
+		die("cc1: overflow in %s identifiers",
 		    (curctx) ? "internal" : "external");
 	}
 	return id;
--- a/cc2/main.c
+++ b/cc2/main.c
@@ -1,12 +1,18 @@
 static char sccsid[] = "@(#) ./cc2/main.c";
+
+#include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
+#include "../inc/arg.h"
 #include "../inc/scc.h"
 #include "cc2.h"
 #include "error.h"
 
+char *argv0;
+
 void
 error(unsigned nerror, ...)
 {
@@ -32,14 +38,23 @@
 	return 1;
 }
 
+static void
+usage(void)
+{
+	fputs("usage: cc2 [irfile]\n", stderr);
+	exit(1);
+}
+
 int
 main(int argc, char *argv[])
 {
-	if (argc > 2)
-		die("usage: cc2 [irfile]");
+	ARGBEGIN {
+	default:
+		usage();
+	} ARGEND
 
-	if (argv[1] && !freopen(argv[1], "r", stdin))
-		die("cc2: cannot open %s", argv[1]);
+	if (argv[0] && !freopen(argv[0], "r", stdin))
+		die("cc2: %s: %s", argv[0], strerror(errno));
 
 	while (moreinput()) {
 		parse();
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -452,15 +452,16 @@
 static void
 usage(void)
 {
-	die("usage: scc [-D def[=val]]... [-U def]... [-I dir]... "
-	    "[-L dir]... [-l dir]...\n"
-	    "           [-dgksw] [-m arch] [-M|-E|-S] [-o outfile] file...\n"
-	    "       scc [-D def[=val]]... [-U def]... [-I dir]... "
-	    "[-L dir]... [-l dir]...\n"
-	    "           [-dgksw] [-m arch] [-M|-E|-S] -c file...\n"
-	    "       scc [-D def[=val]]... [-U def]... [-I dir]... "
-	    "[-L dir]... [-l dir]...\n"
-	    "           [-dgksw] [-m arch] -c -o outfile file");
+	fputs("usage: scc [-D def[=val]]... [-U def]... [-I dir]... "
+	       "[-L dir]... [-l dir]...\n"
+	       "           [-dgksw] [-m arch] [-M|-E|-S] [-o outfile] file...\n"
+	       "       scc [-D def[=val]]... [-U def]... [-I dir]... "
+	       "[-L dir]... [-l dir]...\n"
+	       "           [-dgksw] [-m arch] [-M|-E|-S] -c file...\n"
+	       "       scc [-D def[=val]]... [-U def]... [-I dir]... "
+	       "[-L dir]... [-l dir]...\n"
+	       "           [-dgksw] [-m arch] -c -o outfile file\n", stderr);
+	exit(1);
 }
 
 int
--- a/ld/coff32.c
+++ b/ld/coff32.c
@@ -35,7 +35,7 @@
 	fsetpos(fp, &pos);
 
 	if (ferror(fp))
-		die("nm: %s: %s", fname, strerror(errno));
+		die("ld: %s: %s", fname, strerror(errno));
 
 	if (c1 == EOF || c2 == EOF)
 		return 0;
--- a/lib/scc/newitem.c
+++ b/lib/scc/newitem.c
@@ -4,7 +4,7 @@
 newitem(struct items *items, char *item)
 {
 	if ((items->n + 1) < items->n)
-		die("newitem: overflow (%u + 1)", items->n);
+		die("overflow in newitem (%u + 1)", items->n);
 
 	items->s = xrealloc(items->s, (items->n + 1) * sizeof(char **));
 	items->s[items->n++] = item;
--- a/nm/coff32.c
+++ b/nm/coff32.c
@@ -40,7 +40,7 @@
 		break;
 	default:
 		if (ent->n_scnum > nsect)
-			die("nm:incorrect section index");
+			die("nm: incorrect section index");
 		sec = &sections[ent->n_scnum-1];
 		flags = sec->s_flags;
 		if (flags & STYP_TEXT)
@@ -146,13 +146,13 @@
 	SYMENT ent;
 
 	if (hdr->f_nsyms > SIZE_MAX)
-		die("nm:%s:Too many symbols\n", member);
+		die("nm: %s:Too many symbols\n", member);
 
 	n = hdr->f_nsyms;
 	syms = xcalloc(sizeof(*syms), n);
 
 	if (fseek(fp, symtbl, SEEK_SET) == EOF)
-		die("nm:%s:%s", fname, strerror(errno));
+		die("nm: %s:%s", fname, strerror(errno));
 
 	aux = nsyms = 0;
 	for (i = 0; i < n; i++) {
@@ -205,10 +205,10 @@
 		return;
 
 	if (nsect > SIZE_MAX)
-		die("nm:%s:Too many sections\n", member);
+		die("nm: %s:Too many sections\n", member);
 
 	if (fseek(fp, sectbl, SEEK_SET) == EOF)
-		die("nm:%s:%s", member, strerror(errno));
+		die("nm: %s:%s", member, strerror(errno));
 
 	sections = xcalloc(sizeof(*sections), nsect);
 	for (i = 0; i < nsect; i++) {