]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add fr_command_list()
authorAlan T. DeKok <aland@freeradius.org>
Fri, 6 Jul 2018 16:29:25 +0000 (12:29 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 6 Jul 2018 16:29:25 +0000 (12:29 -0400)
which lists commands and their syntax

src/include/command.h
src/main/command.c

index 4b2b52c44d60e23fa43cde089423718574a448af..bcdd3b32ec894c7393fb79e02226de93dc409253 100644 (file)
@@ -73,6 +73,7 @@ int fr_command_tab_expand(TALLOC_CTX *ctx, fr_cmd_t *head, fr_cmd_info_t *info,
 char const *fr_command_help(fr_cmd_t *head, int argc, char *argv[]);
 int fr_command_run(FILE *fp, FILE *fp_err, fr_cmd_t *head, fr_cmd_info_t *info);
 void fr_command_debug(FILE *fp, fr_cmd_t *head);
+void fr_command_list(FILE *fp, fr_cmd_t *head);
 int fr_command_str_to_argv(fr_cmd_t *head, fr_cmd_info_t *info, char *str);
 
 #ifdef __cplusplus
index a771306011d31713bebbcb4aedfc3d34cb050055..2ca880c6add262c45acc1b9f86e7f689764c2045 100644 (file)
@@ -1464,6 +1464,53 @@ void fr_command_debug(FILE *fp, fr_cmd_t *head)
 }
 
 
+static void fr_command_list_node(FILE *fp, fr_cmd_t *cmd, int depth, char const **argv)
+{
+       int i;
+
+       if (depth == 0) {
+               if (!cmd->syntax) {
+                       fprintf(fp, "%s\n", cmd->name);
+               } else {
+                       fprintf(fp, "%s %s\n", cmd->name, cmd->syntax);
+               }
+
+               return;
+       }
+
+       for (i = 0; i < depth; i++) {
+               fprintf(fp, "%s ", argv[i]);
+       }
+
+       if (!cmd->syntax) {
+               fprintf(fp, "\n");
+       } else {
+               fprintf(fp, "%s\n", cmd->syntax);
+       }
+}
+
+static void fr_command_list_internal(FILE *fp, fr_cmd_t *head, int depth, char const **argv)
+{
+       fr_cmd_t *cmd;
+
+       for (cmd = head; cmd != NULL; cmd = cmd->next) {
+               if (cmd->child) {
+                       argv[depth] = cmd->name;
+                       fr_command_list_internal(fp, cmd->child, depth + 1, argv);
+               } else {
+                       fr_command_list_node(fp, cmd, depth, argv);
+               }
+       }
+}
+
+void fr_command_list(FILE *fp, fr_cmd_t *head)
+{
+       char const *argv[CMD_MAX_ARGV];
+
+       fr_command_list_internal(fp, head, 0, argv);
+}
+
+
 static int fr_command_verify_argv(fr_cmd_info_t *info, int start, int verify, int argc, fr_cmd_argv_t **argv_p, bool optional)
 {
        char quote;