mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-07-06 19:50:22 +00:00
Implement func__files()
This commit is contained in:
parent
260adbfe6b
commit
5c078a1ec1
|
@ -624,17 +624,33 @@ static const char *GetDirectoryEntryName(const char *fileSpec) {
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief
|
/// @brief This mimics MS BASIC PDS 7.1 & VBDOS 1.0 DIR$() function
|
||||||
/// @param qbsFileSpec
|
/// @param qbsFileSpec This can be a path with wildcard for the final level (i.e. C:/Windows/*.* or /usr/lib/* etc.)
|
||||||
/// @param passed
|
/// @param passed Flags for optional parameters
|
||||||
/// @return
|
/// @return Retuns a qbs with the directory entry name or an empty string if there are no more entries
|
||||||
qbs *func__files(qbs *qbsFileSpec, int32_t passed) {
|
qbs *func__files(qbs *qbsFileSpec, int32_t passed) {
|
||||||
qbs *final;
|
const char *entry;
|
||||||
|
|
||||||
// Check if fresh arguments were passed and we need to begin a new session
|
// Check if fresh arguments were passed and we need to begin a new session
|
||||||
if (passed) {
|
if (passed) {
|
||||||
std::string fileSpec(reinterpret_cast<char *>(qbsFileSpec->chr), qbsFileSpec->len);
|
std::string fileSpec(reinterpret_cast<char *>(qbsFileSpec->chr), qbsFileSpec->len);
|
||||||
|
|
||||||
|
entry = GetDirectoryEntryName(fileSpec.c_str());
|
||||||
|
|
||||||
|
if (IsStringEmpty(entry)) {
|
||||||
|
// This is per MS BASIC PDS 7.1 and VBDOS 1.0 behavior
|
||||||
|
error(53);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
entry = GetDirectoryEntryName(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto size = strlen(entry);
|
||||||
|
auto final = qbs_new(size, 1);
|
||||||
|
memcpy(final->chr, entry, size);
|
||||||
|
|
||||||
|
return final;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Prints a list of files in the current directory using a file specification
|
/// @brief Prints a list of files in the current directory using a file specification
|
||||||
|
|
Loading…
Reference in a new issue