sxirc

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 6397e67dc665a7ad72a898f522215e01f70a96f5
parent ec8f02ff2828f38187dcf93d49b66a7a13446d3a
Author: aabacchus <ben@bvnf.space>
Date:   Tue, 29 Nov 2022 15:49:40 +0000

setup for irc

Diffstat:
Ma.c | 34++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/a.c b/a.c @@ -3,6 +3,8 @@ #include <unistd.h> #include <libsx.h> +#define BUFSIZE 513 /* IRC max line length is 510 + \r\n + \0 */ + struct textpair { Widget in, out; }; @@ -60,7 +62,6 @@ quit(Widget w, void *d) { void pollin_cb(XtPointer client_data, int *source, XtInputId *id) { -#define BUFSIZE 30 char c[BUFSIZE] = {'\0'}; if (read(*source, c, BUFSIZE) == 0) XtRemoveInput(*id); @@ -69,10 +70,9 @@ pollin_cb(XtPointer client_data, int *source, XtInputId *id) { } int -setup_sx(int argc, char **argv) { +setup_sx(int argc, char **argv, XtAppContext *app, Widget *output) { static struct textpair tp; - XtAppContext app; - Widget w[4]; + static Widget w[4]; if (OpenDisplay(argc, argv) == 0) { fprintf(stderr, "couldn't open display\n"); @@ -83,6 +83,7 @@ setup_sx(int argc, char **argv) { w[1] = MakeStringEntry(NULL, 200, string_cb, w[0]); tp.in = w[1]; tp.out = w[0]; + *output = w[0]; w[2] = MakeButton("Submit", submit_cb, &tp); w[3] = MakeButton("Quit", quit, NULL); @@ -95,20 +96,37 @@ setup_sx(int argc, char **argv) { if (!w[0] || !w[1]) return 1; - app = XtWidgetToApplicationContext(w[0]); - if (app == NULL) + *app = XtWidgetToApplicationContext(w[0]); + if (*app == NULL) return 1; - XtAppAddInput(app, /* stdin */ 0, XtInputReadMask, pollin_cb, w[0]); return 0; } int +setup_irc(int *sockfd) { + int sfd; + sfd = 0; + + *sockfd = sfd; + return 0; +} + +int main(int argc, char **argv) { - if (setup_sx(argc, argv) != 0) + XtAppContext app; + Widget output; + int sfd; + + if (setup_sx(argc, argv, &app, &output) != 0) return 1; + if (setup_irc(&sfd) != 0) + return 1; + + XtAppAddInput(app, sfd, XtInputReadMask, pollin_cb, output); + ShowDisplay(); GetStandardColors(); MainLoop();