#include #include #include main(argc,argv) int argc; char **argv; { FILE *ft, *fh ; int no,nd,more=1,i,nc,j,header,text=0 ; char buft[512],bufh[1024] ; if (argc < 4) { printf("Missing arguments ...\n"); printf("dos2html dos_file html_file type(TEXT, TT, H1, H2 ...) [cgi-dos-appli]\n"); return(0); } if (argc == 5) header=1 ; else header=0 ; if (strcmp(argv[3],"TEXT") == 0) text=1 ; ft = fopen(argv[1],"rb"); if (ft == NULL) { printf("Can't open %s\n",argv[1]); return(0) ; } fh = fopen(argv[2],"w+b"); if (fh == NULL) { printf("Can't create %s\n",argv[2]); fclose(ft); return(0) ; } if (!text) { strcpy(bufh,"HTTP/1.0 200 OK \r\n") ; strcat(bufh,"Server: Wsplug/3.4 \r\n") ; strcat(bufh,"Content-Type: text/html \r\n"); strcat(bufh,"\r\n"); strcat(bufh,"CGI-DOS

CGI-DOS

"); strcat(bufh,"<");strcat(bufh,argv[3]);strcat(bufh,">"); if (header) { strcat(bufh,"

COMMAND:
"); strcat(bufh,""); strcat(bufh,"
"); } strcat(bufh,"
");

fwrite(bufh,1,strlen(bufh),fh);



  nc = 0;
  while (more)
  {   no = fread(buft,1,512,ft) ;
      nd=0 ;
      if (no <= 0) more=0 ;

      else
      { for(i=0;i");
	    nd+=4 ;
	    nc=0  ;
	  }
	  else if (buft[i] == 0x9)
	  { for(j=0;j<(8-nc%8);j++) nc++; bufh[nd++]=' ';}
	  else
	  { nc++ ; bufh[nd++] = buft[i] ;}

	  if(nd > 512)
	  { fwrite(bufh,1,nd,fh) ; nd=0;}

	}
      }

     if (nd) fwrite(bufh,1,nd,fh);
  }


  strcat(bufh,"\n\r");

  strcpy(bufh,"
\r\n") ; fwrite(bufh,1,strlen(bufh),fh) ; } else /* text mode */ { strcpy(bufh,"HTTP/1.0 200 OK \r\n") ; strcat(bufh,"Server: Wsplug/3.4 \r\n") ; strcat(bufh,"Content-Type: text/plain \r\n"); strcat(bufh,"\r\n"); fwrite(bufh,1,strlen(bufh),fh); while (more) { no = fread(buft,1,512,ft) ; if (no <= 0) more=0 ; else fwrite(buft,1,no,fh) ; } } fclose(ft); fclose(fh); return(0); }