mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 12:08:20 +00:00
Change @PATH to @DIR for clarity. Add @FILENAME. Addresses #869.
@DIR expands to directory path of the script, @FILENAME expands to just the script file name without path.
This commit is contained in:
parent
7e8b504305
commit
022ce2505f
7 changed files with 22 additions and 5 deletions
16
src/scan.l
16
src/scan.l
|
@ -346,7 +346,7 @@ when return TOK_WHEN;
|
|||
|
||||
@DEBUG return TOK_DEBUG; // marks input for debugger
|
||||
|
||||
@PATH {
|
||||
@DIR {
|
||||
string rval = current_scanned_file_path;
|
||||
|
||||
if ( ! rval.empty() && rval[0] == '.' )
|
||||
|
@ -354,7 +354,7 @@ when return TOK_WHEN;
|
|||
char path[MAXPATHLEN];
|
||||
|
||||
if ( ! getcwd(path, MAXPATHLEN) )
|
||||
reporter->Error("getcwd failed: %s", strerror(errno));
|
||||
reporter->InternalError("getcwd failed: %s", strerror(errno));
|
||||
else
|
||||
rval = string(path) + "/" + rval;
|
||||
}
|
||||
|
@ -362,6 +362,18 @@ when return TOK_WHEN;
|
|||
RET_CONST(new StringVal(rval.c_str()));
|
||||
}
|
||||
|
||||
@FILENAME {
|
||||
char* filename_copy = copy_string(::filename);
|
||||
const char* bname = basename(filename_copy);
|
||||
|
||||
if ( ! bname )
|
||||
reporter->InternalError("basename failed: %s", strerror(errno));
|
||||
|
||||
StringVal* rval = new StringVal(bname);
|
||||
delete [] filename_copy;
|
||||
RET_CONST(rval);
|
||||
}
|
||||
|
||||
@load{WS}{FILE} {
|
||||
const char* new_file = skip_whitespace(yytext + 5); // Skip "@load".
|
||||
if ( generate_documentation )
|
||||
|
|
1
testing/btest/Baseline/language.at-dir/out
Normal file
1
testing/btest/Baseline/language.at-dir/out
Normal file
|
@ -0,0 +1 @@
|
|||
/Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.at-dir
|
1
testing/btest/Baseline/language.at-filename/out
Normal file
1
testing/btest/Baseline/language.at-filename/out
Normal file
|
@ -0,0 +1 @@
|
|||
at-filename.bro
|
|
@ -1 +0,0 @@
|
|||
/Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.at-path
|
|
@ -3,8 +3,8 @@
|
|||
# @TEST-EXEC: bro -b ./pathtest.bro >out2
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out2
|
||||
|
||||
print @PATH;
|
||||
print @DIR;
|
||||
|
||||
@TEST-START-FILE pathtest.bro
|
||||
print @PATH;
|
||||
print @DIR;
|
||||
@TEST-END-FILE
|
4
testing/btest/language/at-filename.bro
Normal file
4
testing/btest/language/at-filename.bro
Normal file
|
@ -0,0 +1,4 @@
|
|||
# @TEST-EXEC: bro -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
print @FILENAME;
|
Loading…
Add table
Add a link
Reference in a new issue