--- rpl/src/instructions_p2.c 2018/05/30 09:27:36 1.64 +++ rpl/src/instructions_p2.c 2018/12/24 15:21:31 1.65 @@ -374,6 +374,14 @@ instruction_p_vers_r(struct_processus *s ================================================================================ */ +static int +fonction_comparaison(const void *argument_1, const void *argument_2) +{ + return(strcmp((unsigned char *) argument_1, + (unsigned char *) (**((struct_objet **) argument_2)).objet)); +} + + void instruction_put(struct_processus *s_etat_processus) { @@ -383,6 +391,7 @@ instruction_put(struct_processus *s_etat struct_objet *s_copie_3; struct_objet *s_copie_4; + struct_objet **s_enregistrement; struct_objet *s_objet_1; struct_objet *s_objet_2; struct_objet *s_objet_3; @@ -428,10 +437,10 @@ instruction_put(struct_processus *s_etat " %s, %s, %s, %s, %s,\n" " %s, %s, %s, %s, %s,\n" " %s, %s, %s, %s,\n" - " %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, d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK, - d_SQL, d_SLB, d_PRC, d_MTX); + d_SQL, d_SLB, d_PRC, d_MTX, d_REC); printf("-> 1: %s\n\n", d_LST); printf(" 3: %s\n", d_TAB); @@ -440,22 +449,34 @@ instruction_put(struct_processus *s_etat " %s, %s, %s, %s, %s,\n" " %s, %s, %s, %s, %s,\n" " %s, %s, %s, %s,\n" - " %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, d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK, - d_SQL, d_SLB, d_PRC, d_MTX); + d_SQL, d_SLB, d_PRC, d_MTX, d_REC); printf("-> 1: %s\n\n", d_TAB); + printf(" 3: %s\n", d_REC); + printf(" 2: %s\n", d_CHN); + printf(" 1: %s, %s, %s, %s, %s, %s,\n" + " %s, %s, %s, %s, %s,\n" + " %s, %s, %s, %s, %s,\n" + " %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, + d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK, + d_SQL, d_SLB, d_PRC, d_MTX, d_REC); + printf("-> 1: %s\n\n", d_REC); + printf(" 3: %s\n", d_NOM); printf(" 2: %s, %s\n", d_LST, d_INT); printf(" 1: %s, %s, %s, %s, %s, %s,\n" " %s, %s, %s, %s, %s,\n" " %s, %s, %s, %s, %s,\n" " %s, %s, %s, %s,\n" - " %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, d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK, - d_SQL, d_SLB, d_PRC, d_MTX); + d_SQL, d_SLB, d_PRC, d_MTX, d_REC); return; } @@ -1417,6 +1438,71 @@ instruction_put(struct_processus *s_etat /* -------------------------------------------------------------------------------- + Traitement des enregistrements +-------------------------------------------------------------------------------- +*/ + + else if ((*s_objet_3).type == REC) + { + if ((*s_objet_2).type != CHN) + { + liberation(s_etat_processus, s_objet_1); + liberation(s_etat_processus, s_objet_2); + liberation(s_etat_processus, s_objet_3); + + (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; + return; + } + + if ((*s_objet_3).nombre_occurrences > 1) + { + if ((s_copie_3 = copie_objet(s_etat_processus, s_objet_3, 'N')) + == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + liberation(s_etat_processus, s_objet_3); + s_objet_3 = s_copie_3; + } + + if ((s_enregistrement = bsearch((unsigned char *) (*s_objet_2).objet, + (*((struct_tableau *) (*(*((struct_record *) + (*s_objet_3).objet)).noms).objet)).elements, + (size_t) (*((struct_tableau *) (*(*((struct_record *) + (*s_objet_3).objet)).noms).objet)).nombre_elements, + sizeof(struct_objet *), fonction_comparaison)) == NULL) + { + liberation(s_etat_processus, s_objet_1); + liberation(s_etat_processus, s_objet_2); + liberation(s_etat_processus, s_objet_3); + + (*s_etat_processus).erreur_execution = d_ex_element_inexistant; + return; + } + + indice_i = s_enregistrement - (*((struct_tableau *) + (*(*((struct_record *) (*s_objet_3).objet)).noms).objet)) + .elements; + + liberation(s_etat_processus, (*((struct_tableau *) + (*(*((struct_record *) (*s_objet_3).objet)).donnees).objet)) + .elements[indice_i]); + (*((struct_tableau *) (*(*((struct_record *) (*s_objet_3).objet)) + .donnees).objet)).elements[indice_i] = s_objet_1; + + liberation(s_etat_processus, s_objet_2); + + if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), + s_objet_3) == d_erreur) + { + return; + } + } + +/* +-------------------------------------------------------------------------------- Traitement des noms -------------------------------------------------------------------------------- */ @@ -2838,6 +2924,116 @@ instruction_put(struct_processus *s_etat liberation(s_etat_processus, s_objet_2); } + else if ((*s_objet_4).type == REC) + { + if ((*s_objet_2).type != CHN) + { + if (variable_partagee == d_vrai) + { + if (pthread_mutex_unlock(&((*(*s_etat_processus) + .pointeur_variable_partagee_courante).mutex)) != 0) + { + (*s_etat_processus).erreur_systeme = + d_es_processus; + return; + } + } + + liberation(s_etat_processus, s_objet_1); + liberation(s_etat_processus, s_objet_2); + liberation(s_etat_processus, s_objet_3); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_type_argument; + return; + } + + if ((*s_objet_4).nombre_occurrences > 1) + { + if ((s_copie_4 = copie_objet(s_etat_processus, s_objet_3, 'N')) + == NULL) + { + if (variable_partagee == d_vrai) + { + if (pthread_mutex_unlock(&((*(*s_etat_processus) + .pointeur_variable_partagee_courante).mutex)) + != 0) + { + (*s_etat_processus).erreur_systeme = + d_es_processus; + return; + } + } + + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return; + } + + liberation(s_etat_processus, s_objet_4); + s_objet_4 = s_copie_4; + } + + if ((s_enregistrement = bsearch( + (unsigned char *) (*s_objet_2).objet, + (*((struct_tableau *) (*(*((struct_record *) + (*s_objet_4).objet)).noms).objet)).elements, + (size_t) (*((struct_tableau *) (*(*((struct_record *) + (*s_objet_4).objet)).noms).objet)).nombre_elements, + sizeof(struct_objet *), fonction_comparaison)) == NULL) + { + if (variable_partagee == d_vrai) + { + if (pthread_mutex_unlock(&((*(*s_etat_processus) + .pointeur_variable_partagee_courante).mutex)) + != 0) + { + (*s_etat_processus).erreur_systeme = + d_es_processus; + return; + } + } + + liberation(s_etat_processus, s_objet_1); + liberation(s_etat_processus, s_objet_2); + liberation(s_etat_processus, s_objet_3); + + (*s_etat_processus).erreur_execution = d_ex_element_inexistant; + return; + } + + indice_i = s_enregistrement - (*((struct_tableau *) + (*(*((struct_record *) (*s_objet_4).objet)).noms).objet)) + .elements; + + liberation(s_etat_processus, (*((struct_tableau *) + (*(*((struct_record *) (*s_objet_4).objet)).donnees).objet)) + .elements[indice_i]); + (*((struct_tableau *) (*(*((struct_record *) (*s_objet_4).objet)) + .donnees).objet)).elements[indice_i] = s_objet_1; + + if (variable_partagee == d_faux) + { + (*(*s_etat_processus).pointeur_variable_courante).objet = + s_objet_4; + } + else + { + (*(*s_etat_processus).pointeur_variable_courante).objet = NULL; + (*(*s_etat_processus).pointeur_variable_partagee_courante) + .objet = s_objet_4; + + if (pthread_mutex_unlock(&((*(*s_etat_processus) + .pointeur_variable_partagee_courante).mutex)) != 0) + { + (*s_etat_processus).erreur_systeme = + d_es_processus; + return; + } + } + + liberation(s_etat_processus, s_objet_2); + } else { if (variable_partagee == d_vrai) @@ -2949,10 +3145,10 @@ instruction_puti(struct_processus *s_eta " %s, %s, %s, %s, %s,\n" " %s, %s, %s, %s, %s,\n" " %s, %s, %s, %s,\n" - " %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, d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK, - d_SQL, d_SLB, d_PRC, d_MTX); + d_SQL, d_SLB, d_PRC, d_MTX, d_REC); printf("-> 2: %s, %s\n", d_LST, d_NOM); printf(" 1: %s\n", d_INT);