Diff for /rpl/src/transliteration.c between versions 1.3 and 1.16

version 1.3, 2010/02/10 08:09:30 version 1.16, 2010/08/10 18:02:43
Line 1 Line 1
 /*  /*
 ================================================================================  ================================================================================
   RPL/2 (R) version 4.0.10    RPL/2 (R) version 4.0.18
   Copyright (C) 1989-2010 Dr. BERTRAND Joël    Copyright (C) 1989-2010 Dr. BERTRAND Joël
   
   This file is part of RPL/2.    This file is part of RPL/2.
Line 20 Line 20
 */  */
   
   
 #include "rpl.conv.h"  #include "rpl-conv.h"
   #include "tex-conv.h"
   
 #include <stdarg.h>  #include <stdarg.h>
   
 #undef fprintf  #undef fprintf
 #undef printf  #undef printf
   
Line 47  transliteration(struct_processus *s_etat Line 50  transliteration(struct_processus *s_etat
     unsigned char       *codage_sortie_transliteral;      unsigned char       *codage_sortie_transliteral;
     unsigned char       *tampon;      unsigned char       *tampon;
   
   #   ifdef OS2
       unsigned char       *ptr_e;;
       unsigned char       *ptr_l;;
       unsigned char       *tampon2;
   
       unsigned long       i;
   #   endif
   
     if ((codage_sortie_transliteral = malloc((strlen(codage_sortie)      if ((codage_sortie_transliteral = malloc((strlen(codage_sortie)
             + strlen("//TRANSLIT") + 1) * sizeof(unsigned char))) == NULL)              + strlen("//TRANSLIT") + 1) * sizeof(unsigned char))) == NULL)
     {      {
Line 60  transliteration(struct_processus *s_etat Line 71  transliteration(struct_processus *s_etat
             codage_entree, codage_sortie_transliteral);              codage_entree, codage_sortie_transliteral);
     free(codage_sortie_transliteral);      free(codage_sortie_transliteral);
   
   #   ifdef OS2
   
       i = 0;
       ptr_l = tampon;
   
       while((*ptr_l) != d_code_fin_chaine)
       {
           if ((*ptr_l) == '\n')
           {
               i++;
           }
   
           ptr_l++;
       }
   
       if ((tampon2 = malloc((strlen(tampon) + i + 1) * sizeof(unsigned char)))
               == NULL)
       {
           (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
           return(NULL);
       }
   
       ptr_e = tampon2;
       ptr_l = tampon;
   
       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++;
           }
       }
   
       free(tampon);
       tampon = tampon2;
   
   #   endif
   
     return(tampon);      return(tampon);
 }  }
   
Line 404  localisation_courante(struct_processus * Line 462  localisation_courante(struct_processus *
              * Récupération de la valeur de retour du processus détaché               * Récupération de la valeur de retour du processus détaché
              */               */
   
             if (sem_post(&((*s_etat_processus).semaphore_fork))  #           ifndef SEMAPHORES_NOMMES
                     != 0)              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;                  (*s_etat_processus).erreur_systeme = d_es_processus;
                 return;                  return;
Line 413  localisation_courante(struct_processus * Line 474  localisation_courante(struct_processus *
   
             if (waitpid(pid, &status, 0) == -1)              if (waitpid(pid, &status, 0) == -1)
             {              {
   #               ifndef SEMAPHORES_NOMMES
                 if (sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)                  if (sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
   #               else
                   if (sem_wait((*s_etat_processus).semaphore_fork) == -1)
   #               endif
                 {                  {
                     if (errno != EINTR)                      if (errno != EINTR)
                     {                      {
Line 426  localisation_courante(struct_processus * Line 491  localisation_courante(struct_processus *
                 return;                  return;
             }              }
   
   #           ifndef SEMAPHORES_NOMMES
             if (sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)              if (sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
   #           else
               if (sem_wait((*s_etat_processus).semaphore_fork) == -1)
   #           endif
             {              {
                 if (errno != EINTR)                  if (errno != EINTR)
                 {                  {
Line 447  localisation_courante(struct_processus * Line 516  localisation_courante(struct_processus *
             return;              return;
         }          }
   
   #       ifndef SEMAPHORES_NOMMES
         if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)          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;              (*s_etat_processus).erreur_systeme = d_es_processus;
             return;              return;
Line 457  localisation_courante(struct_processus * Line 530  localisation_courante(struct_processus *
                 pipes_sortie[0], &(tampon[pointeur]),                  pipes_sortie[0], &(tampon[pointeur]),
                 longueur_lecture)) > 0)                  longueur_lecture)) > 0)
         {          {
   #           ifndef SEMAPHORES_NOMMES
             while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)              while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
   #           else
               while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
   #           endif
             {              {
                 if (errno != EINTR)                  if (errno != EINTR)
                 {                  {
Line 479  localisation_courante(struct_processus * Line 556  localisation_courante(struct_processus *
                 return;                  return;
             }              }
   
   #           ifndef SEMAPHORES_NOMMES
             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)              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;                  (*s_etat_processus).erreur_systeme = d_es_processus;
                 return;                  return;
             }              }
         }          }
   
   #       ifndef SEMAPHORES_NOMMES
         while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)          while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
   #       else
           while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
   #       endif
         {          {
             if (errno != EINTR)              if (errno != EINTR)
             {              {
Line 536  localisation_courante(struct_processus * Line 621  localisation_courante(struct_processus *
   
         free(arguments);          free(arguments);
   
   #       ifndef SEMAPHORES_NOMMES
         if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)          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;              (*s_etat_processus).erreur_systeme = d_es_processus;
             return;              return;
Line 546  localisation_courante(struct_processus * Line 635  localisation_courante(struct_processus *
         {          {
             // Le processus fils renvoie une erreur.              // Le processus fils renvoie une erreur.
   
   #           ifndef SEMAPHORES_NOMMES
             while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)              while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
   #           else
               while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
   #           endif
             {              {
                 if (errno != EINTR)                  if (errno != EINTR)
                 {                  {
Line 559  localisation_courante(struct_processus * Line 652  localisation_courante(struct_processus *
             return;              return;
         }          }
   
   #       ifndef SEMAPHORES_NOMMES
         while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)          while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
   #       else
           while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
   #       endif
         {          {
             if (errno != EINTR)              if (errno != EINTR)
             {              {
Line 578  localisation_courante(struct_processus * Line 675  localisation_courante(struct_processus *
     return;      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  int
 transliterated_fprintf(struct_processus *s_etat_processus, file *flux,  transliterated_fprintf(struct_processus *s_etat_processus, file *flux,
         const char *format, ...)          const char *format, ...)
 {  {
     int             ios;      int             ios;
     char            *tampon;  
       unsigned char   *tampon;
     unsigned char   *tampon2;      unsigned char   *tampon2;
   
     va_list         arguments;      va_list         arguments;
   
     va_start(arguments, format);      va_start(arguments, format);
   
     if (vtransliterated_sprintf(&tampon, format, arguments) < 0)      if (valsprintf(&tampon, format, arguments) < 0)
     {      {
         va_end(arguments);          va_end(arguments);
   
Line 646  transliterated_fprintf(struct_processus Line 721  transliterated_fprintf(struct_processus
   
 #   ifdef SunOS  #   ifdef SunOS
     while((ios = fprintf(flux, "%s", tampon2)) < 0)      while((ios = fprintf(flux, "%s", tampon2)) < 0)
       {
           if ((errno != EINTR) && (errno != 0))
           {
               break;
           }
       }
   #   else
       ios = fprintf(flux, "%s", tampon2);
   #   endif
   
       free(tampon2);
   
       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))          if ((errno != EINTR) && (errno != 0))
         {          {

Removed from v.1.3  
changed lines
  Added in v.1.16


CVSweb interface <joel.bertrand@systella.fr>