|
|
7f924d |
From dcdc2aeafb04d09b9d7ba412d8b417c9fd072c2a Mon Sep 17 00:00:00 2001
|
|
|
7f924d |
From: Alexandre Cassen <acassen@gmail.com>
|
|
|
7f924d |
Date: Tue, 7 Jan 2014 15:38:57 +0100
|
|
|
7f924d |
Subject: [PATCH 4/7] lib: extend command lib string parser
|
|
|
7f924d |
|
|
|
7f924d |
Extend cmd_make_strvec to support quoted string as a single slot and
|
|
|
7f924d |
commented string at the end of parsed string.
|
|
|
7f924d |
---
|
|
|
7f924d |
lib/Makefile.in | 2 +-
|
|
|
7f924d |
lib/command.c | 34 +++++++++++++++++++++++-----------
|
|
|
7f924d |
2 files changed, 24 insertions(+), 12 deletions(-)
|
|
|
7f924d |
|
|
|
7f924d |
diff --git a/lib/Makefile.in b/lib/Makefile.in
|
|
|
7f924d |
index 9eb929e..ee4691f 100644
|
|
|
7f924d |
--- a/lib/Makefile.in
|
|
|
7f924d |
+++ b/lib/Makefile.in
|
|
|
7f924d |
@@ -42,6 +42,6 @@ logger.o: logger.c logger.h
|
|
|
7f924d |
list_head.o: list_head.c list_head.h
|
|
|
7f924d |
buffer.o: buffer.c buffer.h memory.h
|
|
|
7f924d |
command.o: command.c command.h vector.h memory.h vty.h timer.h \
|
|
|
7f924d |
- config.h
|
|
|
7f924d |
+ config.h logger.h
|
|
|
7f924d |
vty.o: vty.c vty.h scheduler.h timer.h utils.h command.h logger.h \
|
|
|
7f924d |
memory.h
|
|
|
7f924d |
diff --git a/lib/command.c b/lib/command.c
|
|
|
7f924d |
index eff59de..4814594 100644
|
|
|
7f924d |
--- a/lib/command.c
|
|
|
7f924d |
+++ b/lib/command.c
|
|
|
7f924d |
@@ -35,7 +35,7 @@
|
|
|
7f924d |
#include "timer.h"
|
|
|
7f924d |
|
|
|
7f924d |
/* Command vector which includes some level of command lists. Normally
|
|
|
7f924d |
- * each daemon maintains each own cmdvec. */
|
|
|
7f924d |
+ * each daemon maintains its own cmdvec. */
|
|
|
7f924d |
vector_t *cmdvec = NULL;
|
|
|
7f924d |
|
|
|
7f924d |
desc_t desc_cr;
|
|
|
7f924d |
@@ -156,7 +156,9 @@ sort_node(void)
|
|
|
7f924d |
|
|
|
7f924d |
/* Breaking up string into each command piece. I assume given
|
|
|
7f924d |
* character is separated by a space character. Return value is a
|
|
|
7f924d |
- * vector which includes char ** data element. */
|
|
|
7f924d |
+ * vector which includes char ** data element. It supports
|
|
|
7f924d |
+ * quoted string as a single slot and commented string at
|
|
|
7f924d |
+ * the end of parsed string */
|
|
|
7f924d |
vector_t *
|
|
|
7f924d |
cmd_make_strvec(const char *string)
|
|
|
7f924d |
{
|
|
|
7f924d |
@@ -187,20 +189,30 @@ cmd_make_strvec(const char *string)
|
|
|
7f924d |
/* Copy each command piece and set into vector. */
|
|
|
7f924d |
while (1) {
|
|
|
7f924d |
start = cp;
|
|
|
7f924d |
- while (!(isspace((int) *cp) || *cp == '\r' || *cp == '\n') &&
|
|
|
7f924d |
- *cp != '\0')
|
|
|
7f924d |
+ if (*cp == '"') {
|
|
|
7f924d |
cp++;
|
|
|
7f924d |
- strlen = cp - start;
|
|
|
7f924d |
- token = (char *) MALLOC(strlen + 1);
|
|
|
7f924d |
- memcpy(token, start, strlen);
|
|
|
7f924d |
- *(token + strlen) = '\0';
|
|
|
7f924d |
- vector_set(strvec, token);
|
|
|
7f924d |
+ token = MALLOC(2);
|
|
|
7f924d |
+ *(token) = '"';
|
|
|
7f924d |
+ *(token + 1) = '\0';
|
|
|
7f924d |
+ } else {
|
|
|
7f924d |
+ while (!(isspace((int) *cp) || *cp == '\r' || *cp == '\n') &&
|
|
|
7f924d |
+ *cp != '\0' && *cp != '"')
|
|
|
7f924d |
+ cp++;
|
|
|
7f924d |
+ strlen = cp - start;
|
|
|
7f924d |
+ token = (char *) MALLOC(strlen + 1);
|
|
|
7f924d |
+ memcpy(token, start, strlen);
|
|
|
7f924d |
+ *(token + strlen) = '\0';
|
|
|
7f924d |
+ }
|
|
|
7f924d |
+
|
|
|
7f924d |
+ /* Alloc & set the slot */
|
|
|
7f924d |
+ vector_alloc_slot(strvec);
|
|
|
7f924d |
+ vector_set_slot(strvec, token);
|
|
|
7f924d |
|
|
|
7f924d |
- while ((isspace ((int) *cp) || *cp == '\n' || *cp == '\r') &&
|
|
|
7f924d |
+ while ((isspace((int) *cp) || *cp == '\n' || *cp == '\r') &&
|
|
|
7f924d |
*cp != '\0')
|
|
|
7f924d |
cp++;
|
|
|
7f924d |
|
|
|
7f924d |
- if (*cp == '\0')
|
|
|
7f924d |
+ if (*cp == '\0' || *cp == '!' || *cp == '#')
|
|
|
7f924d |
return strvec;
|
|
|
7f924d |
}
|
|
|
7f924d |
}
|
|
|
7f924d |
--
|
|
|
7f924d |
1.8.1.4
|
|
|
7f924d |
|