summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlum <lum@openbsd.org>2021-03-08 20:01:43 +0000
committerlum <lum@openbsd.org>2021-03-08 20:01:43 +0000
commite5364bf1da4feae1a338f57b579b4afc5b0487bf (patch)
treec86a788e937f26d37e17656495258826606103f4
parentPut regex tests into a function. (diff)
downloadwireguard-openbsd-e5364bf1da4feae1a338f57b579b4afc5b0487bf.tar.xz
wireguard-openbsd-e5364bf1da4feae1a338f57b579b4afc5b0487bf.zip
Start looking at parsing text to find separators.
-rw-r--r--usr.bin/mg/interpreter.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/usr.bin/mg/interpreter.c b/usr.bin/mg/interpreter.c
index a3f81639893..1100237d836 100644
--- a/usr.bin/mg/interpreter.c
+++ b/usr.bin/mg/interpreter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: interpreter.c,v 1.8 2021/03/08 18:27:33 lum Exp $ */
+/* $OpenBSD: interpreter.c,v 1.9 2021/03/08 20:01:43 lum Exp $ */
/*
* This file is in the public domain.
*
@@ -373,7 +373,29 @@ clearvars(void)
int
foundparen(char *funstr)
{
- char *regs;
+ char *regs, *p;
+ int pctr;
+
+ pctr = 0;
+
+ /*
+ * Check for blocks of code with opening and closing ().
+ * One block = (cmd p a r a m)
+ * Two blocks = (cmd p a r a m s)(hola)
+ * Two blocks = (cmd p a r (list a m s))(hola)
+ * Only single line at moment, but more for multiline.
+ */
+ p = funstr;
+ while (*p != '\0') {
+ if (*p == '(') {
+ pctr++;
+ } else if (*p == ')') {
+ pctr--;
+ }
+ p++;
+ }
+ if (pctr != 0)
+ return(dobeep_msg("Opening and closing parentheses error"));
/* Does the line have a list 'define' like: */
/* (define alist(list 1 2 3 4)) */
@@ -411,8 +433,7 @@ doregex(char *r, char *e)
if (!regexec(&regex_buff, e, 0, NULL, 0)) {
regfree(&regex_buff);
return(TRUE);
- } else {
- regfree(&regex_buff);
- return(dobeep_msg("Regex execution error"));
}
+ regfree(&regex_buff);
+ return(FALSE);
}