WARNSify, fix .Nm usage, getopt returns -1 not EOF, deprecate register
This commit is contained in:
parent
0abdfcdfd5
commit
6f9ec05a98
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: eval.c,v 1.9 1997/02/08 23:50:40 cgd Exp $ */
|
||||
/* $NetBSD: eval.c,v 1.10 1997/10/19 04:39:51 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: eval.c,v 1.9 1997/02/08 23:50:40 cgd Exp $";
|
||||
__RCSID("$NetBSD: eval.c,v 1.10 1997/10/19 04:39:51 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -51,6 +52,7 @@ static char rcsid[] = "$NetBSD: eval.c,v 1.9 1997/02/08 23:50:40 cgd Exp $";
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
@ -82,11 +84,11 @@ static char rcsid[] = "$NetBSD: eval.c,v 1.9 1997/02/08 23:50:40 cgd Exp $";
|
||||
|
||||
void
|
||||
eval(argv, argc, td)
|
||||
register char *argv[];
|
||||
register int argc;
|
||||
register int td;
|
||||
char *argv[];
|
||||
int argc;
|
||||
int td;
|
||||
{
|
||||
register int c, n;
|
||||
int c, n;
|
||||
static int sysval = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -193,7 +195,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:
|
||||
@ -204,7 +206,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:
|
||||
@ -236,7 +238,6 @@ register int td;
|
||||
* argv[2])
|
||||
*/
|
||||
if (argc > 3) {
|
||||
int k;
|
||||
for (n = argc - 1; n > 3; n--) {
|
||||
pbstr(rquote);
|
||||
pbstr(argv[n]);
|
||||
@ -371,7 +372,7 @@ register int td;
|
||||
break;
|
||||
|
||||
default:
|
||||
oops("%s: major botch.", "eval");
|
||||
errx(1, "eval: major botch");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -383,13 +384,13 @@ char *dumpfmt = "`%s'\t`%s'\n"; /* format string for dumpdef */
|
||||
*/
|
||||
void
|
||||
expand(argv, argc)
|
||||
register char *argv[];
|
||||
register int argc;
|
||||
char *argv[];
|
||||
int argc;
|
||||
{
|
||||
register char *t;
|
||||
register char *p;
|
||||
register int n;
|
||||
register int argno;
|
||||
char *t;
|
||||
char *p;
|
||||
int n;
|
||||
int argno;
|
||||
|
||||
t = argv[0]; /* defn string as a whole */
|
||||
p = t;
|
||||
@ -454,15 +455,15 @@ register int argc;
|
||||
*/
|
||||
void
|
||||
dodefine(name, defn)
|
||||
register char *name;
|
||||
register char *defn;
|
||||
char *name;
|
||||
char *defn;
|
||||
{
|
||||
register ndptr p;
|
||||
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)
|
||||
@ -480,9 +481,9 @@ register char *defn;
|
||||
*/
|
||||
void
|
||||
dodefn(name)
|
||||
char *name;
|
||||
char *name;
|
||||
{
|
||||
register ndptr p;
|
||||
ndptr p;
|
||||
|
||||
if ((p = lookup(name)) != nil && p->defn != null) {
|
||||
pbstr(rquote);
|
||||
@ -500,15 +501,15 @@ char *name;
|
||||
*/
|
||||
void
|
||||
dopushdef(name, defn)
|
||||
register char *name;
|
||||
register char *defn;
|
||||
char *name;
|
||||
char *defn;
|
||||
{
|
||||
register ndptr p;
|
||||
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;
|
||||
@ -524,10 +525,10 @@ register char *defn;
|
||||
*/
|
||||
void
|
||||
dodump(argv, argc)
|
||||
register char *argv[];
|
||||
register int argc;
|
||||
char *argv[];
|
||||
int argc;
|
||||
{
|
||||
register int n;
|
||||
int n;
|
||||
ndptr p;
|
||||
|
||||
if (argc > 2) {
|
||||
@ -549,8 +550,8 @@ register int argc;
|
||||
*/
|
||||
void
|
||||
doifelse(argv, argc)
|
||||
register char *argv[];
|
||||
register int argc;
|
||||
char *argv[];
|
||||
int argc;
|
||||
{
|
||||
cycle {
|
||||
if (STREQ(argv[2], argv[3]))
|
||||
@ -571,10 +572,10 @@ register int argc;
|
||||
*/
|
||||
int
|
||||
doincl(ifile)
|
||||
char *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;
|
||||
@ -591,10 +592,10 @@ char *ifile;
|
||||
*/
|
||||
int
|
||||
dopaste(pfile)
|
||||
char *pfile;
|
||||
char *pfile;
|
||||
{
|
||||
FILE *pf;
|
||||
register int c;
|
||||
int c;
|
||||
|
||||
if ((pf = fopen(pfile, "r")) != NULL) {
|
||||
while ((c = getc(pf)) != EOF)
|
||||
@ -612,8 +613,8 @@ char *pfile;
|
||||
*/
|
||||
void
|
||||
dochq(argv, argc)
|
||||
register char *argv[];
|
||||
register int argc;
|
||||
char *argv[];
|
||||
int argc;
|
||||
{
|
||||
if (argc > 2) {
|
||||
if (*argv[2])
|
||||
@ -636,8 +637,8 @@ register int argc;
|
||||
*/
|
||||
void
|
||||
dochc(argv, argc)
|
||||
register char *argv[];
|
||||
register int argc;
|
||||
char *argv[];
|
||||
int argc;
|
||||
{
|
||||
if (argc > 2) {
|
||||
if (*argv[2])
|
||||
@ -660,7 +661,7 @@ register int argc;
|
||||
*/
|
||||
void
|
||||
dodiv(n)
|
||||
register int n;
|
||||
int n;
|
||||
{
|
||||
int tempfilenum;
|
||||
|
||||
@ -673,7 +674,7 @@ register int n;
|
||||
if (outfile[tempfilenum] == NULL) {
|
||||
m4temp[UNIQUE] = tempfilenum + '0';
|
||||
if ((outfile[tempfilenum] = fopen(m4temp, "w")) == NULL)
|
||||
oops("%s: cannot divert.", m4temp);
|
||||
err(1, "%s: cannot divert", m4temp);
|
||||
}
|
||||
oindex = n;
|
||||
active = outfile[tempfilenum];
|
||||
@ -685,11 +686,11 @@ register int n;
|
||||
*/
|
||||
void
|
||||
doundiv(argv, argc)
|
||||
register char *argv[];
|
||||
register int argc;
|
||||
char *argv[];
|
||||
int argc;
|
||||
{
|
||||
register int ind;
|
||||
register int n;
|
||||
int ind;
|
||||
int n;
|
||||
|
||||
if (argc > 2) {
|
||||
for (ind = 2; ind < argc; ind++) {
|
||||
@ -710,11 +711,11 @@ register int argc;
|
||||
*/
|
||||
void
|
||||
dosub(argv, argc)
|
||||
register char *argv[];
|
||||
register int argc;
|
||||
char *argv[];
|
||||
int argc;
|
||||
{
|
||||
register char *ap, *fc, *k;
|
||||
register int nc;
|
||||
char *ap, *fc, *k;
|
||||
int nc;
|
||||
|
||||
if (argc < 5)
|
||||
nc = MAXTOK;
|
||||
@ -762,13 +763,13 @@ register int argc;
|
||||
*/
|
||||
void
|
||||
map(dest, src, from, to)
|
||||
register char *dest;
|
||||
register char *src;
|
||||
register char *from;
|
||||
register char *to;
|
||||
char *dest;
|
||||
char *src;
|
||||
char *from;
|
||||
char *to;
|
||||
{
|
||||
register char *tmp;
|
||||
register char sch, dch;
|
||||
char *tmp;
|
||||
char sch, dch;
|
||||
static char mapvec[128] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
|
||||
@ -790,23 +791,23 @@ register char *to;
|
||||
* "to"
|
||||
*/
|
||||
while (*from)
|
||||
mapvec[*from++] = (*to) ? *to++ : (char) 0;
|
||||
mapvec[(int)*from++] = (*to) ? *to++ : (char) 0;
|
||||
|
||||
while (*src) {
|
||||
sch = *src++;
|
||||
dch = mapvec[sch];
|
||||
dch = mapvec[(int)sch];
|
||||
while (dch != sch) {
|
||||
sch = dch;
|
||||
dch = mapvec[sch];
|
||||
dch = mapvec[(int)sch];
|
||||
}
|
||||
if (*dest = dch)
|
||||
if ((*dest = dch) != 0)
|
||||
dest++;
|
||||
}
|
||||
/*
|
||||
* restore all the changed characters
|
||||
*/
|
||||
while (*tmp) {
|
||||
mapvec[*tmp] = *tmp;
|
||||
mapvec[(int)*tmp] = *tmp;
|
||||
tmp++;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: expr.c,v 1.7 1995/09/28 05:37:31 tls Exp $ */
|
||||
/* $NetBSD: expr.c,v 1.8 1997/10/19 04:39:53 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
@ -36,17 +36,21 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)expr.c 8.2 (Berkeley) 4/29/95";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: expr.c,v 1.7 1995/09/28 05:37:31 tls Exp $";
|
||||
__RCSID("$NetBSD: expr.c,v 1.8 1997/10/19 04:39:53 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mdef.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* expression evaluator: performs a standard recursive
|
||||
* descent parse to evaluate any expression permissible
|
||||
@ -138,9 +142,9 @@ static jmp_buf expjump;
|
||||
|
||||
int
|
||||
expr(expbuf)
|
||||
char *expbuf;
|
||||
char *expbuf;
|
||||
{
|
||||
register int rval;
|
||||
int rval;
|
||||
|
||||
nxtch = expbuf;
|
||||
if (setjmp(expjump) != 0)
|
||||
@ -160,7 +164,7 @@ char *expbuf;
|
||||
static int
|
||||
query()
|
||||
{
|
||||
register int bool, true_val, false_val;
|
||||
int bool, true_val, false_val;
|
||||
|
||||
bool = lor();
|
||||
if (skipws() != '?') {
|
||||
@ -182,7 +186,7 @@ query()
|
||||
static int
|
||||
lor()
|
||||
{
|
||||
register int c, vl, vr;
|
||||
int c, vl, vr;
|
||||
|
||||
vl = land();
|
||||
while ((c = skipws()) == '|') {
|
||||
@ -202,7 +206,7 @@ lor()
|
||||
static int
|
||||
land()
|
||||
{
|
||||
register int c, vl, vr;
|
||||
int c, vl, vr;
|
||||
|
||||
vl = not();
|
||||
while ((c = skipws()) == '&') {
|
||||
@ -222,7 +226,7 @@ land()
|
||||
static int
|
||||
not()
|
||||
{
|
||||
register int val, c;
|
||||
int val, c;
|
||||
|
||||
if ((c = skipws()) == '!' && getch() != '=') {
|
||||
ungetch();
|
||||
@ -242,7 +246,7 @@ not()
|
||||
static int
|
||||
eqrel()
|
||||
{
|
||||
register int vl, vr, eqrel;
|
||||
int vl, vr, eqrel;
|
||||
|
||||
vl = shift();
|
||||
while ((eqrel = geteqrel()) != -1) {
|
||||
@ -280,7 +284,7 @@ eqrel()
|
||||
static int
|
||||
shift()
|
||||
{
|
||||
register int vl, vr, c;
|
||||
int vl, vr, c;
|
||||
|
||||
vl = primary();
|
||||
while (((c = skipws()) == '<' || c == '>') && getch() == c) {
|
||||
@ -304,7 +308,7 @@ shift()
|
||||
static int
|
||||
primary()
|
||||
{
|
||||
register int c, vl, vr;
|
||||
int c, vl, vr;
|
||||
|
||||
vl = term();
|
||||
while ((c = skipws()) == '+' || c == '-') {
|
||||
@ -326,7 +330,7 @@ primary()
|
||||
static int
|
||||
term()
|
||||
{
|
||||
register int c, vl, vr;
|
||||
int c, vl, vr;
|
||||
|
||||
vl = exp();
|
||||
while ((c = skipws()) == '*' || c == '/' || c == '%') {
|
||||
@ -354,7 +358,7 @@ term()
|
||||
static int
|
||||
exp()
|
||||
{
|
||||
register c, vl, vr, n;
|
||||
int c, vl, vr, n;
|
||||
|
||||
vl = unary();
|
||||
switch (c = skipws()) {
|
||||
@ -383,7 +387,7 @@ exp()
|
||||
static int
|
||||
unary()
|
||||
{
|
||||
register int val, c;
|
||||
int val, c;
|
||||
|
||||
if ((c = skipws()) == '+' || c == '-' || c == '~') {
|
||||
val = unary();
|
||||
@ -408,7 +412,7 @@ unary()
|
||||
static int
|
||||
factor()
|
||||
{
|
||||
register int val;
|
||||
int val;
|
||||
|
||||
if (skipws() == '(') {
|
||||
val = query();
|
||||
@ -428,9 +432,9 @@ factor()
|
||||
static int
|
||||
constant()
|
||||
{
|
||||
register int i;
|
||||
register int value;
|
||||
register char c;
|
||||
int i;
|
||||
int value;
|
||||
char c;
|
||||
int v[sizeof(int)];
|
||||
|
||||
if (skipws() != '\'') {
|
||||
@ -489,7 +493,7 @@ constant()
|
||||
static int
|
||||
num()
|
||||
{
|
||||
register int rval, c, base;
|
||||
int rval, c, base;
|
||||
int ndig;
|
||||
|
||||
base = ((c = skipws()) == '0') ? OCTAL : DECIMAL;
|
||||
@ -516,7 +520,7 @@ num()
|
||||
static int
|
||||
geteqrel()
|
||||
{
|
||||
register int c1, c2;
|
||||
int c1, c2;
|
||||
|
||||
c1 = skipws();
|
||||
c2 = getch();
|
||||
@ -560,7 +564,7 @@ geteqrel()
|
||||
static int
|
||||
skipws()
|
||||
{
|
||||
register char c;
|
||||
char c;
|
||||
|
||||
while ((c = getch()) <= ' ' && c > EOS)
|
||||
;
|
||||
@ -573,7 +577,7 @@ skipws()
|
||||
*/
|
||||
static void
|
||||
experr(msg)
|
||||
char *msg;
|
||||
char *msg;
|
||||
{
|
||||
printf("m4: %s in expr.\n", msg);
|
||||
longjmp(expjump, -1);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.4 1997/10/19 04:39:55 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -65,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));
|
||||
|
@ -34,8 +34,13 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)look.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: look.c,v 1.6 1997/10/19 04:39:57 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -52,11 +57,14 @@ static char sccsid[] = "@(#)look.c 8.1 (Berkeley) 6/6/93";
|
||||
#include "stdd.h"
|
||||
#include "extern.h"
|
||||
|
||||
static void freent __P((ndptr));
|
||||
|
||||
|
||||
int
|
||||
hash(name)
|
||||
register char *name;
|
||||
char *name;
|
||||
{
|
||||
register unsigned long h = 0;
|
||||
unsigned long h = 0;
|
||||
while (*name)
|
||||
h = (h << 5) + h + *name++;
|
||||
return (h % HASHSIZE);
|
||||
@ -67,9 +75,9 @@ register char *name;
|
||||
*/
|
||||
ndptr
|
||||
lookup(name)
|
||||
char *name;
|
||||
char *name;
|
||||
{
|
||||
register ndptr p;
|
||||
ndptr p;
|
||||
|
||||
for (p = hashtab[hash(name)]; p != nil; p = p->nxtptr)
|
||||
if (STREQ(name, p->name))
|
||||
@ -83,9 +91,9 @@ char *name;
|
||||
*/
|
||||
ndptr
|
||||
addent(name)
|
||||
char *name;
|
||||
char *name;
|
||||
{
|
||||
register int h;
|
||||
int h;
|
||||
ndptr p;
|
||||
|
||||
h = hash(name);
|
||||
@ -98,7 +106,7 @@ char *name;
|
||||
|
||||
static void
|
||||
freent(p)
|
||||
ndptr p;
|
||||
ndptr p;
|
||||
{
|
||||
if (!(p->type & STATIC)) {
|
||||
free((char *) p->name);
|
||||
@ -113,11 +121,11 @@ ndptr p;
|
||||
*/
|
||||
void
|
||||
remhash(name, all)
|
||||
char *name;
|
||||
int all;
|
||||
char *name;
|
||||
int all;
|
||||
{
|
||||
register int h;
|
||||
register ndptr xp, tp, mp;
|
||||
int h;
|
||||
ndptr xp, tp, mp;
|
||||
|
||||
h = hash(name);
|
||||
mp = hashtab[h];
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: m4.1,v 1.6 1997/02/12 07:09:07 mikel Exp $
|
||||
.\" $NetBSD: m4.1,v 1.7 1997/10/19 04:39:58 lukem Exp $
|
||||
.\"
|
||||
.Dd January 26, 1993
|
||||
.Dt m4 1
|
||||
@ -7,7 +7,7 @@
|
||||
.Nm m4
|
||||
.Nd macro language processor
|
||||
.Sh SYNOPSIS
|
||||
.Nm m4
|
||||
.Nm
|
||||
.Oo
|
||||
.Fl D Ns Ar name Ns Op Ar =value
|
||||
.Oc
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
|
||||
/* $NetBSD: main.c,v 1.13 1997/10/19 04:40:00 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1989, 1993
|
||||
@ -36,17 +36,17 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1989, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $";
|
||||
__RCSID("$NetBSD: main.c,v 1.13 1997/10/19 04:40:00 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -57,12 +57,13 @@ static char rcsid[] = "$NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $";
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "mdef.h"
|
||||
#include "stdd.h"
|
||||
#include "extern.h"
|
||||
@ -95,69 +96,68 @@ char scommt[MAXCCHARS+1] = {SCOMMT}; /* start character for comment */
|
||||
char ecommt[MAXCCHARS+1] = {ECOMMT}; /* end character for comment */
|
||||
|
||||
struct keyblk keywrds[] = { /* m4 keywords to be installed */
|
||||
"include", INCLTYPE,
|
||||
"sinclude", SINCTYPE,
|
||||
"define", DEFITYPE,
|
||||
"defn", DEFNTYPE,
|
||||
"divert", DIVRTYPE,
|
||||
"expr", EXPRTYPE,
|
||||
"eval", EXPRTYPE,
|
||||
"substr", SUBSTYPE,
|
||||
"ifelse", IFELTYPE,
|
||||
"ifdef", IFDFTYPE,
|
||||
"len", LENGTYPE,
|
||||
"incr", INCRTYPE,
|
||||
"decr", DECRTYPE,
|
||||
"dnl", DNLNTYPE,
|
||||
"changequote", CHNQTYPE,
|
||||
"changecom", CHNCTYPE,
|
||||
"index", INDXTYPE,
|
||||
{ "include", INCLTYPE },
|
||||
{ "sinclude", SINCTYPE },
|
||||
{ "define", DEFITYPE },
|
||||
{ "defn", DEFNTYPE },
|
||||
{ "divert", DIVRTYPE },
|
||||
{ "expr", EXPRTYPE },
|
||||
{ "eval", EXPRTYPE },
|
||||
{ "substr", SUBSTYPE },
|
||||
{ "ifelse", IFELTYPE },
|
||||
{ "ifdef", IFDFTYPE },
|
||||
{ "len", LENGTYPE },
|
||||
{ "incr", INCRTYPE },
|
||||
{ "decr", DECRTYPE },
|
||||
{ "dnl", DNLNTYPE },
|
||||
{ "changequote", CHNQTYPE },
|
||||
{ "changecom", CHNCTYPE },
|
||||
{ "index", INDXTYPE },
|
||||
#ifdef EXTENDED
|
||||
"paste", PASTTYPE,
|
||||
"spaste", SPASTYPE,
|
||||
{ "paste", PASTTYPE },
|
||||
{ "spaste", SPASTYPE },
|
||||
#endif
|
||||
"popdef", POPDTYPE,
|
||||
"pushdef", PUSDTYPE,
|
||||
"dumpdef", DUMPTYPE,
|
||||
"shift", SHIFTYPE,
|
||||
"translit", TRNLTYPE,
|
||||
"undefine", UNDFTYPE,
|
||||
"undivert", UNDVTYPE,
|
||||
"divnum", DIVNTYPE,
|
||||
"maketemp", MKTMTYPE,
|
||||
"errprint", ERRPTYPE,
|
||||
"m4wrap", M4WRTYPE,
|
||||
"m4exit", EXITTYPE,
|
||||
"syscmd", SYSCTYPE,
|
||||
"sysval", SYSVTYPE,
|
||||
{ "popdef", POPDTYPE },
|
||||
{ "pushdef", PUSDTYPE },
|
||||
{ "dumpdef", DUMPTYPE },
|
||||
{ "shift", SHIFTYPE },
|
||||
{ "translit", TRNLTYPE },
|
||||
{ "undefine", UNDFTYPE },
|
||||
{ "undivert", UNDVTYPE },
|
||||
{ "divnum", DIVNTYPE },
|
||||
{ "maketemp", MKTMTYPE },
|
||||
{ "errprint", ERRPTYPE },
|
||||
{ "m4wrap", M4WRTYPE },
|
||||
{ "m4exit", EXITTYPE },
|
||||
{ "syscmd", SYSCTYPE },
|
||||
{ "sysval", SYSVTYPE },
|
||||
|
||||
#if defined(unix) || defined(__NetBSD__)
|
||||
"unix", MACRTYPE,
|
||||
{ "unix", MACRTYPE },
|
||||
#else
|
||||
#ifdef vms
|
||||
"vms", MACRTYPE,
|
||||
{ "vms", MACRTYPE },
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
#define MAXKEYS (sizeof(keywrds)/sizeof(struct keyblk))
|
||||
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
|
||||
void macro();
|
||||
void initkwds();
|
||||
extern int getopt();
|
||||
int do_look_ahead __P((int, char *));
|
||||
ndptr inspect __P((char *));
|
||||
void initkwds __P((void));
|
||||
void macro __P((void));
|
||||
int main __P((int, char **));
|
||||
|
||||
int
|
||||
main(argc,argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c;
|
||||
register int n;
|
||||
int c;
|
||||
int n;
|
||||
char *p;
|
||||
register FILE *ifp;
|
||||
FILE *ifp;
|
||||
|
||||
progname = basename(argv[0]);
|
||||
|
||||
@ -166,7 +166,7 @@ main(argc,argv)
|
||||
|
||||
initkwds();
|
||||
|
||||
while ((c = getopt(argc, argv, "tD:U:o:")) != EOF)
|
||||
while ((c = getopt(argc, argv, "tD:U:o:")) != -1)
|
||||
switch(c) {
|
||||
|
||||
case 'D': /* define something..*/
|
||||
@ -204,7 +204,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;
|
||||
@ -240,8 +240,6 @@ main(argc,argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ndptr inspect();
|
||||
|
||||
/*
|
||||
* Look ahead (at most MAXCCHARS characters) for `token'.
|
||||
* (on input `t == token[0]')
|
||||
@ -257,7 +255,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();
|
||||
@ -278,13 +276,15 @@ do_look_ahead(t, token)
|
||||
* macro - the work horse..
|
||||
*/
|
||||
void
|
||||
macro() {
|
||||
macro()
|
||||
{
|
||||
char token[MAXTOK], chars[2];
|
||||
register char *s;
|
||||
register int t, l;
|
||||
register ndptr p;
|
||||
register int nlpar;
|
||||
char *s;
|
||||
int t, l;
|
||||
ndptr p;
|
||||
int nlpar;
|
||||
|
||||
s = NULL;
|
||||
cycle {
|
||||
t = gpbc();
|
||||
if (t == '_' || isalpha(t)) {
|
||||
@ -321,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;
|
||||
@ -345,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';
|
||||
@ -404,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);
|
||||
@ -442,19 +442,19 @@ macro() {
|
||||
*/
|
||||
ndptr
|
||||
inspect(tp)
|
||||
register char *tp;
|
||||
char *tp;
|
||||
{
|
||||
register char c;
|
||||
register char *name = tp;
|
||||
register char *etp = tp+MAXTOK;
|
||||
register ndptr p;
|
||||
register unsigned long h = 0;
|
||||
char c;
|
||||
char *name = tp;
|
||||
char *etp = tp+MAXTOK;
|
||||
ndptr p;
|
||||
unsigned long h = 0;
|
||||
|
||||
while ((isalnum(c = gpbc()) || c == '_') && tp < etp)
|
||||
h = (h << 5) + h + (*tp++ = c);
|
||||
putback(c);
|
||||
if (tp == etp)
|
||||
oops("token too long", "");
|
||||
errx(1, "token too long");
|
||||
|
||||
*tp = EOS;
|
||||
|
||||
@ -472,10 +472,11 @@ register char *tp;
|
||||
* within keywrds block.
|
||||
*/
|
||||
void
|
||||
initkwds() {
|
||||
register int i;
|
||||
register int h;
|
||||
register ndptr p;
|
||||
initkwds()
|
||||
{
|
||||
int i;
|
||||
int h;
|
||||
ndptr p;
|
||||
|
||||
for (i = 0; i < MAXKEYS; i++) {
|
||||
h = hash(keywrds[i].knam);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */
|
||||
/* $NetBSD: misc.c,v 1.7 1997/10/19 04:40:03 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
@ -36,15 +36,17 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $";
|
||||
__RCSID("$NetBSD: misc.c,v 1.7 1997/10/19 04:40:03 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
@ -60,31 +62,28 @@ static char rcsid[] = "$NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $";
|
||||
*/
|
||||
int
|
||||
indx(s1, s2)
|
||||
char *s1;
|
||||
char *s2;
|
||||
char *s1;
|
||||
char *s2;
|
||||
{
|
||||
register char *t;
|
||||
register char *p;
|
||||
register char *m;
|
||||
char *t;
|
||||
|
||||
for (p = s1; *p; p++) {
|
||||
for (t = p, m = s2; *m && *m == *t; m++, t++);
|
||||
if (!*m)
|
||||
return (p - s1);
|
||||
}
|
||||
t = strstr(s1, s2);
|
||||
if (t == NULL)
|
||||
return (-1);
|
||||
return (t - s1);
|
||||
}
|
||||
|
||||
/*
|
||||
* putback - push character back onto input
|
||||
*/
|
||||
void
|
||||
putback(c)
|
||||
char c;
|
||||
char c;
|
||||
{
|
||||
if (bp < endpbb)
|
||||
*bp++ = c;
|
||||
else
|
||||
oops("too many characters pushed back");
|
||||
errx(1, "too many characters pushed back");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -94,10 +93,10 @@ char c;
|
||||
*/
|
||||
void
|
||||
pbstr(s)
|
||||
register char *s;
|
||||
char *s;
|
||||
{
|
||||
register char *es;
|
||||
register char *zp;
|
||||
char *es;
|
||||
char *zp;
|
||||
|
||||
es = s;
|
||||
zp = bp;
|
||||
@ -109,7 +108,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");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -117,9 +116,9 @@ register char *s;
|
||||
*/
|
||||
void
|
||||
pbnum(n)
|
||||
int n;
|
||||
int n;
|
||||
{
|
||||
register int num;
|
||||
int num;
|
||||
|
||||
num = (n < 0) ? -n : n;
|
||||
do {
|
||||
@ -136,12 +135,12 @@ int n;
|
||||
*/
|
||||
void
|
||||
chrsave(c)
|
||||
char c;
|
||||
char c;
|
||||
{
|
||||
if (ep < endest)
|
||||
*ep++ = c;
|
||||
else
|
||||
oops("string space overflow");
|
||||
errx(1, "string space overflow");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -149,18 +148,18 @@ char c;
|
||||
*/
|
||||
void
|
||||
getdiv(n)
|
||||
int n;
|
||||
int n;
|
||||
{
|
||||
register int c;
|
||||
register FILE *dfil;
|
||||
int c;
|
||||
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);
|
||||
@ -171,14 +170,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");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -187,7 +186,7 @@ onintr(signo)
|
||||
void
|
||||
killdiv()
|
||||
{
|
||||
register int n;
|
||||
int n;
|
||||
|
||||
for (n = 0; n < MAXOUT; n++)
|
||||
if (outfile[n] != NULL) {
|
||||
@ -203,31 +202,30 @@ killdiv()
|
||||
|
||||
char *
|
||||
xalloc(n)
|
||||
unsigned long n;
|
||||
unsigned long n;
|
||||
{
|
||||
register char *p = malloc(n);
|
||||
char *p = malloc(n);
|
||||
|
||||
if (p == NULL)
|
||||
oops("malloc: %s", strerror(errno));
|
||||
err(1, "malloc");
|
||||
return p;
|
||||
}
|
||||
|
||||
char *
|
||||
xstrdup(s)
|
||||
const char *s;
|
||||
const char *s;
|
||||
{
|
||||
register char *p = strdup(s);
|
||||
char *p = strdup(s);
|
||||
if (p == NULL)
|
||||
oops("strdup: %s", strerror(errno));
|
||||
err(1, "strdup");
|
||||
return p;
|
||||
}
|
||||
|
||||
char *
|
||||
basename(s)
|
||||
register char *s;
|
||||
char *s;
|
||||
{
|
||||
register char *p;
|
||||
extern char *strrchr();
|
||||
char *p;
|
||||
|
||||
if ((p = strrchr(s, '/')) == NULL)
|
||||
return s;
|
||||
@ -241,32 +239,3 @@ usage()
|
||||
fprintf(stderr, "usage: m4 [-Dname[=val]] [-Uname]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
#if __STDC__
|
||||
oops(const char *fmt, ...)
|
||||
#else
|
||||
oops(fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if __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 */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user