Merge trunk.
[jelmer/ctrlproxy.git] / src / help.c
1 /*
2         ctrlproxy: A modular IRC proxy
3         help: module for access the help system
4
5         (c) 2006 Jelmer Vernooij <jelmer@nl.linux.org>
6
7         This program is free software; you can redistribute it and/or modify
8         it under the terms of the GNU General Public License as published by
9         the Free Software Foundation; either version 2 of the License, or
10         (at your option) any later version.
11
12         This program is distributed in the hope that it will be useful,
13         but WITHOUT ANY WARRANTY; without even the implied warranty of
14         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15         GNU General Public License for more details.
16
17         You should have received a copy of the GNU General Public License
18         along with this program; if not, write to the Free Software
19         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "internals.h"
23
24 void admin_cmd_help(admin_handle h, char **args, void *userdata)
25 {
26         extern GList *admin_commands;
27         extern guint longest_command;
28         GList *gl = admin_commands;
29         char *tmp;
30         char **details;
31         int i;
32
33         if(args[1]) {
34                 admin_out(h, "Details for command %s:", args[1]);
35         } else {
36                 admin_out(h, "The following commands are available:");
37         }
38         while(gl) {
39                 struct admin_command *cmd = (struct admin_command *)gl->data;
40                 if(args[1]) {
41                         if(!g_strcasecmp(args[1], cmd->name)) {
42                                 if(cmd->help_details != NULL) {
43                                         details = g_strsplit(cmd->help_details, "\n", 0);
44                                         for(i = 0; details[i] != NULL; i++) {
45                                                 admin_out(h, details[i]);
46                                         }
47                                         return;
48                                 } else {
49                                         admin_out(h, "Sorry, no help for %s available", args[1]);
50                                 }
51                         }
52                 } else {
53                         if(cmd->help != NULL) {
54                                 tmp = g_strdup_printf("%s%s     %s",cmd->name,g_strnfill(longest_command - strlen(cmd->name),' '),cmd->help);
55                                 admin_out(h, tmp);
56                                 g_free(tmp);
57                         } else {
58                                 admin_out(h, cmd->name);
59                         }
60                 }
61                 gl = gl->next;
62         }
63         if(args[1]) {
64                 admin_out(h, "Unknown command");
65         }
66 }