/****************************************************************/ /* parseit.c */ /* This program parses the file articles.txt(compnews articles) */ /* into individual htm files */ /* and eliminates most of the mail header. */ /* The files are named numerically starting with the number */ /* passed into the program e.g 1.htm 2.htm etc. */ /* */ /* This program takes two arguments: the name of the */ /* file to parse, and the starting number to name the files. */ /* Usage: parseit */ /* e.g. paresit articles.txt 100 */ /* */ /* Written by: Ursula Wojcik May 1999 */ /****************************************************************/ #include #include #include #define record_size 80 int main(int argc, char *argv[]) { char line_in[record_size + 1]; FILE *fin,*fout; char fname[15]; int count=0, first=0 ,startflag=0; char *tokenholder; /* Starting of file names */ count=atoi(argv[2]); fin=fopen(argv[1],"r"); if(fin==NULL) { printf("Unable to open %s file as input \n\n", argv[1]); exit(0); } while(fgets(line_in,record_size+1 ,fin) !=NULL) { tokenholder=(char *) malloc(strlen(line_in)+1); strcpy(tokenholder,line_in); if( strstr(tokenholder,"X-Unsub")) /* Usually last of Header Line */ { fgets(line_in,record_size+1 ,fin); if(first==1){ fputs("",fout); /* End of this file */ startflag=0; } sprintf(fname,"%d.htm",count); count++; fclose(fout); fout=fopen(fname,"w"); if(fout==NULL) { printf("Unable to open %s file as output\n\n",fname); exit(0); } fputs("
",fout); /* New file */ first=1; /* set the flag to catch the end of the file */ startflag=1; /* no more headers now */ } else if(strstr(tokenholder,"MIME")) startflag=0; if(startflag==0) { continue; } fputs(line_in,fout); fputs("
",fout); } fclose(fin); fclose(fout); return(0); }