#include <io.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

#define TAILLEMAX 1024000

struct comment {
  char open[10];
  char close[10]; };

static int comment = 0;
static int tag = 0;
static int numeroLigne = 0;
static int par;
static int nbc = 0;
static struct comment *co = NULL;
static char *coulParagraphe = NULL;
static char *coulCommentaires = "008000";
static char *sz = "4";
static char *font = "Courier New";
static int restriction = 0;
static int noSubSpaces = 0;
static int lsp = 0;

void complemente(char *s) {
  int l = strlen(s);
  s[3] = 0x00;
  if ( l == 1 ) {
    s[2] = s[0];
    s[0] = s[1] = '0'; }
  if ( l == 2 ) {
    s[2] = s[1];
    s[1] = s[0];
    s[0] = '0'; }
}

void espaces(long nb,char *chaine) {
  for ( int i = 0 ; i < nb ; i++ )
    chaine[i] = ' ';
  chaine[nb] = 0x00;
}

void conversion(char c1,FILE *dest,long nb) {
  static int numerol = 2;
  char spaces[512];
  espaces(nb+2,spaces);
  switch (c1) {
    case 0x0D  : break;
    case 0x0A  : if ( comment == 1 ) {
                   comment = 0; }
                 if ( comment == 2 ) {
                   comment = 0;
                   fprintf(dest,"</font>"); }
                 if ( numeroLigne ) {
                   char texte[10];
                   sprintf_s(texte,"%d",numerol);
                   complemente(texte);
                   fprintf(dest,"<br />\n%s<font color=\"#%s\">%s</font>&nbsp;&nbsp;",spaces,coulCommentaires,texte);
                   numerol++; }
                   else
                   fprintf(dest,"<br />\n%s",spaces);
                 break;
    case ' '   : if ( tag )
                   fprintf(dest," ");
                   else
                   fprintf(dest,"&nbsp;");
                 break;
    case '<'   : fprintf(dest,"&lt;");
                 break;
    case '>'   : fprintf(dest,"&gt;");
                 break;
    case '"'   : if ( tag )
                   fprintf(dest,"\"");
                   else
                   fprintf(dest,"&quot;");
                 break;
    case '&'   : fprintf(dest,"&amp;");
                 break;
    default    : fwrite(&c1,1,1,dest); }
}

void traitementSpecial1(FILE *src,FILE *dest,long nb) {
  char c1;
  fread(&c1,1,1,src);
  switch ( c1 ) {
    case '*'   : fread(&c1,1,1,src);
                 switch ( c1 ) {
                   case '#' : { char s[100];
                                fscanf(src,"%s",s);
                                fprintf(dest,"%s",s);
                                if ( !strcmp(s,"<font") ) {
                                  fscanf(src,"%s",s);
                                  fprintf(dest," %s",s); }
                                fread(&c1,1,1,src);
                                fread(&c1,1,1,src);
                                fread(&c1,1,1,src); }
                                break;
                   default  : fprintf(dest,"<font color=\"#%s\">/*",coulCommentaires);
                              comment = 1;
                              conversion(c1,dest,nb);
                              break; }
                 break;
    case '/'   : fprintf(dest,"<font color=\"#%s\">//",coulCommentaires);
                 comment = 2;
                 break;
    default    : char signe = '/';
                 fwrite(&signe,1,1,dest);
                 conversion(c1,dest,nb);
                 break; }
}

void traitementSpecial2(FILE *src,FILE *dest,long nb) {
  char c1;
  fread(&c1,1,1,src);
  if ( c1 == '/' ) {
    comment = 0;
    fprintf(dest,"*/</font>"); }
    else {
    char signe = '*';
    fwrite(&signe,1,1,dest);
    conversion(c1,dest,nb); }
}

void traitementSpecial3(FILE *src,FILE *dest,long nb) {
  char c1;
  fread(&c1,1,1,src);
  if ( c1 == '@' ) {
    tag = 1;
    fprintf(dest,"<"); }
    else {
    conversion('<',dest,nb);
    conversion(c1,dest,nb); }
}

