--- rpl/src/transliteration.c 2010/01/26 15:22:44 1.1.1.1 +++ rpl/src/transliteration.c 2013/12/03 09:36:16 1.73 @@ -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.17 + Copyright (C) 1989-2013 Dr. BERTRAND Joël This file is part of RPL/2. @@ -20,8 +20,11 @@ */ -#include "rpl.conv.h" +#include "rpl-conv.h" +#include "tex-conv.h" + #include + #undef fprintf #undef printf @@ -87,6 +90,20 @@ reencodage(struct_processus *s_etat_proc if ((transcodage = iconv_open(codage_sortie, codage_entree)) == (iconv_t) -1) { + // On affiche une erreur ici car la fonction d'affichage + // de l'erreur utilise la macro printf() donc une + // opération de translitération qui échouera elle aussi. + // Le positionnement de l'erreur permet de sortir du programme. + + if ((*s_etat_processus).langue == 'F') + { + fprintf(stderr, "+++Erreur : Erreur de transcodage\n"); + } + else + { + fprintf(stderr, "+++Error : Transcodage error\n"); + } + (*s_etat_processus).erreur_execution = d_ex_erreur_transcodage; return(NULL); } @@ -102,7 +119,8 @@ reencodage(struct_processus *s_etat_proc chaine_sortie[0] = d_code_fin_chaine; - if ((buffer_sortie = malloc((d_LONGUEUR + 1) * sizeof(char))) == NULL) + if ((buffer_sortie = malloc((d_LONGUEUR + 1) * sizeof(unsigned char))) + == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); @@ -117,16 +135,64 @@ reencodage(struct_processus *s_etat_proc &longueur_entree, (char **) &pointeur, &longueur_sortie)) == (size_t) -1) { - // On autorise les erreurs EINVAL et EILSEQ - if (errno == EILSEQ) + // On autorise les erreurs EINVAL si le caractère suivant est non + // nul : la séquence d'entrée est continue sur le bloc suivant. + + if (errno == EINVAL) + { + if ((*(buffer_entree + 1)) == d_code_fin_chaine) + { + free(buffer_sortie); + free(chaine_sortie); + + // On affiche une erreur ici car la fonction d'affichage + // de l'erreur utilise la macro printf() donc une + // opération de translitération qui échouera elle aussi. + // Le positionnement de l'erreur permet de sortir du + // programme. + + if ((*s_etat_processus).langue == 'F') + { + fprintf(stderr, "+++Erreur : Erreur de transcodage\n"); + } + else + { + fprintf(stderr, "+++Error : Transcodage error\n"); + } + + (*s_etat_processus).erreur_execution = + d_ex_erreur_transcodage; + return(NULL); + } + } + + // Si la séquence d'entrée est invalide, on reçoit une erreur + // EILSEQ. + else if (errno == EILSEQ) { free(buffer_sortie); + free(chaine_sortie); + + // On affiche une erreur ici car la fonction d'affichage + // de l'erreur utilise la macro printf() donc une + // opération de translitération qui échouera elle aussi. + // Le positionnement de l'erreur permet de sortir du programme. + + if ((*s_etat_processus).langue == 'F') + { + fprintf(stderr, "+++Erreur : Erreur de transcodage\n"); + } + else + { + fprintf(stderr, "+++Error : Transcodage error\n"); + } + (*s_etat_processus).erreur_execution = d_ex_erreur_transcodage; return(NULL); } } - tampon = (unsigned char *) chaine_sortie; + tampon = chaine_sortie; (*pointeur) = d_code_fin_chaine; if ((chaine_sortie = malloc((strlen(tampon) + strlen(buffer_sortie) + 1) @@ -170,24 +236,17 @@ localisation_courante(struct_processus * int pipes_sortie[2]; int status; - logical1 drapeau_fin; + integer8 i; + integer8 longueur_lecture; + integer8 nombre_arguments; + integer8 nombre_iterations; + integer8 pointeur; - long i; - long nombre_arguments; pid_t pid; - sigset_t oldset; - sigset_t set; - - struct sigaction action_passee; - unsigned char *tampon; - unsigned long longueur_lecture; - unsigned long nombre_iterations; - unsigned long pointeur; - if ((arguments = malloc(3 * sizeof(char **))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -211,7 +270,6 @@ localisation_courante(struct_processus * arguments[2] = NULL; nombre_arguments = 2; - drapeau_fin = d_faux; if (pipe(pipes_entree) != 0) { @@ -231,16 +289,10 @@ localisation_courante(struct_processus * return; } - sigfillset(&set); - pthread_sigmask(SIG_BLOCK, &set, &oldset); - verrouillage_threads_concurrents(s_etat_processus); pid = fork(); deverrouillage_threads_concurrents(s_etat_processus); - pthread_sigmask(SIG_SETMASK, &oldset, NULL); - sigpending(&set); - if (pid < 0) { if (close(pipes_entree[0]) != 0) @@ -402,8 +454,11 @@ localisation_courante(struct_processus * * Récupération de la valeur de retour du processus détaché */ - if (sem_post(&((*s_etat_processus).semaphore_fork)) - != 0) +# ifndef SEMAPHORES_NOMMES + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# else + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -411,7 +466,11 @@ localisation_courante(struct_processus * if (waitpid(pid, &status, 0) == -1) { - if (sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { if (errno != EINTR) { @@ -424,7 +483,11 @@ localisation_courante(struct_processus * return; } - if (sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { if (errno != EINTR) { @@ -438,24 +501,34 @@ localisation_courante(struct_processus * pointeur = 0; nombre_iterations = 1; - if ((tampon = malloc((longueur_lecture + 1) * + if ((tampon = malloc(((size_t) (longueur_lecture + 1)) * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } - if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) + tampon[0] = d_code_fin_chaine; + +# ifndef SEMAPHORES_NOMMES + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# else + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; } - while((ios = read_atomic(s_etat_processus, + while((ios = (int) read_atomic(s_etat_processus, pipes_sortie[0], &(tampon[pointeur]), - longueur_lecture)) > 0) + (size_t) longueur_lecture)) > 0) { - while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { if (errno != EINTR) { @@ -469,7 +542,7 @@ localisation_courante(struct_processus * nombre_iterations++; if ((tampon = realloc(tampon, - ((nombre_iterations * longueur_lecture) + 1) * + ((size_t) ((nombre_iterations * longueur_lecture) + 1)) * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = @@ -477,14 +550,22 @@ localisation_courante(struct_processus * return; } - if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# else + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; } } - while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { if (errno != EINTR) { @@ -513,18 +594,22 @@ localisation_courante(struct_processus * return; } - (*s_etat_processus).localisation = tampon; - - if (sigaction(SIGINT, &action_passee, NULL) != 0) + if (strlen(tampon) > 0) { - for(i = 0; i < nombre_arguments; i++) + (*s_etat_processus).localisation = tampon; + } + else + { + free(tampon); + + if (((*s_etat_processus).localisation = malloc((strlen(d_locale) + + 1) * sizeof(unsigned char))) == NULL) { - free(arguments[i]); + (*s_etat_processus).erreur_systeme = d_es_processus; + return; } - free(arguments); - (*s_etat_processus).erreur_systeme = d_es_signal; - return; + strcpy((*s_etat_processus).localisation, d_locale); } for(i = 0; i < nombre_arguments; i++) @@ -534,7 +619,11 @@ localisation_courante(struct_processus * free(arguments); - if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# else + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -544,20 +633,23 @@ localisation_courante(struct_processus * { // Le processus fils renvoie une erreur. - while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) + free(tampon); + + if (((*s_etat_processus).localisation = malloc((strlen(d_locale) + + 1) * sizeof(unsigned char))) == NULL) { - if (errno != EINTR) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } + (*s_etat_processus).erreur_systeme = d_es_processus; + return; } - (*s_etat_processus).erreur_execution = d_ex_erreur_processus; - return; + strcpy((*s_etat_processus).localisation, d_locale); } - while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { if (errno != EINTR) { @@ -576,43 +668,29 @@ localisation_courante(struct_processus * return; } -static int -vtransliterated_sprintf(char **strp, const char *fmt, va_list ap) -{ - size_t bs, s; - char *b = NULL; - va_list cap; - - va_copy(cap, ap); - - for(bs = 256;; bs *= 2) - { - va_copy(ap, cap); - if (b != NULL) free(b); - if ((b = malloc(sizeof(*b) * bs)) == NULL) return -1; - if (((int) (s = vsnprintf(b, bs, fmt, ap))) < 0) - { va_end(ap); free(b); return -1; } - va_end(ap); - if (s < bs) break; - } - - if (((*strp) = realloc(b, ((s = strlen(b)) + 1) * sizeof(*b))) - == NULL) { free(b); return -1; } - return s; -} int transliterated_fprintf(struct_processus *s_etat_processus, file *flux, const char *format, ...) { int ios; - char *tampon; + + unsigned char *tampon; unsigned char *tampon2; + va_list arguments; va_start(arguments, format); - if (vtransliterated_sprintf(&tampon, format, arguments) < 0) +# ifdef OS2 + unsigned char *ptr_e;; + unsigned char *ptr_l;; + unsigned char *tampon3; + + unsigned long i; +# endif + + if (valsprintf(&tampon, format, arguments) < 0) { va_end(arguments); @@ -642,6 +720,56 @@ transliterated_fprintf(struct_processus tampon2 = tampon; } +# ifdef OS2 + if ((flux == stderr) || (flux == stdout)) + { + i = 0; + ptr_l = tampon2; + + while((*ptr_l) != d_code_fin_chaine) + { + if ((*ptr_l) == '\n') + { + i++; + } + + ptr_l++; + } + + if ((tampon3 = malloc((strlen(tampon2) + i + 1) * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return(-1); + } + + ptr_e = tampon3; + ptr_l = tampon2; + + while((*ptr_l) != d_code_fin_chaine) + { + (*ptr_e) = (*ptr_l); + + if ((*ptr_l) == '\n') + { + (*(++ptr_e)) = '\r'; + ptr_e++; + ptr_l++; + } + else + { + ptr_e++; + ptr_l++; + } + } + + (*ptr_e) = d_code_fin_chaine; + + free(tampon2); + tampon2 = tampon3; + } +# endif + # ifdef SunOS while((ios = fprintf(flux, "%s", tampon2)) < 0) { @@ -659,6 +787,74 @@ transliterated_fprintf(struct_processus return(ios); } + +int +tex_fprintf(struct_processus *s_etat_processus, + file *flux, const char *format, ...) +{ + int ios; + + unsigned char *tampon; + unsigned char *tampon2; + + va_list arguments; + + va_start(arguments, format); + + if (valsprintf(&tampon, format, arguments) < 0) + { + va_end(arguments); + + if (s_etat_processus != NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + } + + return(-1); + } + + va_end(arguments); + + if ((tampon2 = transliteration(s_etat_processus, tampon, + d_locale, ds_tex_encodage_3)) == NULL) + { + free(tampon); + return(-1); + } + + free(tampon); + +# ifdef SunOS + while((ios = fprintf(flux, "%s", tampon2)) < 0) + { + if ((errno != EINTR) && (errno != 0)) + { + break; + } + } +# else + ios = fprintf(flux, "%s", tampon2); +# endif + + free(tampon2); + + return(ios); +} + +#undef readline + +unsigned char * +readline_wrapper(unsigned char *invite) +{ + unsigned char *chaine; + + chaine = readline(invite); + printf("\r"); + + return(chaine); +} + + #define fprintf NULL #define printf NULL