--- rpl/src/compilation.c 2013/02/26 19:56:11 1.54 +++ rpl/src/compilation.c 2013/12/03 09:36:10 1.64 @@ -1,6 +1,6 @@ /* ================================================================================ - RPL/2 (R) version 4.1.12 + RPL/2 (R) version 4.1.17 Copyright (C) 1989-2013 Dr. BERTRAND Joël This file is part of RPL/2. @@ -54,15 +54,15 @@ compilation(struct_processus *s_etat_pro unsigned char ouverture_definition; unsigned char position_debut_nom_definition_valide; - unsigned long *adresse; - unsigned long i; - unsigned long niveau_definition; - unsigned long niveau_definition_registre; - unsigned long position_courante; - unsigned long position_debut_nom_definition; - unsigned long position_fin_nom_definition; - unsigned long validation; - unsigned long validation_registre; + integer8 *adresse; + integer8 i; + integer8 niveau_definition; + integer8 niveau_definition_registre; + integer8 position_courante; + integer8 position_debut_nom_definition; + integer8 position_fin_nom_definition; + integer8 validation; + integer8 validation_registre; (*s_etat_processus).erreur_compilation = d_ec; (*s_etat_processus).erreur_systeme = d_es; @@ -257,9 +257,9 @@ compilation(struct_processus *s_etat_pro s_variable = (struct_variable *) malloc(sizeof(struct_variable)); adresse = (*s_objet).objet; - definition = (unsigned char *) malloc( + definition = (unsigned char *) malloc(((size_t) (position_fin_nom_definition - - position_debut_nom_definition + 2) * + position_debut_nom_definition + 2)) * sizeof(unsigned char)); if ((s_objet == NULL) || (s_variable == NULL) || @@ -980,13 +980,13 @@ readline_effacement(int count, int key) */ void -swap(void *variable_1, void *variable_2, unsigned long taille) +swap(void *variable_1, void *variable_2, integer8 taille) { register unsigned char *t_var_1; register unsigned char *t_var_2; register unsigned char variable_temporaire; - register unsigned long i; + register integer8 i; t_var_1 = (unsigned char *) variable_1; t_var_2 = (unsigned char *) variable_2; @@ -1019,8 +1019,9 @@ recherche_instruction_suivante(struct_pr { logical1 drapeau_fin_objet; logical1 erreur; - logical1 erreur_analyse; - logical1 erreur_format; + + int erreur_analyse; + int erreur_format; unsigned char base_binaire; unsigned char *pointeur_caractere_courant; @@ -1080,6 +1081,10 @@ recherche_instruction_suivante(struct_pr { case ']' : case '}' : + { + break; + } + case ')' : { erreur_format = d_ex_syntaxe; @@ -1418,100 +1423,109 @@ recherche_instruction_suivante(struct_pr while((niveau != 0) && ((*pointeur_caractere_courant) != d_code_fin_chaine)) { - switch(*pointeur_caractere_courant) + (*s_etat_processus).position_courante = + pointeur_caractere_courant + - (*s_etat_processus).definitions_chainees; + + if (recherche_instruction_suivante(s_etat_processus) + == d_erreur) { - case '{' : + if ((*s_etat_processus).instruction_courante + != NULL) { - if (niveau_annexe == 0) - { - niveau++; - } - else - { - erreur_analyse = d_ex_syntaxe; - } - - break; + free((*s_etat_processus).instruction_courante); } - case '}' : - { - if (niveau_annexe == 0) - { - niveau--; - } - else - { - erreur_analyse = d_ex_syntaxe; - } + return(d_erreur); + } - break; - } + pointeur_caractere_courant = + (*s_etat_processus).definitions_chainees + + (*s_etat_processus).position_courante; - case '[' : + if (strcmp((*s_etat_processus).instruction_courante, "{") + == 0) + { + if (niveau_annexe == 0) { - niveau_annexe++; - - if (niveau_annexe > 2) - { - erreur_analyse = d_ex_syntaxe; - } - - break; + niveau++; } - - case ']' : + else { - niveau_annexe--; - - if (niveau_annexe < 0) - { - erreur_analyse = d_ex_syntaxe; - } + erreur_analyse = d_ex_syntaxe; + } + } + else if (strcmp((*s_etat_processus).instruction_courante, + "}") == 0) + { + if (niveau_annexe == 0) + { + niveau--; + } + else + { + erreur_analyse = d_ex_syntaxe; + } + } + else if (strcmp((*s_etat_processus).instruction_courante, + "<[") == 0) + { + niveau++; + } + else if (strcmp((*s_etat_processus).instruction_courante, + "]>") == 0) + { + niveau--; + } + else if (strcmp((*s_etat_processus).instruction_courante, + "[") == 0) + { + niveau_annexe++; - break; + if (niveau_annexe > 2) + { + erreur_analyse = d_ex_syntaxe; } + } + else if (strcmp((*s_etat_processus).instruction_courante, + "[[") == 0) + { + niveau_annexe += 2; - case '"' : + if (niveau_annexe > 2) { - if (niveau_annexe == 0) - { - pointeur_caractere_courant++; + erreur_analyse = d_ex_syntaxe; + } + } + else if (strcmp((*s_etat_processus).instruction_courante, + "]") == 0) + { + niveau_annexe--; - while((*pointeur_caractere_courant != '"') && - ((*pointeur_caractere_courant) != - d_code_fin_chaine)) - { - if (*pointeur_caractere_courant == '\\') - { - pointeur_caractere_courant++; - - switch(*pointeur_caractere_courant) - { - case '\\' : - case '"' : - { - pointeur_caractere_courant++; - break; - } - } - } - else - { - pointeur_caractere_courant++; - } - } - } - else - { - erreur_analyse = d_ex_syntaxe; - } + if (niveau_annexe < 0) + { + erreur_analyse = d_ex_syntaxe; + } + } + else if (strcmp((*s_etat_processus).instruction_courante, + "]]") == 0) + { + niveau_annexe -= 2; - break; + if (niveau_annexe < 0) + { + erreur_analyse = d_ex_syntaxe; + } + } + else if ((*s_etat_processus).instruction_courante[0] == '"') + { + if (niveau_annexe != 0) + { + erreur_analyse = d_ex_syntaxe; } } - pointeur_caractere_courant++; + free((*s_etat_processus).instruction_courante); } if ((niveau != 0) || (niveau_annexe != 0)) @@ -1605,7 +1619,7 @@ recherche_instruction_suivante(struct_pr { if (((*s_etat_processus).autorisation_empilement_programme == 'Y') && ((*pointeur_caractere_courant) == '<')) - { + { // Cas << >> if (pointeur_debut_instruction != (pointeur_caractere_courant - 1)) { @@ -1617,48 +1631,38 @@ recherche_instruction_suivante(struct_pr while((niveau != 0) && ((*pointeur_caractere_courant) != d_code_fin_chaine)) { - if (((*pointeur_caractere_courant) == '<') && - ((*(pointeur_caractere_courant + 1)) == '<')) + (*s_etat_processus).position_courante = + pointeur_caractere_courant + - (*s_etat_processus).definitions_chainees; + + if (recherche_instruction_suivante(s_etat_processus) + == d_erreur) { - niveau++; - pointeur_caractere_courant++; + if ((*s_etat_processus).instruction_courante + != NULL) + { + free((*s_etat_processus).instruction_courante); + } + + return(d_erreur); } - else if (((*pointeur_caractere_courant) == '>') && - ((*(pointeur_caractere_courant + 1)) == '>')) + + pointeur_caractere_courant = + (*s_etat_processus).definitions_chainees + + (*s_etat_processus).position_courante; + + if (strcmp((*s_etat_processus).instruction_courante, + "<<") == 0) { - niveau--; - pointeur_caractere_courant++; + niveau++; } - else if ((*pointeur_caractere_courant) == '"') + else if (strcmp((*s_etat_processus) + .instruction_courante, ">>") == 0) { - pointeur_caractere_courant++; - - while((*pointeur_caractere_courant != '"') && - ((*pointeur_caractere_courant) != - d_code_fin_chaine)) - { - if (*pointeur_caractere_courant == '\\') - { - pointeur_caractere_courant++; - - switch(*pointeur_caractere_courant) - { - case '\\' : - case '"' : - { - pointeur_caractere_courant++; - break; - } - } - } - else - { - pointeur_caractere_courant++; - } - } + niveau--; } - pointeur_caractere_courant++; + free((*s_etat_processus).instruction_courante); } if (niveau != 0) @@ -1669,7 +1673,7 @@ recherche_instruction_suivante(struct_pr drapeau_fin_objet = d_vrai; } else if ((*pointeur_caractere_courant) == '[') - { + { // Cas <[ ]> if (pointeur_debut_instruction != (pointeur_caractere_courant - 1)) { @@ -1745,8 +1749,8 @@ recherche_instruction_suivante(struct_pr pointeur_fin_instruction = pointeur_caractere_courant; (*s_etat_processus).instruction_courante = (unsigned char *) - malloc(((pointeur_fin_instruction - pointeur_debut_instruction) - + 1) * sizeof(unsigned char)); + malloc((((size_t) (pointeur_fin_instruction + - pointeur_debut_instruction)) + 1) * sizeof(unsigned char)); if ((*s_etat_processus).instruction_courante == NULL) { @@ -1803,7 +1807,7 @@ conversion_majuscule(unsigned char *chai register unsigned char *caractere_courant_converti; register unsigned char *chaine_convertie; - unsigned long longueur_chaine_plus_terminaison; + integer8 longueur_chaine_plus_terminaison; longueur_chaine_plus_terminaison = 0; caractere_courant = chaine; @@ -1816,7 +1820,8 @@ conversion_majuscule(unsigned char *chai caractere_courant = chaine; caractere_courant_converti = chaine_convertie = (unsigned char *) malloc( - (longueur_chaine_plus_terminaison + 1) * sizeof(unsigned char)); + ((size_t) (longueur_chaine_plus_terminaison + 1)) + * sizeof(unsigned char)); if (chaine_convertie != NULL) { @@ -1844,9 +1849,9 @@ conversion_majuscule(unsigned char *chai void conversion_majuscule_limitee(unsigned char *chaine_entree, - unsigned char *chaine_sortie, unsigned long longueur) + unsigned char *chaine_sortie, integer8 longueur) { - unsigned long i; + integer8 i; for(i = 0; i < longueur; i++) { @@ -1890,7 +1895,7 @@ initialisation_drapeaux(struct_processus { unsigned long i; - for(i = 0; i < 31; cf(s_etat_processus, i++)); + for(i = 0; i < 31; cf(s_etat_processus, (unsigned char) i++)); if ((*s_etat_processus).lancement_interactif == d_vrai) {