mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
Handle unlimited diverts for m4 -g.
Problem with autoconf noticed by d@
This commit is contained in:
parent
eb0da815ce
commit
25afcddb1d
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: eval.c,v 1.27 2000/07/24 23:08:24 espie Exp $ */
|
||||
/* $OpenBSD: eval.c,v 1.28 2000/07/27 17:44:32 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.27 2000/07/24 23:08:24 espie Exp $";
|
||||
static char rcsid[] = "$OpenBSD: eval.c,v 1.28 2000/07/27 17:44:32 espie Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -743,7 +743,14 @@ dodiv(n)
|
||||
int fd;
|
||||
|
||||
oindex = n;
|
||||
if (n < 0 || n >= MAXOUT)
|
||||
if (n >= maxout) {
|
||||
if (mimic_gnu)
|
||||
resizedivs(n + 10);
|
||||
else
|
||||
n = 0; /* bitbucket */
|
||||
}
|
||||
|
||||
if (n < 0)
|
||||
n = 0; /* bitbucket */
|
||||
if (outfile[n] == NULL) {
|
||||
char fname[] = _PATH_DIVNAME;
|
||||
@ -772,13 +779,13 @@ doundiv(argv, argc)
|
||||
if (argc > 2) {
|
||||
for (ind = 2; ind < argc; ind++) {
|
||||
n = atoi(argv[ind]);
|
||||
if (n > 0 && n < MAXOUT && outfile[n] != NULL)
|
||||
if (n > 0 && n < maxout && outfile[n] != NULL)
|
||||
getdiv(n);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
for (n = 1; n < MAXOUT; n++)
|
||||
for (n = 1; n < maxout; n++)
|
||||
if (outfile[n] != NULL)
|
||||
getdiv(n);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: extern.h,v 1.20 2000/07/24 23:08:25 espie Exp $ */
|
||||
/* $OpenBSD: extern.h,v 1.21 2000/07/27 17:44:33 espie Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
|
||||
|
||||
/*-
|
||||
@ -86,6 +86,7 @@ extern void putback __P((int));
|
||||
extern void *xalloc __P((size_t));
|
||||
extern char *xstrdup __P((const char *));
|
||||
extern void usage __P((void));
|
||||
extern void resizedivs __P((int n));
|
||||
|
||||
extern int obtain_char __P((struct input_file *));
|
||||
extern void set_input __P((struct input_file *, FILE *, const char *));
|
||||
@ -97,7 +98,8 @@ extern stae *mstack; /* stack of m4 machine */
|
||||
extern char *sstack; /* shadow stack, for string space extension */
|
||||
extern FILE *active; /* active output file pointer */
|
||||
extern struct input_file infile[];/* input file stack (0=stdin) */
|
||||
extern FILE *outfile[]; /* diversion array(0=bitbucket) */
|
||||
extern FILE **outfile; /* diversion array(0=bitbucket) */
|
||||
extern int maxout; /* maximum number of diversions */
|
||||
extern int fp; /* m4 call frame pointer */
|
||||
extern int ilevel; /* input file stack pointer */
|
||||
extern int oindex; /* diversion index. */
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" @(#) $OpenBSD: m4.1,v 1.18 2000/07/24 23:08:25 espie Exp $
|
||||
.\" @(#) $OpenBSD: m4.1,v 1.19 2000/07/27 17:44:33 espie Exp $
|
||||
.\"
|
||||
.\"
|
||||
.Dd January 26, 1993
|
||||
@ -70,7 +70,8 @@ to the include path.
|
||||
Activate GNU-m4 compatibility mode.
|
||||
In this mode, changequote with
|
||||
two empty parameters deactivates quotes, translit handles simple character
|
||||
ranges (e.g., a-z) and regular expressions mimic emacs behavior.
|
||||
ranges (e.g., a-z), regular expressions mimic emacs behavior,
|
||||
and the number of diversions is unlimited.
|
||||
.El
|
||||
.Sh SYNTAX
|
||||
.Nm m4
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: main.c,v 1.35 2000/07/24 23:08:25 espie Exp $ */
|
||||
/* $OpenBSD: main.c,v 1.36 2000/07/27 17:44:33 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.35 2000/07/24 23:08:25 espie Exp $";
|
||||
static char rcsid[] = "$OpenBSD: main.c,v 1.36 2000/07/27 17:44:33 espie Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -80,7 +80,8 @@ static size_t STACKMAX; /* current maximum size of stack */
|
||||
int sp; /* current m4 stack pointer */
|
||||
int fp; /* m4 call frame pointer */
|
||||
struct input_file infile[MAXINP];/* input file stack (0=stdin) */
|
||||
FILE *outfile[MAXOUT]; /* diversion array(0=bitbucket)*/
|
||||
FILE **outfile; /* diversion array(0=bitbucket)*/
|
||||
int maxout;
|
||||
FILE *active; /* active output file pointer */
|
||||
int ilevel = 0; /* input file stack pointer */
|
||||
int oindex = 0; /* diversion index.. */
|
||||
@ -188,6 +189,10 @@ main(argc,argv)
|
||||
mstack = (stae *)xalloc(sizeof(stae) * STACKMAX);
|
||||
sstack = (char *)xalloc(STACKMAX);
|
||||
|
||||
maxout = 0;
|
||||
outfile = NULL;
|
||||
resizedivs(MAXOUT);
|
||||
|
||||
while ((c = getopt(argc, argv, "gtD:U:o:I:")) != -1)
|
||||
switch(c) {
|
||||
|
||||
@ -246,7 +251,7 @@ main(argc,argv)
|
||||
|
||||
if (active != stdout)
|
||||
active = stdout; /* reset output just in case */
|
||||
for (n = 1; n < MAXOUT; n++) /* default wrap-up: undivert */
|
||||
for (n = 1; n < maxout; n++) /* default wrap-up: undivert */
|
||||
if (outfile[n] != NULL)
|
||||
getdiv(n);
|
||||
/* remove bitbucket if used */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: misc.c,v 1.19 2000/07/02 01:17:00 espie Exp $ */
|
||||
/* $OpenBSD: misc.c,v 1.20 2000/07/27 17:44:33 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.19 2000/07/02 01:17:00 espie Exp $";
|
||||
static char rcsid[] = "$OpenBSD: misc.c,v 1.20 2000/07/27 17:44:33 espie Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -254,12 +254,28 @@ killdiv()
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n = 0; n < MAXOUT; n++)
|
||||
for (n = 0; n < maxout; n++)
|
||||
if (outfile[n] != NULL) {
|
||||
(void) fclose(outfile[n]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* resizedivs: allocate more diversion files */
|
||||
void
|
||||
resizedivs(n)
|
||||
int n;
|
||||
{
|
||||
int i;
|
||||
|
||||
outfile = (FILE **)realloc(outfile, sizeof(FILE *) * n);
|
||||
if (outfile == NULL)
|
||||
errx(1, "too many diverts %d", n);
|
||||
for (i = maxout; i < n; i++)
|
||||
outfile[i] = NULL;
|
||||
maxout = n;
|
||||
}
|
||||
|
||||
void *
|
||||
xalloc(n)
|
||||
size_t n;
|
||||
|
Loading…
Reference in New Issue
Block a user