diff options
Diffstat (limited to 'grammar')
-rw-r--r-- | grammar/Makefile.am | 4 | ||||
-rw-r--r-- | grammar/grammar.y | 24 | ||||
-rw-r--r-- | grammar/lexer.l | 23 | ||||
-rw-r--r-- | grammar/parserif.h | 2 | ||||
-rw-r--r-- | grammar/rainerscript.c (renamed from grammar/utils.c) | 40 | ||||
-rw-r--r-- | grammar/rainerscript.h (renamed from grammar/utils.h) | 2 | ||||
-rw-r--r-- | grammar/testdriver.c | 2 |
7 files changed, 85 insertions, 12 deletions
diff --git a/grammar/Makefile.am b/grammar/Makefile.am index b482c99e..2b149abe 100644 --- a/grammar/Makefile.am +++ b/grammar/Makefile.am @@ -7,8 +7,8 @@ bin_PROGRAMS = testdriver # TODO: make this conditional libgrammar_la_SOURCES = \ grammar.y \ lexer.l \ - utils.c \ - utils.h \ + rainerscript.c \ + rainerscript.h \ grammar.h testdriver_SOURCES = testdriver.c libgrammar.la diff --git a/grammar/grammar.y b/grammar/grammar.y index 428011c5..b8790411 100644 --- a/grammar/grammar.y +++ b/grammar/grammar.y @@ -9,14 +9,30 @@ * cases. So while we hope that cfsysline support can be dropped some time in * the future, we will probably keep these useful constructs. * - * Copyright (C) 2011 by Rainer Gerhards and Adiscon GmbH - * Released under the GNU GPL v3. For details see LICENSE file. + * Copyright 2011 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of the rsyslog runtime library. + * + * The rsyslog runtime library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The rsyslog runtime library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution. */ - %{ #include <stdio.h> #include <libestr.h> -#include "utils.h" +#include "rainerscript.h" #include "parserif.h" #define YYDEBUG 1 extern int yylineno; diff --git a/grammar/lexer.l b/grammar/lexer.l index ba432b2e..d761003a 100644 --- a/grammar/lexer.l +++ b/grammar/lexer.l @@ -9,8 +9,25 @@ * cases. So while we hope that cfsysline support can be dropped some time in * the future, we will probably keep these useful constructs. * - * Copyright (C) 2011 by Rainer Gerhards and Adiscon GmbH - * Released under the GNU GPL v3. For details see LICENSE file. + * Copyright 2011 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of the rsyslog runtime library. + * + * The rsyslog runtime library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The rsyslog runtime library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution. */ %option noyywrap nodefault case-insensitive yylineno @@ -46,7 +63,7 @@ #include <stdlib.h> #include <strings.h> #include <libestr.h> -#include "utils.h" +#include "rainerscript.h" #include "grammar.h" static int preCommentState; /* save for lex state before a comment */ diff --git a/grammar/parserif.h b/grammar/parserif.h index 0a6434d3..a04abb0c 100644 --- a/grammar/parserif.h +++ b/grammar/parserif.h @@ -1,6 +1,6 @@ #ifndef PARSERIF_H_DEFINED #define PARSERIF_H_DEFINED -#include "utils.h" +#include "rainerscript.h" int cnfSetLexFile(char*); int yyparse(); int yydebug; diff --git a/grammar/utils.c b/grammar/rainerscript.c index f49af9b0..801a52b2 100644 --- a/grammar/utils.c +++ b/grammar/rainerscript.c @@ -1,9 +1,35 @@ +/* rainerscript.c - routines to support RainerScript config language + * + * Module begun 2011-07-01 by Rainer Gerhards + * + * Copyright 2011 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of the rsyslog runtime library. + * + * The rsyslog runtime library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The rsyslog runtime library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution. + */ + +#include "config.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <libestr.h> -#include "utils.h" +#include "rainerscript.h" #include "parserif.h" #include "grammar.h" @@ -388,6 +414,18 @@ cnfexprEval(struct cnfexpr *expr, struct exprret *ret) } } +/* Evaluate an expression as a bool. This is added because expressions are + * mostly used inside filters, and so this function is quite common and + * important. + */ +int +cnfexprEvalBool(struct cnfexpr *expr) +{ + struct exprret ret; + cnfexprEval(expr, &ret); + return exprret2Number(&ret); +} + inline static void doIndent(int indent) { diff --git a/grammar/utils.h b/grammar/rainerscript.h index e75105da..bab7e602 100644 --- a/grammar/utils.h +++ b/grammar/rainerscript.h @@ -1,5 +1,6 @@ #ifndef INC_UTILS_H #define INC_UTILS_H +#include <stdio.h> #include <libestr.h> enum cnfobjType { @@ -161,6 +162,7 @@ struct cnfactlst* cnfactlstReverse(struct cnfactlst *actlst); struct cnfexpr* cnfexprNew(unsigned nodetype, struct cnfexpr *l, struct cnfexpr *r); void cnfexprPrint(struct cnfexpr *expr, int indent); void cnfexprEval(struct cnfexpr *expr, struct exprret *ret); +int cnfexprEvalBool(struct cnfexpr *expr); struct cnfnumval* cnfnumvalNew(long long val); struct cnfstringval* cnfstringvalNew(es_str_t *estr); struct cnfrule * cnfruleNew(enum cnfFiltType filttype, struct cnfactlst *actlst); diff --git a/grammar/testdriver.c b/grammar/testdriver.c index 43f3bd3f..52d2d0c7 100644 --- a/grammar/testdriver.c +++ b/grammar/testdriver.c @@ -26,7 +26,7 @@ #include <stdlib.h> #include <stdarg.h> #include <libestr.h> -#include "utils.h" +#include "rainerscript.h" #include "parserif.h" extern int yylineno; |