]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cmd_fat.c
Reduce static RAM usage
[z180-stamp.git] / avr / cmd_fat.c
index 52ad95f498c524f27f2cb166d2491e8859ae9610..c1d3770096e3acfa196aae45431bd2d9e73625cf 100644 (file)
 #include "debug.h"
 #include "env.h"
 
+
+#define DEBUG_FA               0       /* set to 1 to debug */
+
+#define debug_fa(fmt, args...)                                                        \
+       debug_cond(DEBUG_FA, fmt, ##args)
+
+
 /* TODO: use memory size test function (detect_ramsize() in cmd_loadihex.c) */
 /* TODO: detect_ramsize() should be moved to z80-if.c */
 #define MAX_MEMORY     CONFIG_SYS_RAMSIZE_MAX
@@ -124,7 +131,6 @@ command_ret_t do_pwd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc
        buf = (char *) malloc(BUFFER_SIZE);
        if (buf == NULL) {
                printf_P(PSTR("pwd: Out of Memory!\n"));
-               free(buf);
                return CMD_RET_FAILURE;
        }
 
@@ -160,18 +166,18 @@ command_ret_t do_cd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc,
        } else
                arg = argv[1];
 
-       if (arg[1] == ':') {
-               char drv[3];
-               drv[2] = '\0';
-               drv[1] = ':';
-               drv[0] = arg[0];
-               res = f_chdrive(drv);
-       }
-       if (!res) {
+       if (arg[1] == ':')
+               res = f_chdrive(arg);
+debug_fa("### f_chdrive(): arg: '%s', res: %d\n", arg, res);
+       if (res == FR_OK) {
+               if (arg[2] == '\0') {
+                       arg[0] = '/';
+                       arg[1] = '\0';
+               }
                res = f_chdir(arg);
        }
-
-       if (res) {
+debug_fa("### f_chdir():   arg: '%s', res: %d\n", arg, res);
+       if (res != FR_OK) {
                put_rc(res);
                return CMD_RET_FAILURE;
        }
@@ -529,22 +535,22 @@ command_ret_t do_rw(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc,
 
 cmd_tbl_t cmd_tbl_fat[] = {
 CMD_TBL_ITEM(
-       stat,   2,      CTBL_RPT,       do_stat,
+       status, 2,      CTBL_RPT,       do_stat,
        "Show logical drive status",
        "dev"
 ),
 CMD_TBL_ITEM(
-       pwd,    2,      CTBL_RPT,       do_pwd,
+       pwd,    2,      CTBL_RPT|CTBL_SUBCMDAUTO,       do_pwd,
        "Print name of current/working directory",
        ""
 ),
 CMD_TBL_ITEM(
-       cd,             2,      0,                      do_cd,
+       cd,             2,      0|CTBL_SUBCMDAUTO,                      do_cd,
        "Change the current/working directory.",
        "path"
 ),
 CMD_TBL_ITEM(
-       ls,             2,      CTBL_RPT,       do_ls,
+       ls,             2,      CTBL_RPT|CTBL_SUBCMDAUTO,       do_ls,
        "Directory listing",
        "path"
 ),
@@ -578,7 +584,7 @@ CMD_TBL_ITEM(
 
 /* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
        {FSTR("?"),   CONFIG_SYS_MAXARGS, 1, do_help,
-        FSTR("Alias for 'help'"),
+        NULL,
 #ifdef  CONFIG_SYS_LONGHELP
        FSTR(""),
 #endif /* CONFIG_SYS_LONGHELP */