--- rpl/src/instructions_t3.c 2010/05/24 10:58:35 1.8 +++ rpl/src/instructions_t3.c 2020/01/10 11:15:49 1.72 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.0.16 - Copyright (C) 1989-2010 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.32 + Copyright (C) 1989-2020 Dr. BERTRAND Joël This file is part of RPL/2. @@ -20,7 +20,7 @@ */ -#include "rpl.conv.h" +#include "rpl-conv.h" /* @@ -38,269 +38,270 @@ void instruction_trnc(struct_processus *s_etat_processus) { - int parametre; + integer8 parametre; - logical1 i43; - logical1 i44; - logical1 i49; - logical1 i50; - logical1 i53; - logical1 i54; - logical1 i55; - logical1 i56; - - struct_objet *s_objet_argument_1; - struct_objet *s_objet_argument_2; - struct_objet *s_objet_parametre; - - unsigned char *instruction_courante; - unsigned char *valeur_binaire; - - unsigned long i; - unsigned long j; - - (*s_etat_processus).erreur_execution = d_ex; - - if ((*s_etat_processus).affichage_arguments == 'Y') - { - printf("\n TRNC "); - - if ((*s_etat_processus).langue == 'F') - { - printf("(troncature)\n\n"); - } - else - { - printf("(truncation)\n\n"); - } - - printf(" 1: %s, %s, %s, %s, %s, %s,\n" - " %s, %s, %s\n", - d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX); - printf(" 1: %s\n", d_INT); - printf("-> 1: %s, %s, %s, %s, %s, %s,\n" - " %s, %s, %s\n", - d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX); - - return; - } - else if ((*s_etat_processus).test_instruction == 'Y') - { - (*s_etat_processus).nombre_arguments = -1; - return; - } - - if (test_cfsf(s_etat_processus, 31) == d_vrai) - { - if (empilement_pile_last(s_etat_processus, 2) == d_erreur) - { - return; - } - } - - if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), - &s_objet_argument_1) == d_erreur) - { - (*s_etat_processus).erreur_execution = d_ex_manque_argument; - return; - } - - if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), - &s_objet_argument_2) == d_erreur) - { - liberation(s_etat_processus, s_objet_argument_1); - - (*s_etat_processus).erreur_execution = d_ex_manque_argument; - return; - } - - if (((*s_objet_argument_1).type == INT) && - (((*s_objet_argument_2).type == INT) || - ((*s_objet_argument_2).type == REL) || - ((*s_objet_argument_2).type == CPL) || - ((*s_objet_argument_2).type == VIN) || - ((*s_objet_argument_2).type == VRL) || - ((*s_objet_argument_2).type == VCX) || - ((*s_objet_argument_2).type == MIN) || - ((*s_objet_argument_2).type == MRL) || - ((*s_objet_argument_2).type == MCX))) - { - parametre = (*((integer8 *) (*s_objet_argument_1).objet)); - - if ((parametre >= -15) && (parametre <= 15)) - { - if ((s_objet_parametre = allocation(s_etat_processus, BIN)) + logical1 i43; + logical1 i44; + logical1 i49; + logical1 i50; + logical1 i53; + logical1 i54; + logical1 i55; + logical1 i56; + + struct_objet *s_objet_argument_1; + struct_objet *s_objet_argument_2; + struct_objet *s_objet_parametre; + + unsigned char *instruction_courante; + unsigned char *valeur_binaire; + + unsigned long i; + unsigned long j; + + (*s_etat_processus).erreur_execution = d_ex; + + if ((*s_etat_processus).affichage_arguments == 'Y') + { + printf("\n TRNC "); + + if ((*s_etat_processus).langue == 'F') + { + printf("(troncature)\n\n"); + } + else + { + printf("(truncation)\n\n"); + } + + printf(" 2: %s, %s, %s, %s, %s, %s,\n" + " %s, %s, %s\n", + d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX); + printf(" 1: %s\n", d_INT); + printf("-> 1: %s, %s, %s, %s, %s, %s,\n" + " %s, %s, %s\n", + d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX); + + return; + } + else if ((*s_etat_processus).test_instruction == 'Y') + { + (*s_etat_processus).nombre_arguments = -1; + return; + } + + if (test_cfsf(s_etat_processus, 31) == d_vrai) + { + if (empilement_pile_last(s_etat_processus, 2) == d_erreur) + { + return; + } + } + + if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), + &s_objet_argument_1) == d_erreur) + { + (*s_etat_processus).erreur_execution = d_ex_manque_argument; + return; + } + + if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), + &s_objet_argument_2) == d_erreur) + { + liberation(s_etat_processus, s_objet_argument_1); + + (*s_etat_processus).erreur_execution = d_ex_manque_argument; + return; + } + + if (((*s_objet_argument_1).type == INT) && + (((*s_objet_argument_2).type == INT) || + ((*s_objet_argument_2).type == REL) || + ((*s_objet_argument_2).type == CPL) || + ((*s_objet_argument_2).type == VIN) || + ((*s_objet_argument_2).type == VRL) || + ((*s_objet_argument_2).type == VCX) || + ((*s_objet_argument_2).type == MIN) || + ((*s_objet_argument_2).type == MRL) || + ((*s_objet_argument_2).type == MCX))) + { + parametre = (*((integer8 *) (*s_objet_argument_1).objet)); + + if ((parametre >= -15) && (parametre <= 15)) + { + if ((s_objet_parametre = allocation(s_etat_processus, BIN)) == NULL) - { - (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; - return; - } - - (*((integer8 *) (*s_objet_parametre).objet)) = - abs((*((integer8 *) (*s_objet_argument_1).objet))); - - i43 = test_cfsf(s_etat_processus, 43); - i44 = test_cfsf(s_etat_processus, 44); - - sf(s_etat_processus, 44); - cf(s_etat_processus, 43); - - if ((valeur_binaire = formateur(s_etat_processus, 0, - s_objet_parametre)) == NULL) - { - liberation(s_etat_processus, s_objet_parametre); - - (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; - return; - } - - liberation(s_etat_processus, s_objet_parametre); - - if (i43 == d_vrai) - { - sf(s_etat_processus, 43); - } - else - { - cf(s_etat_processus, 43); - } - - if (i44 == d_vrai) - { - sf(s_etat_processus, 44); - } - else - { - cf(s_etat_processus, 44); - } - - i53 = test_cfsf(s_etat_processus, 53); - i54 = test_cfsf(s_etat_processus, 54); - i55 = test_cfsf(s_etat_processus, 55); - i56 = test_cfsf(s_etat_processus, 56); - - for(j = 53, i = strlen(valeur_binaire) - 2; i >= 2; i--) - { - if (valeur_binaire[i] == '0') - { - cf(s_etat_processus, j++); - } - else - { - sf(s_etat_processus, j++); - } - } - - for(; j <= 56; cf(s_etat_processus, j++)); - - free(valeur_binaire); - - i49 = test_cfsf(s_etat_processus, 49); - i50 = test_cfsf(s_etat_processus, 50); - - if (parametre >= 0) - { - // Troncature FIX - sf(s_etat_processus, 49); - cf(s_etat_processus, 50); - } - else - { - // Troncature SCI - cf(s_etat_processus, 49); - sf(s_etat_processus, 50); - } - - instruction_courante = (*s_etat_processus).instruction_courante; - - if (((*s_etat_processus).instruction_courante = - formateur(s_etat_processus, 0, s_objet_argument_2)) == NULL) - { - (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; - (*s_etat_processus).instruction_courante = instruction_courante; - return; - } - - if (i49 == d_vrai) - { - sf(s_etat_processus, 49); - } - else - { - cf(s_etat_processus, 49); - } - - if (i50 == d_vrai) - { - sf(s_etat_processus, 50); - } - else - { - cf(s_etat_processus, 50); - } - - if (i53 == d_vrai) - { - sf(s_etat_processus, 53); - } - else - { - cf(s_etat_processus, 53); - } - - if (i54 == d_vrai) - { - sf(s_etat_processus, 54); - } - else - { - cf(s_etat_processus, 54); - } - - if (i55 == d_vrai) - { - sf(s_etat_processus, 55); - } - else - { - cf(s_etat_processus, 55); - } - - if (i56 == d_vrai) - { - sf(s_etat_processus, 56); - } - else - { - cf(s_etat_processus, 56); - } - - recherche_type(s_etat_processus); - - free((*s_etat_processus).instruction_courante); - (*s_etat_processus).instruction_courante = instruction_courante; - - if ((*s_etat_processus).erreur_systeme != d_es) - { - return; - } - - if ((*s_etat_processus).erreur_execution != d_ex) - { - liberation(s_etat_processus, s_objet_argument_1); - liberation(s_etat_processus, s_objet_argument_2); - return; - } - } - else - { - liberation(s_etat_processus, s_objet_argument_1); - liberation(s_etat_processus, s_objet_argument_2); - - (*s_etat_processus).erreur_execution = d_ex_argument_invalide; - return; - } - } + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + (*((integer8 *) (*s_objet_parametre).objet)) = + abs((*((integer8 *) (*s_objet_argument_1).objet))); + + i43 = test_cfsf(s_etat_processus, 43); + i44 = test_cfsf(s_etat_processus, 44); + + sf(s_etat_processus, 44); + cf(s_etat_processus, 43); + + if ((valeur_binaire = formateur(s_etat_processus, 0, + s_objet_parametre)) == NULL) + { + liberation(s_etat_processus, s_objet_parametre); + + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + liberation(s_etat_processus, s_objet_parametre); + + if (i43 == d_vrai) + { + sf(s_etat_processus, 43); + } + else + { + cf(s_etat_processus, 43); + } + + if (i44 == d_vrai) + { + sf(s_etat_processus, 44); + } + else + { + cf(s_etat_processus, 44); + } + + i53 = test_cfsf(s_etat_processus, 53); + i54 = test_cfsf(s_etat_processus, 54); + i55 = test_cfsf(s_etat_processus, 55); + i56 = test_cfsf(s_etat_processus, 56); + + for(j = 53, i = strlen(valeur_binaire) - 2; i >= 2; i--) + { + if (valeur_binaire[i] == '0') + { + cf(s_etat_processus, (unsigned char) j++); + } + else + { + sf(s_etat_processus, (unsigned char) j++); + } + } + + for(; j <= 56; cf(s_etat_processus, (unsigned char) j++)); + + free(valeur_binaire); + + i49 = test_cfsf(s_etat_processus, 49); + i50 = test_cfsf(s_etat_processus, 50); + + if (parametre >= 0) + { + // Troncature FIX + sf(s_etat_processus, 49); + cf(s_etat_processus, 50); + } + else + { + // Troncature SCI + cf(s_etat_processus, 49); + sf(s_etat_processus, 50); + } + + instruction_courante = (*s_etat_processus).instruction_courante; + + if (((*s_etat_processus).instruction_courante = + formateur(s_etat_processus, 0, s_objet_argument_2)) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + (*s_etat_processus).instruction_courante = instruction_courante; + return; + } + + if (i49 == d_vrai) + { + sf(s_etat_processus, 49); + } + else + { + cf(s_etat_processus, 49); + } + + if (i50 == d_vrai) + { + sf(s_etat_processus, 50); + } + else + { + cf(s_etat_processus, 50); + } + + if (i53 == d_vrai) + { + sf(s_etat_processus, 53); + } + else + { + cf(s_etat_processus, 53); + } + + if (i54 == d_vrai) + { + sf(s_etat_processus, 54); + } + else + { + cf(s_etat_processus, 54); + } + + if (i55 == d_vrai) + { + sf(s_etat_processus, 55); + } + else + { + cf(s_etat_processus, 55); + } + + if (i56 == d_vrai) + { + sf(s_etat_processus, 56); + } + else + { + cf(s_etat_processus, 56); + } + + (*s_etat_processus).type_en_cours = NON; + recherche_type(s_etat_processus); + + free((*s_etat_processus).instruction_courante); + (*s_etat_processus).instruction_courante = instruction_courante; + + if ((*s_etat_processus).erreur_systeme != d_es) + { + return; + } + + if ((*s_etat_processus).erreur_execution != d_ex) + { + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + return; + } + } + else + { + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + + (*s_etat_processus).erreur_execution = d_ex_argument_invalide; + return; + } + } /* -------------------------------------------------------------------------------- @@ -308,19 +309,19 @@ instruction_trnc(struct_processus *s_eta -------------------------------------------------------------------------------- */ - else - { - liberation(s_etat_processus, s_objet_argument_1); - liberation(s_etat_processus, s_objet_argument_2); - - (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; - return; - } + else + { + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + + (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; + return; + } - liberation(s_etat_processus, s_objet_argument_1); - liberation(s_etat_processus, s_objet_argument_2); + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); - return; + return; } @@ -342,7 +343,11 @@ instruction_table_fleche(struct_processu struct_objet *s_objet; struct_objet *s_objet_resultat; - unsigned long i; + unsigned char *registre_instruction_courante; + unsigned char registre_instruction_valide; + unsigned char registre_test; + + integer8 i; (*s_etat_processus).erreur_execution = d_ex; @@ -361,16 +366,16 @@ instruction_table_fleche(struct_processu printf(" 1: %s\n", d_TAB); printf("-> n: %s, %s, %s, %s, %s, %s,\n" - " %s, %s, %s, %s, %s,\n" - " %s, %s, %s, %s, %s,\n" - " %s, %s\n", + " %s, %s, %s, %s, %s,\n" + " %s, %s, %s, %s, %s,\n" + " %s, %s\n", d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX, d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SLB); printf(" ...\n"); printf(" 2: %s, %s, %s, %s, %s, %s,\n" - " %s, %s, %s, %s, %s,\n" - " %s, %s, %s, %s, %s,\n" - " %s, %s\n", + " %s, %s, %s, %s, %s,\n" + " %s, %s, %s, %s, %s,\n" + " %s, %s\n", d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX, d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SLB); printf(" 1: %s\n", d_INT); @@ -416,12 +421,60 @@ instruction_table_fleche(struct_processu return; } - if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), - (*((struct_tableau *) (*s_objet).objet)).elements[i]) - == d_erreur) + if ((*((*((struct_tableau *) (*s_objet).objet)).elements[i])).type + != FCT) { - (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; - return; + if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), + (*((struct_tableau *) (*s_objet).objet)).elements[i]) + == d_erreur) + { + return; + } + } + else + { + registre_test = (*s_etat_processus).test_instruction; + registre_instruction_courante = (*s_etat_processus) + .instruction_courante; + registre_instruction_valide = (*s_etat_processus) + .instruction_valide; + + (*s_etat_processus).test_instruction = 'Y'; + (*s_etat_processus).instruction_courante = + (*((struct_fonction *) (*((struct_tableau *) + (*s_objet).objet)).elements[i])).nom_fonction; + + analyse(s_etat_processus, NULL); + + (*s_etat_processus).test_instruction = registre_test; + (*s_etat_processus).instruction_courante = + registre_instruction_courante; + + if (((*s_etat_processus).instruction_valide == 'Y') && + (*s_etat_processus).constante_symbolique == 'Y') + { + if (evaluation(s_etat_processus, (*((struct_tableau *) + (*s_objet).objet)).elements[i], 'E') == d_erreur) + { + (*s_etat_processus).instruction_valide = + registre_instruction_valide; + return; + } + } + else + { + if (empilement(s_etat_processus, &((*s_etat_processus) + .l_base_pile), (*((struct_tableau *) (*s_objet).objet)) + .elements[i]) == d_erreur) + { + (*s_etat_processus).instruction_valide = + registre_instruction_valide; + return; + } + } + + (*s_etat_processus).instruction_valide = + registre_instruction_valide; } } @@ -462,59 +515,62 @@ instruction_table_fleche(struct_processu void instruction_trim(struct_processus *s_etat_processus) { - struct_objet *s_objet_argument; - struct_objet *s_objet_resultat; + struct_objet *s_objet_argument; + struct_objet *s_objet_resultat; unsigned char *debut; unsigned char *fin; - (*s_etat_processus).erreur_execution = d_ex; + (*s_etat_processus).erreur_execution = d_ex; - if ((*s_etat_processus).affichage_arguments == 'Y') - { - printf("\n TRIM "); - - if ((*s_etat_processus).langue == 'F') - { - printf("(suppression des espaces initiaux et finaux d'une " + if ((*s_etat_processus).affichage_arguments == 'Y') + { + printf("\n TRIM "); + + if ((*s_etat_processus).langue == 'F') + { + printf("(suppression des espaces initiaux et finaux d'une " "chaîne)\n\n"); - } - else - { - printf("(delete initial and final spaces from string)\n\n"); - } - - printf(" 1: %s\n", d_CHN); - printf("-> 1: %s\n", d_CHN); - - return; - } - else if ((*s_etat_processus).test_instruction == 'Y') - { - (*s_etat_processus).nombre_arguments = -1; - return; - } - - if (test_cfsf(s_etat_processus, 31) == d_vrai) - { - if (empilement_pile_last(s_etat_processus, 1) == d_erreur) - { - return; - } - } - - if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), - &s_objet_argument) == d_erreur) - { - (*s_etat_processus).erreur_execution = d_ex_manque_argument; - return; - } + } + else + { + printf("(delete initial and final spaces from string)\n\n"); + } + + printf(" 1: %s\n", d_CHN); + printf("-> 1: %s\n", d_CHN); - if ((*s_objet_argument).type == CHN) - { + return; + } + else if ((*s_etat_processus).test_instruction == 'Y') + { + (*s_etat_processus).nombre_arguments = -1; + return; + } + + if (test_cfsf(s_etat_processus, 31) == d_vrai) + { + if (empilement_pile_last(s_etat_processus, 1) == d_erreur) + { + return; + } + } + + if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), + &s_objet_argument) == d_erreur) + { + (*s_etat_processus).erreur_execution = d_ex_manque_argument; + return; + } + + if ((*s_objet_argument).type == CHN) + { debut = (unsigned char *) (*s_objet_argument).objet; - while(((*debut) != d_code_fin_chaine) && ((*debut) == d_code_espace)) + while(((*debut) != d_code_fin_chaine) && + (((*debut) == d_code_espace) + || ((*debut) == d_code_retour_chariot) + || ((*debut) == d_code_tabulation))) { debut++; } @@ -522,7 +578,10 @@ instruction_trim(struct_processus *s_eta fin = &(((unsigned char *) (*s_objet_argument).objet) [strlen((unsigned char *) (*s_objet_argument).objet) - 1]); - while((fin > debut) && ((*fin) == d_code_espace)) + while((fin > debut) && + (((*fin) == d_code_espace) + || ((*fin) == d_code_retour_chariot) + || ((*fin) == d_code_tabulation))) { fin--; } @@ -535,7 +594,7 @@ instruction_trim(struct_processus *s_eta return; } - if (((*s_objet_resultat).objet = malloc((1 + fin - debut) + if (((*s_objet_resultat).objet = malloc(((size_t) (1 + fin - debut)) * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -543,7 +602,7 @@ instruction_trim(struct_processus *s_eta } strcpy((unsigned char *) (*s_objet_resultat).objet, debut); - } + } /* -------------------------------------------------------------------------------- @@ -551,13 +610,13 @@ instruction_trim(struct_processus *s_eta -------------------------------------------------------------------------------- */ - else - { - liberation(s_etat_processus, s_objet_argument); - - (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; - return; - } + else + { + liberation(s_etat_processus, s_objet_argument); + + (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; + return; + } if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_resultat) == d_erreur) @@ -565,9 +624,9 @@ instruction_trim(struct_processus *s_eta return; } - liberation(s_etat_processus, s_objet_argument); + liberation(s_etat_processus, s_objet_argument); - return; + return; } @@ -586,60 +645,142 @@ instruction_trim(struct_processus *s_eta void instruction_tokenize(struct_processus *s_etat_processus) { - struct_objet *s_objet_argument; - struct_objet *s_objet_resultat; + struct_objet *s_objet_argument; + struct_objet *s_objet_resultat; struct_liste_chainee *l_element_courant; + unsigned char *ptr; + unsigned char *ptr2; unsigned char *registre_instruction_courante; unsigned char *registre_definitions_chainees; + unsigned char *tampon; + unsigned char *tampon2; + + integer8 nombre_caracteres_echappement; + integer8 registre_longueur_definitions_chainees; + integer8 registre_position_courante; + + (*s_etat_processus).erreur_execution = d_ex; + + if ((*s_etat_processus).affichage_arguments == 'Y') + { + printf("\n TOKENIZE "); + + if ((*s_etat_processus).langue == 'F') + { + printf("(extraction d'objets en sous-chaînes)\n\n"); + } + else + { + printf("(extract objects in substrings)\n\n"); + } + + printf(" 1: %s\n", d_CHN); + printf("-> 1: %s\n", d_LST); + + return; + } + else if ((*s_etat_processus).test_instruction == 'Y') + { + (*s_etat_processus).nombre_arguments = -1; + return; + } + + if (test_cfsf(s_etat_processus, 31) == d_vrai) + { + if (empilement_pile_last(s_etat_processus, 1) == d_erreur) + { + return; + } + } + + if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), + &s_objet_argument) == d_erreur) + { + (*s_etat_processus).erreur_execution = d_ex_manque_argument; + return; + } + + if ((*s_objet_argument).type == CHN) + { + // Conversion des caractères d'échappement + + if ((tampon2 = malloc((strlen((*s_objet_argument).objet) + 1) * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } - unsigned long registre_longueur_definitions_chainees; - unsigned long registre_position_courante; + strcpy(tampon2, (*s_objet_argument).objet); + ptr = tampon2; + ptr2 = ptr; - (*s_etat_processus).erreur_execution = d_ex; + while((*ptr) != d_code_fin_chaine) + { + (*ptr2) = (*ptr); - if ((*s_etat_processus).affichage_arguments == 'Y') - { - printf("\n TOKENIZE "); - - if ((*s_etat_processus).langue == 'F') - { - printf("(extraction d'objets en sous-chaînes)\n\n"); - } - else - { - printf("(extract objects in substrings)\n\n"); - } - - printf(" 1: %s\n", d_CHN); - printf("-> 1: %s\n", d_LST); - - return; - } - else if ((*s_etat_processus).test_instruction == 'Y') - { - (*s_etat_processus).nombre_arguments = -1; - return; - } - - if (test_cfsf(s_etat_processus, 31) == d_vrai) - { - if (empilement_pile_last(s_etat_processus, 1) == d_erreur) - { - return; - } - } - - if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), - &s_objet_argument) == d_erreur) - { - (*s_etat_processus).erreur_execution = d_ex_manque_argument; - return; - } + // Début de la séquence d'échappement + + if ((*ptr) == '\\') + { + if ((*(ptr + 1)) == '"') + { + ptr++; + (*ptr2) = '\"'; + } + else if ((*(ptr + 1)) == 'n') + { + ptr++; + (*ptr2) = '\n'; + } + else if ((*(ptr + 1)) == 't') + { + ptr++; + (*ptr2) = '\t'; + } + else if ((*(ptr + 1)) == '\\') + { + ptr++; + } + else + { + if ((*s_etat_processus).langue == 'F') + { + printf("+++Information : Séquence d'échappement " + "inconnue [%d]\n", (int) getpid()); + } + else + { + printf("+++Warning : Unknown escape code " + "[%d]\n", (int) getpid()); + } + } + } + + ptr++; + ptr2++; + } + + (*ptr2) = d_code_fin_chaine; + + // Remplacement des éventuels retours à la ligne et tabulations par + // des espaces. + + ptr = tampon2; + + while((*ptr) != d_code_fin_chaine) + { + if (((*ptr) == d_code_retour_chariot) || + ((*ptr) == d_code_tabulation)) + { + (*ptr) = d_code_espace; + } + + ptr++; + } - if ((*s_objet_argument).type == CHN) - { if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -654,10 +795,9 @@ instruction_tokenize(struct_processus *s .longueur_definitions_chainees; registre_position_courante = (*s_etat_processus).position_courante; - (*s_etat_processus).definitions_chainees = (unsigned char *) - (*s_objet_argument).objet; + (*s_etat_processus).definitions_chainees = tampon2; (*s_etat_processus).longueur_definitions_chainees = - strlen((*s_etat_processus).definitions_chainees); + (integer8) strlen((*s_etat_processus).definitions_chainees); (*s_etat_processus).position_courante = 0; l_element_courant = NULL; @@ -678,6 +818,8 @@ instruction_tokenize(struct_processus *s (*s_etat_processus).position_courante = registre_position_courante; + free(tampon2); + liberation(s_etat_processus, s_objet_argument); liberation(s_etat_processus, s_objet_resultat); @@ -723,6 +865,60 @@ instruction_tokenize(struct_processus *s (*(*l_element_courant).donnee).objet = (*s_etat_processus) .instruction_courante; (*l_element_courant).suivant = NULL; + + /* + * Rajout du caractère d'échappement devant un guillemet + */ + + nombre_caracteres_echappement = 0; + ptr = (unsigned char *) (*(*l_element_courant).donnee).objet; + + while((*ptr) != d_code_fin_chaine) + { + if ((*ptr) == '\"') + { + nombre_caracteres_echappement++; + } + + ptr++; + } + + if (nombre_caracteres_echappement != 0) + { + tampon = (unsigned char *) (*(*l_element_courant) + .donnee).objet; + + if (((*(*l_element_courant).donnee).objet = malloc( + (strlen(tampon) + 1 + + ((size_t) nombre_caracteres_echappement)) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return; + } + + ptr = tampon; + ptr2 = (*(*l_element_courant).donnee).objet; + + while((*ptr) != d_code_fin_chaine) + { + if ((*ptr) == '\"') + { + (*(ptr2++)) = '\\'; + + } + else if ((*ptr) == '\\') + { + (*(ptr2++)) = '\\'; + } + + (*(ptr2++)) = (*(ptr++)); + } + + (*ptr2) = d_code_fin_chaine; + free(tampon); + } } else { @@ -737,7 +933,9 @@ instruction_tokenize(struct_processus *s (*s_etat_processus).longueur_definitions_chainees = registre_longueur_definitions_chainees; (*s_etat_processus).position_courante = registre_position_courante; - } + + free(tampon2); + } /* -------------------------------------------------------------------------------- @@ -745,13 +943,13 @@ instruction_tokenize(struct_processus *s -------------------------------------------------------------------------------- */ - else - { - liberation(s_etat_processus, s_objet_argument); - - (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; - return; - } + else + { + liberation(s_etat_processus, s_objet_argument); + + (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; + return; + } if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_resultat) == d_erreur) @@ -759,9 +957,81 @@ instruction_tokenize(struct_processus *s return; } - liberation(s_etat_processus, s_objet_argument); - - return; + liberation(s_etat_processus, s_objet_argument); + return; } + +/* +================================================================================ + Fonction 't->l' +================================================================================ + Entrées : pointeur sur une structure struct_processus +-------------------------------------------------------------------------------- + Sorties : +-------------------------------------------------------------------------------- + Effets de bord : néant +================================================================================ +*/ + +void +instruction_t_vers_l(struct_processus *s_etat_processus) +{ + logical1 last; + + (*s_etat_processus).erreur_execution = d_ex; + + if ((*s_etat_processus).affichage_arguments == 'Y') + { + printf("\n T->L "); + + if ((*s_etat_processus).langue == 'F') + { + printf("(converison d'une table en liste)\n\n"); + } + else + { + printf("(convert table to list)\n\n"); + } + + printf(" 1: %s\n", d_TAB); + printf("-> 1: %s\n", d_LST); + return; + } + else if ((*s_etat_processus).test_instruction == 'Y') + { + (*s_etat_processus).nombre_arguments = -1; + return; + } + + if (test_cfsf(s_etat_processus, 31) == d_vrai) + { + last = d_vrai; + cf(s_etat_processus, 31); + + if (empilement_pile_last(s_etat_processus, 1) == d_erreur) + { + return; + } + } + else + { + last = d_faux; + } + + instruction_table_fleche(s_etat_processus); + + if (((*s_etat_processus).erreur_systeme == d_es) && + ((*s_etat_processus).erreur_execution == d_ex)) + { + instruction_fleche_list(s_etat_processus); + } + + if (last == d_vrai) + { + sf(s_etat_processus, 31); + } + + return; +} // vim: ts=4