DIR with wildcards

DIR updated to support wildcards. Directory system calls fixed.
This commit is contained in:
Peter Weingartner 2022-04-24 15:37:56 -04:00
parent 03de9599a9
commit 2581b754d6
6 changed files with 8489 additions and 8395 deletions

BIN
build/foenixmcp_a2560k.bin Normal file

Binary file not shown.

View file

@ -342,19 +342,71 @@ void dir_entry_insert(p_dir_entry * list_pointer, p_dir_entry entry) {
} }
} }
/**
* Examine the optional path/pattern argument and separate it into a path and a pattern
*
* @param arg the string describing the directory and pattern to search
* @param path a pointer to a pointer to a string... set to the path portion or 0 if no path
* @param pattern a pointer to a pointer to a string... set to the pattern poriton, or 0 if none provided
*/
void dir_parse_pattern(char * arg, char ** path, char ** pattern) {
*path = 0;
*pattern = 0;
if ((arg != 0) && (strlen(arg) > 0)) {
// And argument was provided... see if there is a pattern
if ((strchr(arg, '*') == 0) && (strchr(arg, '?') == 0)) {
// No pattern found... return the whole thing as path
*path = arg;
} else {
// Found a pattern... do we specify a folder?
char * x = strrchr(arg, '/');
if (x == 0) {
// No... it's all pattern
*pattern = arg;
} else {
// Yes... split the string into path and pattern at x
*x = 0;
*path = arg;
*pattern = x + 1;
}
}
}
}
short cmd_dir(short screen, int argc, const char * argv[]) { short cmd_dir(short screen, int argc, const char * argv[]) {
short result; short result = 0, dir = -1;
char buffer[80]; char buffer[80];
char arg[128];
t_file_info my_file; t_file_info my_file;
p_dir_entry directories = 0, files = 0, entry = 0, prev = 0; p_dir_entry directories = 0, files = 0, entry = 0, prev = 0;
char * path = ""; char *path=0, *pattern = 0;
char label[40]; char label[40];
if (argc > 1) { if (argc > 1) {
path = (char*)(argv[1]); strcpy(arg, argv[1]);
dir_parse_pattern(arg, &path, &pattern);
}
if (path == 0) {
// Make the path the empty string if it was not provided
path = "";
}
print(0, "Path: ");
print(0, path);
print(0, "\n");
if (pattern != 0) {
// A pattern was provided
dir = sys_fsys_findfirst(path, pattern, &my_file);
} else {
// No pattern... just open the path as a directory
dir = sys_fsys_opendir(path);
} }
short dir = fsys_opendir(path);
if (dir >= 0) { if (dir >= 0) {
result = fsys_getlabel(path, label); result = fsys_getlabel(path, label);
if ((result == 0) && (strlen(label) > 0)) { if ((result == 0) && (strlen(label) > 0)) {
@ -363,9 +415,12 @@ short cmd_dir(short screen, int argc, const char * argv[]) {
} }
while (1) { while (1) {
short result = fsys_readdir(dir, &my_file); if (pattern == 0) {
if ((result == 0) && (my_file.name[0] != 0)) { result = sys_fsys_readdir(dir, &my_file);
if (result != 0) break;
}
if (my_file.name[0] != 0) {
if ((my_file.attributes & AM_HID) == 0) { if ((my_file.attributes & AM_HID) == 0) {
if (my_file.attributes & AM_DIR) { if (my_file.attributes & AM_DIR) {
entry = (p_dir_entry)malloc(sizeof(t_dir_entry)); entry = (p_dir_entry)malloc(sizeof(t_dir_entry));
@ -391,6 +446,13 @@ short cmd_dir(short screen, int argc, const char * argv[]) {
} else { } else {
break; break;
} }
if (pattern != 0) {
result = fsys_findnext(dir, &my_file);
if (result != 0) {
break;
}
}
} }
fsys_closedir(dir); fsys_closedir(dir);

View file

@ -178,6 +178,7 @@ short fsys_opendir(const char * path) {
/* Allocate a directory handle */ /* Allocate a directory handle */
for (i = 0; i < MAX_DIRECTORIES; i++) { for (i = 0; i < MAX_DIRECTORIES; i++) {
if (g_dir_state[i] == 0) { if (g_dir_state[i] == 0) {
g_dir_state[i] = 1;
dir = i; dir = i;
break; break;
} }
@ -315,13 +316,14 @@ short fsys_stat(const char * path, p_file_info file) {
*/ */
short fsys_findfirst(const char * path, const char * pattern, p_file_info file) { short fsys_findfirst(const char * path, const char * pattern, p_file_info file) {
FILINFO finfo; FILINFO finfo;
FRESULT fres; FRESULT fres = -1;
short dir; short dir = 0;
short i; short i = 0;
/* Allocate a directory handle */ /* Allocate a directory handle */
for (i = 0; i < MAX_DIRECTORIES; i++) { for (i = 0; i < MAX_DIRECTORIES; i++) {
if (g_dir_state[i] == 0) { if (g_dir_state[i] == 0) {
g_dir_state[i] = 1;
dir = i; dir = i;
break; break;
} }
@ -331,6 +333,7 @@ short fsys_findfirst(const char * path, const char * pattern, p_file_info file)
return ERR_OUT_OF_HANDLES; return ERR_OUT_OF_HANDLES;
} else { } else {
fres = f_findfirst(&g_directory[dir], &finfo, path, pattern);
if (fres != FR_OK) { if (fres != FR_OK) {
return fatfs_to_foenix(fres); return fatfs_to_foenix(fres);

View file

@ -70,7 +70,7 @@ const char * err_messages[] = {
const char * err_message(short err_number) { const char * err_message(short err_number) {
short index = 0 - err_number; short index = 0 - err_number;
if (index < sizeof(err_messages)) { if (index < 38) {
return err_messages[index]; return err_messages[index];
} else { } else {
return "unknown error"; return "unknown error";
@ -88,7 +88,7 @@ const char * err_message(short err_number) {
void err_print(short channel, const char * message, short err_number) { void err_print(short channel, const char * message, short err_number) {
char buffer[80]; char buffer[80];
if (err_number < 0) { if ((err_number < 0) && (err_number > -38)) {
sprintf(buffer, "%s: %s\n", message, err_message(err_number)); sprintf(buffer, "%s: %s\n", message, err_message(err_number));
} else { } else {
sprintf(buffer, "%s: #%d\n", message, err_number); sprintf(buffer, "%s: #%d\n", message, err_number);

16795
src/mapfile

File diff suppressed because it is too large Load diff

View file

@ -7,6 +7,6 @@
#define VER_MAJOR 0 #define VER_MAJOR 0
#define VER_MINOR 52 #define VER_MINOR 52
#define VER_BUILD 23 #define VER_BUILD 26
#endif #endif