summaryrefslogtreecommitdiffstats
path: root/grammar
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-07-04 16:00:26 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2011-07-04 16:00:26 +0200
commit460010068b1d46c23829e7106380ffb8527df949 (patch)
treed8fbd4284d6769f5659d5d4cd6c71d5509c03fa1 /grammar
parentbffa39ab9539c0e26dbbfb450f42de93638292e1 (diff)
downloadrsyslog-460010068b1d46c23829e7106380ffb8527df949.tar.gz
rsyslog-460010068b1d46c23829e7106380ffb8527df949.tar.xz
rsyslog-460010068b1d46c23829e7106380ffb8527df949.zip
milestone: strings and vars are now stored correctly in in-memory representation
Diffstat (limited to 'grammar')
-rw-r--r--grammar/debian.new6
-rw-r--r--grammar/rscript.l7
-rw-r--r--grammar/rscript.y15
-rw-r--r--grammar/utils.c20
-rw-r--r--grammar/utils.h12
5 files changed, 43 insertions, 17 deletions
diff --git a/grammar/debian.new b/grammar/debian.new
index e995a2e8..6cf9b5e5 100644
--- a/grammar/debian.new
+++ b/grammar/debian.new
@@ -47,7 +47,7 @@ $Umask 0022
#
# Include all config files in /etc/rsyslog.d/
#
-$IncludeConfig /etc/rsyslog.d/*.conf
+#$IncludeConfig /etc/rsyslog.d/*.conf
###############
@@ -102,7 +102,7 @@ daemon.*;mail.*;\
global (dnscache="yes" arg1="1 2" arg2 = "1 2" arg3 ="1=2\"3")
# samples added to get full "flavor" of what we need to support...
:msg, contains, "error" /var/log/somelog
-action(type=omfile target=/var/log/mail/log)
+action(type="omfile" target="/var/log/mail/log")
*.* /* comment */ * # test
*.info :ommysql:, tra, la , la # comment (comment to be part of old style line!)
@@ -134,7 +134,7 @@ then /dev/tty10
& |/dev/xconsole
*.* rger # write to user (ugly...)
-ruleset name
+#ruleset name
# FEDORA, a bit more complex config
# ### begin forwarding rule ###
diff --git a/grammar/rscript.l b/grammar/rscript.l
index 68f4d406..37f08f66 100644
--- a/grammar/rscript.l
+++ b/grammar/rscript.l
@@ -82,8 +82,11 @@ char *currfn; /* name of currently processed file */
<EXPR>0[0-7]+ | /* octal number */
<EXPR>0x[0-7a-f] | /* hex number, following rule is dec; strtoll handles all! */
<EXPR>([1-9][0-9]*|0) { yylval.n = strtoll(yytext, NULL, 0); return NUMBER; }
-<EXPR>\$[$!]{0,1}[a-z][a-z0-9\-_\.]* { printf("VARNAME: '%s'\n", yytext); return VAR; }
-<EXPR>\'([^'\\]|\\['])*\' { printf("EXPR string: -%s-\n", yytext); return STRING; }
+<EXPR>\$[$!]{0,1}[a-z][a-z0-9\-_\.]* { yylval.s = strdup(yytext); return VAR; }
+<EXPR>\'([^'\\]|\\['])*\' { yylval.estr = es_newStrFromBuf(yytext+1, yyleng-2);
+ return STRING; }
+<EXPR>\"([^"\\]|\\["])*\" { yylval.estr = es_newStrFromBuf(yytext+1, yyleng-2);
+ return STRING; }
<EXPR>[ \t\n]
<EXPR>. { printf("invalid char in expr: %s\n", yytext); }
"&" { return '&'; }
diff --git a/grammar/rscript.y b/grammar/rscript.y
index aaf133eb..281a1775 100644
--- a/grammar/rscript.y
+++ b/grammar/rscript.y
@@ -35,7 +35,7 @@ extern int yylineno;
%token OR
%token AND
%token NOT
-%token VAR
+%token <s> VAR
%token <estr> STRING
%token <n> NUMBER
%token CMP_EQ
@@ -148,19 +148,10 @@ expr: expr AND expr { $$ = cnfexprNew(AND, $1, $3); }
| '-' expr %prec UMINUS { $$ = cnfexprNew('M', NULL, $2); }
| NUMBER { $$ = (struct cnfexpr*) cnfnumvalNew($1); }
| STRING { $$ = (struct cnfexpr*) cnfstringvalNew($1); }
- | VAR { printf("variables not yet implemented!\n"); }
+ | VAR { $$ = (struct cnfexpr*) cnfvarNew($1); }
%%
int yyerror(char *s)
{
- printf("yyerror called: %s\n", s);
+ printf("parse failure on or before line %d: %s\n", yylineno, s);
}
-
-/*
-int main()
-{
- yydebug = 0;
- return yyparse();
-}
-
-*/
diff --git a/grammar/utils.c b/grammar/utils.c
index b04274c1..791a8967 100644
--- a/grammar/utils.c
+++ b/grammar/utils.c
@@ -481,6 +481,15 @@ cnfexprPrint(struct cnfexpr *expr, int indent)
doIndent(indent);
printf("%lld\n", ((struct cnfnumval*)expr)->val);
break;
+ case 'V':
+ doIndent(indent);
+ printf("var '%s'\n", ((struct cnfvar*)expr)->name);
+ break;
+ case 'S':
+ doIndent(indent);
+ cstrPrint("string '", ((struct cnfstringval*)expr)->estr);
+ printf("'\n");
+ break;
case '+':
case '-':
case '*':
@@ -522,6 +531,17 @@ cnfstringvalNew(es_str_t *estr)
return strval;
}
+struct cnfvar*
+cnfvarNew(char *name)
+{
+ struct cnfvar *var;
+ if((var = malloc(sizeof(struct cnfvar))) != NULL) {
+ var->nodetype = 'V';
+ var->name = name;
+ }
+ return var;
+}
+
struct cnfrule *
cnfruleNew(enum cnfFiltType filttype, struct cnfactlst *actlst)
{
diff --git a/grammar/utils.h b/grammar/utils.h
index 9dfac5b1..fb1462a3 100644
--- a/grammar/utils.h
+++ b/grammar/utils.h
@@ -60,6 +60,12 @@ struct cnfactlst {
/* the following structures support expressions, and may (very much later
* be the sole foundation for the AST.
+ *
+ * nodetypes (list not yet complete)
+ * S - string
+ * N - number
+ * V - var
+ * R - rule
*/
enum cnfFiltType { CNFFILT_NONE, CNFFILT_PRI, CNFFILT_PROP, CNFFILT_SCRIPT };
static inline char*
@@ -105,6 +111,11 @@ struct cnfstringval {
es_str_t *estr;
};
+struct cnfvar {
+ unsigned nodetype;
+ char *name;
+};
+
/* future extensions
struct x {
int nodetype;
@@ -140,6 +151,7 @@ struct cnfnumval* cnfnumvalNew(long long val);
struct cnfstringval* cnfstringvalNew(es_str_t *estr);
struct cnfrule * cnfruleNew(enum cnfFiltType filttype, struct cnfactlst *actlst);
void cnfrulePrint(struct cnfrule *rule);
+struct cnfvar* cnfvarNew(char *name);
/* debug helper */
void cstrPrint(char *text, es_str_t *estr);