summaryrefslogtreecommitdiff
path: root/src/cparse/cparse_lex.l
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2010-11-12 19:12:53 -0800
committerAn-Cheng Huang <ancheng@vyatta.com>2010-11-12 19:12:53 -0800
commit79a94470b0f3fd4f7924bb096c61b8e064b65750 (patch)
tree049225edbd21f873b9a4bcac6571603a35aa1e89 /src/cparse/cparse_lex.l
parente08c1879028ddd3b594b01c82859f8431894f497 (diff)
downloadvyatta-cfg-79a94470b0f3fd4f7924bb096c61b8e064b65750.tar.gz
vyatta-cfg-79a94470b0f3fd4f7924bb096c61b8e064b65750.zip
initial work to parse config file into data structure.
Diffstat (limited to 'src/cparse/cparse_lex.l')
-rw-r--r--src/cparse/cparse_lex.l24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/cparse/cparse_lex.l b/src/cparse/cparse_lex.l
index 167e2af..1afe886 100644
--- a/src/cparse/cparse_lex.l
+++ b/src/cparse/cparse_lex.l
@@ -9,6 +9,9 @@ ID ([-[:alnum:]_]+)
SPACE ([[:space:]]{-}[\n])
%{
+/* get rid of compiler warning */
+#define YY_NO_INPUT 1
+
#include <string.h>
#include "cparse_def.h"
#include "cparse.h"
@@ -80,8 +83,21 @@ set_ret_str()
}
<sComment>"*/" {
+ char *tmp;
+ size_t tlen;
set_ret_str();
- cparse_lval.str = strdup(out_buf);
+
+ /* need to strip out leading or trailing space */
+ tmp = out_buf;
+ tlen = strlen(tmp);
+ if (tlen > 0 && tmp[tlen - 1] == ' ') {
+ tmp[tlen - 1] = 0;
+ --tlen;
+ }
+ if (tlen > 0 && tmp[0] == ' ') {
+ ++tmp;
+ }
+ cparse_lval.str = strdup(tmp);
BEGIN(INITIAL);
return COMMENT;
}
@@ -90,7 +106,11 @@ set_ret_str()
node_deactivated = 1;
}
-<INITIAL>[[:space:]]+ {
+<INITIAL>{SPACE}+ {
+}
+
+<INITIAL>\n {
+ ++cparse_lineno;
}
<INITIAL>\} {