mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
Clean up comment/quote recognition a little bit:
- use strlcpy to make clear that the strings are line terminated, - remove the number of magic constants, - use assert() for preconditions, - use puts instead of looping over array of chars...
This commit is contained in:
parent
4b30c7b23a
commit
b81b15b273
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: eval.c,v 1.20 1999/11/17 15:34:13 espie Exp $ */
|
||||
/* $OpenBSD: eval.c,v 1.21 1999/11/30 22:19:50 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.20 1999/11/17 15:34:13 espie Exp $";
|
||||
static char rcsid[] = "$OpenBSD: eval.c,v 1.21 1999/11/30 22:19:50 espie Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -638,14 +638,14 @@ dochq(argv, argc)
|
||||
{
|
||||
if (argc > 2) {
|
||||
if (*argv[2])
|
||||
strncpy(lquote, argv[2], MAXCCHARS);
|
||||
strlcpy(lquote, argv[2], sizeof(lquote));
|
||||
else {
|
||||
lquote[0] = LQUOTE;
|
||||
lquote[1] = EOS;
|
||||
}
|
||||
if (argc > 3) {
|
||||
if (*argv[3])
|
||||
strncpy(rquote, argv[3], MAXCCHARS);
|
||||
strlcpy(rquote, argv[3], sizeof(rquote));
|
||||
} else
|
||||
strcpy(rquote, lquote);
|
||||
} else {
|
||||
@ -664,10 +664,10 @@ dochc(argv, argc)
|
||||
{
|
||||
if (argc > 2) {
|
||||
if (*argv[2])
|
||||
strncpy(scommt, argv[2], MAXCCHARS);
|
||||
strlcpy(scommt, argv[2], sizeof(scommt));
|
||||
if (argc > 3) {
|
||||
if (*argv[3])
|
||||
strncpy(ecommt, argv[3], MAXCCHARS);
|
||||
strlcpy(ecommt, argv[3], sizeof(ecommt));
|
||||
}
|
||||
else
|
||||
ecommt[0] = ECOMMT, ecommt[1] = EOS;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: extern.h,v 1.12 1999/11/20 17:48:59 espie Exp $ */
|
||||
/* $OpenBSD: extern.h,v 1.13 1999/11/30 22:19:50 espie Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
|
||||
|
||||
/*-
|
||||
@ -85,11 +85,11 @@ extern pbent *bp; /* first available character */
|
||||
extern pbent *buf; /* push-back buffer */
|
||||
extern pbent *bufbase; /* buffer base for this ilevel */
|
||||
extern pbent *bbase[]; /* buffer base per ilevel */
|
||||
extern char ecommt[]; /* end character for comment */
|
||||
extern char ecommt[MAXCCHARS+1];/* end character for comment */
|
||||
extern char *ep; /* first free char in strspace */
|
||||
extern char lquote[]; /* left quote character (`) */
|
||||
extern char lquote[MAXCCHARS+1];/* left quote character (`) */
|
||||
extern char *m4wraps; /* m4wrap string default. */
|
||||
extern char *null; /* as it says.. just a null. */
|
||||
extern char rquote[]; /* right quote character (') */
|
||||
extern char scommt[]; /* start character for comment */
|
||||
extern char rquote[MAXCCHARS+1];/* right quote character (') */
|
||||
extern char scommt[MAXCCHARS+1];/* start character for comment */
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: main.c,v 1.20 1999/11/25 00:54:22 millert Exp $ */
|
||||
/* $OpenBSD: main.c,v 1.21 1999/11/30 22:19:50 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.20 1999/11/25 00:54:22 millert Exp $";
|
||||
static char rcsid[] = "$OpenBSD: main.c,v 1.21 1999/11/30 22:19:50 espie Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -58,6 +58,7 @@ static char rcsid[] = "$OpenBSD: main.c,v 1.20 1999/11/25 00:54:22 millert Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
@ -230,7 +231,7 @@ main(argc,argv)
|
||||
}
|
||||
|
||||
/*
|
||||
* Look ahead (at most MAXCCHARS characters) for `token'.
|
||||
* Look ahead for `token'.
|
||||
* (on input `t == token[0]')
|
||||
* Used for comment and quoting delimiters.
|
||||
* Returns 1 if `token' present; copied to output.
|
||||
@ -243,8 +244,7 @@ do_look_ahead(t, token)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (t != token[0])
|
||||
errx(1, "internal error");
|
||||
assert(t == token[0]);
|
||||
|
||||
for (i = 1; *++token; i++) {
|
||||
t = gpbc();
|
||||
@ -356,16 +356,12 @@ macro()
|
||||
}
|
||||
|
||||
else if (sp < 0 && LOOK_AHEAD(t, scommt)) {
|
||||
int i;
|
||||
for (i = 0; i < MAXCCHARS && scommt[i]; i++)
|
||||
putc(scommt[i], active);
|
||||
fputs(scommt, active);
|
||||
|
||||
for(;;) {
|
||||
t = gpbc();
|
||||
if (LOOK_AHEAD(t, ecommt)) {
|
||||
for (i = 0; i < MAXCCHARS && ecommt[i];
|
||||
i++)
|
||||
putc(ecommt[i], active);
|
||||
fputs(ecommt, active);
|
||||
break;
|
||||
}
|
||||
if (t == EOF)
|
||||
|
Loading…
Reference in New Issue
Block a user