/* detag.c written by Ben Fasenfest on: 11/18/96 removes tags from HTML documents and either prints the result to the screen or saves them to another file. */ #include #include int mask(void); FILE *infile=NULL; FILE *outfile=NULL; int isreturn=0; int error=0; int main(int argc, char * argv[]) { int c; char *inname=argv[1]; char *outname=argv[2]; printf("\nDETAG HTML converter\n\tcopyright 1996 by NebSoft, Inc.\nWritten by Ben Fasenfest\n\n"); if(argc==1) { printf("\nNo file specified\nPlease use the format\nstrip readfile [writefile]\n"); error=1; } if(error==0 && (infile = fopen (inname,"r+")) == NULL) { printf("\nError - - - File %s not found.",inname); error= 2; } if(error == 0 && argc >2 && (outfile = fopen(outname,"w+"))==NULL) { printf("\nError - - - File %s can not be written to.",outname); error= 3; } if(error==0) { while((c=getc(infile)) != EOF) { if(c=='<' && (c=mask())==0) continue; if(c=='\n') isreturn=1; else isreturn=0; if(argc>2) putc(c, outfile); else printf("%c",c); } if(argc>2) printf("\nFile %s successfully detaged and saved as file %s\n",inname, outname); } fcloseall(); return error; } int mask() { int c; char tag[3]; char *tagpntr=tag; while((c=getc(infile))!=EOF && c!='>') { if(tagpntr==&tag[3]) continue; *tagpntr=(char)c; tagpntr++; } /* following is neccesary to remove the next line characters at the end of a full line tag to prevent an unwanted blank line*/ if(isreturn==1) { c=getc(infile); if(c!='\n') ungetc(c,infile); } *tagpntr=0; if(strcmp(tag,"p\0")==0) return 10; if(strcmp(tag,"li\0")==0) return 9; return 0; }