From c4eda39b4ab1172c488c310cd3af1584db34db87 Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Mon, 6 Sep 1999 13:10:50 +0000 Subject: Misc minor changes: - use err.h and kill oops, - use __progname and kill basename, - let indx use strstr - proper EOS decl --- usr.bin/m4/eval.c | 23 +++++++------- usr.bin/m4/extern.h | 5 +--- usr.bin/m4/look.c | 3 +- usr.bin/m4/main.c | 20 ++++++------- usr.bin/m4/mdef.h | 4 +-- usr.bin/m4/misc.c | 86 ++++++++++++++--------------------------------------- 6 files changed, 48 insertions(+), 93 deletions(-) (limited to 'usr.bin/m4') diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index dbb67ed20e4..470149ad208 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.11 1998/04/25 18:47:18 millert Exp $ */ +/* $OpenBSD: eval.c,v 1.12 1999/09/06 13:10:48 espie Exp $ */ /* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */ /* @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95"; #else -static char rcsid[] = "$OpenBSD: eval.c,v 1.11 1998/04/25 18:47:18 millert Exp $"; +static char rcsid[] = "$OpenBSD: eval.c,v 1.12 1999/09/06 13:10:48 espie Exp $"; #endif #endif /* not lint */ @@ -58,6 +58,7 @@ static char rcsid[] = "$OpenBSD: eval.c,v 1.11 1998/04/25 18:47:18 millert Exp $ #include #include #include +#include #include "mdef.h" #include "stdd.h" #include "extern.h" @@ -195,7 +196,7 @@ register int td; case INCLTYPE: if (argc > 2) if (!doincl(argv[2])) - oops("%s: %s", argv[2], strerror(errno)); + err(1, "%s", argv[2]); break; case SINCTYPE: @@ -206,7 +207,7 @@ register int td; case PASTTYPE: if (argc > 2) if (!dopaste(argv[2])) - oops("%s: %s", argv[2], strerror(errno)); + err(1, "%s", argv[2]); break; case SPASTYPE: @@ -371,7 +372,7 @@ register int td; break; default: - oops("%s: major botch.", "eval"); + errx(1, "eval: major botch."); break; } } @@ -460,9 +461,9 @@ register char *defn; register ndptr p; if (!*name) - oops("null definition."); + errx(1, "null definition."); if (STREQ(name, defn)) - oops("%s: recursive definition.", name); + errx(1, "%s: recursive definition.", name); if ((p = lookup(name)) == nil) p = addent(name); else if (p->defn != null) @@ -506,9 +507,9 @@ register char *defn; register ndptr p; if (!*name) - oops("null definition"); + errx(1, "null definition"); if (STREQ(name, defn)) - oops("%s: recursive definition.", name); + errx(1, "%s: recursive definition.", name); p = addent(name); if (!*defn) p->defn = null; @@ -573,7 +574,7 @@ doincl(ifile) char *ifile; { if (ilevel + 1 == MAXINP) - oops("too many include files."); + errx(1, "too many include files."); if ((infile[ilevel + 1] = fopen(ifile, "r")) != NULL) { ilevel++; bbase[ilevel] = bufbase = bp; @@ -670,7 +671,7 @@ register int n; m4temp[UNIQUE] = n + '0'; if ((fd = open(m4temp, O_CREAT|O_EXCL|O_WRONLY, 0600)) < 0 || (outfile[n] = fdopen(fd, "w")) == NULL) - oops("%s: cannot divert.", m4temp); + err(1, "%s: cannot divert", m4temp); } active = outfile[n]; } diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h index 3fa5d195e60..dab44838e3f 100644 --- a/usr.bin/m4/extern.h +++ b/usr.bin/m4/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.4 1997/12/10 20:24:12 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.5 1999/09/06 13:10:48 espie Exp $ */ /* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */ /*- @@ -39,7 +39,6 @@ * @(#)extern.h 8.1 (Berkeley) 6/6/93 */ -char *basename __P((char *)); char *xalloc __P((unsigned long)); int expr __P((char *)); ndptr addent __P((char *)); @@ -66,7 +65,6 @@ void killdiv __P((void)); ndptr lookup __P((char *)); void map __P((char *, char *, char *, char *)); void onintr __P((int)); -void oops __P((const char *, ...)); void pbnum __P((int)); void pbstr __P((char *)); void putback __P((int)); @@ -94,6 +92,5 @@ extern char lquote[]; /* left quote character (`) */ extern char *m4temp; /* filename for diversions */ extern char *m4wraps; /* m4wrap string default. */ extern char *null; /* as it says.. just a null. */ -extern char *progname; /* program name */ extern char rquote[]; /* right quote character (') */ extern char scommt[]; /* start character for comment */ diff --git a/usr.bin/m4/look.c b/usr.bin/m4/look.c index 4aef4823ebb..db14cffa044 100644 --- a/usr.bin/m4/look.c +++ b/usr.bin/m4/look.c @@ -1,4 +1,4 @@ -/* $OpenBSD: look.c,v 1.2 1996/06/26 05:36:12 deraadt Exp $ */ +/* $OpenBSD: look.c,v 1.3 1999/09/06 13:10:48 espie Exp $ */ /* * Copyright (c) 1989, 1993 @@ -49,6 +49,7 @@ static char sccsid[] = "@(#)look.c 8.1 (Berkeley) 6/6/93"; #include #include #include +#include #include #include "mdef.h" #include "stdd.h" diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index 9668a761e57..050d3585701 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.10 1998/06/02 20:46:40 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.11 1999/09/06 13:10:48 espie Exp $ */ /* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ /*- @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.10 1998/06/02 20:46:40 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.11 1999/09/06 13:10:48 espie Exp $"; #endif #endif /* not lint */ @@ -64,6 +64,7 @@ static char rcsid[] = "$OpenBSD: main.c,v 1.10 1998/06/02 20:46:40 deraadt Exp $ #include #include #include +#include #include "mdef.h" #include "stdd.h" #include "extern.h" @@ -89,7 +90,6 @@ int ilevel = 0; /* input file stack pointer */ int oindex = 0; /* diversion index.. */ char *null = ""; /* as it says.. just a null.. */ char *m4wraps = ""; /* m4wrap string default.. */ -char *progname; /* name of this program */ char lquote[MAXCCHARS+1] = {LQUOTE}; /* left quote character (`) */ char rquote[MAXCCHARS+1] = {RQUOTE}; /* right quote character (') */ char scommt[MAXCCHARS+1] = {SCOMMT}; /* start character for comment */ @@ -160,8 +160,6 @@ main(argc,argv) char *p; register FILE *ifp; - progname = basename(argv[0]); - if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, onintr); @@ -205,7 +203,7 @@ main(argc,argv) if (p[0] == '-' && p[1] == '\0') ifp = stdin; else if ((ifp = fopen(p, "r")) == NULL) - oops("%s: %s", p, strerror(errno)); + err(1, "%s", p); sp = -1; fp = 0; infile[0] = ifp; @@ -258,7 +256,7 @@ do_look_ahead(t, token) int i; if (t != token[0]) - oops("internal error", ""); + errx(1, "internal error"); for (i = 1; *++token; i++) { t = gpbc(); @@ -323,7 +321,7 @@ macro() { } else if (t == EOF) { if (sp > -1) - oops("unexpected end of input", ""); + errx(1, "unexpected end of input"); if (ilevel <= 0) break; /* all done thanks.. */ --ilevel; @@ -347,7 +345,7 @@ macro() { nlpar++; s = lquote; } else if (l == EOF) - oops("missing right quote", ""); + errx(1, "missing right quote"); else { chars[0] = l; chars[1] = '\0'; @@ -406,7 +404,7 @@ macro() { chrsave(EOS); if (sp == STACKMAX) - oops("internal stack overflow", ""); + errx(1, "internal stack overflow"); if (CALTYP == MACRTYPE) expand((char **) mstack+fp+1, sp-fp); @@ -456,7 +454,7 @@ register char *tp; h = (h << 5) + h + (*tp++ = c); putback(c); if (tp == etp) - oops("token too long", ""); + errx(1, "token too long"); *tp = EOS; diff --git a/usr.bin/m4/mdef.h b/usr.bin/m4/mdef.h index 51eb5d60372..f4498c057ba 100644 --- a/usr.bin/m4/mdef.h +++ b/usr.bin/m4/mdef.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mdef.h,v 1.4 1997/12/10 20:24:16 deraadt Exp $ */ +/* $OpenBSD: mdef.h,v 1.5 1999/09/06 13:10:48 espie Exp $ */ /* $NetBSD: mdef.h,v 1.7 1996/01/13 23:25:27 pk Exp $ */ /* @@ -96,7 +96,7 @@ * other important constants */ -#define EOS (char) 0 +#define EOS '\0' #define MAXINP 10 /* maximum include files */ #define MAXOUT 10 /* maximum # of diversions */ #define MAXSTR 512 /* maximum size of string */ diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c index ba9a97c3eaf..02d83e6c330 100644 --- a/usr.bin/m4/misc.c +++ b/usr.bin/m4/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.6 1997/12/10 20:24:17 deraadt Exp $ */ +/* $OpenBSD: misc.c,v 1.7 1999/09/06 13:10:49 espie Exp $ */ /* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */ /* @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: misc.c,v 1.6 1997/12/10 20:24:17 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: misc.c,v 1.7 1999/09/06 13:10:49 espie Exp $"; #endif #endif /* not lint */ @@ -50,7 +50,9 @@ static char rcsid[] = "$OpenBSD: misc.c,v 1.6 1997/12/10 20:24:17 deraadt Exp $" #include #include #include +#include #include +#include #include "mdef.h" #include "stdd.h" #include "extern.h" @@ -59,21 +61,18 @@ static char rcsid[] = "$OpenBSD: misc.c,v 1.6 1997/12/10 20:24:17 deraadt Exp $" /* * find the index of second str in the first str. */ -int +ptrdiff_t indx(s1, s2) -char *s1; -char *s2; +const char *s1; +const char *s2; { - register char *t; - register char *p; - register char *m; + char *r; - for (p = s1; *p; p++) { - for (t = p, m = s2; *m && *m == *t; m++, t++); - if (!*m) - return (p - s1); - } - return (-1); + r = strstr(s1, s2); + if (r) + return (r - s1); + else + return (-1); } /* * putback - push character back onto input @@ -85,7 +84,7 @@ pbent c; if (bp < endpbb) *bp++ = c; else - oops("too many characters pushed back"); + errx(1, "too many characters pushed back"); } /* @@ -110,7 +109,7 @@ register char *s; if (zp < endpbb) *zp++ = *es--; if ((bp = zp) == endpbb) - oops("too many characters pushed back"); + errx(1, "too many characters pushed back"); } /* @@ -142,7 +141,7 @@ char c; if (ep < endest) *ep++ = c; else - oops("string space overflow"); + errx(1, "string space overflow"); } /* @@ -156,12 +155,12 @@ int n; register FILE *dfil; if (active == outfile[n]) - oops("%s: diversion still active.", "undivert"); + errx(1, "undivert: diversion still active"); (void) fclose(outfile[n]); outfile[n] = NULL; m4temp[UNIQUE] = n + '0'; if ((dfil = fopen(m4temp, "r")) == NULL) - oops("%s: cannot undivert.", m4temp); + err(1, "%s: cannot undivert", m4temp); else while ((c = getc(dfil)) != EOF) putc(c, active); @@ -172,14 +171,14 @@ int n; #else if (unlink(m4temp) == -1) #endif - oops("%s: cannot unlink.", m4temp); + err(1, "%s: cannot unlink", m4temp); } void onintr(signo) int signo; { - oops("interrupted."); + errx(1, "interrupted."); } /* @@ -209,7 +208,7 @@ unsigned long n; register char *p = malloc(n); if (p == NULL) - oops("malloc: %s", strerror(errno)); + err(1, "malloc"); return p; } @@ -219,23 +218,10 @@ const char *s; { register char *p = strdup(s); if (p == NULL) - oops("strdup: %s", strerror(errno)); + err(1, "strdup"); return p; } -char * -basename(s) -register char *s; -{ - register char *p; - extern char *strrchr(); - - if ((p = strrchr(s, '/')) == NULL) - return s; - - return ++p; -} - void usage() { @@ -243,31 +229,3 @@ usage() exit(1); } -#ifdef __STDC__ -#include -#else -#include -#endif - -void -#ifdef __STDC__ -oops(const char *fmt, ...) -#else -oops(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - va_list ap; -#ifdef __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)fprintf(stderr, "%s: ", progname); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - exit(1); - /* NOTREACHED */ -} -- cgit v1.2.3