// Program replace with a print code for a HTML File to replace
#include
#include
#include
void main(int argc, char *argv[])
{
FILE *sfp,*dfp;
if( argc < 2 )
{
printf("Usage : html2pl HTML_file PERL_FILE");
return;
}
sfp = fopen(argv[1],"r");
if ( sfp == NULL )
{
printf("File %s could not be opened for reading",argv[1]);
return;
}
if( argc == 3 )
{
dfp = fopen(argv[2],"w");
if( dfp == NULL )
{
printf(" File %s could not be opened for writing.",argv[2]);
return;
}
}
else
{
dfp = fopen("conv.pl","w");
if ( dfp == NULL )
{
printf(" File conv.pl could not be opened for writing\n");
return;
}
}
unsigned long flen,count=0;
int ch;
fseek(sfp,0,2);
flen = ftell(sfp);
fseek(sfp,0,0);
fprintf(dfp,"print \"");
while ( count <= flen )
{
ch = fgetc(sfp); if( ch == '$' || ch== '\"' || ch == '\\' || ch ==
'@' )
{
fputc('\\',dfp); fputc(ch,dfp);
}
else if( ch == '\n' )
{
fprintf(dfp,"\",\"\\n\";");
fputc('\n',dfp);
ch = fgetc(sfp);
if ( ch == EOF ) break;
else fprintf(dfp,"print \""),ungetc(ch,sfp);
}
else
fputc(ch,dfp);
count++;
}
fclose(sfp);
fclose(dfp);
}