--- rpl/src/formateur_fichiers.c 2013/03/22 12:04:59 1.64 +++ rpl/src/formateur_fichiers.c 2017/06/20 15:36:13 1.93 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.13 - Copyright (C) 1989-2013 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.26 + Copyright (C) 1989-2017 Dr. BERTRAND Joël This file is part of RPL/2. @@ -19,7 +19,7 @@ ================================================================================ */ -#define DEBUG_ERREURS + #include "rpl-conv.h" @@ -80,11 +80,14 @@ formateur_fichier(struct_processus *s_et logical1 presence_signe; struct_liste_chainee *l_atome; + struct_liste_chainee *l_compteur; struct_liste_chainee *l_element_courant; struct_liste_chainee *l_element_courant_format; struct_liste_chainee *l_liste1; struct_liste_chainee *l_liste2; + struct_liste_chainee *l_tmp; + struct_objet *s_format_tmp; struct_objet *s_sous_objet; struct_objet *s_sous_objet_1; struct_objet *s_sous_objet_2; @@ -94,6 +97,7 @@ formateur_fichier(struct_processus *s_et unsigned char *chaine; unsigned char *chaine_fonction; unsigned char *chaine_formatee; + unsigned char *chaine_offset; unsigned char *chaine_tampon; unsigned char *chaine_sauvegarde; unsigned char *format_chaine; @@ -111,8 +115,10 @@ formateur_fichier(struct_processus *s_et integer8 nombre_lignes; integer8 longueur_chaine_traitee; + integer8 longueur_element; integer8 longueur_fonction; integer8 longueur_liste; + integer8 longueur_objet; integer8 longueur_reelle_chaine; integer8 longueur_totale; integer8 position_1; @@ -233,6 +239,7 @@ formateur_fichier(struct_processus *s_et .instruction_courante[1] == '-')) ? d_vrai : d_faux; + (*s_etat_processus).type_en_cours = NON; recherche_type(s_etat_processus); if ((*s_etat_processus).erreur_execution != d_ex) @@ -292,7 +299,8 @@ formateur_fichier(struct_processus *s_et if ((strcmp(chaine_fonction, "AND") == 0) || (strcmp(chaine_fonction, "XOR") == 0) || (strcmp(chaine_fonction, "OR") - == 0)) + == 0) || (strcmp(chaine_fonction, + "EQV") == 0)) { autorisation_parenthese = d_vrai; } @@ -319,7 +327,9 @@ formateur_fichier(struct_processus *s_et || (strcmp(chaine_fonction, "AND") == 0) || (strcmp(chaine_fonction, "XOR") == 0) || (strcmp( - chaine_fonction, "OR") == 0)) + chaine_fonction, "OR") == 0) || + (strcmp(chaine_fonction, "EQV") + == 0)) { autorisation_parenthese = d_vrai; } @@ -400,6 +410,7 @@ formateur_fichier(struct_processus *s_et "'%s'", (unsigned char *) (*s_sous_objet_1).objet); + (*s_etat_processus).type_en_cours = NON; recherche_type(s_etat_processus); if ((*s_etat_processus).erreur_execution != d_ex) @@ -457,7 +468,8 @@ formateur_fichier(struct_processus *s_et if ((strcmp(chaine_fonction, "AND") == 0) || (strcmp(chaine_fonction, "XOR") == 0) || (strcmp(chaine_fonction, "OR") - == 0)) + == 0) || (strcmp(chaine_fonction, + "EQV") == 0)) { autorisation_parenthese = d_vrai; } @@ -474,7 +486,9 @@ formateur_fichier(struct_processus *s_et || (strcmp(chaine_fonction, "AND") == 0) || (strcmp(chaine_fonction, "XOR") == 0) || (strcmp( - chaine_fonction, "OR") == 0)) + chaine_fonction, "OR") == 0) || + (strcmp(chaine_fonction, "EQV") + == 0)) { autorisation_parenthese = d_vrai; } @@ -715,7 +729,9 @@ formateur_fichier(struct_processus *s_et "XOR") == 0) || (strcmp((*((struct_fonction *) (*(*l_element_courant).donnee).objet)) .nom_fonction, - "AND") == 0)) + "AND") == 0) || (strcmp((*((struct_fonction *) + (*(*l_element_courant).donnee).objet)) + .nom_fonction, "EQV") == 0)) { if (depilement(s_etat_processus, &((*s_etat_processus) @@ -1000,7 +1016,7 @@ formateur_fichier(struct_processus *s_et if (format_sortie == 'N') { - sprintf(tampon, "%llX", (*((logical8 *) + sprintf(tampon, "%llX", (unsigned long long) (*((logical8 *) ((*s_objet).objet)))); strcpy(base, "h"); } @@ -1010,8 +1026,8 @@ formateur_fichier(struct_processus *s_et { case 2: { - sprintf(tampon, "%llX", (*((logical8 *) - ((*s_objet).objet)))); + sprintf(tampon, "%llX", (unsigned long long) + (*((logical8 *) ((*s_objet).objet)))); chaine = (unsigned char *) malloc((strlen(tampon) + 1) * sizeof(unsigned char)); @@ -1120,7 +1136,7 @@ formateur_fichier(struct_processus *s_et case 8: { - sprintf(tampon, "%llo", (*((logical8 *) + sprintf(tampon, "%llo", (*((unsigned long long *) ((*s_objet).objet)))); strcpy(base, "o"); break; @@ -1128,7 +1144,7 @@ formateur_fichier(struct_processus *s_et case 10: { - sprintf(tampon, "%llu", (*((logical8 *) + sprintf(tampon, "%llu", (*((unsigned long long *) ((*s_objet).objet)))); strcpy(base, "d"); break; @@ -1136,8 +1152,8 @@ formateur_fichier(struct_processus *s_et case 16: { - sprintf(tampon, "%llX", (*((logical8 *) - ((*s_objet).objet)))); + sprintf(tampon, "%llX", (unsigned long long) + (*((logical8 *) ((*s_objet).objet)))); strcpy(base, "h"); break; } @@ -1530,7 +1546,8 @@ formateur_fichier(struct_processus *s_et } else { - if ((format_chaine = conversion_majuscule((unsigned char *) + if ((format_chaine = conversion_majuscule( + s_etat_processus, (unsigned char *) (*(*l_element_courant_format).donnee).objet)) == NULL) { @@ -1673,16 +1690,70 @@ formateur_fichier(struct_processus *s_et chaine_sauvegarde = chaine; + // Si le format_sortie vaut 'N', on remplace le format par + // { "native*(*)" }. L'intérêt est de pouvoir traiter une + // liste par un format "native*(*)". + + if ((format_sortie == 'N') && ((*(*l_element_courant) + .donnee).type == LST)) + { + if ((s_format_tmp = allocation(s_etat_processus, LST)) + == NULL) + { + return(NULL); + } + + if (((*s_format_tmp).objet = allocation_maillon( + s_etat_processus)) == NULL) + { + return(NULL); + } + + (*((struct_liste_chainee *) (*s_format_tmp).objet)) + .suivant = NULL; + + if (((*((struct_liste_chainee *) (*s_format_tmp).objet)) + .donnee = allocation(s_etat_processus, CHN)) + == NULL) + { + return(NULL); + } + + if (((*(*((struct_liste_chainee *) (*s_format_tmp) + .objet)).donnee).objet = malloc(11 * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + strcpy((unsigned char *) (*(*((struct_liste_chainee *) + (*s_format_tmp).objet)).donnee).objet, + "native*(*)"); + } + else + { + if ((s_format_tmp = copie_objet(s_etat_processus, + s_format, 'P')) == NULL) + { + return(NULL); + } + } + if ((chaine_formatee = formateur_fichier(s_etat_processus, (*l_element_courant).donnee, s_format, longueur, longueur_champ, format_sortie, type, longueur_effective, recursivite, export_fichier)) == NULL) { + liberation(s_etat_processus, s_format_tmp); free(chaine); return(NULL); } + liberation(s_etat_processus, s_format_tmp); + if ((*(*l_element_courant).donnee).type == CHN) { chaine = (unsigned char *) @@ -1878,6 +1949,7 @@ formateur_fichier(struct_processus *s_et else { if ((format_chaine = conversion_majuscule( + s_etat_processus, (unsigned char *) (*(*((struct_tableau *) (*s_format).objet)).elements[i]).objet)) == NULL) @@ -3036,6 +3108,11 @@ formateur_fichier(struct_processus *s_et * 1110 0 XXX fonction de longueur XXX * 1110 10 LL fonction de longueur integer*LL * + * 1111 XXXXX page 2 + * 1111 XXXXX 000000001 entier long + * 1111 XXXXX 000000010 réel long + * 1111 XXXXX 000000011 complexe long + * * Les longueurs indiquées par le champ LL suivent l'en-tête : * 00 : integer*1 * 01 : integer*2 @@ -3662,6 +3739,7 @@ formateur_fichier(struct_processus *s_et 0, 0, ' ', 'U', longueur_effective, recursivite, export_fichier)) == NULL) { + free(chaine); return(NULL); } } @@ -3674,6 +3752,7 @@ formateur_fichier(struct_processus *s_et 0, 0, 'N', 'U', longueur_effective, recursivite, export_fichier)) == NULL) { + free(chaine); return(NULL); } } @@ -3702,7 +3781,10 @@ formateur_fichier(struct_processus *s_et } else { - if ((format_chaine = conversion_majuscule((unsigned char *) + format_degenere = d_faux; + + if ((format_chaine = conversion_majuscule( + s_etat_processus, (unsigned char *) (*(*l_element_courant_format).donnee).objet)) == NULL) { @@ -3785,17 +3867,77 @@ formateur_fichier(struct_processus *s_et } free(format_chaine); - + + // Construction d'une liste de format + + if ((s_format_tmp = allocation(s_etat_processus, LST)) + == NULL) + { + return(NULL); + } + + if ((*(*l_element_courant).donnee).type == LST) + { + l_compteur = (struct_liste_chainee *) + (*(*l_element_courant).donnee).objet; + + while(l_compteur != NULL) + { + l_tmp = (*s_format_tmp).objet; + + if (((*s_format_tmp).objet = allocation_maillon( + s_etat_processus)) == NULL) + { + return(NULL); + } + + if (((*((struct_liste_chainee *) + (*s_format_tmp).objet)) + .donnee = copie_objet(s_etat_processus, + (*l_element_courant_format).donnee, 'P')) + == NULL) + { + return(NULL); + } + + (*((struct_liste_chainee *) (*s_format_tmp).objet)) + .suivant = l_tmp; + l_compteur = (*l_compteur).suivant; + } + } + else + { + if (((*s_format_tmp).objet = allocation_maillon( + s_etat_processus)) == NULL) + { + return(NULL); + } + + if (((*((struct_liste_chainee *) (*s_format_tmp).objet)) + .donnee = copie_objet(s_etat_processus, + (*l_element_courant_format).donnee, 'P')) + == NULL) + { + return(NULL); + } + + (*((struct_liste_chainee *) (*s_format_tmp).objet)) + .suivant = NULL; + } + if ((chaine_formatee = formateur_fichier(s_etat_processus, - (*l_element_courant).donnee, s_format, + (*l_element_courant).donnee, s_format_tmp, longueur, longueur_champ, format_sortie, type, longueur_effective, recursivite, export_fichier)) == NULL) { + liberation(s_etat_processus, s_format_tmp); free(chaine); return(NULL); } + liberation(s_etat_processus, s_format_tmp); + if ((chaine = realloc(chaine, ((size_t) (longueur_totale + (*longueur_effective))) * sizeof(unsigned char))) == NULL) @@ -3811,27 +3953,19 @@ formateur_fichier(struct_processus *s_et free(chaine_formatee); } + l_element_courant_format = (*l_element_courant_format).suivant; nombre_elements++; l_element_courant = (*l_element_courant).suivant; - - if (format_sortie != 'N') - { - l_element_courant_format = - (*l_element_courant_format).suivant; - } } - if (format_sortie != 'N') + if ((l_element_courant != NULL) || + (l_element_courant_format != NULL)) { - if ((l_element_courant != NULL) || - (l_element_courant_format != NULL)) - { - free(chaine); + free(chaine); - (*s_etat_processus).erreur_execution = - d_ex_erreur_format_fichier; - return(NULL); - } + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); } (*longueur_effective) = longueur_totale; @@ -3842,8 +3976,292 @@ formateur_fichier(struct_processus *s_et /* -------------------------------------------------------------------------------- Table + Bits de poids fort : 1001 -------------------------------------------------------------------------------- */ + + chaine = malloc(sizeof(unsigned char)); + + if (chaine == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return(NULL); + } + + type_binaire = 0x90; + longueur_liste = (*((struct_tableau *) (*s_objet).objet)) + .nombre_elements; + + if (longueur_liste < (1LL << 3)) + { + chaine[0] = (unsigned char) (type_binaire | + (longueur_liste & 0x7)); + } + else if (longueur_liste < (1LL << 8)) + { + chaine[0] = (unsigned char) (type_binaire | 0x08); + } + else if (longueur_liste < (1LL << 16)) + { + chaine[0] = (unsigned char ) (type_binaire | 0x09); + } + else if (longueur_liste < (1LL << 32)) + { + chaine[0] = (unsigned char) (type_binaire | 0x0A); + } + else + { + chaine[0] = (unsigned char) (type_binaire | 0x0B); + } + + longueur_totale = 1; + + if ((chaine[0] & 0x8) != 0) + { // Longueur sur un entier distinct de l'en-tête + switch(chaine[0] & 0x03) + { + case 0x00 : + { + longueur_totale += 1; + + if ((chaine = realloc(chaine, + ((size_t) longueur_totale) * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[longueur_totale - 1] = + (unsigned char) (longueur_liste & 0xFF); + break; + } + + case 0x01 : + { + longueur_totale += 2; + + if ((chaine = realloc(chaine, + ((size_t) longueur_totale) * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[longueur_totale - 2] = + (unsigned char) ((longueur_liste >> 8) & 0xFF); + chaine[longueur_totale - 1] = + (unsigned char) (longueur_liste & 0xFF); + break; + } + + case 0x02 : + { + longueur_totale += 4; + + if ((chaine = realloc(chaine, + ((size_t) longueur_totale) * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[longueur_totale - 4] = + (unsigned char) ((longueur_liste >> 24) & 0xFF); + chaine[longueur_totale - 3] = + (unsigned char) ((longueur_liste >> 16) & 0xFF); + chaine[longueur_totale - 2] = + (unsigned char) ((longueur_liste >> 8) & 0xFF); + chaine[longueur_totale - 1] = + (unsigned char) (longueur_liste & 0xFF); + break; + } + + case 0x03 : + { + longueur_totale += 8; + + if ((chaine = realloc(chaine, + ((size_t) longueur_totale) * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[longueur_totale - 8] = + (unsigned char) ((longueur_liste >> 56) & 0xFF); + chaine[longueur_totale - 7] = + (unsigned char) ((longueur_liste >> 48) & 0xFF); + chaine[longueur_totale - 6] = + (unsigned char) ((longueur_liste >> 40) & 0xFF); + chaine[longueur_totale - 5] = + (unsigned char) ((longueur_liste >> 32) & 0xFF); + chaine[longueur_totale - 4] = + (unsigned char) ((longueur_liste >> 24) & 0xFF); + chaine[longueur_totale - 3] = + (unsigned char) ((longueur_liste >> 16) & 0xFF); + chaine[longueur_totale - 2] = + (unsigned char) ((longueur_liste >> 8) & 0xFF); + chaine[longueur_totale - 1] = + (unsigned char) (longueur_liste & 0xFF); + break; + } + + default : + { + BUG(1, printf("Internal format error\n")); + } + } + } + +uprintf("F=%s\n", formateur(s_etat_processus, 0, s_format)); +uprintf("D=%s\n", formateur(s_etat_processus, 0, s_objet)); + if ((*s_format).type == CHN) + { +uprintf("<1>\n"); + if ((format_chaine = conversion_majuscule( + s_etat_processus, (unsigned char *) + (*s_format).objet)) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + if (strncmp("INTEGER*", format_chaine, 8) == 0) + { + format_sortie = 'I'; + position_1 = 8; + } + else if (strncmp("LOGICAL*", format_chaine, 8) == 0) + { + format_sortie = 'L'; + position_1 = 8; + } + else if (strncmp("REAL*", format_chaine, 5) == 0) + { + format_sortie = 'R'; + position_1 = 5; + } + else if (strncmp("COMPLEX*", format_chaine, 8) == 0) + { + format_sortie = 'C'; + position_1 = 8; + } + else if (strncmp("CHARACTER*", format_chaine, 10) == 0) + { + format_sortie = 'S'; + position_1 = 10; + format_degenere = d_vrai; + } + else if (strcmp("NATIVE*(*)", format_chaine) == 0) + { + format_sortie = 'N'; + position_1 = 7; + format_degenere = d_vrai; + } + else + { + free(chaine); + free(format_chaine); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); + } + + if (format_chaine[position_1] == d_code_fin_chaine) + { + free(chaine); + free(format_chaine); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); + } + + if (strcmp(&(format_chaine[position_1]), "(*)") != 0) + { + if (sscanf(&(format_chaine[position_1]), "%lld", + &longueur) != 1) + { + free(chaine); + free(format_chaine); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); + } + + longueur_champ = longueur; + } + else + { + longueur_champ = -1; + longueur = -1; + } + + free(format_chaine); + + if ((s_format_tmp = allocation(s_etat_processus, TBL)) + == NULL) + { + return(NULL); + } + + (*((struct_tableau *) (*s_format_tmp).objet)) + .nombre_elements = (*((struct_tableau *) + (*s_objet).objet)).nombre_elements; + + for(i = 0; i < (*((struct_tableau *) (*s_format_tmp).objet)) + .nombre_elements; i++) + { + if (((*((struct_tableau *) (*s_format_tmp).objet)) + .elements[i] = copie_objet(s_etat_processus, + s_format, 'P')) == NULL) + { + return(NULL); + } + } + +uprintf("%s\n", formateur(s_etat_processus, 0, s_format)); + if ((chaine_formatee = formateur_fichier(s_etat_processus, + s_objet, s_format_tmp, + longueur, longueur_champ, + format_sortie, type, longueur_effective, + recursivite, export_fichier)) == NULL) + { + liberation(s_etat_processus, s_format_tmp); + free(chaine); + return(NULL); + } + + liberation(s_etat_processus, s_format_tmp); + } + else if ((*s_format).type == TBL) + { +uprintf("<2>\n"); + free(chaine); + // A FIXER + } + else + { +uprintf("<3>\n"); + free(chaine); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); + } + + (*longueur_effective) = longueur_totale; } else if ((*s_objet).type == MCX) { @@ -3853,6 +4271,188 @@ formateur_fichier(struct_processus *s_et Matrice complexe -------------------------------------------------------------------------------- */ + + if (format_sortie == 'N') + { + format_sortie = 'C'; + longueur = 16; + } + + if (format_sortie != 'C') + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); + } + + longueur_objet = (*((struct_matrice *) (*s_objet).objet)) + .nombre_lignes * (*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes; + + if (((*((struct_matrice *) (*s_objet).objet)).nombre_lignes + < (1LL << 8)) && ((*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes < (1LL << 8))) + { + // Taille sur un octet + if ((chaine = malloc((size_t) ((*longueur_effective) = + (3 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xD2; + chaine[1] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[2] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 3; + } + else if (((*((struct_matrice *) (*s_objet).objet)).nombre_lignes + < (1LL << 16)) && ((*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes < (1LL << 16))) + { + // Taille sur deux octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (5 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xD6; + chaine[1] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 8) & 0xFF); + chaine[2] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[3] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 8) & 0xFF); + chaine[4] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 5; + } + else if (((*((struct_matrice *) (*s_objet).objet)).nombre_lignes + < (1LL << 32)) && ((*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes < (1LL << 32))) + { + // Taille sur quatre octets + if ((chaine = malloc((size_t) (((*longueur_effective) = + 9 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xDA; + chaine[1] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 24) & 0xFF); + chaine[2] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 16) & 0xFF); + chaine[3] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 8) & 0xFF); + chaine[4] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[5] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 24) & 0xFF); + chaine[6] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 16) & 0xFF); + chaine[7] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 8) & 0xFF); + chaine[8] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 9; + } + else + { + // Taille sur huit octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (17 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xDE; + chaine[1] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 56) & 0xFF); + chaine[2] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 48) & 0xFF); + chaine[3] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 40) & 0xFF); + chaine[4] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 32) & 0xFF); + chaine[5] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 24) & 0xFF); + chaine[6] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 16) & 0xFF); + chaine[7] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 8) & 0xFF); + chaine[8] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[9] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 56) & 0xFF); + chaine[10] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 48) & 0xFF); + chaine[11] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 40) & 0xFF); + chaine[12] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 32) & 0xFF); + chaine[13] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 24) & 0xFF); + chaine[14] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 16) & 0xFF); + chaine[15] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 8) & 0xFF); + chaine[16] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 17; + } + + switch(longueur) + { + case 8: + { + break; + } + + default: + case 16: + { + chaine[0] |= 0x01; + break; + } + } + + for(i = 0; i < (*((struct_matrice *) (*s_objet).objet)) + .nombre_lignes; i++) + { + for(j = 0; j < (*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes; j++) + { + if ((chaine_tampon = formateur_fichier_binaire_nombre( + s_etat_processus, &(((complex16 **) + (*((struct_matrice *) (*s_objet).objet)).tableau) + [i][j]), 'R', format_sortie, + longueur, &longueur_element)) == NULL) + { + free(chaine); + return(NULL); + } + + memcpy(chaine_offset + (((i * (*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes) + j) * + longueur), chaine_tampon + 1, (size_t) longueur); + free(chaine_tampon); + } + } } else if ((*s_objet).type == MIN) { @@ -3862,6 +4462,253 @@ formateur_fichier(struct_processus *s_et Matrice entière -------------------------------------------------------------------------------- */ + + if (format_sortie == 'N') + { + format_sortie = 'I'; + longueur = 8; + } + + if ((format_sortie != 'I') && (format_sortie != 'R') + && (format_sortie != 'C')) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); + } + + longueur_objet = (*((struct_matrice *) (*s_objet).objet)) + .nombre_lignes * (*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes; + + if (((*((struct_matrice *) (*s_objet).objet)).nombre_lignes + < (1LL << 8)) && ((*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes < (1LL << 8))) + { + // Taille sur un octet + if ((chaine = malloc((size_t) ((*longueur_effective) = + (3 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0x00; + chaine[1] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[2] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 3; + } + else if (((*((struct_matrice *) (*s_objet).objet)).nombre_lignes + < (1LL << 16)) && ((*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes < (1LL << 16))) + { + // Taille sur deux octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (5 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0x04; + chaine[1] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 8) & 0xFF); + chaine[2] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[3] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 8) & 0xFF); + chaine[4] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 5; + } + else if (((*((struct_matrice *) (*s_objet).objet)).nombre_lignes + < (1LL << 32)) && ((*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes < (1LL << 32))) + { + // Taille sur quatre octets + if ((chaine = malloc((size_t) (((*longueur_effective) = + 9 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0x08; + chaine[1] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 24) & 0xFF); + chaine[2] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 16) & 0xFF); + chaine[3] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 8) & 0xFF); + chaine[4] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[5] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 24) & 0xFF); + chaine[6] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 16) & 0xFF); + chaine[7] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 8) & 0xFF); + chaine[8] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 9; + } + else + { + // Taille sur huit octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (17 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0x0C; + chaine[1] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 56) & 0xFF); + chaine[2] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 48) & 0xFF); + chaine[3] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 40) & 0xFF); + chaine[4] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 32) & 0xFF); + chaine[5] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 24) & 0xFF); + chaine[6] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 16) & 0xFF); + chaine[7] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 8) & 0xFF); + chaine[8] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[9] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 56) & 0xFF); + chaine[10] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 48) & 0xFF); + chaine[11] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 40) & 0xFF); + chaine[12] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 32) & 0xFF); + chaine[13] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 24) & 0xFF); + chaine[14] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 16) & 0xFF); + chaine[15] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 8) & 0xFF); + chaine[16] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 17; + } + + switch(format_sortie) + { + default: + case 'I': + { + switch(longueur) + { + case 1: + { + break; + } + + case 2: + { + chaine[0] |= 0x01; + break; + } + + case 4: + { + chaine[0] |= 0x02; + break; + } + + default: + case 8: + { + chaine[0] |= 0x03; + break; + } + } + + chaine[0] |= 0x30; + break; + } + + case 'R': + { + switch(longueur) + { + case 4: + { + break; + } + + default: + case 8: + { + chaine[0] |= 0x01; + break; + } + } + + chaine[0] |= 0xC0; + break; + } + + case 'C': + { + switch(longueur) + { + case 8: + { + break; + } + + default: + case 16: + { + chaine[0] |= 0x01; + break; + } + } + + chaine[0] |= 0xD0; + break; + } + } + + for(i = 0; i < (*((struct_matrice *) (*s_objet).objet)) + .nombre_lignes; i++) + { + for(j = 0; j < (*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes; j++) + { + if ((chaine_tampon = formateur_fichier_binaire_nombre( + s_etat_processus, &(((integer8 **) + (*((struct_matrice *) (*s_objet).objet)).tableau) + [i][j]), 'I', format_sortie, + longueur, &longueur_element)) == NULL) + { + free(chaine); + return(NULL); + } + + memcpy(chaine_offset + (((i * (*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes) + j) * + longueur), chaine_tampon + 1, (size_t) longueur); + free(chaine_tampon); + } + } } else if ((*s_objet).type == MRL) { @@ -3871,6 +4718,217 @@ formateur_fichier(struct_processus *s_et Matrice réelle -------------------------------------------------------------------------------- */ + if (format_sortie == 'N') + { + format_sortie = 'R'; + longueur = 8; + } + + if ((format_sortie != 'R') && (format_sortie != 'C')) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); + } + + longueur_objet = (*((struct_matrice *) (*s_objet).objet)) + .nombre_lignes * (*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes; + + if (((*((struct_matrice *) (*s_objet).objet)).nombre_lignes + < (1LL << 8)) && ((*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes < (1LL << 8))) + { + // Taille sur un octet + if ((chaine = malloc((size_t) ((*longueur_effective) = + (3 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xC2; + chaine[1] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[2] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 3; + } + else if (((*((struct_matrice *) (*s_objet).objet)).nombre_lignes + < (1LL << 16)) && ((*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes < (1LL << 16))) + { + // Taille sur deux octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (5 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xC6; + chaine[1] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 8) & 0xFF); + chaine[2] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[3] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 8) & 0xFF); + chaine[4] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 5; + } + else if (((*((struct_matrice *) (*s_objet).objet)).nombre_lignes + < (1LL << 32)) && ((*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes < (1LL << 32))) + { + // Taille sur quatre octets + if ((chaine = malloc((size_t) (((*longueur_effective) = + 9 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xCA; + chaine[1] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 24) & 0xFF); + chaine[2] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 16) & 0xFF); + chaine[3] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 8) & 0xFF); + chaine[4] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[5] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 24) & 0xFF); + chaine[6] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 16) & 0xFF); + chaine[7] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 8) & 0xFF); + chaine[8] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 9; + } + else + { + // Taille sur huit octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (17 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xCE; + chaine[1] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 56) & 0xFF); + chaine[2] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 48) & 0xFF); + chaine[3] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 40) & 0xFF); + chaine[4] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 32) & 0xFF); + chaine[5] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 24) & 0xFF); + chaine[6] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 16) & 0xFF); + chaine[7] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes >> 8) & 0xFF); + chaine[8] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_lignes & 0xFF); + chaine[9] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 56) & 0xFF); + chaine[10] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 48) & 0xFF); + chaine[11] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 40) & 0xFF); + chaine[12] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 32) & 0xFF); + chaine[13] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 24) & 0xFF); + chaine[14] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 16) & 0xFF); + chaine[15] = (unsigned char) (((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes >> 8) & 0xFF); + chaine[16] = (unsigned char) ((*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes & 0xFF); + chaine_offset = chaine + 17; + } + + switch(format_sortie) + { + default: + case 'R': + { + switch(longueur) + { + case 4: + { + break; + } + + default: + case 8: + { + chaine[0] |= 0x01; + break; + } + } + + break; + } + + case 'C': + { + switch(longueur) + { + case 8: + { + break; + } + + default: + case 16: + { + chaine[0] |= 0x01; + break; + } + } + + chaine[0] |= 0x10; + break; + } + } + + for(i = 0; i < (*((struct_matrice *) (*s_objet).objet)) + .nombre_lignes; i++) + { + for(j = 0; j < (*((struct_matrice *) (*s_objet).objet)) + .nombre_colonnes; j++) + { + if ((chaine_tampon = formateur_fichier_binaire_nombre( + s_etat_processus, &(((real8 **) + (*((struct_matrice *) (*s_objet).objet)).tableau) + [i][j]), 'R', format_sortie, + longueur, &longueur_element)) == NULL) + { + free(chaine); + return(NULL); + } + + memcpy(chaine_offset + (((i * (*((struct_matrice *) + (*s_objet).objet)).nombre_colonnes) + j) * + longueur), chaine_tampon + 1, (size_t) longueur); + free(chaine_tampon); + } + } } else if ((*s_objet).type == NOM) { @@ -4023,6 +5081,128 @@ formateur_fichier(struct_processus *s_et Vecteur complexe -------------------------------------------------------------------------------- */ + + if (format_sortie == 'N') + { + format_sortie = 'C'; + longueur = 16; + } + + if (format_sortie != 'C') + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); + } + + longueur_objet = (*((struct_vecteur *) (*s_objet).objet)).taille; + + if (longueur_objet < (1LL << 8)) + { + // Taille sur un octet + if ((chaine = malloc((size_t) ((*longueur_effective) = + (2 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xB2; + chaine[1] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 2; + } + else if (longueur_objet < (1LL << 16)) + { + // Taille sur deux octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (3 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xB6; + chaine[1] = (unsigned char) ((longueur_objet >> 8) & 0xFF); + chaine[2] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 3; + } + else if (longueur_objet < (1LL << 32)) + { + // Taille sur quatre octets + if ((chaine = malloc((size_t) (((*longueur_effective) = + 5 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xBA; + chaine[1] = (unsigned char) ((longueur_objet >> 24) & 0xFF); + chaine[2] = (unsigned char) ((longueur_objet >> 16) & 0xFF); + chaine[3] = (unsigned char) ((longueur_objet >> 8) & 0xFF); + chaine[4] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 5; + } + else + { + // Taille sur huit octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (9 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xBE; + chaine[1] = (unsigned char) ((longueur_objet >> 56) & 0xFF); + chaine[2] = (unsigned char) ((longueur_objet >> 48) & 0xFF); + chaine[3] = (unsigned char) ((longueur_objet >> 40) & 0xFF); + chaine[4] = (unsigned char) ((longueur_objet >> 32) & 0xFF); + chaine[5] = (unsigned char) ((longueur_objet >> 24) & 0xFF); + chaine[6] = (unsigned char) ((longueur_objet >> 16) & 0xFF); + chaine[7] = (unsigned char) ((longueur_objet >> 8) & 0xFF); + chaine[8] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 9; + } + + switch(longueur) + { + case 8: + { + break; + } + + default: + case 16: + { + chaine[0] |= 0x01; + break; + } + } + + for(i = 0; i < longueur_objet; i++) + { + if ((chaine_tampon = formateur_fichier_binaire_nombre( + s_etat_processus, &(((complex16 *) (*((struct_vecteur *) + (*s_objet).objet)).tableau)[i]), 'C', format_sortie, + longueur, &longueur_element)) == NULL) + { + free(chaine); + return(NULL); + } + + memcpy(chaine_offset + (i * longueur), chaine_tampon + 1, + (size_t) longueur); + free(chaine_tampon); + } } else if ((*s_objet).type == VIN) { @@ -4032,6 +5212,192 @@ formateur_fichier(struct_processus *s_et Vecteur entier -------------------------------------------------------------------------------- */ + + if (format_sortie == 'N') + { + format_sortie = 'I'; + longueur = 8; + } + + if ((format_sortie != 'I') && (format_sortie != 'R') + && (format_sortie != 'C')) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); + } + + longueur_objet = (*((struct_vecteur *) (*s_objet).objet)).taille; + + if (longueur_objet < (1LL << 8)) + { + // Taille sur un octet + if ((chaine = malloc((size_t) ((*longueur_effective) = + (2 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0x20; + chaine[1] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 2; + } + else if (longueur_objet < (1LL << 16)) + { + // Taille sur deux octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (3 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0x24; + chaine[1] = (unsigned char) ((longueur_objet >> 8) & 0xFF); + chaine[2] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 3; + } + else if (longueur_objet < (1LL << 32)) + { + // Taille sur quatre octets + if ((chaine = malloc((size_t) (((*longueur_effective) = + 5 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0x28; + chaine[1] = (unsigned char) ((longueur_objet >> 24) & 0xFF); + chaine[2] = (unsigned char) ((longueur_objet >> 16) & 0xFF); + chaine[3] = (unsigned char) ((longueur_objet >> 8) & 0xFF); + chaine[4] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 5; + } + else + { + // Taille sur huit octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (9 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0x2C; + chaine[1] = (unsigned char) ((longueur_objet >> 56) & 0xFF); + chaine[2] = (unsigned char) ((longueur_objet >> 48) & 0xFF); + chaine[3] = (unsigned char) ((longueur_objet >> 40) & 0xFF); + chaine[4] = (unsigned char) ((longueur_objet >> 32) & 0xFF); + chaine[5] = (unsigned char) ((longueur_objet >> 24) & 0xFF); + chaine[6] = (unsigned char) ((longueur_objet >> 16) & 0xFF); + chaine[7] = (unsigned char) ((longueur_objet >> 8) & 0xFF); + chaine[8] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 9; + } + + switch(format_sortie) + { + default: + case 'I': + { + switch(longueur) + { + case 1: + { + break; + } + + case 2: + { + chaine[0] |= 0x01; + break; + } + + case 4: + { + chaine[0] |= 0x02; + break; + } + + default: + case 8: + { + chaine[0] |= 0x03; + break; + } + } + + break; + } + + case 'R': + { + switch(longueur) + { + case 4: + { + break; + } + + default: + case 8: + { + chaine[0] |= 0x01; + break; + } + } + + chaine[0] |= 0x80; + break; + } + + case 'C': + { + switch(longueur) + { + case 8: + { + break; + } + + default: + case 16: + { + chaine[0] |= 0x01; + break; + } + } + + chaine[0] |= 0x90; + break; + } + } + + for(i = 0; i < longueur_objet; i++) + { + if ((chaine_tampon = formateur_fichier_binaire_nombre( + s_etat_processus, &(((integer8 *) (*((struct_vecteur *) + (*s_objet).objet)).tableau)[i]), 'I', format_sortie, + longueur, &longueur_element)) == NULL) + { + free(chaine); + return(NULL); + } + + memcpy(chaine_offset + (i * longueur), chaine_tampon + 1, + (size_t) longueur); + free(chaine_tampon); + } } else if ((*s_objet).type == VRL) { @@ -4041,6 +5407,143 @@ formateur_fichier(struct_processus *s_et Vecteur réel -------------------------------------------------------------------------------- */ + + if (format_sortie == 'N') + { + format_sortie = 'R'; + longueur = 8; + } + + if ((format_sortie != 'R') && (format_sortie != 'C')) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); + } + + longueur_objet = (*((struct_vecteur *) (*s_objet).objet)).taille; + + if (longueur_objet < (1LL << 8)) + { + // Taille sur un octet + if ((chaine = malloc((size_t) ((*longueur_effective) = + (2 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xA2; + chaine[1] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 2; + } + else if (longueur_objet < (1LL << 16)) + { + // Taille sur deux octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (3 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xA6; + chaine[1] = (unsigned char) ((longueur_objet >> 8) & 0xFF); + chaine[2] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 3; + } + else if (longueur_objet < (1LL << 32)) + { + // Taille sur quatre octets + if ((chaine = malloc((size_t) (((*longueur_effective) = + 5 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xAA; + chaine[1] = (unsigned char) ((longueur_objet >> 24) & 0xFF); + chaine[2] = (unsigned char) ((longueur_objet >> 16) & 0xFF); + chaine[3] = (unsigned char) ((longueur_objet >> 8) & 0xFF); + chaine[4] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 5; + } + else + { + // Taille sur huit octets + if ((chaine = malloc((size_t) ((*longueur_effective) = + (9 + (longueur_objet * longueur))) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + chaine[0] = 0xAE; + chaine[1] = (unsigned char) ((longueur_objet >> 56) & 0xFF); + chaine[2] = (unsigned char) ((longueur_objet >> 48) & 0xFF); + chaine[3] = (unsigned char) ((longueur_objet >> 40) & 0xFF); + chaine[4] = (unsigned char) ((longueur_objet >> 32) & 0xFF); + chaine[5] = (unsigned char) ((longueur_objet >> 24) & 0xFF); + chaine[6] = (unsigned char) ((longueur_objet >> 16) & 0xFF); + chaine[7] = (unsigned char) ((longueur_objet >> 8) & 0xFF); + chaine[8] = (unsigned char) (longueur_objet & 0xFF); + chaine_offset = chaine + 9; + } + + switch(format_sortie) + { + default: + case 'R': + { + break; + } + + case 'C': + { + chaine[0] |= 0x10; + break; + } + } + + switch(longueur) + { + case 4: + { + break; + } + + default: + case 8: + { + chaine[0] |= 0x01; + break; + } + } + + for(i = 0; i < longueur_objet; i++) + { + if ((chaine_tampon = formateur_fichier_binaire_nombre( + s_etat_processus, &(((real8 *) (*((struct_vecteur *) + (*s_objet).objet)).tableau)[i]), 'R', format_sortie, + longueur, &longueur_element)) == NULL) + { + free(chaine); + return(NULL); + } + + memcpy(chaine_offset + (i * longueur), chaine_tampon + 1, + (size_t) longueur); + free(chaine_tampon); + } } else { @@ -4078,11 +5581,15 @@ formateur_fichier(struct_processus *s_et memcpy(&(chaine[longueur_totale]), tampon, 1); longueur_totale += 1; } - else if (longueur_totale < (((integer8) 1) << 16)) + else { longueur_totale++; - for(i = 0; i < 7; i++) + // i = { 0 (16 bits) 2 (32 bits) 6 (64 bits) } + + i = 0; + + for(;;) { if ((longueur_totale < (((integer8) 1) << (8 * (i + 2)))) || (i == 6)) @@ -4106,9 +5613,29 @@ formateur_fichier(struct_processus *s_et | ((i + 1) << 1)); break; } + + switch(i) + { + case 0 : + { + i = 2; + break; + } + + case 2 : + { + i = 6; + break; + } + } } - if ((chaine = realloc(chaine, (((size_t) longueur_totale) + 3) + // i = 0 => +3 (16 bits) + // i = 2 => +5 (32 bits) + // i = 6 => +9 (64 bits) + + if ((chaine = realloc(chaine, (((size_t) longueur_totale) + + ((i == 0) ? 3 : ((i == 2) ? 5 : 9))) * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = @@ -4119,9 +5646,6 @@ formateur_fichier(struct_processus *s_et memcpy(&(chaine[longueur_totale]), tampon, 3); longueur_totale += 3; } - else if (longueur_totale < (((integer8) 1) << 32)) - { - } __zone(); (*longueur_effective) = longueur_totale; @@ -4697,14 +6221,19 @@ formateur_fichier_binaire_nombre(struct_ vinf = nextafter(valeur, 0); vsup = nextafter(valeur, valeur * 2); } - else + else if (valeur < 0) { vinf = nextafter(valeur, valeur * 2); vsup = nextafter(valeur, 0); } + else + { + vinf = valeur; + vsup = valeur; + } - if (!((vinf <= ((real4) valeur)) && - (((real4) valeur) <= vsup))) + if (!((((real4) vinf) <= ((real4) valeur)) && + (((real4) valeur) <= ((real4) vsup)))) { (*s_etat_processus).erreur_execution = d_ex_representation; @@ -5275,25 +6804,23 @@ lecture_fichier_non_formate(struct_proce switch(deplacement) { case 1: - i1 |= (integer1) (i1 << - (8 * ((((signed) deplacement) - 1) - - i))); + i1 = (integer1) octets[0]; break; case 2: - i2 |= (integer2) (i2 << + i2 |= (integer2) (((integer8) octets[i]) << (8 * ((((signed) deplacement) - 1) - i))); break; case 4: - i4 |= (integer4) (i4 << + i4 |= (integer4) (((integer8) octets[i]) << (8 * ((((signed) deplacement) - 1) - i))); break; case 8: - i8 |= (integer8) (i8 << + i8 |= (integer8) (((integer8) octets[i]) << (8 * ((((signed) deplacement) - 1) - i))); break;