2 * Citadel/UX message support routines
3 * see copyright.txt for copyright information
10 #include <sys/types.h>
31 #define MAXWORDBUF 256
36 char text[MAXWORDBUF];
39 void sttybbs(int cmd);
40 int struncmp(char *lstr, char *rstr, int len);
41 int fmout(int width, FILE *fp, char pagin, int height, int starting_lp, char subst);
42 int haschar(char *st, int ch);
43 int checkpagin(int lp, int pagin, int height);
44 void getline(char *string, int lim);
45 void formout(char *name);
47 void newprompt(char *prompt, char *str, int len);
48 int file_checksum(char *filename);
49 void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd);
52 long msg_arr[MAXMSGS];
54 extern char room_name[];
55 extern unsigned room_flags;
56 extern long highest_msg_read;
57 extern struct CtdlServInfo serv_info;
60 extern int screenwidth;
61 extern int screenheight;
62 extern long maxmsgnum;
65 extern char is_room_aide;
66 extern char fullname[];
68 extern unsigned userflags;
69 extern char sigcaught;
70 extern char editor_path[];
71 extern char printcmd[];
72 extern int rc_allow_attachments;
73 extern int rc_display_message_numbers;
74 extern int rc_force_mail_prompts;
76 extern int editor_pid;
80 void ka_sigcatch(int signum) {
83 signal(SIGALRM, ka_sigcatch);
90 * server keep-alive version of wait() (needed for external editor)
92 pid_t ka_wait(int *kstatus)
97 signal(SIGALRM, ka_sigcatch);
101 } while (errno==EINTR);
102 signal(SIGALRM,SIG_IGN);
109 * version of system() that uses ka_wait()
111 int ka_system(char *shc)
120 perror("Cannot fork");
122 return((pid_t)childpid);
126 execlp("/bin/sh","sh","-c",shc,NULL);
132 waitpid = ka_wait(&retcode);
133 } while (waitpid != childpid);
143 * add a newline to the buffer...
145 void add_newline(struct cittext *textlist)
150 while (ptr->next != NULL) ptr = ptr->next;
152 while (ptr->text[strlen(ptr->text)-1]==32)
153 ptr->text[strlen(ptr->text)-1] = 0;
154 /* strcat(ptr->text,"\n"); */
156 ptr->next = (struct cittext *)
157 malloc(sizeof(struct cittext));
160 strcpy(ptr->text,"");
165 * add a word to the buffer...
167 void add_word(struct cittext *textlist, char *wordbuf)
173 while (ptr->next != NULL) ptr = ptr->next;
175 if (3+strlen(ptr->text)+strlen(wordbuf) > screenwidth) {
176 ptr->next = (struct cittext *)
177 malloc(sizeof(struct cittext));
180 strcpy(ptr->text,"");
183 strcat(ptr->text,wordbuf);
184 strcat(ptr->text," ");
189 * begin editing of an opened file pointed to by fp
191 void citedit(FILE *fp)
193 int a,prev,finished,b,last_space;
195 struct cittext *textlist = NULL;
197 char wordbuf[MAXWORDBUF];
199 /* first, load the text into the buffer */
201 textlist = (struct cittext *)malloc(sizeof(struct cittext));
202 textlist->next = NULL;
203 strcpy(textlist->text,"");
207 while (a=getc(fp), a>=0) {
209 if ((a==32)||(a==9)||(a==13)||(a==10)) {
210 add_word(textlist,wordbuf);
212 if ((prev==13)||(prev==10)) {
213 add_word(textlist,"\n");
214 add_newline(textlist);
215 add_word(textlist,"");
219 wordbuf[strlen(wordbuf)+1] = 0;
220 wordbuf[strlen(wordbuf)] = a;
222 if (strlen(wordbuf)+3 > screenwidth) {
223 add_word(textlist,wordbuf);
231 prev = (appending ? 13 : (-1));
239 if ((a==32)&&(prev==13)) {
240 add_word(textlist,"\n");
241 add_newline(textlist);
244 if (strlen(wordbuf)>0) {
245 wordbuf[strlen(wordbuf)-1] = 0;
253 if (strlen(wordbuf)==0) finished = 1;
255 for (b=0; b<strlen(wordbuf); ++b)
256 if (wordbuf[b]==32) {
258 add_word(textlist,wordbuf);
259 strcpy(wordbuf,&wordbuf[b+1]);
262 add_word(textlist,wordbuf);
268 wordbuf[strlen(wordbuf)+1] = 0;
269 wordbuf[strlen(wordbuf)] = a;
271 if ((strlen(wordbuf)+3) > screenwidth) {
273 for (b=0; b<strlen(wordbuf); ++b)
274 if (wordbuf[b]==32) last_space = b;
276 for (b=0; b<strlen(wordbuf); ++b)
277 if (wordbuf[b]==32) {
279 add_word(textlist,wordbuf);
280 strcpy(wordbuf,&wordbuf[b+1]);
283 for (b=0; b<strlen(wordbuf); ++b) {
288 printf("\n%s",wordbuf);
291 add_word(textlist,wordbuf);
297 } while (finished==0);
300 /* write the buffer back to disk */
302 for (ptr=textlist; ptr!=NULL; ptr=ptr->next) {
303 fprintf(fp,"%s",ptr->text);
307 ftruncate(fileno(fp), ftell(fp));
309 /* and deallocate the memory we used */
310 while (textlist!=NULL) {
318 int read_message(long int num, char pagin) /* Read a message from the server */
320 /* 0 = normal read, 1 = read with pagination, 2 = header */
324 char from[256], node[256], rfca[256];
333 sprintf(buf,"MSG0 %ld|%d",num,(pagin==READ_HEADER ? 1 : 0));
337 printf("*** msg #%ld: %s\n",num,buf);
339 lines_printed = checkpagin(lines_printed,pagin,screenheight);
344 strcpy(m_subject,"");
345 strcpy(reply_to, "nobody ... xxxxx");
352 lines_printed = checkpagin(lines_printed,pagin,screenheight);
354 if (pagin == 1) color(BRIGHT_CYAN);
357 while(serv_gets(buf), strcmp(buf,"000")) {
362 checkpagin(lines_printed,
370 while(serv_gets(buf), struncmp(buf,"text",4)) {
371 if (!struncmp(buf,"nhdr=yes",8)) nhdr=1;
372 if (!struncmp(buf,"from=",5)) {
373 strcpy(from,&buf[5]);
375 if (nhdr==1) buf[0]='_';
376 if (!struncmp(buf,"type=",5))
377 format_type=atoi(&buf[5]);
378 if ((!struncmp(buf,"msgn=",5))&&(rc_display_message_numbers)) {
382 printf("#%s",&buf[5]);
386 if (!struncmp(buf,"from=",5)) {
390 printf("%s ",&buf[5]);
392 if (!struncmp(buf,"subj=",5))
393 strcpy(m_subject,&buf[5]);
395 if (!struncmp(buf,"rfca=",5)) {
396 safestrncpy(rfca, &buf[5], sizeof(rfca) - 5);
400 printf("%s",&buf[5]);
404 if ((!struncmp(buf,"hnod=",5))
405 && (strucmp(&buf[5],serv_info.serv_humannode))
406 && (strlen(rfca) == 0) ) {
410 printf("%s",&buf[5]);
414 if ((!struncmp(buf,"room=",5))
415 && (strucmp(&buf[5],room_name))
416 && (strlen(rfca) == 0)) {
419 color(BRIGHT_MAGENTA);
420 printf("%s> ",&buf[5]);
423 if (!struncmp(buf,"node=",5)) {
424 safestrncpy(node, &buf[5], sizeof(buf) - 5);
425 if ( (room_flags&QR_NETWORK)
426 || ((strucmp(&buf[5],serv_info.serv_nodename)
427 &&(strucmp(&buf[5],serv_info.serv_fqdn)))) )
429 if (strlen(rfca) == 0) {
432 color(BRIGHT_YELLOW);
433 printf("%s ",&buf[5]);
438 if (!struncmp(buf,"rcpt=",5)) {
442 printf("%s ",&buf[5]);
444 if (!struncmp(buf,"time=",5)) {
445 fmt_date(now, atol(&buf[5]));
460 if (strlen(rfca) > 0) {
461 strcpy(reply_to, rfca);
464 snprintf(reply_to, sizeof(reply_to), "%s @ %s", from, node);
467 if (pagin == 1) color(BRIGHT_WHITE);
469 lines_printed = checkpagin(lines_printed,pagin,screenheight);
471 if (strlen(m_subject)>0) {
472 printf("Subject: %s\n",m_subject);
474 lines_printed = checkpagin(lines_printed,pagin,screenheight);
477 if (format_type == 0) {
478 fr=fmout(screenwidth,NULL,
479 ((pagin==1) ? 1 : 0),
480 screenheight,(-1),1);
483 while(serv_gets(buf), strcmp(buf,"000")) {
486 lines_printed = lines_printed + 1 +
487 (strlen(buf)/screenwidth);
489 checkpagin(lines_printed,pagin,screenheight);
496 lines_printed = checkpagin(lines_printed,pagin,screenheight);
498 if (pagin == 1) color(DIM_WHITE);
504 * replace string function for the built-in editor
506 void replace_string(char *filename, long int startpos)
515 int substitutions = 0;
518 printf("Enter text to be replaced:\n: ");
519 getline(srch_str,128);
520 if (strlen(srch_str)==0) return;
522 printf("Enter text to replace it with:\n: ");
523 getline(rplc_str,128);
525 fp=fopen(filename,"r+");
526 if (fp==NULL) return;
529 fseek(fp,startpos,0);
531 while (a=getc(fp), a>0) {
533 buf[strlen(buf)+1] = 0;
534 buf[strlen(buf)] = a;
535 if ( strlen(buf) >= strlen(srch_str) ) {
536 ptr=&buf[strlen(buf)-strlen(srch_str)];
537 if (!struncmp(ptr,srch_str,strlen(srch_str))) {
538 strcpy(ptr,rplc_str);
542 if (strlen(buf)>384) {
545 fwrite((char *)buf,128,1,fp);
546 strcpy(buf,&buf[128]);
552 if (strlen(buf)>0) fwrite((char *)buf,strlen(buf),1,fp);
555 truncate(filename, wpos);
556 printf("<R>eplace made %d substitution(s).\n\n",substitutions);
560 int make_message(char *filename, /* temporary file name */
561 char *recipient, /* NULL if it's not mail */
562 int anon_type, /* see MES_ types in header file */
572 if (mode==2) if (strlen(editor_path)==0) {
573 printf("*** No editor available, using built-in editor\n");
577 fmt_date(datestr, time(NULL));
579 if (room_flags & QR_ANONONLY) {
583 printf(" %s from %s",datestr,fullname);
584 if (strlen(recipient)>0) printf(" to %s",recipient);
590 if (mode==1) printf("(Press ctrl-d when finished)\n");
592 fp=fopen(filename,"r");
594 fmout(screenwidth,fp,0,screenheight,0,0);
599 fp=fopen(filename,"w");
607 fp=fopen(filename,"r+");
613 fp=fopen(filename,"w");
615 a=inkey(); if (a==255) a=32;
621 if (a==10) putc(13,stdout);
627 e_ex_code = 1; /* start with a failed exit code */
629 cksum = file_checksum(filename);
631 chmod(filename,0600);
633 execlp(editor_path,editor_path,filename,NULL);
636 if (editor_pid>0) do {
638 b=ka_wait(&e_ex_code);
639 } while((b!=editor_pid)&&(b>=0));
646 if (file_checksum(filename) == cksum) {
647 printf("*** Aborted message.\n");
650 if (e_ex_code==0) goto MEFIN;
654 b = keymenu("Entry command (? for options)",
655 "<A>bort|<C>ontinue|<S>ave message|<P>rint formatted|"
656 "<R>eplace string|<H>old message");
658 if (b=='a') goto MEABT;
659 if (b=='c') goto ME1;
660 if (b=='s') goto MEFIN;
662 printf(" %s from %s",datestr,fullname);
663 if (strlen(recipient)>0) printf(" to %s",recipient);
665 fp=fopen(filename,"r");
667 fmout(screenwidth,fp,
668 ((userflags & US_PAGINATOR) ? 1 : 0),
676 replace_string(filename,0L);
685 MEABT: printf("Are you sure? ");
686 if (yesno()==0) goto ME1;
687 MEABT2: unlink(filename);
692 * transmit message text to the server
694 void transmit_message(FILE *fp)
701 fseek(fp, 0L, SEEK_END);
704 lasttick = time(NULL);
706 while (ch=getc(fp), (ch>=0)) {
708 if (!strcmp(buf,"000")) strcpy(buf,">000");
716 if ((ch==32)&&(strlen(buf)>200)) {
718 if (!strcmp(buf,"000")) strcpy(buf,">000");
722 if (strlen(buf)>250) {
723 if (!strcmp(buf,"000")) strcpy(buf,">000");
729 if ( (time(NULL) - lasttick) > 2L ) {
730 printf(" %3ld%% completed\r",
731 ((ftell(fp) * 100L) / msglen) );
733 lasttick = time(NULL);
745 * entmsg() - edit and create a message
746 * returns 0 if message was saved
748 int entmsg(int is_reply, int c)
749 /* nonzero if this was a <R>eply command */
762 sprintf(cmd,"ENT0 0||0|%d",mode);
766 if ((strncmp(cmd,"570",3)) && (strncmp(cmd,"200",3))) {
767 printf("%s\n",&cmd[4]);
771 if (!strncmp(cmd,"570",3)) need_recp = 1;
773 if ((userflags & US_EXPERT) == 0) formout("entermsg");
779 strcpy(buf,reply_to);
782 printf("Enter recipient: ");
784 if (strlen(buf)==0) return(1);
787 else strcpy(buf,"sysop");
791 if (room_flags&QR_ANONOPT) {
792 printf("Anonymous (Y/N)? ");
796 /* if it's mail, we've got to check the validity of the recipient... */
798 sprintf(cmd,"ENT0 0|%s|%d|%d",buf,b,mode);
802 printf("%s\n",&cmd[4]);
807 /* learn the number of the newest message in in the room, so we can tell
808 * upon saving whether someone else has posted too
811 serv_puts("MSGS LAST|1");
814 printf("%s\n",&cmd[5]);
817 while (serv_gets(cmd), strcmp(cmd,"000")) {
818 msg_arr[num_msgs++] = atol(cmd);
822 /* now put together the message */
823 if ( make_message(temp,buf,b,0,c) != 0 ) return(2);
825 /* and send it to the server */
826 sprintf(cmd,"ENT0 1|%s|%d|%d||",buf,b,mode);
830 printf("%s\n",&cmd[4]);
835 transmit_message(fp);
841 highmsg = msg_arr[num_msgs - 1];
843 serv_puts("MSGS NEW");
846 printf("%s\n",&cmd[5]);
849 while (serv_gets(cmd), strcmp(cmd,"000")) {
850 msg_arr[num_msgs++] = atol(cmd);
854 /* get new highest message number in room to set lrp for goto... */
855 maxmsgnum = msg_arr[num_msgs - 1];
857 /* now see if anyone else has posted in here */
859 for (a=0; a<num_msgs; ++a) if (msg_arr[a]>highmsg) ++b;
861 /* in the Mail> room, this algorithm always counts one message
862 * higher than in public rooms, so we decrement it by one */
866 "*** 1 additional message has been entered in this room by another user.\n");
868 "*** %d additional messages have been entered in this room by other users.\n",b);
873 void process_quote(void) { /* do editing on quoted file */
876 int line,qstart,qend;
878 /* Unlink the second temp file as soon as it's opened, so it'll get
879 * deleted even if the program dies
881 qfile = fopen(temp2,"r");
884 /* Display the quotable text with line numbers added */
886 fgets(buf,128,qfile);
887 while (fgets(buf,128,qfile)!=NULL) {
888 printf("%2d %s",++line,buf);
890 printf("Begin quoting at [ 1] : ");
892 qstart = (buf[0]==0) ? (1) : atoi(buf);
893 printf(" End quoting at [%d] : ",line);
895 qend = (buf[0]==0) ? (line) : atoi(buf);
898 fgets(buf,128,qfile);
899 tfile=fopen(temp,"w");
900 while(fgets(buf,128,qfile)!=NULL) {
901 if ((++line>=qstart)&&(line<=qend)) fprintf(tfile," >%s",buf);
903 fprintf(tfile," \n");
912 * List the URL's which were embedded in the previous message
919 printf("There were no URL's in the previous message.\n\n");
923 for (i=0; i<num_urls; ++i) {
924 printf("%3d %s\n", i+1, urls[i]);
927 if((i = num_urls) != 1)
928 i = intprompt("Display which one", 1, 1, num_urls);
930 sprintf(cmd, rc_url_cmd, urls[i-1]);
936 void readmsgs(int c, int rdir, int q) /* read contents of a room */
937 /* 0=Read all 1=Read new 2=Read old 3=Read last q */
938 /* 1=Forward (-1)=Reverse */
939 /* Number of msgs to read (if c==3) */
946 char prtfile[PATH_MAX];
949 char targ[ROOMNAMELEN];
952 signal(SIGINT,SIG_IGN);
953 signal(SIGQUIT,SIG_IGN);
955 if (c<0) b=(MAXMSGS-1);
958 sprintf(prtfile, tmpnam(NULL));
963 case 0: strcat(cmd,"ALL");
965 case 1: strcat(cmd,"NEW");
967 case 2: strcat(cmd,"OLD");
969 case 3: sprintf(&cmd[strlen(cmd)], "LAST|%d", q);
975 printf("%s\n",&cmd[5]);
978 while (serv_gets(cmd), strcmp(cmd,"000")) {
979 if (num_msgs == MAXMSGS) {
980 memcpy(&msg_arr[0], &msg_arr[1],
981 (sizeof(long) * (MAXMSGS - 1)) );
984 msg_arr[num_msgs++] = atol(cmd);
990 /* this loop cycles through each message... */
991 start = ( (rdir==1) ? 0 : (num_msgs-1) );
992 for (a=start; ((a<num_msgs)&&(a>=0)); a=a+rdir) {
993 while (msg_arr[a]==0L) {
994 a=a+rdir; if ((a==MAXMSGS)||(a==(-1))) return;
997 RAGAIN: pagin=((arcflag==0)&&(quotflag==0)&&
998 (userflags & US_PAGINATOR)) ? 1 : 0;
1000 /* If we're doing a quote, set the screenwidth to 72 temporarily */
1002 hold_sw = screenwidth;
1006 /* If printing or archiving, set the screenwidth to 80 temporarily */
1008 hold_sw = screenwidth;
1012 /* now read the message... */
1013 e=read_message(msg_arr[a],pagin);
1015 /* ...and set the screenwidth back if we have to */
1016 if ((quotflag)||(arcflag)) {
1017 screenwidth = hold_sw;
1019 RMSGREAD: fflush(stdout);
1020 highest_msg_read = msg_arr[a];
1022 freopen("/dev/tty","r+",stdout);
1024 enable_color = hold_color;
1028 freopen("/dev/tty","r+",stdout);
1030 enable_color = hold_color;
1033 freopen(prtfile, "r", stdin);
1034 sttybbs(SB_RESTORE);
1035 ka_system(printcmd);
1036 sttybbs(SB_NO_INTR);
1042 } while((g!=f)&&(g>=0));
1043 printf("Message printed.\n");
1046 if ( ((userflags&US_NOPROMPT)||(e==2))
1047 && (((room_flags&QR_MAILBOX)==0)
1048 ||(rc_force_mail_prompts==0)) ) {
1054 color(BRIGHT_WHITE);
1055 printf("%d",num_msgs-a-1);
1059 if (is_mail==1) keyopt("<R>eply ");
1060 keyopt("<B>ack <A>gain <Q>uote <N>ext <S>top ");
1061 if (rc_url_cmd[0] && num_urls) keyopt("<U>RL View ");
1062 keyopt("<?>Help/others -> ");
1066 e=(inkey()&127); e=tolower(e);
1067 /* return key same as <N> */ if (e==13) e='n';
1068 /* space key same as <N> */ if (e==32) e='n';
1069 /* del/move for aides only */ if ((!is_room_aide)
1070 &&((room_flags&QR_MAILBOX)==0)) {
1071 if ((e=='d')||(e=='m')||(e=='c')) e=0;
1073 /* print only if available */ if ((e=='p')&&(strlen(printcmd)==0)) e=0;
1074 /* can't reply in public rms */ if ((e=='r')&&(is_mail!=1)) e=0;
1075 /* can't file if not allowed */ if ((e=='f')&&(rc_allow_attachments==0)) e=0;
1076 /* link only if browser avail*/ if ((e=='u')&&(strlen(rc_url_cmd)==0)) e=0;
1077 } while((e!='a')&&(e!='n')&&(e!='s')
1078 &&(e!='d')&&(e!='m')&&(e!='p')
1079 &&(e!='q')&&(e!='b')&&(e!='h')
1080 &&(e!='r')&&(e!='f')&&(e!='?')
1081 &&(e!='u')&&(e!='c'));
1083 case 's': printf("Stop\r"); break;
1084 case 'a': printf("Again\r"); break;
1085 case 'd': printf("Delete\r"); break;
1086 case 'm': printf("Move\r"); break;
1087 case 'c': printf("Copy\r"); break;
1088 case 'n': printf("Next\r"); break;
1089 case 'p': printf("Print\r"); break;
1090 case 'q': printf("Quote\r"); break;
1091 case 'b': printf("Back\r"); break;
1092 case 'h': printf("Header\r"); break;
1093 case 'r': printf("Reply\r"); break;
1094 case 'f': printf("File\r"); break;
1095 case 'u': printf("URL's\r"); break;
1096 case '?': printf("? <help>\r"); break;
1098 if (userflags & US_DISAPPEAR)
1099 printf("\r%79s\r","");
1105 case '?': printf("Options available here:\n");
1106 printf(" ? Help (prints this message)\n");
1107 printf(" S Stop reading immediately\n");
1108 printf(" A Again (repeats last message)\n");
1109 printf(" N Next (continue with next message)\n");
1110 printf(" B Back (go back to previous message)\n");
1112 ||(room_flags&QR_MAILBOX)) {
1113 printf(" D Delete this message\n");
1114 printf(" M Move message to another room\n");
1115 printf(" C Copy message to another room\n");
1117 if (strlen(printcmd)>0)
1118 printf(" P Print this message\n");
1119 printf(" Q Quote portions of this message for your next post\n");
1120 printf(" H Headers (display message headers only)\n");
1122 printf(" R Reply to this message\n");
1123 if (rc_allow_attachments)
1124 printf(" F (save attachments to a file)\n");
1125 if (strlen(rc_url_cmd)>0)
1126 printf(" U (list URL's for display)\n");
1129 case 'p': fflush(stdout);
1130 freopen(prtfile,"w",stdout);
1132 hold_color = enable_color;
1135 case 'q': fflush(stdout);
1136 freopen(temp2,"w",stdout);
1138 hold_color = enable_color;
1142 case 'a': goto RAGAIN;
1143 case 'b': a=a-(rdir*2);
1147 newprompt("Enter target room: ",
1148 targ,ROOMNAMELEN-1);
1149 if (strlen(targ)>0) {
1150 sprintf(cmd,"MOVE %ld|%s|%d",
1155 printf("%s\n",&cmd[4]);
1156 if (cmd[0]=='2') msg_arr[a]=0L;
1161 if (cmd[0]!='2') goto RMSGREAD;
1163 case 'f': newprompt("Which section? ", filename,
1164 ((sizeof filename) -1));
1165 snprintf(cmd, sizeof cmd,
1166 "OPNA %ld|%s", msg_arr[a], filename);
1170 extract(filename, &cmd[4], 2);
1171 download_to_local_disk(filename,
1172 extract_int(&cmd[4], 0));
1175 printf("%s\n",&cmd[4]);
1178 case 'd': printf("*** Delete this message? ");
1180 sprintf(cmd,"DELE %ld",msg_arr[a]);
1183 printf("%s\n",&cmd[4]);
1184 if (cmd[0]=='2') msg_arr[a]=0L;
1190 case 'h': read_message(msg_arr[a],READ_HEADER);
1192 case 'r': entmsg(1,(DEFAULT_ENTRY==46 ? 2 : 0));
1194 case 'u': list_urls();
1197 } /* end for loop */
1198 } /* end read routine */
1204 * View and edit a system message
1206 void edit_system_message(char *which_message)
1212 sprintf(desc, "system message '%s'", which_message);
1213 sprintf(read_cmd, "MESG %s", which_message);
1214 sprintf(write_cmd, "EMSG %s", which_message);
1215 do_edit(desc, read_cmd, "NOOP", write_cmd);
1222 * Verify the message base
1224 void check_message_base(void) {
1227 printf("Please read the documentation before running this command.\n");
1228 printf("Having done so, do you still want to check the message base? ");
1229 if (yesno()==0) return;
1233 if (buf[0] != '1') {
1234 printf("%s\n", &buf[4]);
1238 while (serv_gets(buf), strcmp(buf, "000")) {
1239 printf("%s\n", buf);