Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Packetdrill_tarr_ext
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stefan Gense
Packetdrill_tarr_ext
Commits
d45b9a76
Commit
d45b9a76
authored
8 years ago
by
Michael Tüxen
Browse files
Options
Downloads
Patches
Plain Diff
Add support for #ifdef Omnet.
parent
f3b269b6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gtests/net/packetdrill/lexer.l
+19
-14
19 additions, 14 deletions
gtests/net/packetdrill/lexer.l
with
19 additions
and
14 deletions
gtests/net/packetdrill/lexer.l
+
19
−
14
View file @
d45b9a76
...
@@ -104,7 +104,7 @@ static s64 hextol(const char *s)
...
@@ -104,7 +104,7 @@ static s64 hextol(const char *s)
}
}
enum ifdef_os {
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
#define MAX_IFDEF_DEPTH 1
...
@@ -121,6 +121,8 @@ static inline int get_os_name_length(enum ifdef_os os) {
...
@@ -121,6 +121,8 @@ static inline int get_os_name_length(enum ifdef_os os) {
return strlen("NetBSD");
return strlen("NetBSD");
case OpenBSD_IFDEF:
case OpenBSD_IFDEF:
return strlen("OpenBSD");
return strlen("OpenBSD");
case Omnet_IFDEF:
return strlen("Omnet");
default:
default:
return -1;
return -1;
}
}
...
@@ -147,7 +149,7 @@ static inline bool ignore_ifdef(enum ifdef_os os) {
...
@@ -147,7 +149,7 @@ static inline bool ignore_ifdef(enum ifdef_os os) {
return false;
return false;
}
}
#endif
#endif
/* no need to handle Omnet here */
return true;
return true;
}
}
...
@@ -156,39 +158,39 @@ static inline char* remove_ifdef_start_and_endtag(char *code, int os_name_length
...
@@ -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 endif_length = strlen("#endif");
unsigned int newline_before_endif = 0;
unsigned int newline_before_endif = 0;
char *code_without_ifdef = NULL;
char *code_without_ifdef = NULL;
code_without_ifdef = code + ifdef_length + os_name_length;
code_without_ifdef = code + ifdef_length + os_name_length;
newline_before_endif = strlen(code_without_ifdef) - endif_length;
newline_before_endif = strlen(code_without_ifdef) - endif_length;
code_without_ifdef[newline_before_endif] = (char) 0;
code_without_ifdef[newline_before_endif] = (char) 0;
return code_without_ifdef;
return code_without_ifdef;
}
}
static void handle_ifdef(enum ifdef_os os, const char *s) {
static void handle_ifdef(enum ifdef_os os, const char *s) {
char *code = NULL;
char *code = NULL;
char *code_without_ifdef = NULL;
char *code_without_ifdef = NULL;
int os_name_length = get_os_name_length(os);
int os_name_length = get_os_name_length(os);
if (os_name_length == -1) {
if (os_name_length == -1) {
fprintf(stderr, "handle_ifdef with unknown os called.\n");
fprintf(stderr, "handle_ifdef with unknown os called.\n");
exit(1);
exit(1);
}
}
if (ignore_ifdef(os)) {
if (ignore_ifdef(os)) {
return;
return;
}
}
if (ifdef_stack_ptr >= MAX_IFDEF_DEPTH) {
if (ifdef_stack_ptr >= MAX_IFDEF_DEPTH) {
fprintf(stderr, "Ifdefs nested too deeply");
fprintf(stderr, "Ifdefs nested too deeply");
exit(1);
exit(1);
}
}
code = strdup(s);
code = strdup(s);
code_without_ifdef = remove_ifdef_start_and_endtag(code, os_name_length);
code_without_ifdef = remove_ifdef_start_and_endtag(code, os_name_length);
ifdef_stack[ifdef_stack_ptr++] = YY_CURRENT_BUFFER;
ifdef_stack[ifdef_stack_ptr++] = YY_CURRENT_BUFFER;
yy_switch_to_buffer(yy_scan_string(code_without_ifdef));
yy_switch_to_buffer(yy_scan_string(code_without_ifdef));
free(code);
free(code);
}
}
...
@@ -214,9 +216,10 @@ c_comment \/\*(([^*])|(\*[^\/]))*\*\/
...
@@ -214,9 +216,10 @@ c_comment \/\*(([^*])|(\*[^\/]))*\*\/
/* This matches the following platform specific #ifdef-forms:
/* This matches the following platform specific #ifdef-forms:
* #ifdef Linux => Code that only Linux hosts should execute
* #ifdef Linux => Code that only Linux hosts should execute
* #ifdef FreeBSD => Code that only FreeBSD 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 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:
* the pattern for using #ifdef is like this:
* #ifdef Linux
* #ifdef Linux
* (specific code only for linux)
* (specific code only for linux)
...
@@ -230,9 +233,10 @@ ifdef_end #endif
...
@@ -230,9 +233,10 @@ ifdef_end #endif
end_matcher (([^#])|(#[^e])|(#e[^n])|(#en[^d])|(#end[^i])|(#endi[^f]))*
end_matcher (([^#])|(#[^e])|(#e[^n])|(#en[^d])|(#end[^i])|(#endi[^f]))*
ifdef_freebsd {ifdef_begin}(?i:FreeBSD){end_matcher}{ifdef_end}
ifdef_freebsd {ifdef_begin}(?i:FreeBSD){end_matcher}{ifdef_end}
ifdef_linux {ifdef_begin}(?i:Linux){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_netbsd {ifdef_begin}(?i:NetBSD){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.
/* The regexp for code snippets is analogous to that for C comments.
* Here is a summary of the regexp for code snippets:
* Here is a summary of the regexp for code snippets:
...
@@ -634,8 +638,9 @@ NULL return NULL_;
...
@@ -634,8 +638,9 @@ NULL return NULL_;
{c_comment} /* ignore C-style comment */;
{c_comment} /* ignore C-style comment */;
{ifdef_freebsd} handle_ifdef(FreeBSD_IFDEF, yytext);
{ifdef_freebsd} handle_ifdef(FreeBSD_IFDEF, yytext);
{ifdef_linux} handle_ifdef(Linux_IFDEF, yytext);
{ifdef_linux} handle_ifdef(Linux_IFDEF, yytext);
{ifdef_openbsd} handle_ifdef(OpenBSD_IFDEF, yytext);
{ifdef_netbsd} handle_ifdef(NetBSD_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;
{code} yylval.string = code(yytext); return CODE;
{ipv4_addr} yylval.string = strdup(yytext); return IPV4_ADDR;
{ipv4_addr} yylval.string = strdup(yytext); return IPV4_ADDR;
{ipv6_addr} yylval.string = strdup(yytext); return IPV6_ADDR;
{ipv6_addr} yylval.string = strdup(yytext); return IPV6_ADDR;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment