From f6ea0a79a8742c34400886ec8ab851408a2c43a8 Mon Sep 17 00:00:00 2001 From: David Adrian Date: Fri, 4 Oct 2013 10:53:03 -0400 Subject: [PATCH] Build filter using CMake --- CMakeLists.txt | 2 +- src/.gitignore | 4 ++++ src/CMakeLists.txt | 14 ++++++++++++++ src/expression.h | 2 ++ src/filter.c | 3 ++- src/lexer.c | 11 ++++++----- src/lexer.h | 6 ++++-- src/lexer.l | 2 +- src/parser.c | 6 +++--- src/y.tab.h | 20 -------------------- 10 files changed, 37 insertions(+), 33 deletions(-) create mode 100644 src/.gitignore delete mode 100644 src/y.tab.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a403b7..e27443e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ if(ENABLE_DEVELOPMENT) "-Wnested-externs -Wbad-function-cast -Winit-self" "-Wmissing-noreturn -Wnormalized=id" "-Wstack-protector" - "-Werror" + #"-Werror" ) # Fix line breaks diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..87de78c --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,4 @@ +lexer.c +lexer.h +parser.c +parser.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50bf1ee..44ce551 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,7 @@ SET(LIB_SOURCES ${PROJECT_SOURCE_DIR}/lib/logger.c ${PROJECT_SOURCE_DIR}/lib/random.c ${PROJECT_SOURCE_DIR}/lib/rijndael-alg-fst.c + ${PROJECT_SOURCE_DIR}/lib/xalloc.c ) # ADD YOUR PROBE MODULE HERE @@ -41,16 +42,21 @@ SET(PROBE_MODULE_SOURCES SET(SOURCES aesrand.c cyclic.c + expression.c fieldset.c + filter.c get_gateway.c monitor.c recv.c send.c + stack.c state.c validate.c zmap.c zopt_compat.c "${CMAKE_CURRENT_BINARY_DIR}/zopt.h" + "${CMAKE_CURRENT_BINARY_DIR}/lexer.c" + "${CMAKE_CURRENT_BINARY_DIR}/parser.c" ${EXTRA_PROBE_MODULES} ${EXTRA_OUTPUT_MODULES} ${PROBE_MODULE_SOURCES} @@ -70,6 +76,14 @@ add_custom_command(OUTPUT zopt.h COMMAND gengetopt -C --no-help --no-version -i "${CMAKE_CURRENT_SOURCE_DIR}/zopt.ggo" -F "${CMAKE_CURRENT_BINARY_DIR}/zopt" ) +add_custom_command(OUTPUT lexer.c + COMMAND flex -o "${CMAKE_CURRENT_BINARY_DIR}/lexer.c" --header-file="${CMAKE_CURRENT_BINARY_DIR}/lexer.h" lexer.l + ) + +add_custom_command(OUTPUT parser.c + COMMAND byacc -d -o parser.c parser.y + ) + add_executable(zmap ${SOURCES}) target_link_libraries( diff --git a/src/expression.h b/src/expression.h index 7ff5068..d65668d 100644 --- a/src/expression.h +++ b/src/expression.h @@ -45,4 +45,6 @@ node_t* make_int_node(int literal); int evaluate_expression(node_t *root, fieldset_t *fields); +void print_expression(node_t *root); + #endif /* ZMAP_TREE_H */ \ No newline at end of file diff --git a/src/filter.c b/src/filter.c index 49165f3..7bc4c8d 100644 --- a/src/filter.c +++ b/src/filter.c @@ -1,7 +1,8 @@ #include "filter.h" #include "state.h" #include "lexer.h" -#include "y.tab.h" +#include "parser.h" +#include "expression.h" #include "../lib/logger.h" #include diff --git a/src/lexer.c b/src/lexer.c index b5be489..52a5b1c 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -1,5 +1,6 @@ +#line 2 "/home/david/mac/SourceCode/zmap/src/lexer.c" -#line 3 "" +#line 4 "/home/david/mac/SourceCode/zmap/src/lexer.c" #define YY_INT_ALIGNED short int @@ -469,10 +470,10 @@ char *yytext; #line 1 "lexer.l" #line 2 "lexer.l" #include -#include "y.tab.h" +#include "parser.h" #define YY_NO_INPUT 1 -#line 476 "" +#line 477 "/home/david/mac/SourceCode/zmap/src/lexer.c" #define INITIAL 0 @@ -659,7 +660,7 @@ YY_DECL #line 9 "lexer.l" -#line 663 "" +#line 664 "/home/david/mac/SourceCode/zmap/src/lexer.c" if ( !(yy_init) ) { @@ -818,7 +819,7 @@ YY_RULE_SETUP #line 25 "lexer.l" ECHO; YY_BREAK -#line 822 "" +#line 823 "/home/david/mac/SourceCode/zmap/src/lexer.c" case YY_STATE_EOF(INITIAL): yyterminate(); diff --git a/src/lexer.h b/src/lexer.h index 42a19e9..fe793da 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -2,7 +2,9 @@ #define yyHEADER_H 1 #define yyIN_HEADER 1 -#line 6 "lexer.h" +#line 6 "/home/david/mac/SourceCode/zmap/src/lexer.h" + +#line 8 "/home/david/mac/SourceCode/zmap/src/lexer.h" #define YY_INT_ALIGNED short int @@ -325,6 +327,6 @@ extern int yylex (void); #line 25 "lexer.l" -#line 329 "lexer.h" +#line 331 "/home/david/mac/SourceCode/zmap/src/lexer.h" #undef yyIN_HEADER #endif /* yyHEADER_H */ diff --git a/src/lexer.l b/src/lexer.l index 0fa3b90..f1ee546 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -1,6 +1,6 @@ %{ #include -#include "y.tab.h" +#include "parser.h" %} diff --git a/src/parser.c b/src/parser.c index 86802d1..43047ca 100644 --- a/src/parser.c +++ b/src/parser.c @@ -49,7 +49,7 @@ typedef union { struct node *expr; } YYSTYPE; #endif /* !YYSTYPE_IS_DECLARED */ -#line 52 "y.tab.c" +#line 52 "parser.c" /* compatibility with bison */ #ifdef YYPARSE_PARAM @@ -250,7 +250,7 @@ static YYSTACKDATA yystack; #line 144 "parser.y" -#line 253 "y.tab.c" +#line 253 "parser.c" #if YYDEBUG #include /* needed for printf */ @@ -566,7 +566,7 @@ case 15: yyval.expr->right_child = make_field_node(yystack.l_mark[0].string_literal); } break; -#line 569 "y.tab.c" +#line 569 "parser.c" } yystack.s_mark -= yym; yystate = *yystack.s_mark; diff --git a/src/y.tab.h b/src/y.tab.h deleted file mode 100644 index 8f8af3a..0000000 --- a/src/y.tab.h +++ /dev/null @@ -1,20 +0,0 @@ -#define T_AND 257 -#define T_OR 258 -#define T_NUMBER 259 -#define T_FIELD 260 -#define T_NOT_EQ 261 -#define T_GT_EQ 262 -#define T_LT_EQ 263 -#ifdef YYSTYPE -#undef YYSTYPE_IS_DECLARED -#define YYSTYPE_IS_DECLARED 1 -#endif -#ifndef YYSTYPE_IS_DECLARED -#define YYSTYPE_IS_DECLARED 1 -typedef union { - int int_literal; - char *string_literal; - struct node *expr; -} YYSTYPE; -#endif /* !YYSTYPE_IS_DECLARED */ -extern YYSTYPE yylval;