This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository e16.

View the commit online.

commit 30bdaa84cb48bce58a3bb73f8e0919234285c7f0
Author: Kim Woelders <k...@woelders.dk>
AuthorDate: Mon Jun 26 15:43:28 2023 +0200

    bindings: Handle quoting in AclassConfigLineParse()
    
    Commands in bindings can now use quoting.
    
    Suggested by Dennis Nezic.
---
 src/aclass.c |  5 +----
 src/string.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 src/util.h   |  1 +
 3 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/src/aclass.c b/src/aclass.c
index d1434296..c9daa5ec 100644
--- a/src/aclass.c
+++ b/src/aclass.c
@@ -693,10 +693,7 @@ AclassConfigLineParse(char *s, ActionClass ** pac, Action ** paa)
    Action             *aa = *paa;
    int                 len, len2;
 
-   len = strcspn(s, "#\r\n");
-   if (len <= 0)
-      return;
-   s[len] = '\0';
+   s = Estrtrim2(s);
 
    prm2[0] = prm3[0] = '\0';
    len2 = 0;
diff --git a/src/string.c b/src/string.c
index e479b3d3..425e8847 100644
--- a/src/string.c
+++ b/src/string.c
@@ -142,6 +142,51 @@ Estrtrim(char *s)
    return s;
 }
 
+/*
+ * Trim comments and trailing whitespace
+ */
+char               *
+Estrtrim2(char *s)
+{
+   int                 len, len2, ch, quote;
+
+   while (isspace(*s) == ' ')
+      s++;
+
+   quote = '\0';
+   for (len = len2 = 0;; len++)
+     {
+	ch = s[len];
+	switch (ch)
+	  {
+	  default:
+	     break;
+	  case '\0':
+	  case '\n':
+	  case '\r':
+	     goto got_len;
+	  case '\'':
+	  case '"':
+	     quote = (ch == quote) ? '\0' : ch;
+	     break;
+	  case '#':
+	     if (quote)
+		break;
+	     goto got_len;
+	  case ' ':
+	  case '\t':
+	     if (quote)
+		break;
+	     continue;
+	  }
+	len2 = len + 1;
+     }
+ got_len:
+   s[len2] = '\0';
+
+   return s;
+}
+
 #if 0				/* Unused */
 char              **
 StrlistDup(char **lst, int num)
diff --git a/src/util.h b/src/util.h
index 6bbf4f43..d560bda4 100644
--- a/src/util.h
+++ b/src/util.h
@@ -110,6 +110,7 @@ void __PRINTF__     Eprintf(const char *fmt, ...);
 void                EnvSubst(const char *str, char *bptr, unsigned int blen);
 
 char               *Estrtrim(char *s);
+char               *Estrtrim2(char *s);
 
 char              **StrlistDup(char **lst, int num);
 void                StrlistFree(char **lst, int num);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to