]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
add fat commands rm, rmdir, mkdir (WIP)
authorLeo C <leo@lenti.loc>
Fri, 18 May 2018 11:07:45 +0000 (13:07 +0200)
committerLeo C <leo@lenti.loc>
Fri, 18 May 2018 11:07:45 +0000 (13:07 +0200)
avr/cmd_fat.c
include/command.h

index 4d3e751ae6a292038f7797bafffc728b6ad1f816..0e7063a2686131b543200ff8066a6a7f45cabed5 100644 (file)
@@ -396,6 +396,53 @@ void strip_trailing_slash_relpath(char *p)
 }
 #endif
 
+command_ret_t do_rm(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
+{
+       DIR Dir;                                        /* Directory object */
+       FILINFO Finfo;
+       FRESULT res;
+
+       if (argc < 2)
+               err("missing operand");
+
+       for (int i = 1; i < argc; i++) {
+               if (!path_set(&from, argv[1])) {
+                       /* TODO: error out*/
+               }
+               char *pattern = path_basename_pattern(&from);
+
+               //debug_rm("==== path: '%s', pattern: '%s'\n", from.p_path ? from.p_path : "<NULL>", pattern ? pattern : "<NULL>");
+
+               res = f_findfirst(&Dir, &Finfo, from.p_path, pattern);
+               while (res == FR_OK && Finfo.fname[0]) {
+                       if (!(Finfo.fattrib & AM_DIR)) {
+                               if ((res = f_unlink(Finfo.fname)) != FR_OK) {
+                                       put_rc(res);
+                                       break;
+                               }
+                       }
+                       res = f_findnext(&Dir, &Finfo);
+               }
+               f_closedir(&Dir);
+       }
+
+       if (res) {
+               put_rc(res);
+               return CMD_RET_FAILURE;
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+command_ret_t do_rmdir(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
+{
+}
+
+command_ret_t do_mkdir(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
+{
+}
+
+
 int print_dirent(FILINFO *f)
 {
        return printf_P(PSTR("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu  %s\n"),
@@ -1217,6 +1264,21 @@ CMD_TBL_ITEM(
        "Change the current/working directory.",
        "path"
 ),
+CMD_TBL_ITEM(
+       rm,             CONFIG_SYS_MAXARGS,     0,                      do_rm,
+       "Remove FILE(s)",
+       "[OPTION]... [FILE]..."
+),
+CMD_TBL_ITEM(
+       rmdir,          CONFIG_SYS_MAXARGS,     0,                      do_rmdir,
+       "Remove the DIRECTORY(ies), if they are empty",
+       "[OPTION]... DIRECTORY..."
+),
+CMD_TBL_ITEM(
+       mkdir,          CONFIG_SYS_MAXARGS,     0,                      do_mkdir,
+       "Create the DIRECTORY(ies), if they do not already exist.",
+       "[OPTION]... DIRECTORY..."
+),
 CMD_TBL_ITEM(
        ls,             2,      CTBL_RPT,       do_ls,
        "Directory listing",
index d7eccc932da18dbb624ce3186412f0729b627978..54c04727f92df4f5abbc461c5a5148de95320a7b 100644 (file)
@@ -50,13 +50,12 @@ struct cmd_tbl_s {
        uint8_t         maxargs;                        /* maximum number of arguments  */
        uint8_t         flags;                  /* autorepeat allowed?          */
                                                                /* Implementation function      */
-       command_ret_t   (*cmd)(const FLASH struct cmd_tbl_s *, uint_fast8_t, int, char * const []);
+       command_ret_t   (*cmd)(cmd_tbl_t *, uint_fast8_t, int, char * const []);
        const FLASH char *usage;        /* Usage message        (short) */
 #ifdef CONFIG_SYS_LONGHELP
        const FLASH char *help;         /* Help  message        (long)  */
 #endif
        cmd_tbl_t *subcmd;
-//     const FLASH struct cmd_tbl_s *subcommands;
 #ifdef CONFIG_AUTO_COMPLETE
        /* do auto completion on the arguments */
        int             (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]);