+ int count = 0;
+
+ while (p->name != NULL) {
+ if (p->subcmd) {
+ cmd_tbl_t *sub = p->subcmd;
+ while (sub->name != NULL) {
+ if (sub->flags & CTBL_SUBCMDAUTO)
+ count++;
+ sub++;
+ }
+ }
+ if ((p->flags & CTBL_SUBCMDAUTO) == 0)
+ count++;
+ p++;
+ }
+ return count;
+}
+#endif
+
+static cmd_tbl_t *get_cmd_tbl_base(cmd_tbl_t *cmdtp)
+{
+ cmd_tbl_t *p = cmdtp;
+
+ while (p->name != NULL)
+ ++p;
+
+ return p->subcmd;
+}
+
+static cmd_tbl_t *get_cmd_tbl_parent(cmd_tbl_t *child)
+{
+ if ((child->flags & CTBL_SUBCMDAUTO) == 0) {
+
+ cmd_tbl_t *tbl_start = get_cmd_tbl_base(child);
+ if (tbl_start != cmd_tbl) {
+ cmd_tbl_t *top = cmd_tbl;
+ while (top->subcmd != tbl_start)
+ ++top;
+ return top;
+ }
+ }
+ return NULL;
+}
+
+static int print_nameprefix(cmd_tbl_t *p)
+{
+ cmd_tbl_t *top = get_cmd_tbl_parent(p);
+
+ int width = 0;
+ if (top) {
+ width = printf_P(PSTR("%S "), top->name);
+ }
+
+ return width;
+}
+
+static int print_prefixed_name(cmd_tbl_t *p)
+{
+ int len;
+
+ len = print_nameprefix(p);
+ len += strlen_P(p->name);
+ my_puts_P(p->name);
+
+ return len;
+}
+
+static void print_usage_line(cmd_tbl_t *p, int width)
+{
+ width -= print_prefixed_name(p);