4 * client_chat.c -- front end for chat mode
5 * (the "single process" version - no more fork() anymore)
19 #include <sys/types.h>
21 #include <sys/select.h>
24 #include "client_chat.h"
28 #include "citadel_decls.h"
37 int send_complete_line;
38 int recv_complete_line;
49 printf("%s\n",&buf[4]);
53 printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
54 set_keepalives(KA_CHAT);
60 send_complete_line = 0;
61 recv_complete_line = 0;
67 FD_SET(getsockfd(),&rfds);
68 tv.tv_sec = S_KEEPALIVE;
70 retval = select(getsockfd()+1, &rfds, NULL, NULL, &tv);
72 if (FD_ISSET(getsockfd(), &rfds)) {
75 recv_complete_line = 1;
76 goto RCL; /* ugly, but we've gotta get out! */
79 buf[strlen(buf) + 1] = 0;
80 buf[strlen(buf)] = ch;
85 if (FD_ISSET(0, &rfds)) {
87 if ((ch == 10) || (ch == 13)) {
88 send_complete_line = 1;
90 else if ((ch == 8) || (ch == 127)) {
91 if (strlen(wbuf) > 0) {
92 wbuf[strlen(wbuf)-1] = 0;
98 wbuf[strlen(wbuf) + 1] = 0;
99 wbuf[strlen(wbuf)] = ch;
104 /* if the user hit return, send the line */
105 RCL: if (send_complete_line) {
108 send_complete_line = 0;
111 /* if it's time to word wrap, send a partial line */
112 if ( strlen(wbuf) >= (77-strlen(fullname)) ) {
114 for (a=0; a<strlen(wbuf); ++a) {
115 if (wbuf[a] == 32) pos = a;
120 send_complete_line = 0;
125 strcpy(wbuf,&wbuf[pos+1]);
129 if (recv_complete_line) {
130 printf("\r%79s\r","");
131 if (!strcmp(buf,"000")) {
133 printf("Exiting chat mode\n");
136 set_keepalives(KA_YES);
139 if (num_parms(buf)>=2) {
140 extract(c_user,buf,0);
141 extract(c_text,buf,1);
142 if (num_parms(buf)>2)
144 extract(c_room,buf,2);
145 printf("Got room %s\n", c_room);
148 if (strucmp(c_text,"NOOP")) {
149 if (!strcmp(c_user, fullname)) {
152 else if (!strcmp(c_user,":")) {
158 if (strcmp(c_user,last_user)) {
159 sprintf(buf,"%s: %s",c_user,c_text);
162 sprintf(buf,"%40s","");
163 sprintf(&buf[strlen(c_user)+2],
166 while (strlen(buf)<79) strcat(buf," ");
167 if (strcmp(c_user,last_user)) {
168 printf("\r%79s\n","");
169 strcpy(last_user,c_user);
171 printf("\r%s\n",buf);
177 recv_complete_line = 0;