-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
71 lines (64 loc) · 1.58 KB
/
utils.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
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include "include/bot.h"
#include "include/irc.h"
#include "include/utils.h"
void debug_print_msg(struct IRC_MSG *msg) {
printf("IRC_MSG: {\n\t %s: ", "_raw");
print_buf(msg->_raw, msg->_raw_len);
printf(",\n\t%s: %lu,\n\t",
"_raw_len", msg->_raw_len);
printf("IRC_SRC: {\n\t\t%s: %s,\n\t\t%s: %s,\n\t\t%s: %s,\n\t\t%s: %s\n\t},\n\t",
"server_name", msg->src->server_name,
"nick", msg->src->nick,
"user", msg->src->user,
"host", msg->src->host);
printf("%s: %s,\n\t%s: %d,\n\t",
"command", msg->command,
"argc", msg->argc);
printf("argv: [");
for (int i = 0; i < msg->argc; i++) {
printf("%s", msg->argv[i]);
if (i != (msg->argc - 1))
printf(", ");
}
printf("],\n\t");
printf("%s: %s,\n\t%s: %d\n}\n",
"text", msg->text,
"valid", msg->valid
);
}
void print_buf(char *buf, size_t len) {
for (int i = 0; i < len; i++) {
switch (buf[i]) {
case '\n':
fputs("\\n", stdout);
break;
case '\r':
fputs("\\r", stdout);
break;
case '\0':
fputs("\\0", stdout);
break;
case '\t':
fputs("\\t", stdout);
break;
default:
putchar(buf[i]);
}
}
}
void sigint_handler(int signo) {
error("sigint");
}
void sigpipe_handler(int signo) {
error("sigpipe");
}
void error(char *msg) {
printf(msg);
}
void success(char *msg) {
printf(msg);
}