4 * client_chat.c -- front end for chat mode
5 * (the "single process" version - no more fork() anymore)
21 #include <sys/types.h>
22 #ifdef HAVE_SYS_SELECT_H
23 #include <sys/select.h>
26 #include "client_chat.h"
30 #include "citadel_decls.h"
39 int send_complete_line;
40 int recv_complete_line;
51 printf("%s\n",&buf[4]);
55 printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
56 set_keepalives(KA_CHAT);
62 send_complete_line = 0;
63 recv_complete_line = 0;
69 FD_SET(getsockfd(),&rfds);
70 tv.tv_sec = S_KEEPALIVE;
72 retval = select(getsockfd()+1, &rfds, NULL, NULL, &tv);
74 if (FD_ISSET(getsockfd(), &rfds)) {
77 recv_complete_line = 1;
78 goto RCL; /* ugly, but we've gotta get out! */
81 buf[strlen(buf) + 1] = 0;
82 buf[strlen(buf)] = ch;
87 if (FD_ISSET(0, &rfds)) {
89 if ((ch == 10) || (ch == 13)) {
90 send_complete_line = 1;
92 else if ((ch == 8) || (ch == 127)) {
93 if (strlen(wbuf) > 0) {
94 wbuf[strlen(wbuf)-1] = 0;
100 wbuf[strlen(wbuf) + 1] = 0;
101 wbuf[strlen(wbuf)] = ch;
106 /* if the user hit return, send the line */
107 RCL: if (send_complete_line) {
110 send_complete_line = 0;
113 /* if it's time to word wrap, send a partial line */
114 if ( strlen(wbuf) >= (77-strlen(fullname)) ) {
116 for (a=0; a<strlen(wbuf); ++a) {
117 if (wbuf[a] == 32) pos = a;
122 send_complete_line = 0;
127 strcpy(wbuf,&wbuf[pos+1]);
131 if (recv_complete_line) {
132 printf("\r%79s\r","");
133 if (!strcmp(buf,"000")) {
135 printf("Exiting chat mode\n");
138 set_keepalives(KA_YES);
141 if (num_parms(buf)>=2) {
142 extract(c_user,buf,0);
143 extract(c_text,buf,1);
144 if (num_parms(buf)>2)
146 extract(c_room,buf,2);
147 printf("Got room %s\n", c_room);
150 if (strucmp(c_text,"NOOP")) {
151 if (!strcmp(c_user, fullname)) {
154 else if (!strcmp(c_user,":")) {
160 if (strcmp(c_user,last_user)) {
161 sprintf(buf,"%s: %s",c_user,c_text);
164 sprintf(buf,"%40s","");
165 sprintf(&buf[strlen(c_user)+2],
168 while (strlen(buf)<79) strcat(buf," ");
169 if (strcmp(c_user,last_user)) {
170 printf("\r%79s\n","");
171 strcpy(last_user,c_user);
173 printf("\r%s\n",buf);
179 recv_complete_line = 0;