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 )