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)
if (p->p_path == p->p_end) {
*p->p_end++ = '.';
- *p->p_end = 0;
+ *p->p_end = '\0';
}
strip_trailing_slash(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)
{
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 : "<NULL>", to.p_path ? to.p_path : "<NULL>");
+ debug_ls("==== path: '%s', pattern: '%s'\n", from.p_path ? from.p_path : "<NULL>", pattern ? pattern : "<NULL>");
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++;
}
}
-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);
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))) {
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);
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);
*/
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) {