// conversion d'un source C en fichier HTML
#include "stdio.h"
#include <string.h>
void convert_html(char repto[],char repfrom[],char arg[])
{
FILE *pfin, *pfout;
char nomin[64],nomout[64],titre[];
char ch=NULL; char prevch=NULL;
int commentaire = 0,commentligne=0;
int i_titre =0;
printf("\nConversion du programme %s",arg);
strcpy(nomin,"");
strcat(nomin,repfrom);
strcat(nomin,arg);
strcat(nomin,".cpp");
strcpy(nomout,"");
strcat(nomout,repto);
strcat(nomout,arg);
strcat(nomout,".htm");
pfin=fopen(nomin,"r");
pfout=fopen(nomout,"w");
printf("\nfichiers %s et %s",nomin,nomout);
if (pfin==NULL) {printf("\n ***pb acces au fichier in %s",nomin);};
if (pfout==NULL) {printf("\n ***pb acces au fichier out %s", nomout);};
if ((pfin!=NULL)&&(pfout!=NULL))
{
printf("\nfichier in %s",nomin);
printf("\nfichier out %s", nomout);
fprintf(pfout,"<html><head><title>Cours C< /title>");
fprintf(pfout,"<link rel=\"stylesheet\" href=\"styles.css\" type=\"text /css\">");
fprintf(pfout,"< /head><body><h1>");
ch = fgetc(pfin);
while (ch != '\n')
{fputc(ch,pfout);
ch = fgetc(pfin);};
fprintf(pfout,"< /h1><pre class=\"normal\">");
while (ch != EOF)
{
switch (ch)
{
case ' *':if (prevch==' /')
{fprintf(pfout,"< /pre><pre class=\"comment\">
< /pre><pre class=\"normal\">");
commentaire=0;prevch=' ';};break;
case ' /':
if ((commentaire!=1)&&(commentligne==0))
{fprintf(pfout,"<i class=\"comment\">
commentligne=1;prevch=' ';};break;
default:fputc(prevch,pfout);prevch=ch;break;
}
break;
case '<':fprintf(pfout,"%s","<");break;
case '>':fprintf(pfout,"%s",">");break;
case '\n':
if (commentligne==1)
{fprintf(pfout,"< /i>");
commentligne=0;prevch=' ';};
fputc(ch,pfout);break;
default:
if (prevch!=' ') {fputc(prevch,pfout);prevch=' ';};
fputc(ch,pfout);break;
};
ch = fgetc(pfin);
};
fprintf(pfout,"< /pre>< /body>< /html>");
};
fclose(pfout);
fclose(pfin);
};
void main()
{
char repto[64],repfrom[64];
char c=' ';
char nomfic[];
strcpy(repfrom,"f:\\autocad\\cpp\\");
strcpy(repto,"f:\\siteweb\\cours\\c_src\\");
printf("\nDebut programme");
while (nomfic[0]!=' ')
{
printf("\nEntrez un nom de fichier (ctrl&C pour terminer) :");
scanf("%s",nomfic);
convert_html(repto,repfrom,nomfic);
};
printf("\nFin programme\n");
};