void traitementSpecial4(FILE *src,FILE *dest,long nb) {
  char c1;
  fread(&c1,1,1,src);
  if ( c1 == '@' ) {
    tag = 0;
    fprintf(dest,">"); }
    else {
    conversion('>',dest,nb);
    conversion(c1,dest,nb); }
}

int longueur(char *s) {
  int cpt = 0;
  while ( s[cpt] != 0x00 )
    cpt++;
  return(cpt);
}

void substitution2(char *buf,char *src,char *dst,int p) {
  int l = longueur(buf);
  int lsrc = longueur(src);
  int ldst = longueur(dst);
  printf("*");
  int nbo = l-p-lsrc+1;
  for ( int j = 0 ; j < nbo ; j++ )
    buf[l+ldst-lsrc-j] = buf[l-j];
  for ( int i = 0 ; i < ldst ; i++ ) {
    buf[p+i] = dst[i]; }
}

void substitution3(char *buf,char *src,char *dst,int p) {
  int l = longueur(buf);
  int lsrc = longueur(src);
  int ldst = longueur(dst);
  int dt = lsrc-ldst;
  printf("*");
  for ( int i = 0 ; i < ldst ; i++ ) {
    buf[p+i] = dst[i]; }
  for ( int i = p+ldst ; i < l-dt+1 ; i++ ) {
    buf[i] = buf[i+dt]; }
}

int firstIndexOf(char *s,char *c) {
  int ns = longueur(s);
  int nc = longueur(c);
  int stop;
  int p = 0;
  do {
    stop = 1;
    for ( int i = 0 ; i < nc ; i++ )
      if ( s[p+i] != c[i] ) {
        stop = 0;
        i = nc ; }
    p++; }
  while ( ( !stop ) && ( p+nc <= ns ) );
  p--;
  return(p);
}

int firstIndex(char *s,char *c) {
  int ns = longueur(s);
  int nc = longueur(c);
  int stop;
  int p = 0;
  int found = 0;
  do {
    stop = 1;
    found = 1;
    for ( int i = 0 ; i < nc ; i++ )
      if ( s[p+i] != c[i] ) {
        stop = 0;
        found = 0;
        i = nc ; }
    p++; }
  while ( ( !stop ) && ( p+nc <= ns ) );
  if ( !found )
    return(-1);
  p--;
  return(p);
}

int firstIndex(char *s,char *c,int p) {
  int ns = longueur(s);
  int nc = longueur(c);
  int stop;
  int found = 0;
  do {
    stop = 1;
    found = 1;
    for ( int i = 0 ; i < nc ; i++ )
      if ( s[p+i] != c[i] ) {
        stop = 0;
        found = 0;
        i = nc ; }
    p++; }
  while ( ( !stop ) && ( p+nc <= ns ) );
  if ( !found )
    return(-1);
  p--;
  return(p);
}

int firstIndexOfException(char *s,char *c,int p) {
  int ns = longueur(s);
  int nc = longueur(c);
  int stop;
  do {
    stop = 1;
    for ( int i = 0 ; i < nc ; i++ )
      if ( s[p+i] != c[i] ) {
        stop = 0;
        i = nc ; }
    p++; }
  while ( ( !stop ) && ( p+nc <= ns ) );
  p--;
  if ( !stop )
    return(-1);
  if ( p == 0 )
    return(p);
  return(p);
}

int firstIndexOf(char *s,char *c,int p) {
  int ns = longueur(s);
  int nc = longueur(c);
  int stop;
  do {
    stop = 1;
    for ( int i = 0 ; i < nc ; i++ )
      if ( s[p+i] != c[i] ) {
        stop = 0;
        i = nc ; }
    p++; }
  while ( ( !stop ) && ( p+nc <= ns ) );
  p--;
  if ( !stop )
    return(-1);
  if ( p == 0 )
    return(p);
  if ( p+nc < ns ) {
    if ( isalnum(s[p+nc]) )
      return(-p); }
  if ( isalnum(s[p-1]) )
    return(-p);
  if ( p+nc+2 < ns ) {
    if ( ( s[p+nc] == '<' ) && ( s[p+nc+1] == '@' ) && ( s[p+nc+2] == '/' ) )
      return(-p); }
  return(p);
}

