return basename;
}
+#if 0
char *path_basename_pattern(PATH_T *p)
{
char *pattern = path_basename(p);
}
return pattern;
}
+#endif
/*
* Split path
* Return basename/pattern of path.
*/
-static char *path_split_pattern(PATH_T *p)
+char *path_split_pattern(PATH_T *p)
{
char *pp = path_skip_heading(p->p_path);
char *pattern = strrchr(pp, '/');
return pattern;
}
-static void path_fix(PATH_T *p)
+void path_fix(PATH_T *p)
{
char *pp = path_skip_heading(p->p_path);
}
}
-static void path_unfix(PATH_T *p)
+void path_unfix(PATH_T *p)
{
char *pp = path_skip_heading(p->p_path);
return command_ret;
}
-#if 0
-/*
- * Remove trailing slashes,
- * but keep a leading slash (absolute path)
- */
-void strip_trailing_slash_relpath(char *p)
-{
- int n = strlen(p);
- if (n >= 2 && (p[0] & 0x38) == '0' && p[1] == ':') {
- p += 2;
- n -= 2;
- }
- if (n >= 1 && p[0] == '/') {
- p++;
- n--;
- }
- while (n-- != 0 && p[n] == '/')
- p[n] = '\0';
-}
-#endif
command_ret_t do_rm(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
{
}
-int print_dirent(FILINFO *f)
+static void print_dirent(FILINFO *f)
{
- return printf_P(PSTR("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %s\n"),
+ printf_P(PSTR("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %s\n"),
(f->fattrib & AM_DIR) ? 'D' : '-',
(f->fattrib & AM_RDO) ? 'R' : '-',
(f->fattrib & AM_HID) ? 'H' : '-',
FRESULT res;
cmdname = argv[0];
-
+ command_ret = CMD_RET_SUCCESS;
path_init();
if (argc > 1)
/* TODO: error out*/
}
+#if 0
char *pattern = path_basename_pattern(&from);
-
+#else
+ char *pattern = path_split_pattern(&from);
+ if (*pattern == '\0')
+ pattern = "*";
+#endif
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, pattern); /* Start to search for files */
- while (res == FR_OK && Finfo.fname[0]) {
- if (Finfo.fattrib & AM_DIR) {
- s2++;
- } else {
- s1++; p1 += Finfo.fsize;
- }
- print_dirent(&Finfo);
- if (check_abort())
- break;
- res = f_findnext(&Dir, &Finfo);
+ if (res != FR_OK || !Finfo.fname[0]) {
+ path_fix(&from);
+ err(PSTR("'%s%s': No such file or directory"), from.p_path, pattern);
+ } else {
+ do {
+ if (Finfo.fattrib & AM_DIR) {
+ s2++;
+ } else {
+ s1++; p1 += Finfo.fsize;
+ }
+ print_dirent(&Finfo);
+ if (check_abort())
+ break;
+ res = f_findnext(&Dir, &Finfo);
+ } while (res == FR_OK && Finfo.fname[0]);
}
f_closedir(&Dir);
- if (res == FR_OK) {
+ if (res == FR_OK && command_ret == CMD_RET_SUCCESS) {
printf_P(PSTR("%4u File(s),%10lu bytes total\n%4u Dir(s)"), s1, p1, s2);
if (f_getfree(from.p_path, (DWORD*)&p1, &fs) == FR_OK)
printf_P(PSTR(", %10luK bytes free\n"), p1 * fs->csize / 2);
}
- if (res) {
+ if (res && command_ret == CMD_RET_SUCCESS) {
put_rc(res);
return CMD_RET_FAILURE;
}
- return CMD_RET_SUCCESS;
+ return command_ret;
}
/*