/************************************************************************** * * * Lynx version HTML documents generator * * * * Programmed by Ondrej Jombik * * Copyright (c) 1999-2001 Condy software inc., All rights reserved. * * Copyright (c) 2002-2003 Platon Software Development Group * * * * Updates: x/1999, x/2000, 20.2.2001 * * * **************************************************************************/ #ifndef __PRGVERSION__ # define __PRGVERSION__ "1.3" #endif #define BUFSIZE 500U #include #include #include #include #ifdef __MSDOS__ # include #endif /* Platon header files */ #include #include #include #include #include void write_header(FILE*f); int main(int argc,char*argv[]) { FILE*fin,*fout; int i,f_script=0,f_body=0; char buf[BUFSIZE+1]; htmlTag*tag; /* Program information and help print. */ if (argc < 3) { printf("MAKELYNX - Dos/Unix Lynx version HTML generator " "v" __PRGVERSION__ " / " __DATE__ " " __TIME__ "\n"); puts("Programmed by Ondrej Jombik, e-mail: nepto@platon.sk, " "http://nepto.sk/"); puts("(c) Copyright 1999-2001 Condy software inc., " "All rights reserved."); puts("\nUsage: MAKELYNX "); return 1; } if((fin=fopen(argv[1],"rt"))==NULL){ printf("Can't open input file. [%s]\n",argv[1]); exit(1); } if((fout=fopen(argv[2],"wt"))==NULL){ printf("Can't open output file. [%s]\n",argv[2]); exit(1); } printf("Converting %20s to %-20s",argv[1],argv[2]); write_header(fout); while(1){ i=html_read(fin,buf,sizeof(buf)); if(i==HTML_ERROR){ puts("\t\tRead error."); exit(1); } if(i==HTML_EOF){ break; } if(f_body){ while(strchr(buf,'\n')!=NULL) strchr(buf,'\n')[0]=' '; while(strchr(buf,'\r')!=NULL) strdel(strchr(buf,'\r')); } /* strconv(buf, charset_windows_1250, charset_ascii); */ if(i==HTML_TAG){ if((tag=new htmlTag)==NULL)printf("new htmlTag Error!\n"); else{ if(!tag->init(buf)<0)printf("init() Error!\n"); if(!strcmp(tag->getName(),"script"))f_script=1; if(!f_script){ if(tag->isName("a")||tag->isName("img")){ int index; if((index=tag->getIndexParam("href"))<0) index=tag->getIndexParam("src"); if(index>=0){ char value[151]; strncpy(value+4,tag->getValue(index),146); value[146]='\0'; if((value+4)[0]=='"')strdel(value+4); if(strchr(value+4,':')==NULL&& (strchr(value+4,'/')!=NULL|| strstr(value+4,".htm")==NULL)){ strncpy(value,"\"../",4); tag->removeParam(index); tag->addParam(tag->isName("a")?"href":"src", (strchr(value,'\0')-1)[0]=='"' ?value:value+1); } } } tag->removeParam("onmouseover"); tag->removeParam("onmouseout"); tag->removeParam("onload"); tag->removeParam("bgcolor"); tag->removeParam("color"); tag->removeParam("background"); tag->removeParam("size"); tag->removeParam("face"); if(tag->isName("body")){ f_body=1; tag->removeParam("nosave"); tag->removeParam("text"); tag->removeParam("link"); tag->removeParam("alink"); tag->removeParam("vlink"); } if(tag->isName("meta")&&tag->isParam("name", "\"GENERATOR\"")){ tag->removeParam("content"); if(tag->addParam("content", "\"MAKELYNX v" __PRGVERSION__ " by Ondrej Jombik, " "(c) Copyright 1999-2003 " "Condy software inc.\"")<0) exit(1); } if(tag->isName("/title"))fputs(" (LYNX version)",fout); if(!strcmp(tag->getName(),"table"))fputs("",fout); if(!strcmp(tag->getName(),"tr"))fputs("",fout); if(!strcmp(tag->getName(),"td"))fputs("
",fout); if(!strcmp(tag->getName(),"th"))fputs("",fout); if(strcmp(tag->getName(),"i")&& strcmp(tag->getName(),"/i")&& strcmp(tag->getName(),"b")&& strcmp(tag->getName(),"/b")&& strcmp(tag->getName(),"center")&& strcmp(tag->getName(),"/center")&& strcmp(tag->getName(),"tr")&& strcmp(tag->getName(),"td")&& strcmp(tag->getName(),"th")&& strcmp(tag->getName(),"table")&& strcmp(tag->getName(),"link")) tag->writeToFile(fout); fflush(fout); if(!strcmp(tag->getName(),"/table")) fputs("
",fout); fflush(fout); } /* if(f_script) */ if(!strcmp(tag->getName(),"/script")) f_script=0; delete tag; } } if(i==HTML_TEXT) fwrite((void*)buf,strlen(buf),1,fout); } fclose(fin); fclose(fout); puts("\t\tOK"); return(0); } void write_header(FILE*f) { time_t t; t=time(NULL); fputs("\n",f); fprintf(f,"\n",ctime(&t)); fputs("\n",f); fputs("\n",f); fputs("\n",f); }