int compare(char *buf,char *s) {
  int l = strlen(s);
  for ( int i = 0 ; i < l ; i++ )
    if ( buf[i] != s[i] )
      return(0);
  return(1);
}

int inComment(char *buf,int p) {
  int stop = 0;
  int rc = 0;
  while ( !stop ) {
    if ( p == -1 )
      return(0);
    if ( nbc > 0 ) {
      if ( compare(&buf[p],co[0].open) )
        return(1);
      if ( compare(&buf[p],co[0].close) )
        return(0); }
    if ( ( buf[p] == '/' ) && ( buf[p+1] == '*' ) )
      return(1);
    if ( ( buf[p] == '*' ) && ( buf[p+1] == '/' ) )
      return(0);
    if ( ( buf[p] == 0x0D ) && ( buf[p+1] == 0x0A ) )
      rc = 1;
    if ( ( buf[p] == '/' ) && ( buf[p+1] == '/' ) ) {
      if ( !rc )
        return(1);
        else
        return(0); }
    p--; }
  return(0);
}

int colorHtml(char *buf,int p) {
//  printf("%s %d\n",buf,p);
  return(0);
}

char *decoupage(char *buf) {
  int p = firstIndex(buf,"////////");
  if ( p != -1 ) {
    while ( buf[p] != 0x0D )
      p++;
    while ( ( buf[p] == 0x0D ) || ( buf[p] == 0x0A ) || ( buf[p] == 0x20 ) ) {
      p++; }
    while ( buf[p-1] == 0x20 )
      p--;
    buf = &buf[p];
    p = firstIndex(buf,"////////");
    p--;
    while ( ( buf[p] == 0x0D ) || ( buf[p] == 0x0A ) || ( buf[p] == 0x20 ) ) {
      p--; }
    buf[p+1] = 0x00;
    if ( lsp ) {
//      printf("%d\n",lsp);
      { char st[512];
        for ( int i = 0 ; i < lsp ; i++ )
          st[i] = 0x20;
        st[lsp] = 0x00;
        char sbst[1] = { 0x00 };
        if ( firstIndex(buf,st,0) == 0 ) {
          substitution3(buf,st,sbst,0);
          p += 2; } }
      { char st[512] = { 0x0D,0x0A };
        for ( int i = 0 ; i < lsp ; i++ )
          st[i+2] = 0x20;
        st[lsp+2] = 0x00;
        char sbst[3] = { 0x0D,0x0A,0x00 };
        p = 0;
        while ( (p = firstIndex(buf,st,p)) != -1 ) {
          substitution3(buf,st,sbst,p);
          p += 2; } } }
    if ( !noSubSpaces ) {
      static int dcp = 1;
      if ( dcp ) {
        dcp = 0;
        char st[5] = { 0x0D,0x0A,0x20,0x20,0x00 };
        char sbst[3] = { 0x0D,0x0A,0x00 };
        p = 0;
        while ( (p = firstIndex(buf,st,p)) != -1 ) {
          substitution3(buf,st,sbst,p);
          p += 2; } } }
    printf("|"); }
  return(buf);
}

void pretraiteException(char *src,char *dst,char **chaine,int nb,char *coul) {
  int size;
  { struct _finddata_t fileinfo ;
    long hld = _findfirst(src,&fileinfo) ;
    size = fileinfo.size;
    _findclose(hld) ; }
  FILE *fsrc;
  fsrc = fopen(src,"rb");
  FILE *fdst;
  fdst = fopen(dst,"wb");
  if ( fsrc && fdst ) {
    char *buf =(char *) calloc(1,size+1000000);
    fread(buf,1,size,fsrc);
    buf[size] = 0x00;
    if ( restriction )
      buf = decoupage(buf);
    for ( int i = 0 ; i < nb ; i += 2 ) {
      int pos = 0;
      char subst[1024];
      if ( coul == NULL )
        sprintf_s(subst,"<@font color=\"#800000\">@%s<@/font>@",chaine[i+1]);
        else
        sprintf_s(subst,"<@font color=\"#%s\">@%s<@/font>@",coul,chaine[i+1]);
      int p;
      do {
        p = firstIndexOfException(buf,chaine[i],pos);
        if ( p != -1 ) {
          if ( p >= 0 ) {
            if ( ( !inComment(buf,p) ) && ( !colorHtml(buf,p) ) ) {
              int p2 = firstIndexOfException(chaine[i],chaine[i+1],0);
              substitution2(buf,chaine[i+1],subst,p+p2);
              pos = p+strlen(subst); }
              else
              pos = p+strlen(chaine[i]); }
            else
            pos = -p+strlen(chaine[i]); } }
      while ( p != -1 ) ; }
    fwrite(buf,1,longueur(buf),fdst);
    fclose(fdst);
    fclose(fsrc); }
}

