Skip to content

Commit ed5c381

Browse files
authored
Add usage() function
1 parent 2718692 commit ed5c381

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

kirc.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515

1616
#define MSG_MAX 512 /* guaranteed max message length */
1717
#define CHA_MAX 200 /* guaranteed max channel length */
18-
#define VERSION "0.1.1" /* software version */
19-
#define USAGE "kirc [-s hostname] [-p port] [-c channel] [-n nick] \
20-
[-r real_name] [-u username] [-k password] [-a token] [-x init_command] \
21-
[-w columns] [-W columns] [-o path] [-h|v|V]"
2218

2319
static int conn; /* connection socket */
2420
static char chan_default[MSG_MAX]; /* default channel for PRIVMSG */
@@ -275,35 +271,42 @@ keyboard_hit() {
275271
return byteswaiting;
276272
}
277273

274+
static void
275+
usage(void) {
276+
fputs("kirc [-s hostname] [-p port] [-c channel] [-n nick] \
277+
[-r real_name] [-u username] [-k password] [-a token] [-x init_command] \
278+
[-w columns] [-W columns] [-o path] [-h|v|V]\n", stderr);
279+
exit(EXIT_FAILURE);
280+
}
281+
278282
int
279283
main(int argc, char **argv) {
280284

281285
int cval;
282286

283287
while ((cval = getopt(argc, argv, "s:p:o:n:k:c:u:r:x:w:W:a:hvV")) != -1) {
284288
switch (cval) {
285-
case 'V' : verb = 1; break;
286-
case 's' : host = optarg; break;
287-
case 'p' : port = optarg; break;
288-
case 'r' : real = optarg; break;
289-
case 'u' : user = optarg; break;
290-
case 'a' : auth = optarg; break;
291-
case 'o' : olog = optarg; break;
292-
case 'n' : nick = optarg; break;
293-
case 'k' : pass = optarg; break;
294-
case 'c' : chan = optarg; break;
295-
case 'x' : inic = optarg; break;
296-
case 'w' : gutl = atoi(optarg); break;
297-
case 'W' : cmax = atoi(optarg); break;
298-
case 'v' : printf("kirc %s\n", VERSION); return EXIT_SUCCESS;
299-
case 'h' : printf("usage: %s\n", USAGE); return EXIT_SUCCESS;
300-
case '?' : return EXIT_FAILURE;
289+
case 'V' : verb = 1; break;
290+
case 's' : host = optarg; break;
291+
case 'p' : port = optarg; break;
292+
case 'r' : real = optarg; break;
293+
case 'u' : user = optarg; break;
294+
case 'a' : auth = optarg; break;
295+
case 'o' : olog = optarg; break;
296+
case 'n' : nick = optarg; break;
297+
case 'k' : pass = optarg; break;
298+
case 'c' : chan = optarg; break;
299+
case 'x' : inic = optarg; break;
300+
case 'w' : gutl = atoi(optarg); break;
301+
case 'W' : cmax = atoi(optarg); break;
302+
case 'v' : puts("kirc 0.1.2\n"); break;
303+
case '?' : usage(); break;
301304
}
302305
}
303306

304307
if (!nick) {
305308
fputs("Nick not specified\n", stderr);
306-
return EXIT_FAILURE;
309+
usage();
307310
}
308311

309312
if (connection_initialize() != 0) {

0 commit comments

Comments
 (0)