--- rpl/src/formateur.c 2010/01/26 15:22:44 1.1 +++ rpl/src/formateur.c 2012/04/13 14:12:48 1.48 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.0.9 - Copyright (C) 1989-2010 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.8 + Copyright (C) 1989-2012 Dr. BERTRAND Joël This file is part of RPL/2. @@ -20,7 +20,7 @@ */ -#include "rpl.conv.h" +#include "rpl-conv.h" /* @@ -47,6 +47,8 @@ formateur(struct_processus *s_etat_proce logical4 autorisation_parenthese; logical4 presence_signe; + long longueur_chaine; + struct_liste_chainee *l_atome; struct_liste_chainee *l_element_courant; struct_liste_chainee *l_liste1; @@ -73,7 +75,6 @@ formateur(struct_processus *s_etat_proce unsigned long i; unsigned long j; unsigned long k; - unsigned long longueur_binaire; unsigned long longueur_courante; unsigned long longueur_decimale_courante; unsigned long *longueurs_maximales; @@ -92,7 +93,6 @@ formateur(struct_processus *s_etat_proce strcpy(base, " "); - longueur_binaire = 0; masque_binaire = 0; if ((*s_objet).type == ADR) @@ -104,19 +104,12 @@ formateur(struct_processus *s_etat_proce -------------------------------------------------------------------------------- */ - sprintf(tampon, "%016lX", (*((unsigned long *) ((*s_objet).objet)))); - - chaine = (unsigned char *) malloc((strlen(tampon) + 3) - * sizeof(unsigned char)); - - if (chaine == NULL) + if (alsprintf(&chaine, "@ %016lX", (*((unsigned long *) + ((*s_objet).objet)))) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } - - strcpy(chaine, "@ "); - strcat(chaine, tampon); } else if ((*s_objet).type == SLB) { @@ -127,34 +120,14 @@ formateur(struct_processus *s_etat_proce -------------------------------------------------------------------------------- */ - sprintf(tampon, " %016lX", (unsigned long) (*((struct_bibliotheque *) - (*s_objet).objet)).descripteur); - - chaine = (unsigned char *) malloc((strlen(tampon) + 10) - * sizeof(unsigned char)); - - if (chaine == NULL) - { - (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; - return(NULL); - } - - strcpy(chaine, "Library $"); - strcat(chaine, tampon); - - registre = chaine; - - if ((chaine = malloc((strlen(registre) + 2 + - strlen((*(struct_bibliotheque *) ((*s_objet).objet)).nom) - + 2) * sizeof(unsigned char))) == NULL) + if (alsprintf(&chaine, "Library $ %016lX [%s]", + (unsigned long) (*((struct_bibliotheque *) + (*s_objet).objet)).descripteur, (*((struct_bibliotheque *) + (*s_objet).objet)).nom) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } - - sprintf(chaine, "%s [%s]", registre, (*((struct_bibliotheque *) - (*s_objet).objet)).nom); - free(registre); } else if ((*s_objet).type == SPH) { @@ -165,21 +138,13 @@ formateur(struct_processus *s_etat_proce -------------------------------------------------------------------------------- */ - sprintf(tampon, "%016lX", (unsigned long) - &((*((struct_semaphore *) (*s_objet).objet)).semaphore)); - - chaine = (unsigned char *) malloc((strlen(tampon) + 15 + - strlen((*((struct_semaphore *) (*s_objet).objet)).nom)) - * sizeof(unsigned char)); - - if (chaine == NULL) + if (alsprintf(&chaine, "Semaphore $ %016lX '%s'", + &((*((struct_semaphore *) (*s_objet).objet)).semaphore), + (*((struct_semaphore *) (*s_objet).objet)).nom) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } - - sprintf(chaine, "Semaphore $%s '%s'", tampon, - (*((struct_semaphore *) (*s_objet).objet)).nom); } else if ((*s_objet).type == SQL) { @@ -194,10 +159,14 @@ formateur(struct_processus *s_etat_proce "MYSQL") == 0) { # ifdef MYSQL_SUPPORT - sprintf(tampon, "Sql $%016lX (%s)", + if (alsprintf(&chaine, "Sql $ %016lX (%s)", (long unsigned int) (*((struct_connecteur_sql *) (*s_objet).objet)).descripteur.mysql, - (*((struct_connecteur_sql *) (*s_objet).objet)).type); + (*((struct_connecteur_sql *) (*s_objet).objet)).type) < 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return(NULL); + } # else if ((*s_etat_processus).langue == 'F') { @@ -217,10 +186,14 @@ formateur(struct_processus *s_etat_proce "POSTGRESQL") == 0) { # ifdef POSTGRESQL_SUPPORT - sprintf(tampon, "Sql $%016lX [ %s ]", + if (alsprintf(&chaine, "Sql $ %016lX (%s)", (long unsigned int) (*((struct_connecteur_sql *) (*s_objet).objet)).descripteur.postgresql, - (*((struct_connecteur_sql *) (*s_objet).objet)).type); + (*((struct_connecteur_sql *) (*s_objet).objet)).type) < 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return(NULL); + } # else if ((*s_etat_processus).langue == 'F') { @@ -242,17 +215,6 @@ formateur(struct_processus *s_etat_proce (*((struct_connecteur_sql *) (*s_objet).objet)) .type)); } - - chaine = (unsigned char *) malloc((strlen(tampon) + 1) - * sizeof(unsigned char)); - - if (chaine == NULL) - { - (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; - return(NULL); - } - - strcpy(chaine, tampon); } else if ((*s_objet).type == PRC) { @@ -266,41 +228,25 @@ formateur(struct_processus *s_etat_proce if ((*(*((struct_processus_fils *) (*s_objet).objet)).thread) .processus_detache == d_vrai) { - sprintf(tampon, " %016lX", (unsigned long) + if (alsprintf(&chaine, "Process $ %016lX", (unsigned long) (*(*((struct_processus_fils *) (*s_objet).objet)).thread) - .pid); - - chaine = (unsigned char *) malloc((strlen(tampon) + 10) - * sizeof(unsigned char)); - - if (chaine == NULL) + .pid) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } - - strcpy(chaine, "Process $"); - strcat(chaine, tampon); } else { - sprintf(tampon, " %016lX/%016lX", + if (alsprintf(&chaine, "Light weight process $ %016lX/%016lX", (unsigned long) (*(*((struct_processus_fils *) (*s_objet).objet)).thread).pid, (unsigned long) (*(*((struct_processus_fils *) - (*s_objet).objet)).thread).tid); - - chaine = (unsigned char *) malloc((strlen(tampon) + 23) - * sizeof(unsigned char)); - - if (chaine == NULL) + (*s_objet).objet)).thread).tid) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } - - strcpy(chaine, "Light weight process $"); - strcat(chaine, tampon); } } else if ((*s_objet).type == FCH) @@ -312,21 +258,13 @@ formateur(struct_processus *s_etat_proce -------------------------------------------------------------------------------- */ - sprintf(tampon, " %016lX", (unsigned long) (*((struct_fichier *) - ((*s_objet).objet))).descripteur); - - chaine = (unsigned char *) malloc((strlen(tampon) + 7) - * sizeof(unsigned char)); - - if (chaine == NULL) + if (alsprintf(&chaine, "File $ %016lX", (unsigned long) + (*((struct_fichier *) ((*s_objet).objet))).descripteur) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } - strcpy(chaine, "File $"); - strcat(chaine, tampon); - registre45 = test_cfsf(s_etat_processus, 45); cf(s_etat_processus, 45); @@ -452,21 +390,14 @@ formateur(struct_processus *s_etat_proce -------------------------------------------------------------------------------- */ - sprintf(tampon, " %016lX", (unsigned long) (*((struct_socket *) - ((*s_objet).objet))).socket); - - chaine = (unsigned char *) malloc((strlen(tampon) + 9) - * sizeof(unsigned char)); - - if (chaine == NULL) + if (alsprintf(&chaine, "Socket $ %016lX", + (unsigned long) (*((struct_socket *) + ((*s_objet).objet))).socket) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } - strcpy(chaine, "Socket $"); - strcat(chaine, tampon); - registre45 = test_cfsf(s_etat_processus, 45); cf(s_etat_processus, 45); @@ -1647,7 +1578,6 @@ formateur(struct_processus *s_etat_proce -------------------------------------------------------------------------------- */ - longueur_binaire = longueur_entiers_binaires(s_etat_processus); masque_binaire = masque_entiers_binaires(s_etat_processus); if ((test_cfsf(s_etat_processus, 43) == d_faux) && @@ -1819,16 +1749,27 @@ formateur(struct_processus *s_etat_proce -------------------------------------------------------------------------------- */ - chaine = (unsigned char *) malloc((strlen((unsigned char *) - ((*s_objet).objet)) + 1) * sizeof(unsigned char)); - - if (chaine == NULL) + if (((*s_etat_processus).autorisation_conversion_chaine == 'Y') && + (test_cfsf(s_etat_processus, 34) == d_vrai)) { - (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; - return(NULL); + if ((chaine = formateur_flux(s_etat_processus, + (unsigned char *) (*s_objet).objet, &longueur_chaine)) + == NULL) + { + return(NULL); + } } + else + { + if ((chaine = malloc((strlen((unsigned char *) + ((*s_objet).objet)) + 1) * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return(NULL); + } - strcpy(chaine, (unsigned char *) ((*s_objet).objet)); + strcpy(chaine, (unsigned char *) ((*s_objet).objet)); + } } else if ((*s_objet).type == CPL) { @@ -3052,20 +2993,13 @@ formateur(struct_processus *s_etat_proce } else if ((*s_objet).type == MTX) { - sprintf(tampon, " %016lX", (unsigned long) - &((*((struct_mutex *) (*s_objet).objet)).mutex)); - - chaine = (unsigned char *) malloc((strlen(tampon) + 8) - * sizeof(unsigned char)); - - if (chaine == NULL) + if (alsprintf(&chaine, "Mutex $ %016lX owned by $ %016lX", + (unsigned long) &((*((struct_mutex *) (*s_objet).objet)).mutex), + (unsigned long) (*((struct_mutex *) (*s_objet).objet)).tid) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } - - strcpy(chaine, "Mutex $"); - strcat(chaine, tampon); } else if ((*s_objet).type == NOM) { @@ -3512,15 +3446,16 @@ formateur_reel(struct_processus *s_etat_ logical1 i50; long correction; + long dernier_chiffre_significatif; long exposant; long longueur_utile; long longueur_utile_limite; unsigned char *chaine; - unsigned char format[16 + 1]; + unsigned char format[32 + 1]; unsigned char mode[3 + 1]; unsigned char *ptr; - unsigned char tampon[16 + 1]; + unsigned char tampon[32 + 1]; unsigned long i; unsigned long j; @@ -3536,6 +3471,30 @@ formateur_reel(struct_processus *s_etat_ if (type == 'R') { +# ifdef FP_INFINITE + int signe; + + if ((signe = isinf((*((real8 *) valeur_numerique)))) != 0) + { + if (signe > 0) + { + strcpy(chaine, "infinity"); + } + else + { + strcpy(chaine, "-infinity"); + } + + return(chaine); + } +# endif + + if (isnan((*((real8 *) valeur_numerique)))) + { + strcpy(chaine, "undef"); + return(chaine); + } + tampon_reel = *((real8 *) valeur_numerique); if (tampon_reel > ((real8) 0)) @@ -3644,9 +3603,42 @@ formateur_reel(struct_processus *s_etat_ } } + // Test portant sur le nombre de chiffres significatifs dans + // le cas du format STD pour que 1.2E-15 apparaisse en notation + // SCI car il y a une perte de précision dans l'affichage. + + if ((strcmp(mode, "STD") == 0) && (type == 'R')) + { + if (abs(*((real8 *) valeur_numerique)) < 1) + { + dernier_chiffre_significatif = -exposant; + sprintf(tampon, ".%f", mantisse); + + ptr = &(tampon[strlen(tampon) - 1]); + + while((*ptr) != '.') + { + if ((*ptr) != '0') + { + dernier_chiffre_significatif++; + } + + ptr--; + } + } + else + { + dernier_chiffre_significatif = 0; + } + } + else + { + dernier_chiffre_significatif = 0; + } + if ((strcmp(mode, "SCI") == 0) || ((strcmp(mode, "STD") == 0) && ((exposant > - longueur_utile_limite) || + longueur_utile_limite) || (dernier_chiffre_significatif > 15) || (exposant < -longueur_utile_limite))) || ((strcmp(mode, "FIX") == 0) && ((exposant >= longueur_utile_limite) || @@ -3733,8 +3725,15 @@ formateur_reel(struct_processus *s_etat_ if (exposant >= 0) { - sprintf(format, "%%.%luf", (longueur_utile_limite - exposant - - 1)); + if ((exposant + 1) < longueur_utile_limite) + { + sprintf(format, "%%.%luf", (longueur_utile_limite - exposant + - 1)); + } + else + { + strcpy(format, "%.0f."); + } } else { @@ -3759,6 +3758,7 @@ formateur_reel(struct_processus *s_etat_ } } } + strcpy(chaine, tampon); }