|
1 | 1 | /* See LICENSE file for license details. */
|
2 | 2 | #define _POSIX_C_SOURCE 200809L
|
3 |
| -#include <ctype.h> |
4 | 3 | #include <stdarg.h>
|
5 | 4 | #include <netdb.h>
|
6 | 5 | #include <stdio.h>
|
|
18 | 17 | #define CHA_MAX 200 /* guaranteed max channel length */
|
19 | 18 | #define VERSION "0.1.0" /* software version */
|
20 | 19 | #define USAGE "kirc [-s hostname] [-p port] [-c channel] [-n nick] \
|
21 |
| -[-r real name] [-u username] [-k password] [-x init command] [-w columns] \ |
22 |
| -[-W columns] [-o path] [-h|v|V]" |
23 |
| -#define HELP "\ |
24 |
| -<message> Send a message to the current channel.\n\ |
25 |
| -/m <nick|channel> <message> Send a message to a specified channel or nick.\n\ |
26 |
| -/M <message> Send a message to NickServ.\n\ |
27 |
| -/Q <message> Send a message and close the host connection.\n\ |
28 |
| -/x <message> Send a message directly to the server.\n\ |
29 |
| -/j <channel> Join a specified channel.\n\ |
30 |
| -/p <channel> Leave (part) a specified channel.\n\ |
31 |
| -/u <channel> Assign new default message channel.\n\ |
32 |
| -/n List all users on the current channel.\n\ |
33 |
| -/q Close the host connection.\n\ |
34 |
| -/h Print a list of available kirc commands." |
35 |
| - |
| 20 | +[-r real_name] [-u username] [-k password] [-a token] [-x init_command] \ |
| 21 | +[-w columns] [-W columns] [-o path] [-h|v|V]" |
36 | 22 |
|
37 | 23 | static int conn; /* connection socket */
|
38 | 24 | static int verb = 0; /* verbose output (e.g. raw stream) */
|
@@ -143,7 +129,7 @@ printw(const char *format, ...) {
|
143 | 129 |
|
144 | 130 | if (olog) log_append(line, olog);
|
145 | 131 |
|
146 |
| - for (i = 0; isspace(line[i]); ++i) putchar(line[i]); |
| 132 | + for (i = 0; line[i] == ' '; ++i) putchar(line[i]); |
147 | 133 |
|
148 | 134 | spaceleft = cmax + gutl - (i - 1);
|
149 | 135 |
|
@@ -176,7 +162,7 @@ raw_parser(char *usrin) {
|
176 | 162 | if (!strncmp(usrin, "AUTHENTICATE +", 14)) {
|
177 | 163 | raw("AUTHENTICATE %s\r\n", auth);
|
178 | 164 | return;
|
179 |
| - } |
| 165 | + } |
180 | 166 |
|
181 | 167 | if (usrin[0] != ':') return;
|
182 | 168 |
|
@@ -244,28 +230,25 @@ handle_server_message(void) {
|
244 | 230 | static void
|
245 | 231 | handle_user_input(void) {
|
246 | 232 |
|
247 |
| - char usrin[MSG_MAX], v1[MSG_MAX - CHA_MAX], v2[CHA_MAX], c1; |
| 233 | + char usrin[MSG_MAX]; |
248 | 234 |
|
249 | 235 | fgets(usrin, MSG_MAX, stdin);
|
250 |
| - if (sscanf(usrin, "/%[m] %s %[^\n]\n", &c1, v2, v1) > 2 || |
251 |
| - sscanf(usrin, "/%[a-zA-Z] %[^\n]\n", &c1, v1) > 0) { |
252 |
| - switch (c1) { |
253 |
| - case 'x': raw("%s\r\n", v1); break; |
254 |
| - case 'q': raw("quit\r\n"); break; |
255 |
| - case 'Q': raw("quit %s\r\n", v1); break; |
256 |
| - case 'j': raw("join %s\r\n", v1); break; |
257 |
| - case 'p': raw("part %s\r\n", v1); break; |
258 |
| - case 'n': raw("names #%s\r\n", chan); break; |
259 |
| - case 'M': raw("privmsg nickserv :%s\r\n", v1); break; |
260 |
| - case 'm': raw("privmsg %s :%s\r\n", v2, v1); break; |
261 |
| - case 'u': strcpy(chan, v1); break; |
262 |
| - default : puts(HELP); break; |
| 236 | + |
| 237 | + size_t msg_len = strlen(usrin); |
| 238 | + if (usrin[msg_len - 1] == '\n') { |
| 239 | + usrin[msg_len - 1] = '\0'; |
| 240 | + } |
| 241 | + |
| 242 | + if (usrin[0] == '/') { |
| 243 | + if (usrin[1] == '#') { |
| 244 | + strcpy(chan, usrin + 2); |
| 245 | + printf("new channel: #%s\n", chan); |
| 246 | + } else if (usrin[1] == '?' && msg_len == 3) { |
| 247 | + printf("current channel: #%s\n", chan); |
| 248 | + } else { |
| 249 | + raw("%s\r\n", usrin + 1); |
263 | 250 | }
|
264 | 251 | } else {
|
265 |
| - size_t msg_len = strlen(usrin); |
266 |
| - if (usrin[msg_len - 1] == '\n') { |
267 |
| - usrin[msg_len - 1] = '\0'; |
268 |
| - } |
269 | 252 | raw("privmsg #%s :%s\r\n", chan, usrin);
|
270 | 253 | }
|
271 | 254 | }
|
|
0 commit comments