void pretraite(char *src,char *dst,char **chaine,int nb,char *coul) {
  int size;
  { struct _finddata_t fileinfo ;
    long hld = _findfirst(src,&fileinfo) ;
    size = fileinfo.size;
    _findclose(hld) ; }
  FILE *fsrc;
  fsrc = fopen(src,"rb");
  FILE *fdst;
  fdst = fopen(dst,"wb");
  if ( fsrc && fdst ) {
    char *buf =(char *) calloc(1,size+1000000);
    fread(buf,1,size,fsrc);
    buf[size] = 0x00;
    if ( restriction )
      buf = decoupage(buf);
    for ( int i = 0 ; i < nb ; i++ ) {
      int pos = 0;
      char subst[1024];
      if ( coul == NULL )
        sprintf_s(subst,"<@font color=\"#800000\">@%s<@/font>@",chaine[i]);
        else
        sprintf_s(subst,"<@font color=\"#%s\">@%s<@/font>@",coul,chaine[i]);
      int p;
      do {
        p = firstIndexOf(buf,chaine[i],pos);
        if ( p != -1 ) {
          if ( p >= 0 ) {
            if ( ( !inComment(buf,p) ) && ( !colorHtml(buf,p) ) ) {
              substitution2(buf,chaine[i],subst,p);
              pos = p+strlen(subst); }
              else
              pos = p+strlen(chaine[i]); }
            else
            pos = -p+strlen(chaine[i]); } }
      while ( p != -1 ) ; }
    fwrite(buf,1,longueur(buf),fdst);
    fclose(fdst);
    fclose(fsrc); }
}

char **listeColoration(char *file,int *nb) {
  int size;
  { struct _finddata_t fileinfo ;
    long hld = _findfirst(file,&fileinfo) ;
    size = fileinfo.size;
    _findclose(hld) ; }
  FILE *fsrc;
  fsrc = fopen(file,"rb");
  if ( fsrc ) {
    char *buf =(char *) calloc(1,size+1);
    fread(buf,1,size,fsrc);
    buf[size] = 0x00;
    int cpt = 1;
    int i = 0;
    int last = -1;
    while ( buf[i] ) {
      if ( ( buf[i] == 0x0D ) && ( last != i-1 ) ) {
        cpt++;
        last = i; }
      i++; }
    *nb = cpt;
    char **st =(char **) calloc(cpt,sizeof(char *));  
    cpt = 0;
    i = 0;
    last = -2;  
    while ( buf[i] ) {
      if ( ( buf[i] == 0x0D ) && ( last != i-1 ) ) {
        int l = i-last-2;
        st[cpt] =(char *) calloc(l+1,sizeof(char));
        memcpy(st[cpt],&buf[last+2],l);
        cpt++;
        last = i; }
      i++; }
    if ( last != i-1 ) {
      int l = i-last-2;
      st[cpt] =(char *) calloc(l+1,sizeof(char));
      memcpy(st[cpt],&buf[last+2],l); }
    free(buf);
    return(st); }
   return(NULL);
}

char **listeColoration2(char *file,int *nb) {
  char mot[200];
  FILE *fsrc;
  fsrc = fopen(file,"rb");
  if ( !fsrc )
    return(NULL);
  int cpt = 0;
  while ( fscanf(fsrc,"%s",mot) != EOF )
    cpt++;
  fseek(fsrc,0L,SEEK_SET);
  fflush(fsrc);
  *nb = cpt;
  char **st =(char **) calloc(cpt,sizeof(char *));  
  cpt = 0;
  while ( fscanf(fsrc,"%s",mot) != EOF ) {
    st[cpt] =(char *) calloc(strlen(mot)+1,sizeof(char));
    strcpy(st[cpt],mot);
    cpt++; }
  fclose(fsrc);
  return(st);
}

