]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/command.c
User Timer0 as Z180 Clock
[z180-stamp.git] / avr / command.c
index 9eb0ed262ef12f959972d1fe46e94f586924ccf3..f1e184a65c973b70260c2e7ce052bb96c55864d2 100644 (file)
@@ -24,10 +24,14 @@ static void print_blanks(int_fast8_t count)
                my_puts_P(PSTR(" "));
 }
 
-static void print_usage_line(const FLASH char *name, const FLASH char *usage)
+static void print_usage_line(const FLASH char *name, int width,
+                               const FLASH char *usage)
 {
+       width -= strlen_P(name);
+       if (width < 0)
+               width = 0;
        my_puts_P(name);
-       print_blanks(CONFIG_SYS_MAXARGS - strlen_P(name));
+       print_blanks(width);
        my_puts_P(PSTR(" - "));
        my_puts_P(usage);
        my_puts_P(PSTR("\n"));
@@ -70,7 +74,7 @@ int cmd_tbl_item_count(void)
 command_ret_t _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp,
                int flag, int argc, char * const argv[])
 {
-       uint_fast8_t i;
+       uint_fast8_t i, max_len = 0;
        command_ret_t rcode = CMD_RET_SUCCESS;
 
        (void) flag;
@@ -83,6 +87,9 @@ command_ret_t _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp,
                cmdtp = cmd_start;
                for (i = 0; i < cmd_items; i++) {
                        cmd_array[i] = cmdtp++;
+                       uint_fast8_t l = strlen_P(cmd_array[i]->name);
+                       if (l > max_len)
+                               max_len = l;
                }
 
                /* Sort command list */
@@ -98,9 +105,9 @@ command_ret_t _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp,
                        if (usage == NULL)
                                continue;
 #ifdef GCC_BUG_61443 
-                       print_usage_line(cmd_array[i]->name, usage);
+                       print_usage_line(cmd_array[i]->name, max_len, usage);
 #else
-                       printf_P(PSTR("%-" stringify(CONFIG_SYS_MAXARGS) "S - %S\n"), 
+                       printf_P(PSTR("%-" stringify(8) /*FIXME*/ "S - %S\n"), 
                                        cmd_array[i]->name, usage);
 #endif
                }
@@ -165,10 +172,10 @@ cmd_tbl_t *find_cmd (const char *cmd)
 command_ret_t cmd_usage(const FLASH cmd_tbl_t *cmdtp)
 {
 //     printf("%s - %s\n\n", cmdtp->name, cmdtp->usage);
-       print_usage_line(cmdtp->name, cmdtp->usage);
+       print_usage_line(cmdtp->name, 0, cmdtp->usage);
 #if 0
        my_puts_P(cmdtp->name);
-       print_blanks(CONFIG_SYS_MAXARGS - strlen_P(cmdtp->name));
+       print_blanks(/*FIXME*/ 8 - strlen_P(cmdtp->name));
        my_puts_P(PSTR(" - "));
        my_puts_P(cmdtp->usage);
        my_puts_P(PSTR("\n\n"));
@@ -194,7 +201,7 @@ command_ret_t cmd_usage(const FLASH cmd_tbl_t *cmdtp)
 
 int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])
 {
-       static char tmp_buf[512];
+       static char tmp_buf[CONFIG_SYS_CBSIZE];
        int space;
 
        space = last_char == '\0' || isblank(last_char);
@@ -210,6 +217,8 @@ int var_complete(int argc, char * const argv[], char last_char, int maxv, char *
 
 /*************************************************************************************/
 
+/* TODO: cmdtp points to FLASH */
+
 static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])
 {
        cmd_tbl_t *cmdtp = cmd_tbl;
@@ -357,6 +366,7 @@ static int find_common_prefix(char * const argv[])
 
 static char tmp_buf[CONFIG_SYS_CBSIZE];        /* copy of console I/O buffer   */
 
+
 int cmd_auto_complete(const FLASH char *const prompt, char *buf, int *np, int *colp)
 {
        int n = *np, col = *colp;