ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/vendor/pxys2-2.0.0/pxyservd/src/cmd_showcmds.c
Revision: 3252
Committed: Wed Apr 2 20:41:43 2014 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 2423 byte(s)
Log Message:
- Imported pxys2-2.0.0

File Contents

# Content
1 /* Copyright (C) 2003 Stephane Thiell
2 *
3 * This file is part of pxyservd (from pxys)
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 */
20 #define RCSID "$Id: cmd_showcmds.c,v 1.1.1.1 2003/12/30 17:09:29 mbuna Exp $"
21
22 #include "irc_cmd.h"
23 #include "irc_msg.h"
24 #include "irc_send.h"
25 #include "cfgloader.h"
26
27 #include "irc_membership.h"
28 #include "irc_channel.h"
29 #include "irc_client.h"
30
31 #include <libbcl/memory.h>
32
33 #include <assert.h>
34 #include <string.h>
35 #include <peak/dict.h>
36
37 extern peak_dict cmds_map;
38
39 static int
40 showcmds_sort(const void *val1, const void *val2)
41 {
42 const char *cmd1 = *(const char **)val1;
43 const char *cmd2 = *(const char **)val2;
44
45 return strcmp(cmd1, cmd2);
46 }
47
48 void
49 cmd_showcmds(struct Client *cptr, toktabptr ttab)
50 {
51 const char *dst = ttab->tok[0];
52 int cnt;
53 const char *cmds_buf[100];
54 const char **cmds, *p;
55 int i;
56
57 if (!(cptr->flags & CLIENT_FLAG_OPER))
58 return; /* Non opers go play balls. */
59
60 cnt = peak_dict_get_count(cmds_map);
61 assert(cnt > 0);
62
63 send_client_to_one(dst, "%d COMMANDS ENABLED", cnt);
64 send_client_to_one(dst, "------------------------", cnt);
65
66 /* Allocate on stack if possible. Could use peak_dict_apply() too, but
67 * it's less readable.
68 */
69 cmds = (cnt > 100)
70 ? (const char **)memory_alloc(cnt * sizeof(const char *))
71 : cmds_buf;
72
73 peak_dict_get_all(cmds_map, (const void **)cmds, NULL);
74
75 qsort(cmds, cnt, sizeof(const char *), showcmds_sort);
76
77 for (i = 0; i < cnt; i += 2)
78 {
79 p = *cmds++;
80 if (i + 1 < cnt)
81 send_client_to_one(dst, " %-10s %s", p, *cmds++);
82 else
83 send_client_to_one(dst, " %-10s", p);
84 }
85
86 if (cnt > 100)
87 memory_free(cmds);
88
89 send_client_to_one(dst, "------------------------");
90 }