struct comment *lectureCommentaires(char *s,int *nbc,struct comment *co) {
  char st[100];
  strcpy(st,s);
  struct comment *co2;
  co2 =(struct comment *) realloc(co,(*nbc)+1*sizeof(struct comment));
  int pos = firstIndexOf(s,"-");
  strcpy(co2[*nbc].close,(char *) &s[pos+1]);
  st[pos] = 0x00;
  strcpy(co2[*nbc].open,st);
  (*nbc)++;
  return(co2);
}

int traitementCommentaires(char c1,struct comment *co,int nbc,FILE *dest,long nb) {
  for ( int i = 0 ; i < nbc ; i++ )
    if ( strlen(co[i].open) == 1 ) {
      if ( c1 == co[i].open[0] ) {
        fprintf(dest,"<font color=\"#%s\">",coulCommentaires);
        comment = 1;
        conversion(c1,dest,nb);
        return(1); }
      if ( c1 == co[i].close[0] ) {
        conversion(c1,dest,nb);
        fprintf(dest,"</font>");
        comment = 0;
        return(1); } }
  return(0);
}

void substitution(char *buf,char *src,char *dst,int p,int l) {
  int lsrc = longueur(src);
  int ldst = longueur(dst);
  for ( int j = 0 ; j < ldst ; j++ )
    buf[p+j] = dst[j];
  for ( int j = p+ldst ; j < l-lsrc+ldst ; j++ ) {
    buf[j] = buf[j+lsrc-ldst]; }
  buf[l-lsrc+ldst] = 0x00;
}

int firstIndexOf(char *s,char *c,int p,int ns) {
  int nc = longueur(c);
  int stop;
  do {
    stop = 1;
    for ( int i = 0 ; i < nc ; i++ )
      if ( s[p+i] != c[i] ) {
        stop = 0;
        i = nc ; }
    p++; }
  while ( ( !stop ) && ( p+nc <= ns ) );
  p--;
  if ( !stop )
    return(-1);
  if ( p == 0 )
    return(p);
  if ( p+nc+2 < ns ) {
    if ( ( s[p+nc] == '<' ) && ( s[p+nc+1] == '@' ) && ( s[p+nc+2] == '/' ) )
      return(-p); }
  if ( isalnum(s[p-1]) )
    return(-p);
  if ( p+nc < ns )
    if ( isalnum(s[p+nc]) )
      return(-p);
  return(p);
}

void copyFile(char *src,char *dst) {
  FILE *fsrc = fopen(src,"rb");
  FILE *fdst = fopen(dst,"wb");
  if ( fsrc && fdst ) {
    char c;
    while ( fread(&c,1,1,fsrc) ) {
      fwrite(&c,1,1,fdst); } }
  if ( fsrc )
    fclose(fsrc);
  if ( fdst )
    fclose(fdst);
}

long nombreEspacesIndentation(char *htm,long pos) {
  long nb = 0L;
  FILE *f = fopen(htm,"rb");
  char c = 0x20;
  int go = 1;
  while ( go) {
    fseek(f,pos,0);
    fread(&c,1,1,f);
    if ( c == '<' )
      go = 0;
      else
      pos++; }
  go = 1;
  pos--;
  while ( ( pos >= 0 ) && go ) {
    fseek(f,pos,0);
    fread(&c,1,1,f);
    if ( c == 0x20 ) {
      nb++;
      pos--; }
      else
      go = 0; }
  return(nb);
}

