--- rpl/src/formateur_flux.c 2011/11/19 17:53:46 1.17 +++ rpl/src/formateur_flux.c 2013/03/01 09:29:30 1.33 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.4 - Copyright (C) 1989-2011 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.13 + Copyright (C) 1989-2013 Dr. BERTRAND Joël This file is part of RPL/2. @@ -165,14 +165,16 @@ formateur_flux(struct_processus *s_etat_ { printf("+++Information : " "Séquence d'échappement " - "inconnue [%d]\n", + "inconnue (\\x%c%c) [%d]\n", + *ptr_lecture, *(ptr_lecture + 1), (int) getpid()); } else { printf("+++Warning : Unknown " - "escape code " - "[%d]\n", (int) getpid()); + "escape code (\\x%c%c) [%d]\n", + *ptr_lecture, *(ptr_lecture + 1), + (int) getpid()); } } } @@ -182,11 +184,11 @@ formateur_flux(struct_processus *s_etat_ { printf("+++Information : " "Séquence d'échappement " - "inconnue [%d]\n", (int) getpid()); + "tronquée [%d]\n", (int) getpid()); } else { - printf("+++Warning : Unknown escape code " + printf("+++Warning : Truncated escape code " "[%d]\n", (int) getpid()); } } @@ -212,15 +214,35 @@ formateur_flux(struct_processus *s_etat_ } else { - if ((*s_etat_processus).langue == 'F') + if ((*(ptr_lecture + 1)) == d_code_fin_chaine) { - printf("+++Information : Séquence d'échappement " - "inconnue [%d]\n", (int) getpid()); + if ((*s_etat_processus).langue == 'F') + { + printf("+++Information : " + "Séquence d'échappement " + "tronquée [%d]\n", (int) getpid()); + } + else + { + printf("+++Warning : Truncated escape code " + "[%d]\n", (int) getpid()); + } } else - { - printf("+++Warning : Unknown escape code " - "[%d]\n", (int) getpid()); + { + if ((*s_etat_processus).langue == 'F') + { + printf("+++Information : Séquence d'échappement " + "inconnue (%c%c) [%d]\n", + *ptr_lecture, *(ptr_lecture + 1), + (int) getpid()); + } + else + { + printf("+++Warning : Unknown escape code (%c%c) " + "[%d]\n", *ptr_lecture, *(ptr_lecture + 1), + (int) getpid()); + } } } } @@ -240,6 +262,149 @@ formateur_flux(struct_processus *s_etat_ return(chaine); } + + +/* +================================================================================ + Routine de d'analyse d'un flux +================================================================================ + Entrées : structure sur l'état du processus et objet à afficher +-------------------------------------------------------------------------------- + Sorties : chaine de caractères +-------------------------------------------------------------------------------- + Effets de bord : néant +================================================================================ +*/ + +unsigned char * +analyse_flux(struct_processus *s_etat_processus, unsigned char *donnees, + long longueur) +{ + long longueur_courante; + long offset; + + unsigned char *chaine; + unsigned char hexadecimal[3]; + unsigned char *ptr_ecriture; + unsigned char *ptr_lecture; + + if ((chaine = malloc((longueur_courante = longueur + 1) * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return(NULL); + } + + ptr_lecture = donnees; + ptr_ecriture = chaine; + + while(longueur > 0) + { + // Début de la séquence d'échappement + + switch((*ptr_lecture)) + { + case '"': + case '\b': + case '\n': + case '\t': + case '\\': + { + offset = ptr_ecriture - chaine; + + if ((chaine = realloc(chaine, (++longueur_courante) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + ptr_ecriture = chaine + offset; + *ptr_ecriture++ = '\\'; + + switch((*ptr_lecture++)) + { + case '"': + { + *ptr_ecriture++ = '"'; + break; + } + + case '\b': + { + *ptr_ecriture++ = 'b'; + break; + } + + case '\n': + { + *ptr_ecriture++ = 'n'; + break; + } + + case '\t': + { + *ptr_ecriture++ = 't'; + break; + } + + case '\\': + { + *ptr_ecriture++ = '\\'; + break; + } + } + + break; + } + + case ' ': + { + *ptr_ecriture++ = *ptr_lecture++; + break; + } + + default: + { + if (isgraph((*ptr_lecture))) + { + *ptr_ecriture++ = *ptr_lecture++; + } + else + { + offset = ptr_ecriture - chaine; + + if ((chaine = realloc(chaine, (longueur_courante = + longueur_courante + 3) * sizeof(unsigned char))) + == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return(NULL); + } + + ptr_ecriture = chaine + offset; + *ptr_ecriture++ = '\\'; + *ptr_ecriture++ = 'x'; + + sprintf(hexadecimal, "%02X", *ptr_lecture++); + + *ptr_ecriture++ = hexadecimal[0]; + *ptr_ecriture++ = hexadecimal[1]; + } + + break; + } + } + + longueur--; + } + + (*ptr_ecriture) = d_code_fin_chaine; + + return(chaine); +} /*