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:
Jon Siwek 2013-06-05 11:01:11 -05:00
parent 7e8b504305
commit 022ce2505f
7 changed files with 22 additions and 5 deletions

View file

@ -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 )

View file

@ -0,0 +1 @@
/Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.at-dir

View file

@ -0,0 +1 @@
at-filename.bro

View file

@ -1 +0,0 @@
/Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.at-path

View file

@ -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

View file

@ -0,0 +1,4 @@
# @TEST-EXEC: bro -b %INPUT >out
# @TEST-EXEC: btest-diff out
print @FILENAME;