scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit bcf34c9b169850dd66471f5c79738e73d7813f26
parent 7ecbfcb7da78a8c794f981c179c5431edbbc4326
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 14 Mar 2018 11:28:22 +0100

Add name of the tool in die() messages

Diffstat:
Mas/parser.c | 9+++++----
Mas/symbol.c | 4++--
Mcc1/cpp.c | 4++--
Mcc1/lex.c | 9++++-----
Mcc1/main.c | 6++++--
Mcc1/symbol.c | 2+-
Mcc2/main.c | 23+++++++++++++++++++----
Mdriver/posix/scc.c | 19++++++++++---------
Mld/coff32.c | 2+-
Mlib/scc/newitem.c | 2+-
Mnm/coff32.c | 10+++++-----
11 files changed, 54 insertions(+), 36 deletions(-)

diff --git 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 @@ repeat: } 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 @@ addinput(char *fname) 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 @@ delinput(void) 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; } diff --git a/as/symbol.c b/as/symbol.c @@ -147,7 +147,7 @@ incpc(int siz) curpc > cursec->curpc || cursec->curpc > maxaddr || cursec->pc > maxaddr) { - die("address overflow"); + die("as: address overflow in section '%s'"); } } @@ -238,7 +238,7 @@ cleansecs(void) 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; diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -416,7 +416,7 @@ void incdir(char *dir) { if (!dir || *dir == '\0') - die("incorrect -I flag"); + die("cc1: incorrect -I flag"); newitem(&dirinclude, dir); } @@ -454,7 +454,7 @@ cwd(char *buf) 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; diff --git a/cc1/lex.c b/cc1/lex.c @@ -75,7 +75,7 @@ setloc(char *fname, unsigned line) 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 @@ addinput(char *fname, Symbol *hide, char *buffer) /* 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 @@ delinput(void) 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 @@ static void newline(void) { if (++lineno == 0) - die("error: input file '%s' too long", filenam); + die("cc1: %s: file too long", filenam); } /* diff --git 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 @@ defmacro(char *macro) 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 diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -198,7 +198,7 @@ newid(void) return 0; id = ++counterid; if (id == 0) { - die("Overflow in %s identifiers", + die("cc1: overflow in %s identifiers", (curctx) ? "internal" : "external"); } return id; diff --git 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 @@ repeat: 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(); diff --git a/driver/posix/scc.c b/driver/posix/scc.c @@ -452,15 +452,16 @@ build(struct items *chain, int link) 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 diff --git a/ld/coff32.c b/ld/coff32.c @@ -35,7 +35,7 @@ probe(char *fname, char *member, FILE *fp) 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; diff --git a/lib/scc/newitem.c b/lib/scc/newitem.c @@ -4,7 +4,7 @@ void 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; diff --git a/nm/coff32.c b/nm/coff32.c @@ -40,7 +40,7 @@ typeof(SYMENT *ent) 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 @@ getsyms(char *fname, char *member, FILE *fp, FILHDR *hdr) 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 @@ getsects(char *fname, char *member, FILE *fp, FILHDR *hdr) 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++) {