ticl

tiny irc channel linker
git clone git://git.ircforever.org/ticl
Log | Files | Refs | Submodules | README | LICENSE

commit 8c6dee8c450f9a7d9b97e51d47429d353a42ff9d
parent c8499f76236656b20c24d0e2bc0690d4ae049b8f
Author: libredev <libredev@ircforever.org>
Date:   Wed, 22 Mar 2023 18:31:26 +0530

fixed openbsd build

Diffstat:
Mconfig.mk | 1-
Mmain.c | 41+++++++++++++++++++++++------------------
Mutil.c | 29+++++++++--------------------
3 files changed, 32 insertions(+), 39 deletions(-)

diff --git a/config.mk b/config.mk @@ -9,7 +9,6 @@ MANPREFIX = $(PREFIX)/share/man 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 diff --git 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_del(int, char *, int); 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 @@ event_timeout(void) 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 @@ event_timeout(void) state = CLONING; htiter_init(&it); } - log1("."); + debug(1, "."); j = 0; while (htiterate(usertofds, &it)) { @@ -472,7 +468,6 @@ fd_read(int fd) (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 @@ fd_read(int fd) 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 @@ fd_read(int fd) } 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_new(int netid, char *user) 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 @@ fd_del(int fd, char *msg, int reconnection) 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 @@ nick_add_symb(char *nick, int netid) * 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 @@ privmsg_update(char *dst, char *src, int netid) } /* 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; } } diff --git 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 @@ print_log(int level, FILE *stream, const char *fmt, va_list arg) } void -log1(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, ...) +debug(int level, 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); }