--- rpl/src/formateur_fichiers.c 2015/03/26 16:12:31 1.85 +++ rpl/src/formateur_fichiers.c 2015/04/14 11:26:18 1.86 @@ -19,7 +19,7 @@ ================================================================================ */ - +#define DEBUG_ERREURS #include "rpl-conv.h" @@ -80,10 +80,12 @@ 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; @@ -3866,55 +3868,61 @@ formateur_fichier(struct_processus *s_et free(format_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*(*)". + // Construction d'une liste de format - if ((format_sortie == 'N') && ((*(*l_element_courant) - .donnee).type == LST)) + if ((s_format_tmp = allocation(s_etat_processus, LST)) + == NULL) { - 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) { - return(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); } - (*((struct_liste_chainee *) (*s_format_tmp).objet)) - .suivant = NULL; - if (((*((struct_liste_chainee *) (*s_format_tmp).objet)) - .donnee = allocation(s_etat_processus, CHN)) + .donnee = copie_objet(s_etat_processus, + (*l_element_courant_format).donnee, 'P')) == 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); - } + (*((struct_liste_chainee *) (*s_format_tmp).objet)) + .suivant = NULL; } if ((chaine_formatee = formateur_fichier(s_etat_processus, @@ -3945,27 +3953,19 @@ formateur_fichier(struct_processus *s_et free(chaine_formatee); } - if (format_sortie != 'N') - { - l_element_courant_format = - (*l_element_courant_format).suivant; - } - + l_element_courant_format = (*l_element_courant_format).suivant; nombre_elements++; l_element_courant = (*l_element_courant).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; @@ -4121,8 +4121,11 @@ formateur_fichier(struct_processus *s_et } } +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) @@ -4207,280 +4210,56 @@ formateur_fichier(struct_processus *s_et free(format_chaine); - for(i = 0; i < longueur_liste; i++) + if ((s_format_tmp = allocation(s_etat_processus, TBL)) + == NULL) { - if ((chaine_formatee = formateur_fichier(s_etat_processus, - (*((struct_tableau *) (*s_objet).objet)) - .elements[i], (*s_format).objet, - longueur, longueur_champ, - format_sortie, type, longueur_effective, - recursivite, export_fichier)) == NULL) - { - free(chaine); - return(NULL); - } + return(NULL); } - } - else if ((*s_format).type == TBL) - { - } - else - { - free(chaine); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_format_fichier; - return(NULL); - } - - // A FIXER + (*((struct_tableau *) (*s_format_tmp).objet)) + .nombre_elements = (*((struct_tableau *) + (*s_objet).objet)).nombre_elements; - /* - while((l_element_courant != NULL) && - (l_element_courant_format != NULL)) - { - if ((((*(*l_element_courant_format).donnee).type == LST) - && ((*(*l_element_courant).donnee).type == LST)) || - (((*(*l_element_courant_format).donnee).type == TBL) - && ((*(*l_element_courant).donnee).type == TBL))) + for(i = 0; i < (*((struct_tableau *) (*s_format_tmp).objet)) + .nombre_elements; i++) { - if (format_sortie != 'N') - { - if ((chaine_formatee = formateur_fichier( - s_etat_processus, - (*l_element_courant).donnee, - (*l_element_courant_format).donnee, - 0, 0, ' ', 'U', longueur_effective, recursivite, - export_fichier)) == NULL) - { - return(NULL); - } - } - else - { - if ((chaine_formatee = formateur_fichier( - s_etat_processus, - (*l_element_courant).donnee, - (*l_element_courant_format).donnee, - 0, 0, 'N', 'U', longueur_effective, recursivite, - export_fichier)) == NULL) - { - return(NULL); - } - } - - if ((chaine = realloc(chaine, ((size_t) (longueur_totale + - (*longueur_effective))) * sizeof(unsigned char))) - == NULL) + if (((*((struct_tableau *) (*s_format_tmp).objet)) + .elements[i] = copie_objet(s_etat_processus, + s_format, 'P')) == NULL) { - (*s_etat_processus).erreur_systeme = - d_es_allocation_memoire; return(NULL); } - - memcpy(&(chaine[longueur_totale]), chaine_formatee, - (size_t) (*longueur_effective)); - longueur_totale += (*longueur_effective); - free(chaine_formatee); } - else if ((*(*l_element_courant_format).donnee).type != CHN) - { - free(chaine); - (*s_etat_processus).erreur_execution = - d_ex_erreur_format_fichier; - return(NULL); - } - else +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) { - if ((format_chaine = conversion_majuscule( - s_etat_processus, (unsigned char *) - (*(*l_element_courant_format).donnee).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); - - // 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_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) - { - (*s_etat_processus).erreur_systeme = - d_es_allocation_memoire; - return(NULL); - } - - memcpy(&(chaine[longueur_totale]), chaine_formatee, - (size_t) (*longueur_effective)); - longueur_totale += (*longueur_effective); - free(chaine_formatee); - } - - if (format_sortie != 'N') - { - l_element_courant_format = - (*l_element_courant_format).suivant; + free(chaine); + return(NULL); } - nombre_elements++; - l_element_courant = (*l_element_courant).suivant; + liberation(s_etat_processus, s_format_tmp); } - - if (format_sortie != 'N') + else if ((*s_format).type == TBL) { - if ((l_element_courant != NULL) || - (l_element_courant_format != NULL)) - { - free(chaine); +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); - } + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return(NULL); } - */ (*longueur_effective) = longueur_totale; }