home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 31
/
CDASC_31_1996_juillet_aout.iso
/
internet
/
wsplug31.zip
/
DOS2HTML.C
< prev
next >
Wrap
Text File
|
1996-02-06
|
2KB
|
96 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main(argc,argv)
int argc;
char **argv;
{ FILE *ft, *fh ;
int no,nd,more=1,i,nc,j,header ;
char buft[512],bufh[1024] ;
if (argc < 4)
{ printf("Missing arguments ...\n");
printf("dos2html dos_file html_file type(TT, H1, H2 ...) [cgi-dos-appli]\n");
return(0);
}
if (argc == 5) header=1 ;
else header=0 ;
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) ;
}
strcpy(bufh,"HTTP/1.0 200 OK \r\n") ;
strcat(bufh,"Server: Wsplug/3.0 \r\n") ;
strcat(bufh,"Content-Type: text/html \r\n");
strcat(bufh,"\r\n");
strcat(bufh,"<html><head><TITLE>CGI-DOS</TITLE></head><body><H1>CGI-DOS</H1>");
strcat(bufh,"<");strcat(bufh,argv[3]);strcat(bufh,">");
if (header)
{ strcat(bufh,"<FORM ACTION=\"");
strcat(bufh,argv[4]);
strcat(bufh,"\"><HR>COMMAND:<INPUT NAME=\"\" SIZE=\"60\"><br>");
strcat(bufh,"<INPUT VALUE=\"Send\" TYPE=submit><INPUT VALUE=\"Cancel\" TYPE=reset>");
strcat(bufh,"</FORM>");
}
strcat(bufh,"<HR>");
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<no;i++)
{ if (buft[i] == 0xD) bufh[nd++] = buft[i] ;
else if (buft[i] == 0xA)
{ bufh[nd++] = buft[i] ;
strcpy(&bufh[nd],"<br>");
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</");strcat(bufh,argv[3]);strcat(bufh,">");
strcpy(bufh,"</body></html>\r\n") ;
fwrite(bufh,1,strlen(bufh),fh) ;
fclose(ft);
fclose(fh);
return(0);
}