summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorlum <lum@openbsd.org>2021-03-25 12:46:11 +0000
committerlum <lum@openbsd.org>2021-03-25 12:46:11 +0000
commit93960a547c091f52084d4abca39db7a9dc189e73 (patch)
tree577fe1b38c104ddbf8c09258702698727c3a800d /usr.bin
parentAdjust HTTP client code a bit. Add support for 304 Not Modified responses, (diff)
downloadwireguard-openbsd-93960a547c091f52084d4abca39db7a9dc189e73.tar.xz
wireguard-openbsd-93960a547c091f52084d4abca39db7a9dc189e73.zip
Use length of line to indicate end of characters to process in
foundparen(). No intended functional change. regress tests ok and they all use excline().
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/def.h6
-rw-r--r--usr.bin/mg/extend.c30
-rw-r--r--usr.bin/mg/interpreter.c20
3 files changed, 34 insertions, 22 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 0c436ef5bc2..c224f86c29a 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.170 2021/03/21 12:56:16 lum Exp $ */
+/* $OpenBSD: def.h,v 1.171 2021/03/25 12:46:11 lum Exp $ */
/* This file is in the public domain. */
@@ -582,7 +582,7 @@ int evalexpr(int, int);
int evalbuffer(int, int);
int evalfile(int, int);
int load(const char *);
-int excline(char *);
+int excline(char *, int);
char *skipwhite(char *);
/* help.c X */
@@ -720,7 +720,7 @@ int dobeep_msg(const char *);
void dobeep(void);
/* interpreter.c */
-int foundparen(char *);
+int foundparen(char *, int);
void cleanup(void);
/*
diff --git a/usr.bin/mg/extend.c b/usr.bin/mg/extend.c
index 31c7f378074..3d6009044a0 100644
--- a/usr.bin/mg/extend.c
+++ b/usr.bin/mg/extend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: extend.c,v 1.73 2021/03/21 12:56:16 lum Exp $ */
+/* $OpenBSD: extend.c,v 1.74 2021/03/25 12:46:11 lum Exp $ */
/* This file is in the public domain. */
/*
@@ -570,19 +570,24 @@ extend(int f, int n)
/*
* evalexpr - get one line from the user, and run it.
+ * Use strlen for length of line, assume user is not typing in a '\0' in the
+ * modeline. llen only used for foundparen() so old-school will be ok.
*/
/* ARGSUSED */
int
evalexpr(int f, int n)
{
char exbuf[BUFSIZE], *bufp;
+ int llen;
if ((bufp = eread("Eval: ", exbuf, sizeof(exbuf),
EFNEW | EFCR)) == NULL)
return (ABORT);
else if (bufp[0] == '\0')
return (FALSE);
- return (excline(exbuf));
+ llen = strlen(bufp);
+
+ return (excline(exbuf, llen));
}
/*
@@ -595,17 +600,18 @@ evalbuffer(int f, int n)
{
struct line *lp;
struct buffer *bp = curbp;
- int s;
+ int s, llen;
static char excbuf[BUFSIZE];
for (lp = bfirstlp(bp); lp != bp->b_headp; lp = lforw(lp)) {
- if (llength(lp) >= BUFSIZE)
+ llen = llength(lp);
+ if (llen >= BUFSIZE)
return (FALSE);
- (void)strncpy(excbuf, ltext(lp), llength(lp));
+ (void)strncpy(excbuf, ltext(lp), llen);
- /* make sure it's terminated */
- excbuf[llength(lp)] = '\0';
- if ((s = excline(excbuf)) != TRUE) {
+ /* make sure the line is terminated */
+ excbuf[llen] = '\0';
+ if ((s = excline(excbuf, llen)) != TRUE) {
cleanup();
return (s);
}
@@ -661,7 +667,7 @@ load(const char *fname)
== FIOSUC) {
line++;
excbuf[nbytes] = '\0';
- if (excline(excbuf) != TRUE) {
+ if (excline(excbuf, nbytes) != TRUE) {
s = FIOERR;
dobeep();
ewprintf("Error loading file %s at line %d", fncpy, line);
@@ -670,7 +676,7 @@ load(const char *fname)
}
(void)ffclose(ffp, NULL);
excbuf[nbytes] = '\0';
- if (s != FIOEOF || (nbytes && excline(excbuf) != TRUE))
+ if (s != FIOEOF || (nbytes && excline(excbuf, nbytes) != TRUE))
return (FALSE);
return (TRUE);
}
@@ -679,7 +685,7 @@ load(const char *fname)
* excline - run a line from a load file or eval-expression.
*/
int
-excline(char *line)
+excline(char *line, int llen)
{
PF fp;
struct line *lp, *np;
@@ -706,7 +712,7 @@ excline(char *line)
if (*funcp == '\0')
return (TRUE); /* No error on blank lines */
if (*funcp == '(')
- return (foundparen(funcp));
+ return (foundparen(funcp, llen));
line = parsetoken(funcp);
if (*line != '\0') {
*line++ = '\0';
diff --git a/usr.bin/mg/interpreter.c b/usr.bin/mg/interpreter.c
index d71ce4159f3..6c52b0f45bf 100644
--- a/usr.bin/mg/interpreter.c
+++ b/usr.bin/mg/interpreter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: interpreter.c,v 1.13 2021/03/23 15:22:25 lum Exp $ */
+/* $OpenBSD: interpreter.c,v 1.14 2021/03/25 12:46:11 lum Exp $ */
/*
* This file is in the public domain.
*
@@ -41,6 +41,12 @@
* [...]
* n. implement user definable functions.
*
+ * Notes:
+ * - Currently calls to excline() from this file have the line length set to
+ * zero. That's because excline() uses '\0' as the end of line indicator
+ * and only the call to foundparen() within excline() uses excline's 2nd
+ * argument. Importantly, any lines sent to there from here will not be
+ * coming back here.
*/
#include <sys/queue.h>
@@ -108,12 +114,12 @@ char scharkey[NUMSCHKEYS][MAXLENSCHKEYS] =
* Multi-line not supported at the moment, To do.
*/
int
-foundparen(char *funstr)
+foundparen(char *funstr, int llen)
{
struct expentry *e1 = NULL, *e2 = NULL;
char *p, *valp, *endp = NULL, *regs;
char expbuf[BUFSIZE], tmpbuf[BUFSIZE];
- int ret, pctr, fndstart, expctr, blkid, fndchr, fndend;
+ int i, ret, pctr, fndstart, expctr, blkid, fndchr, fndend;
int inquote;
pctr = fndstart = expctr = fndchr = fndend = inquote = 0;
@@ -146,7 +152,7 @@ foundparen(char *funstr)
*/
TAILQ_INIT(&ehead);
- while (*p != '\0') {
+ for (i = llen; i > 0; --i) {
if (*p == '(') {
if (fndstart == 1) {
if (endp == NULL)
@@ -241,7 +247,7 @@ foundparen(char *funstr)
mglog_misc("exp|%s|\n", e1->exp);
#endif
}
-
+
ret = parseexp(expbuf);
if (ret == FALSE)
cleanup();
@@ -309,7 +315,7 @@ multiarg(char *funstr)
/* mg function name regex */
if (doregex("^[A-Za-z-]+$", funstr))
- return(excline(funstr));
+ return(excline(funstr, 0));
cmdp = funstr;
fendp = strchr(cmdp, ' ');
@@ -406,7 +412,7 @@ multiarg(char *funstr)
>= sizeof(excbuf))
return (dobeep_msg("strlcat error"));
- excline(excbuf);
+ excline(excbuf, 0);
if (fin)
break;