-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.c
166 lines (152 loc) · 3.85 KB
/
list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* Routines to handle `listnicks' and `listchans' invocations.
*
* Services is copyright (c) 1996-1999 Andy Church.
* E-mail: <[email protected]>
* This program is free but copyrighted software; see the file COPYING for
* details.
*/
#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())
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())
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);
}
/*************************************************************************/