int main(int argc,char *argv[]) {
  char htm[300] ;
  char cpp[300] ;
  char des[300] ;
  char occ[300] ;
  char file[300] ;
  strcpy(htm,argv[1]) ;
  strcpy(des,argv[1]) ;
  strcat(des,"l") ;
  strcpy(cpp,argv[2]) ;
  if ( argc >= 4 )
    strcpy(occ,argv[3]) ;
  long pos;
  FILE *f1 = fopen(htm,"r");
  if ( f1 != NULL ) {
    char *chaine =(char *) calloc(TAILLEMAX,sizeof(char));
    if ( argc >= 4 ) {
      do {
        do {
          pos = ftell(f1);
          fscanf(f1,"%s",chaine); }
        while ( ( strcmp(chaine,"<!--") ) && ( strcmp(chaine,"<p><!--") ) );
        fscanf(f1,"%s",chaine);
        if ( !strcmp(chaine,"substitution") ) {
          fscanf(f1,"%s",chaine); } }
      while ( strcmp(chaine,occ) ); }
      else {
      do {
        pos = ftell(f1);
        fscanf(f1,"%s",chaine); }
      while ( strcmp(chaine,"<!--") );
      fscanf(f1,"%s",chaine);
      if ( !strcmp(chaine,"substitution") ) {
        fscanf(f1,"%s",chaine); } }
    strcat(cpp,"\\") ;
    strcat(cpp,chaine) ;
    strcpy(file,chaine) ;
    fscanf(f1,"%s",chaine);
    long pos2 = ftell(f1);
    fclose(f1);
    long nbEspaces = nombreEspacesIndentation(htm,pos);
    char cpp2[2048];
    strcpy(cpp2,cpp);
    strcat(cpp2,"2");
    char cpp3[2048];
    strcpy(cpp3,cpp);
    strcat(cpp3,"3");
    int *nb =(int *) calloc(10,sizeof(int));
    char ***chain =(char ***) calloc(10,sizeof(char **));
    char **coul =(char **) calloc(10,sizeof(char *));
    int cptCoul = 0;
    int cptChain = 0;
    int good = 0;
    int *nbException =(int *) calloc(10,sizeof(int));
    char ***chainException =(char ***) calloc(10,sizeof(char **));
    char **coulException =(char **) calloc(10,sizeof(char *));
    int cptCoulException = 0;
    int cptChainException = 0;
    int goodException = 0;
    for ( int arg = 4 ; arg < argc ; arg++ ) {
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 'r' ) ) {
        restriction = 1; }
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 'n' ) && ( argv[arg][2] == 's' ) ) {
        noSubSpaces = 1; }
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 's' ) && ( argv[arg][2] == 'p' ) ) {
        lsp = atoi(&argv[arg][3]); }
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 'm' ) ) {
        good =(int) (chain[cptChain] = listeColoration2(&argv[arg][2],&nb[cptChain])) ;
        if ( chain[cptChain] )
          cptChain++; }
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 'n' ) && ( good ) ) {
        coul[cptCoul] = &argv[arg][2];
        cptCoul++; }
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 'g' ) ) {
        goodException =(int) (chainException[cptChainException] = listeColoration(&argv[arg][2],&nbException[cptChainException])) ;
        if ( chainException[cptChainException] )
          cptChainException++; }
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 'h' ) && ( goodException ) ) {
        coulException[cptCoulException] = &argv[arg][2];
        cptCoulException++; }
      if ( !strcmp(argv[arg],"-l" ) )
        numeroLigne = 1;
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 'c' ) ) {
        co = lectureCommentaires(&argv[arg][2],&nbc,co); }
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 'p' ) ) {
        coulParagraphe = &argv[arg][2]; }
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 'q' ) ) {
        coulCommentaires = &argv[arg][2]; }
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 's' ) ) {
        sz = &argv[arg][2]; }
      if ( ( argv[arg][0] == '-' ) && ( argv[arg][1] == 'f' ) ) {
        font = &argv[arg][2]; } }
    int first = 1;
    for ( int i = 0 ; i < cptChainException ; i++ ) {
      if ( first ) {
        pretraiteException(cpp,cpp2,chainException[i],nbException[i],coulException[i]);
        first = 0;
        printf("|"); }
        else {
        pretraiteException(cpp2,cpp3,chainException[i],nbException[i],coulException[i]);
        printf("|");
      /*char cm[500];
      sprintf_s(cm,"copy %s %s",cpp3,cpp2);
      system(cm);*/
        copyFile(cpp3,cpp2); } }
    for ( int i = 0 ; i < cptChain ; i++ ) {
      if ( first ) {
        pretraite(cpp,cpp2,chain[i],nb[i],coul[i]);
        first = 0;
        printf("|"); }
        else {
        pretraite(cpp2,cpp3,chain[i],nb[i],coul[i]);
        printf("|");
      /*char cm[500];
      sprintf_s(cm,"copy %s %s",cpp3,cpp2);
      system(cm);*/
        copyFile(cpp3,cpp2); } }
    printf("\n");
    free(chain);
    free(nb);
    FILE *f2;
    f2 = fopen(cpp2,"r");
    FILE *dest;
    dest = fopen(des,"w");
    if ( f2 != NULL ) {
      f1 = fopen(htm,"r");
      char c1;
      do {
        fread(&c1,1,1,f1);
        fwrite(&c1,1,1,dest); }
      while ( ftell(f1) < pos2 ) ;
      char spcs[512];
      espaces(nbEspaces,spcs);
      if ( coulParagraphe )
        fprintf(dest,"\n%s<p style=\"background-color: rgb(%s); font-size: %s;\"><strong><font face=\"%s\">",spcs,coulParagraphe,sz,font);
        else
        fprintf(dest,"\n%s<p style=\"font-size: %s;\"><strong><font face=\"%s\">",spcs,sz,font);
      if ( numeroLigne )
        fprintf(dest,"<font color=\"#%s\">001</font>&nbsp;&nbsp;",coulCommentaires);
      while ( fread(&c1,1,1,f2) ) {
        switch (c1) {
          case '/'   : traitementSpecial1(f2,dest,nbEspaces);
                       break;
          case '*'   : traitementSpecial2(f2,dest,nbEspaces);
                       break;
          case '>'   : traitementSpecial4(f2,dest,nbEspaces);
                       break;
          case '<'   : traitementSpecial3(f2,dest,nbEspaces);
                       break;
          default    : if ( !traitementCommentaires(c1,co,nbc,dest,nbEspaces) )
                         conversion(c1,dest,nbEspaces); } }
      fprintf(dest,"</font></strong></p>\n");
      do {
        fscanf(f1,"%s",chaine); }
      while ( strcmp(chaine,"<!--") );
      fscanf(f1,"%s",chaine);
      fscanf(f1,"%s",chaine);
      fscanf(f1,"%s",chaine);
      fscanf(f1,"%s",chaine);
      fprintf(dest,"%s<!-- fin substitution %s -->",spcs,file);
      while ( fread(&c1,1,1,f1) ) {
        fwrite(&c1,1,1,dest); }
      fclose(f1);
      fclose(f2);
      fflush(dest);
      fclose(dest);
      _unlink(cpp2);
      _unlink(cpp3);

      { dest = fopen(des,"rb");
        int i = 0;
        char *tab =(char *) calloc(TAILLEMAX,sizeof(char));
        while ( !feof(dest) ) {
          fread((void *) (&tab[i]),1,1,dest) ;
          i++ ; }
        int n = i-1;
        int p = 0;
        int modif = 0;
        while ( (p = firstIndexOf(tab,"/**</font>",p,n)) != -1 ) {
          substitution(tab,"/**</font>","/**",p,n);
          printf(".");
          modif = 1;
          n -= 7; }
        fclose(dest);
        if ( modif ) {
          dest = fopen(des,"wb");
          fwrite((void *) tab,1,n,dest) ;
          fclose(dest); }
        free(tab); }
      { dest = fopen(des,"rb");
        int i = 0;
        char *tab =(char *) calloc(TAILLEMAX,sizeof(char));
        while ( !feof(dest) ) {
          fread((void *) (&tab[i]),1,1,dest) ;
          i++ ; }
        int n = i-1;
        int p = 0;
        int modif = 0;
        while ( (p = firstIndexOf(tab,"/*</font>",p,n)) != -1 ) {
          substitution(tab,"/*</font>","/*",p,n);
          printf(".");
          modif = 1;
          n -= 7; }
        fclose(dest);
        if ( modif ) {
          dest = fopen(des,"wb");
          fwrite((void *) tab,1,n,dest) ;
          fclose(dest); }
        free(tab); }
      printf("\n"); }
    free(chaine); }
	return 0;
}
