commit d9a3211df7a1365704c4fd1d06c0074aa41a2756
parent 2b82fd514708a80dc4f2e59d52e9f57a0dd31ec9
Author: aabacchus <ben@bvnf.space>
Date: Tue, 29 Nov 2022 16:24:27 +0000
write to socket too
Diffstat:
M | sxirc.c | | | 39 | +++++++++++++++++++++------------------ |
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/sxirc.c b/sxirc.c
@@ -13,6 +13,20 @@ struct textpair {
Widget in, out;
};
+static int sfd;
+
+int sock_write(int sfd, char *msg, ...){
+ va_list ap;
+ va_start(ap, msg);
+ if (vdprintf(sfd, msg, ap) < 0) {
+ perror("sock_write");
+ va_end(ap);
+ return 1;
+ }
+ va_end(ap);
+ return 0;
+}
+
void
add_text_to_display_newline(char *s, Widget w) {
size_t len;
@@ -49,12 +63,14 @@ submit_cb(Widget w, void *d) {
exit(1);
}
+ sock_write(sfd, "%s\r\n", /* TODO: conditionally add \r\n */ new);
add_text_to_display_newline(new, tp->out);
SetStringEntry(tp->in, "");
}
void
string_cb(Widget w, char *s, void *data) {
+ sock_write(sfd, "%s\r\n", /* TODO: conditionally add \r\n */ s);
add_text_to_display_newline(s, (Widget)data);
SetStringEntry(w, "");
}
@@ -108,18 +124,6 @@ setup_sx(int argc, char **argv, XtAppContext *app, Widget *output) {
return 0;
}
-int sock_write(int sfd, char *msg, ...){
- va_list ap;
- va_start(ap, msg);
- if (vdprintf(sfd, msg, ap) < 0) {
- perror("sock_write");
- va_end(ap);
- return 1;
- }
- va_end(ap);
- return 0;
-}
-
int
server_connect(char *nodename, char *servname) {
int s, sfd;
@@ -162,16 +166,16 @@ setup_irc(int *sockfd) {
char nodename[] = "irc.libera.chat";
char servname[] = "6667";
char nick[] = "sxirc";
- int sfd;
+ int s;
- sfd = server_connect(nodename, servname);
- if (sfd == -1)
+ s = server_connect(nodename, servname);
+ if (s == -1)
return 1;
/* identify */
- sock_write(sfd, "NICK %s\r\nUSER %s 8 x :%s\r\n", nick, nick, nick);
+ sock_write(s, "NICK %s\r\nUSER %s 8 x :%s\r\n", nick, nick, nick);
- *sockfd = sfd;
+ *sockfd = s;
return 0;
}
@@ -179,7 +183,6 @@ int
main(int argc, char **argv) {
XtAppContext app;
Widget output;
- int sfd;
if (setup_sx(argc, argv, &app, &output) != 0)
return 1;