home *** CD-ROM | disk | FTP | other *** search
Wrap
OPT OSVERSION=37 /* Traitements des erreurs */ /*SF*/ ENUM OUT_OF_MEMORY,ARGS_ERROR,IO_ERROR,FILE_END_REACHED,INCORRECT_DEFINE,WRONG_MACRO_NAME, WRONG_MACRO_ARGS,WRONG_MACRO_BODY,WRONG_MACRO_USE RAISE OUT_OF_MEMORY IF New()=NIL, OUT_OF_MEMORY IF List()=NIL, OUT_OF_MEMORY IF String()=NIL, ARGS_ERROR IF ReadArgs()=NIL, IO_ERROR IF Open()=NIL /*EF*/ /* Definition des constantes */ /*SF*/ CONST LONG_DEF_MACRO=4 CONST LONG_MORCEAU_CORPS=6 /*EF*/ /* Definition des objets */ /*SF*/ OBJECT ident_hash ident :LONG hash :LONG ENDOBJECT OBJECT def_macro nom :LONG nbre_args :LONG corps :LONG analysee :LONG ENDOBJECT OBJECT entree_table liste_macros:LONG nbre_macros :LONG ENDOBJECT OBJECT morceau_chaine macro :LONG ptr_macro :LONG /* si c'est une macro */ parametres :LONG chaine_traite :LONG ptr_texte :LONG /* si c'est une macro */ longueur :LONG ENDOBJECT /*EF*/ /* Definition des variables globales */ /*SF*/ DEF table_macros[256]:ARRAY OF entree_table DEF num_ligne /*EF*/ /**********************/ /* Corps du programme */ /**********************/ PROC main() HANDLE /*SF*/ DEF rdargs=NIL,arguments:PTR TO LONG DEF version,i Vprintf(' \c1;33;40\cPreMac2E\c0;31;40\c v1.1\n',[$9B,$6D,$9B,$6D]) PutStr('Copyright © 1994, Lionel Vintenat\n') Vprintf('\c1;32;40\c---------------------------------\c0;31;40\c\n',[$9B,$6D,$9B,$6D]) version:='$VER: PreMac2E 1.1 (12.07.94)' arguments:=[NIL,NIL,0,0] rdargs:=ReadArgs('FROM/A,TO/A,VER=VERBOSE/S,KS=KEEPSPACES/S',arguments,NIL) FOR i:=0 TO 255 table_macros[i].liste_macros:=NIL table_macros[i].nbre_macros:=0 ENDFOR PutStr('Analysing macro file...\n') analyser_fichier_macros(arguments[0],arguments[3]) PutStr('Replacing macro calls inside macro bodies...\n') pre_analyser(arguments[2]) PutStr('Writing pre-analyzed macro file...\n') ecrire_fichier_macros_analyse(arguments[1]) FreeArgs(rdargs) EXCEPT SELECT exception CASE ARGS_ERROR PrintFault(IoErr(),NIL) CASE OUT_OF_MEMORY PutStr('Out of memory !\n') CASE IO_ERROR PrintFault(IoErr(),NIL) CASE FILE_END_REACHED Vprintf('Source file ends in the middle of a macro definition in line \d !\n',[num_ligne]) CASE INCORRECT_DEFINE Vprintf('Missing space or tabulation after #define in line \d !\n',[num_ligne]) CASE WRONG_MACRO_NAME Vprintf('Wrong macro name in line \d !\n',[num_ligne]) CASE WRONG_MACRO_ARGS Vprintf('Error in the declaration of the macro parameters in line \d !\n',[num_ligne]) CASE WRONG_MACRO_BODY Vprintf('Null body found in line \d !\n',[num_ligne]) ENDSELECT IF rdargs THEN FreeArgs(rdargs) CleanUp(100) ENDPROC /*EF*/ /***************************************************************************/ /* Analyse un fichier ne contenant que des macros pour recuperer celles-ci */ /***************************************************************************/ PROC analyser_fichier_macros(nom_fichier:PTR TO CHAR,garder_espaces) /*SF*/ DEF fichier,adr_fichier,fin_fichier,long_fichier DEF pointeur_car:PTR TO CHAR fichier:=Open(nom_fichier,OLDFILE) long_fichier:=FileLength(nom_fichier) adr_fichier:=New(long_fichier) fin_fichier:=adr_fichier+long_fichier pointeur_car:=adr_fichier Read(fichier,adr_fichier,long_fichier) Close(fichier) num_ligne:=1 /* cherche la chaine #define */ MOVE.L pointeur_car,A0 MOVE.L fin_fichier,A1 afm_while0: CMPA.L A1,A0 /* pointeur_car=fin_fichier ? */ BEQ.W afm_fin_while MOVE.B (A0)+,D0 afm_while1: CMP.B #10,D0 /* Char(pointeur_car)=10 ? */ BNE.B afm_non_add_ligne INC num_ligne BRA.B afm_while0 afm_non_add_ligne: CMP.B #"#",D0 /* Char(pointeur_car)="#" ? */ BNE.B afm_while0 CMPA.L A1,A0 /* pointeur_car=fin_fichier ? */ BEQ.W afm_fin_while MOVE.B (A0)+,D0 CMP.B #"d",D0 /* Char(pointeur_car)="d" ? */ BNE.B afm_while1 CMPA.L A1,A0 /* pointeur_car=fin_fichier ? */ BEQ.W afm_fin_while MOVE.B (A0)+,D0 CMP.B #"e",D0 /* Char(pointeur_car)="e" ? */ BNE.B afm_while1 CMPA.L A1,A0 /* pointeur_car=fin_fichier ? */ BEQ.W afm_fin_while MOVE.B (A0)+,D0 CMP.B #"f",D0 /* Char(pointeur_car)="f" ? */ BNE.B afm_while1 CMPA.L A1,A0 /* pointeur_car=fin_fichier ? */ BEQ.B afm_fin_while MOVE.B (A0)+,D0 CMP.B #"i",D0 /* Char(pointeur_car)="i" ? */ BNE.B afm_while1 CMPA.L A1,A0 /* pointeur_car=fin_fichier ? */ BEQ.B afm_fin_while MOVE.B (A0)+,D0 CMP.B #"n",D0 /* Char(pointeur_car)="n" ? */ BNE.B afm_while1 CMPA.L A1,A0 /* pointeur_car=fin_fichier ? */ BEQ.B afm_fin_while MOVE.B (A0)+,D0 CMP.B #"e",D0 /* Char(pointeur_car)="e" ? */ BNE.B afm_while1 CMPA.L A1,A0 /* pointeur_car=fin_fichier ? */ BEQ.B erreur_define MOVE.B (A0)+,D0 CMP.B #" ",D0 /* Char(pointeur_car)=" " ? */ BEQ.B define_trouve CMP.B #9,D0 /* Char(pointeur_car)=9 ? */ BEQ.W define_trouve erreur_define: Raise(INCORRECT_DEFINE) define_trouve: MOVE.L A0,pointeur_car pointeur_car:=analyser_macro(pointeur_car,fin_fichier,garder_espaces) MOVE.L pointeur_car,A0 MOVE.L fin_fichier,A1 BRA.W afm_while0 afm_fin_while: Dispose(adr_fichier) ENDPROC /*EF*/ /*********************************************************************/ /* Analyse une macro et en extrait les informations la caracterisant */ /*********************************************************************/ PROC analyser_macro(pointeur_car:PTR TO CHAR,fin_fichier,garder_espaces) /*SF*/ DEF nom_macro:ident_hash,liste_macros_hash:PTR TO def_macro,parametres pointeur_car:=eliminer_tab_space(pointeur_car,fin_fichier) IF pointeur_car<fin_fichier pointeur_car:=chercher_identificateur_hash(pointeur_car,fin_fichier,nom_macro) IF nom_macro.ident table_macros[nom_macro.hash].nbre_macros:=table_macros[nom_macro.hash].nbre_macros+1 liste_macros_hash:=table_macros[nom_macro.hash].liste_macros liste_macros_hash:=Link(List(LONG_DEF_MACRO),liste_macros_hash) table_macros[nom_macro.hash].liste_macros:=liste_macros_hash liste_macros_hash.nom:=nom_macro.ident liste_macros_hash.analysee:=FALSE pointeur_car:=args_macro(pointeur_car,fin_fichier,liste_macros_hash,{parametres}) pointeur_car:=corps_macro(pointeur_car,fin_fichier,liste_macros_hash,parametres,garder_espaces) ELSE Raise(WRONG_MACRO_NAME) ENDIF ELSE Raise(FILE_END_REACHED) ENDIF ENDPROC pointeur_car /*EF*/ /**********************************************************************************/ /* Elimine tous les espaces et toutes les tabulations jusqu'au prochain caractere */ /**********************************************************************************/ PROC eliminer_tab_space(pointeur_car:PTR TO CHAR,fin_fichier) /*SF*/ /* WHILE ((Char(pointeur_car)=" ") OR (Char(pointeur_car)=9)) AND (pointeur_car<fin_fichier) DO INC pointeur_car */ MOVE.L pointeur_car,A0 MOVE.L fin_fichier,A1 ets_while: CMPA.L A1,A0 /* pointeur_car=fin_fichier ? */ BEQ.B ets_fin_while MOVE.B (A0)+,D0 CMP.B #" ",D0 /* Char(pointeur_car)=" " ? */ BEQ.B ets_while CMP.B #9,D0 /* Char(pointeur_car)=9 ? */ BEQ.B ets_while SUBQ.L #1,A0 ets_fin_while: MOVE.L A0,pointeur_car ENDPROC pointeur_car /*EF*/ /********************************************************************************************/ /* Retourne l'identificateur pointe actuellement dans le fichier, avec sa valeur hash-codee */ /********************************************************************************************/ PROC chercher_identificateur_hash(pointeur_car:PTR TO CHAR,fin_fichier,ident_reconnu:PTR TO ident_hash) /*SF*/ DEF debut_ident,long_ident,hash debut_ident:=pointeur_car MOVE.L pointeur_car,A0 MOVE.L fin_fichier,A1 CLR.L D1 /* WHILE (caractere(Char(pointeur_car))) AND (pointeur_car<fin_fichier) DO INC pointeur_car */ cih_while: CMPA.L A1,A0 /* pointeur_car=fin_fichier ? */ BEQ.B cih_fin_while MOVE.B (A0)+,D0 ADD.B D0,D1 CMP.B #"_",D0 /* Char(pointeur_car)="_" ? */ BEQ.B cih_while CMP.B #"A",D0 /* Char(pointeur_car)E["A".."Z"] ?*/ BCS.B cih_non_majuscule CMP.B #"Z",D0 BLS.B cih_while cih_non_majuscule: CMP.B #"a",D0 /* Char(pointeur_car)E["a".."z"] ?*/ BCS.B cih_non_minuscule CMP.B #"z",D0 BLS.B cih_while cih_non_minuscule: CMP.B #"0",D0 /* Char(pointeur_car)E["0".."9"] ?*/ BCS.B cih_non_chiffre CMP.B #"9",D0 BLS.B cih_while cih_non_chiffre: SUBQ.L #1,A0 SUB.B D0,D1 cih_fin_while: MOVE.L A0,pointeur_car MOVE.L D1,hash IF long_ident:=(pointeur_car-debut_ident) ident_reconnu.ident:=String(long_ident) StrCopy(ident_reconnu.ident,debut_ident,long_ident) ident_reconnu.hash:=hash ELSE ident_reconnu.ident:=NIL ENDIF ENDPROC pointeur_car /*EF*/ /*****************************************************************/ /* Retourne l'identificateur pointe actuellement dans le fichier */ /*****************************************************************/ PROC chercher_identificateur(pointeur_car:PTR TO CHAR,fin_fichier,adr_ident:PTR TO CHAR) /*SF*/ DEF debut_ident,long_ident debut_ident:=pointeur_car MOVE.L pointeur_car,A0 MOVE.L fin_fichier,A1 /* WHILE (caractere(Char(pointeur_car))) AND (pointeur_car<fin_fichier) DO INC pointeur_car */ ci_while: CMPA.L A1,A0 /* pointeur_car=fin_fichier ? */ BEQ.B ci_fin_while MOVE.B (A0)+,D0 CMP.B #"_",D0 /* Char(pointeur_car)="_" ? */ BEQ.B ci_while CMP.B #"A",D0 /* Char(pointeur_car)E["A".."Z"] ?*/ BCS.B ci_non_majuscule CMP.B #"Z",D0 BLS.B ci_while ci_non_majuscule: CMP.B #"a",D0 /* Char(pointeur_car)E["a".."z"] ?*/ BCS.B ci_non_minuscule CMP.B #"z",D0 BLS.B ci_while ci_non_minuscule: CMP.B #"0",D0 /* Char(pointeur_car)E["0".."9"] ?*/ BCS.B ci_non_chiffre CMP.B #"9",D0 BLS.B ci_while ci_non_chiffre: SUBQ.L #1,A0 ci_fin_while: MOVE.L A0,pointeur_car IF long_ident:=(pointeur_car-debut_ident) ^adr_ident:=String(long_ident) StrCopy(^adr_ident,debut_ident,long_ident) ELSE ^adr_ident:=NIL ENDIF ENDPROC pointeur_car /*EF*/ /*******************************************/ /* Recupere tous les arguments d'une macro */ /*******************************************/ PROC args_macro(pointeur_car:PTR TO CHAR,fin_fichier,ptr_macro:PTR TO def_macro,adr_liste_params) /*SF*/ DEF car,ident_attendu=TRUE,param ptr_macro.nbre_args:=0 ^adr_liste_params:=NIL IF pointeur_car<fin_fichier car:=Char(pointeur_car++) IF (car=9) OR (car=" ") pointeur_car:=eliminer_tab_space(pointeur_car,fin_fichier) ELSEIF car="(" pointeur_car:=eliminer_tab_space(pointeur_car,fin_fichier) WHILE pointeur_car<fin_fichier IF (car:=Char(pointeur_car++))=10 THEN INC num_ligne SELECT car CASE "," IF ident_attendu Raise(WRONG_MACRO_ARGS) ELSE pointeur_car:=eliminer_tab_space(pointeur_car,fin_fichier) ident_attendu:=TRUE ENDIF CASE ")" IF ident_attendu Raise(WRONG_MACRO_ARGS) ELSE pointeur_car:=eliminer_tab_space(pointeur_car,fin_fichier) RETURN pointeur_car ENDIF DEFAULT DEC pointeur_car pointeur_car:=chercher_identificateur(pointeur_car,fin_fichier,{param}) IF param ^adr_liste_params:=Link(param,^adr_liste_params) ptr_macro.nbre_args:=ptr_macro.nbre_args+1 ident_attendu:=FALSE pointeur_car:=eliminer_tab_space(pointeur_car,fin_fichier) ELSE Raise(WRONG_MACRO_ARGS) ENDIF ENDSELECT ENDWHILE ELSE Raise(WRONG_MACRO_ARGS) ENDIF ELSE Raise(FILE_END_REACHED) ENDIF ENDPROC pointeur_car /*EF*/ /*****************************************************************/ /* Retourne le corps de la macro, ou NIL si pas de corps reconnu */ /*****************************************************************/ PROC corps_macro(pointeur_car:PTR TO CHAR,fin_fichier,ptr_macro:PTR TO def_macro,parametres,garder_espaces) /*SF*/ DEF code_arg[1]:STRING,corps_temp[4096]:STRING DEF long_corps,car,suite=FALSE,ident,pos WHILE pointeur_car<fin_fichier car:=Char(pointeur_car++) SELECT car CASE "\" IF suite THEN StrAdd(corps_temp,'\\',1) ELSE suite:=TRUE CASE 10 INC num_ligne IF suite suite:=FALSE IF garder_espaces=FALSE THEN pointeur_car:=eliminer_tab_space(pointeur_car,fin_fichier) ELSE IF long_corps:=EstrLen(corps_temp) ptr_macro.corps:=String(long_corps) StrCopy(ptr_macro.corps,corps_temp,long_corps) RETURN pointeur_car ELSE DEC num_ligne Raise(WRONG_MACRO_BODY) ENDIF ENDIF DEFAULT IF suite StrAdd(corps_temp,'\\',1) suite:=FALSE ENDIF pointeur_car:=chercher_identificateur(pointeur_car--,fin_fichier,{ident}) IF ident IF (pos:=est_ce_arg(ident,parametres))<>-1 StringF(code_arg,'\c',pos+128) StrAdd(corps_temp,code_arg,1) ELSE StrAdd(corps_temp,ident,ALL) ENDIF ELSE StrAdd(corps_temp,pointeur_car,1) INC pointeur_car ENDIF ENDSELECT ENDWHILE IF long_corps:=EstrLen(corps_temp) ptr_macro.corps:=String(long_corps) StrCopy(ptr_macro.corps,corps_temp,long_corps) ELSE Raise(WRONG_MACRO_BODY) ENDIF ENDPROC pointeur_car /*EF*/ /**************************************************************************/ /* Renvoie le numero (0..nbre_args-1) de l'argument de la macro, -1 sinon */ /**************************************************************************/ PROC est_ce_arg(arg,parametres) /*SF*/ DEF num_arg=0 WHILE parametres IF StrCmp(parametres,arg,ALL) RETURN num_arg ELSE parametres:=Next(parametres) INC num_arg ENDIF ENDWHILE ENDPROC -1 /*EF*/ /**********************************************/ /* Dirige la pre-analyse des corps des macros */ /**********************************************/ PROC pre_analyser(verbose) /*SF*/ DEF liste_macros_hash:PTR TO def_macro,i FOR i:=0 TO 255 liste_macros_hash:=table_macros[i].liste_macros WHILE liste_macros_hash pre_analyser_macro(liste_macros_hash,verbose) liste_macros_hash:=Next(liste_macros_hash) ENDWHILE ENDFOR ENDPROC /*EF*/ /**********************************************************************/ /* Effectue tous les remplacements possibles dans le corps des macros */ /**********************************************************************/ PROC pre_analyser_macro(ptr_macro:PTR TO def_macro,verbose) /*SF*/ IF ptr_macro.analysee=FALSE IF verbose THEN Vprintf('\t--> \s\n',[ptr_macro.nom]) ptr_macro.corps:=traiter_chaine(ptr_macro.corps,verbose) ptr_macro.analysee:=TRUE ENDIF ENDPROC /*EF*/ /****************************************************************************************/ /* Remplace dans chaine_avant toutes les macros par leur corps et retourne chaine_apres */ /****************************************************************************************/ PROC traiter_chaine(chaine_avant:PTR TO CHAR,verbose) /*SF*/ DEF chaine_apres:PTR TO CHAR,long_chaine_apres=0,fin_chaine_avant DEF nom_ident:ident_hash,ptr_macro:PTR TO def_macro DEF deb_morceau,morceaux:PTR TO morceau_chaine,morceaux_temp:PTR TO morceau_chaine DEF morceau:PTR TO morceau_chaine,parametres:PTR TO LONG DEF pointeur_car,pointeur_car_temp,long_temp,i fin_chaine_avant:=chaine_avant+EstrLen(chaine_avant) morceaux:=NIL pointeur_car:=chaine_avant deb_morceau:=chaine_avant WHILE pointeur_car<fin_chaine_avant pointeur_car_temp:=pointeur_car pointeur_car:=chercher_identificateur_hash(pointeur_car,fin_chaine_avant,nom_ident) IF nom_ident.ident IF ptr_macro:=est_ce_macro(nom_ident.ident,nom_ident.hash) IF long_temp:=(pointeur_car_temp-deb_morceau) morceaux:=Link(List(LONG_MORCEAU_CORPS),morceaux) morceaux.macro:=FALSE morceaux.ptr_texte:=deb_morceau morceaux.longueur:=long_temp long_chaine_apres:=long_chaine_apres+morceaux.longueur ENDIF morceaux:=Link(List(LONG_MORCEAU_CORPS),morceaux) morceaux.macro:=TRUE morceaux.ptr_macro:=ptr_macro IF ptr_macro.nbre_args morceaux.parametres:=List(ptr_macro.nbre_args) pointeur_car:=recuperer_args_macro(pointeur_car,fin_chaine_avant,ptr_macro,morceaux.parametres) ELSE IF (Char(pointeur_car)="(") AND (pointeur_car<>fin_chaine_avant) Vprintf('Wrong number of args in \s call !\n',[ptr_macro.nom]) Raise(WRONG_MACRO_USE) ENDIF ENDIF deb_morceau:=pointeur_car ENDIF ELSE IF (Char(pointeur_car)="'") AND ((Char(pointeur_car-1)<>34) OR ((pointeur_car-1)<chaine_avant)) INC pointeur_car WHILE (pointeur_car<fin_chaine_avant) AND (Char(pointeur_car)<>"'") DO INC pointeur_car ENDIF INC pointeur_car ENDIF ENDWHILE IF long_temp:=(pointeur_car-deb_morceau) morceaux:=Link(List(LONG_MORCEAU_CORPS),morceaux) morceaux.macro:=FALSE morceaux.ptr_texte:=deb_morceau morceaux.longueur:=long_temp long_chaine_apres:=long_chaine_apres+morceaux.longueur ENDIF morceaux_temp:=NIL WHILE morceaux morceau:=morceaux morceaux:=Next(morceaux) morceaux_temp:=Link(morceau,morceaux_temp) IF morceau.macro ptr_macro:=morceau.ptr_macro pre_analyser_macro(ptr_macro,verbose) IF ptr_macro.nbre_args parametres:=morceau.parametres FOR i:=0 TO ptr_macro.nbre_args-1 DO parametres[i]:=traiter_chaine(parametres[i],verbose) morceau.chaine_traite:=traiter_corps_macro(ptr_macro,parametres) ELSE morceau.chaine_traite:=String(EstrLen(ptr_macro.corps)) StrCopy(morceau.chaine_traite,ptr_macro.corps,ALL) ENDIF long_chaine_apres:=long_chaine_apres+EstrLen(morceau.chaine_traite) ENDIF ENDWHILE chaine_apres:=String(long_chaine_apres) morceaux:=morceaux_temp WHILE morceaux IF morceaux.macro THEN StrAdd(chaine_apres,morceaux.chaine_traite,ALL) ELSE StrAdd(chaine_apres,morceaux.ptr_texte,morceaux.longueur) morceaux:=Next(morceaux) ENDWHILE ENDPROC chaine_apres /*EF*/ /****************************************************************************************/ /* Retourne un pointeur sur le descriptif de la macro dont le nom est passe en argument */ /****************************************************************************************/ PROC est_ce_macro(nom_macro:PTR TO CHAR,hash_code) /*SF*/ DEF liste_macros_hash:PTR TO def_macro liste_macros_hash:=table_macros[hash_code].liste_macros WHILE liste_macros_hash IF StrCmp(liste_macros_hash.nom,nom_macro,ALL) RETURN liste_macros_hash ELSE liste_macros_hash:=Next(liste_macros_hash) ENDIF ENDWHILE ENDPROC NIL /*EF*/ /*******************************************************/ /* Retourne un tableau des arguments passes a la macro */ /*******************************************************/ PROC recuperer_args_macro(pointeur_car:PTR TO CHAR,fin_chaine,ptr_macro:PTR TO def_macro,parametres:PTR TO LONG) /*SF*/ DEF car,encore=TRUE,level=0 DEF deb_arg,long_arg,num_arg num_arg:=ptr_macro.nbre_args-1 IF pointeur_car<fin_chaine IF (car:=Char(pointeur_car++))="(" deb_arg:=pointeur_car WHILE (pointeur_car<fin_chaine) AND encore car:=Char(pointeur_car++) SELECT car CASE 34 pointeur_car:=pointeur_car+2 CASE "," IF level=0 long_arg:=pointeur_car-deb_arg-1 parametres[num_arg]:=String(long_arg) StrCopy(parametres[num_arg],deb_arg,long_arg) DEC num_arg deb_arg:=pointeur_car IF num_arg<0 Vprintf('Wrong number of args in \s call !\n',[ptr_macro.nom]) Raise(WRONG_MACRO_USE) ENDIF ENDIF CASE "(" INC level CASE ")" IF level DEC level ELSE long_arg:=pointeur_car-deb_arg-1 parametres[num_arg]:=String(long_arg) StrCopy(parametres[num_arg],deb_arg,long_arg) DEC num_arg encore:=FALSE ENDIF CASE "'" WHILE (pointeur_car<fin_chaine) AND (Char(pointeur_car)<>"'") DO INC pointeur_car INC pointeur_car ENDSELECT ENDWHILE IF encore Vprintf('Unexpected end of macro body in the middle of \s call !\n',[ptr_macro.nom]) Raise(WRONG_MACRO_USE) ENDIF ELSE DEC pointeur_car IF car=10 THEN DEC num_ligne ENDIF ENDIF IF num_arg>=0 Vprintf('Wrong number of args in \s call !\n',[ptr_macro.nom]) Raise(WRONG_MACRO_USE) ENDIF ENDPROC pointeur_car /*EF*/ /*************************************************************/ /* Retourne le corps de la macro en remplacant les arguments */ /*************************************************************/ PROC traiter_corps_macro(ptr_macro:PTR TO def_macro,parametres:PTR TO LONG) /*SF*/ DEF long_corps,long_corps_temp,long_args:PTR TO LONG DEF corps_macro_expandee,car,pos:PTR TO CHAR,i long_args:=List(ptr_macro.nbre_args) FOR i:=0 TO ptr_macro.nbre_args-1 DO long_args[i]:=EstrLen(parametres[i]) long_corps:=EstrLen(ptr_macro.corps) long_corps_temp:=long_corps pos:=ptr_macro.corps FOR i:=0 TO long_corps_temp-1 DO IF (car:=pos[i])>=128 THEN long_corps:=long_corps+long_args[car-128]-1 corps_macro_expandee:=String(long_corps) pos:=ptr_macro.corps FOR i:=0 TO long_corps_temp-1 DO IF (car:=pos[i])>=128 THEN StrAdd(corps_macro_expandee,parametres[car-128],ALL) ELSE StrAdd(corps_macro_expandee,(pos+i),1) ENDPROC corps_macro_expandee /*EF*/ /*******************************************/ /* Sauvegarde le fichier de macros analyse */ /*******************************************/ PROC ecrire_fichier_macros_analyse(nom_fichier:PTR TO CHAR) /*SF*/ DEF fichier,liste_macros_hash:PTR TO def_macro DEF quotient,i fichier:=Open(nom_fichier,NEWFILE) Fputs(fichier,'PreMac2E_Save_Format_V1.0') FputC(fichier,0) FOR i:=0 TO 255 quotient:=table_macros[i].nbre_macros/256 FputC(fichier,quotient) FputC(fichier,table_macros[i].nbre_macros-(quotient*256)) liste_macros_hash:=table_macros[i].liste_macros WHILE liste_macros_hash FputC(fichier,EstrLen(liste_macros_hash.nom)) Fputs(fichier,liste_macros_hash.nom) FputC(fichier,0) FputC(fichier,liste_macros_hash.nbre_args) quotient:=EstrLen(liste_macros_hash.corps)/256 FputC(fichier,quotient) FputC(fichier,EstrLen(liste_macros_hash.corps)-(quotient*256)) Fputs(fichier,liste_macros_hash.corps) FputC(fichier,0) liste_macros_hash:=Next(liste_macros_hash) ENDWHILE ENDFOR Close(fichier) ENDPROC /*EF*/