Simplify help code.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 17 Feb 2007 16:13:40 +0000 (17:13 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 17 Feb 2007 16:13:40 +0000 (17:13 +0100)
src/admin.c
src/help.c

index e51565fe25d25519a0dce31e5c2b3fab7512d5a5..0ab4b4831fb2e43df6d5ddcfb359c15008c14616 100644 (file)
@@ -391,7 +391,7 @@ void register_admin_command(const struct admin_command *cmd)
 
 void unregister_admin_command(const struct admin_command *cmd)
 {
-       commands = g_list_remove(commands, cmd);
+       admin_commands = g_list_remove(admin_commands, cmd);
 }
 
 gboolean process_cmd(admin_handle h, const char *cmd)
index 18cc4e422ee4ce27e83bcf181040f7cbff888d26..43e7c8ecaff9a7c9746012a634b495c50035dfe6 100644 (file)
@@ -25,19 +25,15 @@ void admin_cmd_help(admin_handle h, char **args, void *userdata)
 {
        extern GList *admin_commands;
        extern guint longest_command;
-       GList *gl = admin_commands;
+       GList *gl;
        char *tmp;
        char **details;
        int i;
 
        if(args[1]) {
                admin_out(h, "Details for command %s:", args[1]);
-       } else {
-               admin_out(h, "The following commands are available:");
-       }
-       while(gl) {
-               struct admin_command *cmd = (struct admin_command *)gl->data;
-               if(args[1]) {
+               for (gl = admin_commands; gl; gl = gl->next) {
+                       struct admin_command *cmd = (struct admin_command *)gl->data;
                        if(!g_strcasecmp(args[1], cmd->name)) {
                                if(cmd->help_details != NULL) {
                                        details = g_strsplit(cmd->help_details, "\n", 0);
@@ -49,7 +45,12 @@ void admin_cmd_help(admin_handle h, char **args, void *userdata)
                                        admin_out(h, "Sorry, no help for %s available", args[1]);
                                }
                        }
-               } else {
+               }
+               admin_out(h, "Unknown command");
+       } else {
+               admin_out(h, "The following commands are available:");
+               for (gl = admin_commands; gl; gl = gl->next) {
+                       struct admin_command *cmd = (struct admin_command *)gl->data;
                        if(cmd->help != NULL) {
                                tmp = g_strdup_printf("%s%s     %s",cmd->name,g_strnfill(longest_command - strlen(cmd->name),' '),cmd->help);
                                admin_out(h, tmp);
@@ -58,9 +59,5 @@ void admin_cmd_help(admin_handle h, char **args, void *userdata)
                                admin_out(h, cmd->name);
                        }
                }
-               gl = gl->next;
-       }
-       if(args[1]) {
-               admin_out(h, "Unknown command");
        }
 }