diff --git a/gtests/net/packetdrill/lexer.l b/gtests/net/packetdrill/lexer.l index 5ad8469738501d5cc0e150ea61e5605dff2b6d4d..d68bf4eed187d38a1f1870a384836f3ba59f601a 100644 --- a/gtests/net/packetdrill/lexer.l +++ b/gtests/net/packetdrill/lexer.l @@ -104,7 +104,7 @@ static s64 hextol(const char *s) } enum ifdef_os { - Linux_IFDEF = 1, FreeBSD_IFDEF, NetBSD_IFDEF, OpenBSD_IFDEF + Linux_IFDEF = 1, FreeBSD_IFDEF, NetBSD_IFDEF, OpenBSD_IFDEF, Omnet_IFDEF }; #define MAX_IFDEF_DEPTH 1 @@ -121,6 +121,8 @@ static inline int get_os_name_length(enum ifdef_os os) { return strlen("NetBSD"); case OpenBSD_IFDEF: return strlen("OpenBSD"); + case Omnet_IFDEF: + return strlen("Omnet"); default: return -1; } @@ -147,7 +149,7 @@ static inline bool ignore_ifdef(enum ifdef_os os) { return false; } #endif - + /* no need to handle Omnet here */ return true; } @@ -156,39 +158,39 @@ static inline char* remove_ifdef_start_and_endtag(char *code, int os_name_length unsigned int endif_length = strlen("#endif"); unsigned int newline_before_endif = 0; char *code_without_ifdef = NULL; - + code_without_ifdef = code + ifdef_length + os_name_length; newline_before_endif = strlen(code_without_ifdef) - endif_length; code_without_ifdef[newline_before_endif] = (char) 0; return code_without_ifdef; } - + static void handle_ifdef(enum ifdef_os os, const char *s) { char *code = NULL; char *code_without_ifdef = NULL; int os_name_length = get_os_name_length(os); - + if (os_name_length == -1) { fprintf(stderr, "handle_ifdef with unknown os called.\n"); exit(1); } - + if (ignore_ifdef(os)) { return; } - + if (ifdef_stack_ptr >= MAX_IFDEF_DEPTH) { fprintf(stderr, "Ifdefs nested too deeply"); exit(1); } - + code = strdup(s); code_without_ifdef = remove_ifdef_start_and_endtag(code, os_name_length); ifdef_stack[ifdef_stack_ptr++] = YY_CURRENT_BUFFER; yy_switch_to_buffer(yy_scan_string(code_without_ifdef)); - + free(code); } @@ -214,9 +216,10 @@ c_comment \/\*(([^*])|(\*[^\/]))*\*\/ /* This matches the following platform specific #ifdef-forms: * #ifdef Linux => Code that only Linux hosts should execute * #ifdef FreeBSD => Code that only FreeBSD hosts should execute - * #ifdef OpenBSD => Code that only OpenBSD hosts should execute * #ifdef NetBSD => Code that only NetBSD hosts should execute - * + * #ifdef OpenBSD => Code that only OpenBSD hosts should execute + * #ifdef Omnet => Code that only an Omnet based simulation should execute + * * the pattern for using #ifdef is like this: * #ifdef Linux * (specific code only for linux) @@ -230,9 +233,10 @@ ifdef_end #endif end_matcher (([^#])|(#[^e])|(#e[^n])|(#en[^d])|(#end[^i])|(#endi[^f]))* ifdef_freebsd {ifdef_begin}(?i:FreeBSD){end_matcher}{ifdef_end} -ifdef_linux {ifdef_begin}(?i:Linux){end_matcher}{ifdef_end} -ifdef_openbsd {ifdef_begin}(?i:OpenBSD){end_matcher}{ifdef_end} +ifdef_linux {ifdef_begin}(?i:Linux){end_matcher}{ifdef_end} ifdef_netbsd {ifdef_begin}(?i:NetBSD){end_matcher}{ifdef_end} +ifdef_openbsd {ifdef_begin}(?i:OpenBSD){end_matcher}{ifdef_end} +ifdef_omnet {ifdef_begin}(?i:Omnet){end_matcher}{ifdef_end} /* The regexp for code snippets is analogous to that for C comments. * Here is a summary of the regexp for code snippets: @@ -634,8 +638,9 @@ NULL return NULL_; {c_comment} /* ignore C-style comment */; {ifdef_freebsd} handle_ifdef(FreeBSD_IFDEF, yytext); {ifdef_linux} handle_ifdef(Linux_IFDEF, yytext); -{ifdef_openbsd} handle_ifdef(OpenBSD_IFDEF, yytext); {ifdef_netbsd} handle_ifdef(NetBSD_IFDEF, yytext); +{ifdef_openbsd} handle_ifdef(OpenBSD_IFDEF, yytext); +{ifdef_omnet} handle_ifdef(Omnet_IFDEF, yytext); {code} yylval.string = code(yytext); return CODE; {ipv4_addr} yylval.string = strdup(yytext); return IPV4_ADDR; {ipv6_addr} yylval.string = strdup(yytext); return IPV6_ADDR;