ref: 8c6dee8c450f9a7d9b97e51d47429d353a42ff9d
parent: c8499f76236656b20c24d0e2bc0690d4ae049b8f
author: libredev <libredev@ircforever.org>
date: Wed Mar 22 14:31:26 EDT 2023
fixed openbsd build
--- a/config.mk
+++ b/config.mk
@@ -9,7 +9,6 @@
CPPFLAGS = -D_DEFAULT_SOURCE -DVERSION=\"$(VERSION)\"
CFLAGS = -g -std=c89 -Wall -Wextra -pedantic -Wfatal-errors -Wconversion\
-Wstrict-prototypes -Wold-style-definition $(CPPFLAGS)
-CFLAGS += -rdynamic
LDFLAGS = $(LIBS)
CC = cc
--- a/main.c
+++ b/main.c
@@ -14,10 +14,6 @@
#ifdef __gnu_linux__
#include <sys/epoll.h>
-char *strlcpy(char *dst, const char *src, size_t n)
-{
- return strncpy(dst, src, n);
-}
#else
#include <sys/event.h>
#endif
@@ -112,7 +108,7 @@
void fd_reconn(int, char *);
int *clone_get_fds(char *, int);
void nick_add_symb(char *, int);
-void privmsg_update(char *, char *, int);
+void privmsg_update(char *, char *, int, int);
void print_table(void);
void print_htable(void);
void print_users(void);
@@ -338,7 +334,7 @@
if (state == IDLE) {
struct fd_ref *tmp;
- log1("Reconnecting");
+ debug(1, "Reconnecting");
while(reconn_list_head != NULL) {
user = reconn_list_head->user;
i = reconn_list_head->netid;
@@ -363,7 +359,7 @@
state = CLONING;
htiter_init(&it);
}
- log1(".");
+ debug(1, ".");
j = 0;
while (htiterate(usertofds, &it)) {
@@ -472,7 +468,6 @@
(strcmp(cmd, "003") == 0) ||
(strcmp(cmd, "004") == 0) ||
(strcmp(cmd, "005") == 0) ||
- (strcmp(cmd, "003") == 0) ||
(strcmp(cmd, "251") == 0) ||
(strcmp(cmd, "252") == 0) ||
(strcmp(cmd, "253") == 0) || /* unknown connection(s) */
@@ -526,9 +521,10 @@
return;
split(&buf, ':'); /* set buf to msg */
- privmsg_update(privmsg, buf, netid);
for (i = 0; i < netlen; i++) {
+ printf("%s\n", buf);
if (fds[i] > 0) {
+ privmsg_update(privmsg, buf, netid, fds[i]);
snprintf(msg, sizeof(msg), "PRIVMSG %s :%s\r\n", networks[i].chan, privmsg);
writeall(fds[i], msg);
}
@@ -557,7 +553,7 @@
}
split(&buf, ':'); /* set buf to msg */
- privmsg_update(privmsg, buf, netid);
+ privmsg_update(privmsg, buf, netid, fds[i]);
snprintf(msg, sizeof(msg), "PRIVMSG %s :%s\r\n", user, privmsg);
writeall(fds[i], msg);
}
@@ -914,9 +910,9 @@
fd_register(fd, EV_WRITE);
if (user == NULL)
- log1("%d: netadd: %s[%s]", fd, n->name, n->symb);
+ debug(1, "%d: netadd: %s[%s]", fd, n->name, n->symb);
else
- log1("%d: add[%s]: %s", fd, n->symb, user);
+ debug(1, "%d: add[%s]: %s", fd, n->symb, user);
if (fd+1 > fdcap) {
fdcap *= 2;
@@ -945,10 +941,10 @@
netid = fdtodata[fd]->netid;
if (user == NULL) {
- log1("%d: netdel: %s[%s]", fd, networks[netid].name, networks[netid].symb);
+ debug(1, "%d: netdel: %s[%s]", fd, networks[netid].name, networks[netid].symb);
networks[netid].fd = reconnection ? -3 : -2;
} else {
- log1("%d: del[%s]: %s", fd, networks[netid].symb, user);
+ debug(1, "%d: del[%s]: %s", fd, networks[netid].symb, user);
if ((fds = htsearch(usertofds, user)) == NULL)
fatal("%s: user doesn't exist", user);
fds[netid] = reconnection ? -3 : -2;
@@ -1011,10 +1007,11 @@
* src will be destructed
*/
void
-privmsg_update(char *dst, char *src, int netid)
+privmsg_update(char *dst, char *src, int netid, int fd)
{
char d; /* delimiter */
char *n;
+ int i, *fds;
while (src != NULL) {
n = strpbrk(src, " :;,<>@&~%+\\");
@@ -1027,12 +1024,20 @@
}
/* check if the word is nick */
- if (clone_get_fds(src, netid) != NULL)
+ if ((fds = clone_get_fds(src, netid)) != NULL) {
+ int netid2 = fdtodata[fd]->netid;
*strrchr(src, '[') = '\0';
+ src[strlen(src)] = '[';
+ if (fds[netid2] > 0) {
+ nick_add_symb(dst, netid2);
+ for (i = 0; i < fdtodata[fds[netid2]]->suffix; i++)
+ strcat(dst, "_");
+ }
+ } else {
+ strcat(dst, src);
+ }
- strcat(dst, src);
strncat(dst, &d, 1);
-
src = n;
}
}
--- a/util.c
+++ b/util.c
@@ -18,6 +18,13 @@
#define FALSE 0
#define TRUE 1
+#ifdef __gnu_linux__
+char *strlcpy(char *dst, const char *src, size_t n)
+{
+ return strncpy(dst, src, n);
+}
+#endif
+
void
print_log(int level, FILE *stream, const char *fmt, va_list arg)
{
@@ -35,29 +42,11 @@
}
void
-log1(const char *fmt, ...)
+debug(int level, const char *fmt, ...)
{
va_list arg;
va_start(arg, fmt);
- print_log(1, stdout, fmt, arg);
- va_end(arg);
-}
-
-void
-log2(const char *fmt, ...)
-{
- va_list arg;
- va_start(arg, fmt);
- print_log(2, stdout, fmt, arg);
- va_end(arg);
-}
-
-void
-log3(const char *fmt, ...)
-{
- va_list arg;
- va_start(arg, fmt);
- print_log(3, stdout, fmt, arg);
+ print_log(level, stdout, fmt, arg);
va_end(arg);
}