Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make _FILES$() throw an error if it is called without an argument the first time #426

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions internal/c/libqb/src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,13 @@ qbs *func__files(qbs *qbsFileSpec, int32_t passed) {
if (passed) {
std::string fileSpec(reinterpret_cast<char *>(qbsFileSpec->chr), qbsFileSpec->len);

if (FS_DirectoryExists(filepath_fix_directory(fileSpec)))
if (FS_DirectoryExists(filepath_fix_directory(fileSpec))) {
directory = fileSpec;
else
} else {
filepath_split(fileSpec, directory, pathName); // split the file path
if (directory.empty())
directory = "./";
}

entry = FS_GetDirectoryEntryName(fileSpec.c_str());

Expand All @@ -639,7 +642,15 @@ qbs *func__files(qbs *qbsFileSpec, int32_t passed) {
return qbsFinal;
}
} else {
entry = FS_GetDirectoryEntryName(nullptr);
// Check if we've been called the first time without a filespec
if (directory.empty()) {
// This is per MS BASIC PDS 7.1 and VBDOS 1.0 behavior
qbsFinal = qbs_new(0, 1);
error(QB_ERROR_ILLEGAL_FUNCTION_CALL);
return qbsFinal;
}

entry = FS_GetDirectoryEntryName(nullptr); // get the next entry
}

filepath_join(pathName, directory, entry);
Expand All @@ -655,6 +666,9 @@ qbs *func__files(qbs *qbsFileSpec, int32_t passed) {
memcpy(qbsFinal->chr, entry, size);
}

if (!size)
directory.clear(); // clear the directory string since we are done with the session

return qbsFinal;
}

Expand Down Expand Up @@ -785,7 +799,7 @@ void sub_files(qbs *str, int32_t passed) {
directory = FS_GetFQN(fileSpec.c_str());
}

if (!directory.size()) {
if (directory.empty()) {
// Invalid filespec
error(QB_ERROR_ILLEGAL_FUNCTION_CALL);
return;
Expand Down