/************************************************************************************************** ** Function name : moulineFormule ** ** Description : Apres detection d'une formule, on la mouline de facon a rectifier les absurdites de formatage de RTF-Fields. ** Input : void ** Output : void **************************************************************************************************/ void moulineFormule(void) { int c; int i=0; int j=0; int k=0; int l=0; int FLAG_Inblock=0; int MFlongeur=5000; char MFcalutemp; char * MFtableau; char * MFtableautemp; char TABFmt[5][128]; /* Esperons qu'il n'y aura pas plus de 5 blocs imbriques avec 128 caracteres de mots de commande... */ MFtableau=(char *) malloc (MFlongeur); fclose(auxiliaire); if ((auxiliaire=fopen(nomsort,"r"))==NULL) { fprintf(stderr,"FATAL ERROR: Could not open Auxiliary File:%s\n",nomsort); fclose(entree); fclose(sortie); exit(0); } rewind(auxiliaire); c=fgetc(auxiliaire); while(c!=EOF) { if (i==MFlongeur) { MFlongeur*=2; MFtableau=(char * ) realloc (MFtableau, MFlongeur + 1); } if (c!='\n') /* On supprime les retours a la ligne a l'interieur des formules */ MFtableau[i++]=c; c=fgetc(auxiliaire); } MFtableau[i]='\0'; fclose(auxiliaire); if ((auxiliaire=fopen(nomsort,"w"))==NULL) { fprintf(stderr,"FATAL ERROR: Could not open Auxiliary File:%s\n",nomsort); fclose(entree); fclose(sortie); exit(0); } /* On a recupere la formule dans le sale format de RTF. On essaye de la purifier.*/ /* Toute formule commence par "eq " */ i=0; MFtableautemp=(char *) malloc (strlen(MFtableau)); while (i0 && MFtableau[i-1]!='\\') FLAG_Inblock++; else if (MFtableau[i]=='}' && i>0 && MFtableau[i-1]!='\\') { FLAG_Inblock--; if (FLAG_Inblock==-1) { FLAG_Inblock=0; FLAG_WasInBlock=1; }; } else if (MFtableau[i]=='\\' && i>0 && i+2<=strlen(MFtableau) && MFtableau[i+1]=='\\' && MFtableau[i+2]=='\\') { strcpy(&MFtableau[i],&MFtableau[i+1]); /* Le pipe a ete transforme en antislash, donc il y en a quatre maintenant (un en trop). On le vire. */ } else if ( (MFtableau[i]=='\\' && MFtableau[i+1]!='\\') && FLAG_Inblock && MFtableau[i+1]!='\'') { /* Lire les mots de commande et les enregistrer dans un tableau. Remarque: On les conserve toujours dans MFtableau */ j=0; while (MFtableau[i]!=' ' && i