--- rpl/src/instructions_r4.c 2015/01/05 13:12:38 1.91 +++ rpl/src/instructions_r4.c 2022/09/07 13:40:38 1.115 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.19 - Copyright (C) 1989-2015 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.34 + Copyright (C) 1989-2021 Dr. BERTRAND Joël This file is part of RPL/2. @@ -869,6 +869,7 @@ instruction_read(struct_processus *s_eta logical1 device; logical1 format_degenere; + logical1 format_oriente_ligne; logical1 indicateur_48; logical1 presence_chaine; logical1 presence_indicateur; @@ -1331,9 +1332,9 @@ instruction_read(struct_processus *s_eta return; } - if (alsprintf(&commande, "select data from data where " - "id = %lld", (*((integer8 *) (*s_objet_argument_2) - .objet))) < 0) + if (alsprintf(s_etat_processus, &commande, + "select data from data where id = %lld", + (*((integer8 *) (*s_objet_argument_2).objet))) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1504,8 +1505,8 @@ instruction_read(struct_processus *s_eta // Récupération de la position de la clef - if (alsprintf(&commande, "select key from control " - "where id = 1") < 0) + if (alsprintf(s_etat_processus, &commande, + "select key from control where id = 1") < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1578,8 +1579,9 @@ instruction_read(struct_processus *s_eta // Récupération de l'identifiant de la clef - if (alsprintf(&commande, "select id from key where key = " - "'{ \"%s\" }'", clef_utf8) < 0) + if (alsprintf(s_etat_processus, &commande, + "select id from key where key = '{ \"%s\" }'", + clef_utf8) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1671,7 +1673,8 @@ instruction_read(struct_processus *s_eta free(commande); - if (alsprintf(&commande, "select data from data where " + if (alsprintf(s_etat_processus, &commande, + "select data from data where " "key_id = %lld order by sequence asc", id) < 0) { (*s_etat_processus).erreur_systeme = @@ -1801,8 +1804,8 @@ instruction_read(struct_processus *s_eta return; } - if (alsprintf(&tampon2, "{ \"%s\" }", - (*s_etat_processus) + if (alsprintf(s_etat_processus, &tampon2, + "{ \"%s\" }", (*s_etat_processus) .instruction_courante) < 0) { (*s_etat_processus).erreur_systeme = @@ -2060,7 +2063,8 @@ instruction_read(struct_processus *s_eta return; } - if ((format_chaine = conversion_majuscule((unsigned char *) + if ((format_chaine = conversion_majuscule( + s_etat_processus, (unsigned char *) (*(*l_element_courant_format).donnee).objet)) == NULL) { @@ -2069,42 +2073,29 @@ instruction_read(struct_processus *s_eta return; } - if (strncmp("LENGTH*(", format_chaine, 8) != 0) + if (strcmp("LINE*(*)", format_chaine) == 0) { - liberation(s_etat_processus, s_objet_argument_1); - liberation(s_etat_processus, s_objet_resultat); - free(format_chaine); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_format_fichier; - return; + format_degenere = d_vrai; + format_oriente_ligne = d_vrai; } - - longueur = (integer8) strlen(format_chaine); - - if (format_chaine[longueur - 1] != ')') + else { - liberation(s_etat_processus, s_objet_argument_1); - liberation(s_etat_processus, s_objet_resultat); - free(format_chaine); + format_oriente_ligne = d_faux; - (*s_etat_processus).erreur_execution = - d_ex_erreur_format_fichier; - return; - } + if (strncmp("LENGTH*(", format_chaine, 8) != 0) + { + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_resultat); + free(format_chaine); - format_chaine[longueur] = d_code_fin_chaine; + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return; + } - if (format_chaine[8] == '*') - { - format_degenere = d_vrai; - } - else - { - // Détermination de la longueur - format_degenere = d_faux; + longueur = (integer8) strlen(format_chaine); - if (sscanf(&(format_chaine[8]), "%lld", &longueur) != 1) + if (format_chaine[longueur - 1] != ')') { liberation(s_etat_processus, s_objet_argument_1); liberation(s_etat_processus, s_objet_resultat); @@ -2114,6 +2105,31 @@ instruction_read(struct_processus *s_eta d_ex_erreur_format_fichier; return; } + + format_chaine[longueur] = d_code_fin_chaine; + + if (format_chaine[8] == '*') + { + format_degenere = d_vrai; + } + else + { + // Détermination de la longueur + format_degenere = d_faux; + + if (sscanf(&(format_chaine[8]), "%lld", &longueur) + != 1) + { + liberation(s_etat_processus, + s_objet_argument_1); + liberation(s_etat_processus, s_objet_resultat); + free(format_chaine); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return; + } + } } free(format_chaine); @@ -2160,6 +2176,13 @@ instruction_read(struct_processus *s_eta } } } + else + { + // Évite un warning de gcc. + longueur_questure = 0; + index = 0; + timeout = 0; + } do { @@ -2191,6 +2214,14 @@ instruction_read(struct_processus *s_eta tampon3[index++] = (unsigned char) c; } + + if (format_oriente_ligne == d_vrai) + { + if (c == '\n') + { + break; + } + } } while(c != EOF); if (device == d_faux) @@ -3512,13 +3543,12 @@ instruction_read(struct_processus *s_eta } else { // FLOW -#if 0 longueur_questure = 256; do { - if ((tampon_lecture = malloc((longueur_questure + 1) * - sizeof(unsigned char))) == NULL) + if ((tampon_lecture = malloc((((size_t) longueur_questure) + 1) + * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -3546,7 +3576,8 @@ instruction_read(struct_processus *s_eta longueur_adresse = sizeof(adresse_unix); longueur_effective = recvfrom((*((struct_socket *) (*s_objet_argument_1).objet)).socket, - tampon_lecture, longueur_questure, + tampon_lecture, (long unsigned int) + longueur_questure, MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *) &adresse_unix, &longueur_adresse); } @@ -3556,7 +3587,8 @@ instruction_read(struct_processus *s_eta longueur_adresse = sizeof(adresse_ipv4); longueur_effective = recvfrom((*((struct_socket *) (*s_objet_argument_1).objet)).socket, - tampon_lecture, longueur_questure, + tampon_lecture, (long unsigned int) + longueur_questure, MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *) &adresse_ipv4, &longueur_adresse); } @@ -3567,7 +3599,8 @@ instruction_read(struct_processus *s_eta longueur_adresse = sizeof(adresse_ipv6); longueur_effective = recvfrom((*((struct_socket *) (*s_objet_argument_1).objet)).socket, - tampon_lecture, longueur_questure, + tampon_lecture, (long unsigned int) + longueur_questure, MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *) &adresse_ipv6, &longueur_adresse); # else @@ -3695,8 +3728,8 @@ instruction_read(struct_processus *s_eta return; } - if (((*s_objet_type).objet = malloc(longueur_enregistrement * - sizeof(unsigned char))) == NULL) + if (((*s_objet_type).objet = malloc((size_t) longueur_enregistrement + * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; @@ -3779,7 +3812,7 @@ instruction_read(struct_processus *s_eta longueur_adresse = 0; recvfrom((*((struct_socket *) (*s_objet_argument_1).objet)).socket, tampon_lecture, - position_finale, MSG_DONTWAIT, + (long unsigned int) longueur_effective, MSG_DONTWAIT, NULL, &longueur_adresse); (*s_objet_adresse).objet = NULL; @@ -3790,7 +3823,7 @@ instruction_read(struct_processus *s_eta longueur_adresse = sizeof(adresse_ipv4); recvfrom((*((struct_socket *) (*s_objet_argument_1).objet)).socket, tampon_lecture, - position_finale, MSG_DONTWAIT, + (long unsigned int) longueur_effective, MSG_DONTWAIT, (struct sockaddr *) &adresse_ipv4, &longueur_adresse); if (((*s_objet_adresse).objet = @@ -3870,7 +3903,7 @@ instruction_read(struct_processus *s_eta longueur_adresse = sizeof(adresse_ipv6); recvfrom((*((struct_socket *) (*s_objet_argument_1).objet)).socket, tampon_lecture, - position_finale, MSG_DONTWAIT, + (long unsigned int) longueur_effective, MSG_DONTWAIT, (struct sockaddr *) &adresse_ipv6, &longueur_adresse); if (((*s_objet_adresse).objet = @@ -3951,7 +3984,7 @@ instruction_read(struct_processus *s_eta longueur_adresse = 0; recvfrom((*((struct_socket *) (*s_objet_argument_1).objet)).socket, tampon_lecture, - position_finale, MSG_DONTWAIT, + (long unsigned int) longueur_effective, MSG_DONTWAIT, NULL, &longueur_adresse); } @@ -3962,7 +3995,6 @@ instruction_read(struct_processus *s_eta { return; } -#endif } } else