From: Leo C Date: Mon, 23 Apr 2018 06:28:41 +0000 (+0200) Subject: wildcards X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/commitdiff_plain/6afaef202b6eba718d0f02674ba4a2c3470bcda5 wildcards --- diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index 0fcc72c..4d3e751 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -177,8 +177,8 @@ void err(const char *fmt, ...) static void path_init(void) { - from.p_end = from.p_path; from.p_path[0] = '\0'; - to.p_end = to.p_path; to.p_path[0] = '\0'; + from.p_path[0] = '\0'; from.p_end = from.p_path; + to.p_path[0] = '\0'; to.p_end = to.p_path; } static void strip_trailing_slash(PATH_T *p) @@ -212,7 +212,7 @@ path_set(PATH_T *p, char *string) if (p->p_path == p->p_end) { *p->p_end++ = '.'; - *p->p_end = 0; + *p->p_end = '\0'; } strip_trailing_slash(p); @@ -280,7 +280,20 @@ char *path_basename(PATH_T *p) return basename; } - +char *path_basename_pattern(PATH_T *p) +{ + char *pattern = path_basename(p); + if (strpbrk_P(pattern, PSTR("*?"))) { + memmove(pattern+1, pattern, strlen(pattern)+1); + *pattern++ = '\0'; + } else { + //p->p_pattern = p->p_end + 1; + pattern = p->p_end + 1; + pattern[0] = '*'; + pattern[1] = '\0'; + } + return pattern; +} static void swirl(void) { @@ -409,27 +422,18 @@ command_ret_t do_ls(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, unsigned int s1, s2; FRESULT res; - path_init(); if (argc > 1) if (!path_set(&from, argv[1])) { /* TODO: error out*/ } - char *p = path_basename(&from); - if (strpbrk_P(p, PSTR("*?")) || - (f_stat(from.p_path, &Finfo) == FR_OK && !(Finfo.fattrib & AM_DIR))) { - path_set(&to, p); - *p = '\0'; - } else { - to.p_path[0] = '*'; - to.p_path[1] = '\0'; - } + char *pattern = path_basename_pattern(&from); -debug_ls("==== path: '%s', pattern: '%s'\n", from.p_path ? from.p_path : "", to.p_path ? to.p_path : ""); + debug_ls("==== path: '%s', pattern: '%s'\n", from.p_path ? from.p_path : "", pattern ? pattern : ""); p1 = s1 = s2 = 0; - res = f_findfirst(&Dir, &Finfo, from.p_path, to.p_path); /* Start to search for files */ + res = f_findfirst(&Dir, &Finfo, from.p_path, pattern); /* Start to search for files */ while (res == FR_OK && Finfo.fname[0]) { if (Finfo.fattrib & AM_DIR) { s2++; @@ -557,7 +561,7 @@ void copy_file(FILINFO *fs, uint_fast8_t dne) } } -debug_cp("==== copy_file(): dne: %u, blockbuf_size: %d\n", dne, blockbuf_size); +debug_cp("==== copy_file(): dne: %u, blockbuf_size: %d, freemem: %u\n", dne, blockbuf_size, get_freemem()); debug_cp(" from:'%s' to:'%s'\n", from.p_path, to.p_path); @@ -642,13 +646,13 @@ static void copy_dir(void) FRESULT res; char *pattern = {"*"}; -debug_cp("==== copy_dir()"); +debug_cp("==== copy_dir(): freemem: %u\n", get_freemem()); debug_cp(" from:'%s' to:'%s'\n", from.p_path, to.p_path); for (res = f_findfirst(&Dir, &Finfo, from.p_path, pattern); res == FR_OK && Finfo.fname[0]; - res = f_findfirst(&Dir, &Finfo, from.p_path, pattern)) { + res = f_findnext(&Dir, &Finfo)) { if (!(Finfo.fattrib & AM_DIR) && (old_from = path_append(&from, Finfo.fname))) { @@ -683,7 +687,7 @@ static void copy_dir(void) int dir_cnt, i; char *old_from, *old_to; -debug_cp("==== copy_file(): dne: %u\n", dne); +debug_cp("==== copy_file(): dne: %u\n", dne, ); debug_cp(" from:'%s' to:'%s'\n", from->p_path, to.p_path); dir_cnt = scandir(from->p_path, &dir_list, NULL, NULL); @@ -765,7 +769,7 @@ static void copy() uint_fast8_t dne; FRESULT fr; -debug_cp("==== copy()\n"); +debug_cp("==== copy(); freemem: %u\n", get_freemem()); debug_cp(" from:'%s' to:'%s'\n", from.p_path, to.p_path); fr = f_stat(from.p_path, &from_stat); @@ -889,7 +893,8 @@ command_ret_t do_cp(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, */ fr = f_stat(to.p_path, &to_stat); -debug_cp("==== main, stat to: fr: %d, attr: %02x, flags:%02x\n", fr, to_stat.fattrib, flags); +debug_cp("==== main, stat to: fr: %d, attr: %02x, flags:%02x, freemem: %u\n", + fr, to_stat.fattrib, flags, get_freemem()); debug_cp(" from:'%s' to:'%s'\n", from.p_path, to.p_path); if (fr != FR_OK && fr != FR_NO_FILE && fr != FR_NO_PATH) {