diff options
| author | rob rob@31f1291d-b8d6-0310-a050-a5561fc1590b <rob rob@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2004-07-19 14:08:30 +0000 |
|---|---|---|
| committer | rob rob@31f1291d-b8d6-0310-a050-a5561fc1590b <rob rob@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2004-07-19 14:08:30 +0000 |
| commit | a1479a87757fb5e9b48f3c8bb5dd9cc247406f1a (patch) | |
| tree | 06d23a51082a398c512ed8f1e39bdac60d4dd658 /src/list.c | |
| parent | 7fffea77edbe72cd66f7a55f41a3966204f9cf86 (diff) | |
BUILD : 1.7.4 (264) BUGS : N/A NOTES : Switched to autoconf - try to commit part 1
git-svn-id: svn://svn.anope.org/anope/trunk@264 31f1291d-b8d6-0310-a050-a5561fc1590b
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@169 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/list.c')
| -rw-r--r-- | src/list.c | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/src/list.c b/src/list.c new file mode 100644 index 000000000..da73f1ab7 --- /dev/null +++ b/src/list.c @@ -0,0 +1,178 @@ +/* Routines to handle `listnicks' and `listchans' invocations. + * + * (C) 2003 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for furhter details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ + +#include "services.h" + +/*************************************************************************/ + +void do_listnicks(int ac, char **av) +{ + int count = 0; /* Count only rather than display? */ + int usage = 0; /* Display command usage? (>0 also indicates error) */ + int i; + + i = 1; + while (i < ac) { + if (av[i][0] == '-') { + switch (av[i][1]) { + case 'h': + usage = -1; + break; + case 'c': + if (i > 1) + usage = 1; + count = 1; + break; + case 'd': + if (av[i][2]) { + services_dir = av[i] + 2; + } else { + if (i >= ac - 1) { + usage = 1; + break; + } + ac--; + memmove(av + i, av + i + 1, sizeof(char *) * ac - i); + services_dir = av[i]; + } + default: + usage = 1; + break; + } /* switch */ + ac--; + if (i < ac) + memmove(av + i, av + i + 1, sizeof(char *) * ac - i); + } else { + if (count) + usage = 1; + i++; + } + } + if (usage) { + fprintf(stderr, "\ +\n\ +Usage: listnicks [-c] [-d data-dir] [nick [nick...]]\n\ + -c: display only count of registered nicks\n\ + (cannot be combined with nicks)\n\ + nick: nickname(s) to display information for\n\ +\n\ +If no nicks are given, the entire nickname database is printed out in\n\ +compact format followed by the number of registered nicks (with -c, the\n\ +list is suppressed and only the count is printed). If one or more nicks\n\ +are given, detailed information about those nicks is displayed.\n\ +\n"); + exit(usage > 0 ? 1 : 0); + } + + if (chdir(services_dir) < 0) { + fprintf(stderr, "chdir(%s): %s\n", services_dir, strerror(errno)); + exit(1); + } + if (!read_config(0)) + exit(1); + load_ns_dbase(); + + lang_init(); + + if (ac > 1) { + for (i = 1; i < ac; i++) + listnicks(0, av[i]); + } else { + listnicks(count, NULL); + } + exit(0); +} + +/*************************************************************************/ + +void do_listchans(int ac, char **av) +{ + int count = 0; /* Count only rather than display? */ + int usage = 0; /* Display command usage? (>0 also indicates error) */ + int i; + + i = 1; + while (i < ac) { + if (av[i][0] == '-') { + switch (av[i][1]) { + case 'h': + usage = -1; + break; + case 'c': + if (i > 1) + usage = 1; + count = 1; + break; + case 'd': + if (av[i][2]) { + services_dir = av[i] + 2; + } else { + if (i >= ac - 1) { + usage = 1; + break; + } + ac--; + memmove(av + i, av + i + 1, sizeof(char *) * ac - i); + services_dir = av[i]; + } + default: + usage = 1; + break; + } /* switch */ + ac--; + if (i < ac) + memmove(av + i, av + i + 1, sizeof(char *) * ac - i); + } else { + if (count) + usage = 1; + i++; + } + } + if (usage) { + fprintf(stderr, "\ +\n\ +Usage: listchans [-c] [-d data-dir] [channel [channel...]]\n\ + -c: display only count of registered channels\n\ + (cannot be combined with channels)\n\ +channel: channel(s) to display information for\n\ +\n\ +If no channels are given, the entire channel database is printed out in\n\ +compact format followed by the number of registered channels (with -c, the\n\ +list is suppressed and only the count is printed). If one or more channels\n\ +are given, detailed information about those channels is displayed.\n\ +\n"); + exit(usage > 0 ? 1 : 0); + } + + if (chdir(services_dir) < 0) { + fprintf(stderr, "chdir(%s): %s\n", services_dir, strerror(errno)); + exit(1); + } + if (!read_config(0)) + exit(1); + load_ns_dbase(); + load_cs_dbase(); + + lang_init(); + + if (ac > 1) { + for (i = 1; i < ac; i++) + listchans(0, av[i]); + } else { + listchans(count, NULL); + } + exit(0); +} + +/*************************************************************************/ |
