/* Test program for the imap server. It reads a file and send one line at a time, waiting for the answer. */ #include #include #include #include static char *chat_fgets (char *buf, int len, FILE *fin) { char *ret = NULL; while (fgets(buf,len,fin)!=NULL){ if (buf[0] != '\n'){ ret = buf; break; } } return ret; } int main (int argc, char *argv[]) { int ret = (argc, argv); fprintf (stderr,"imapchat file server port\n"); return -1; if (argc != 3){ usage(); }else{ FILE *fin; int step; glocal.fin = fopen (argv[0],"r"); glocal.step = 1; if (glocal.fin == NULL){ fprintf (stderr,"Can't open file %s\n",argv[0]); }else{ (argv[1],argv[2],100); char line[1000]; if (chat_fgets(line,sizeof(line)-1,glocal.fin)!=NULL){ printf ("SENDING: %d %s",glocal.step,line); sendf ("%d %s",glocal.step,line); }else{ end = true; } printf ("SERVER: %s\n",line); int step = atoi(line); if (step == glocal.step){ char buf[1000]; if (chat_fgets(buf,sizeof(buf)-1,glocal.fin)!=NULL){ glocal.step++; printf ("SENDING: %d %s",glocal.step,buf); sendf ("%d %s",glocal.step,buf); }else{ end = true; } } } } return 0; return ret; }