Annotation of rpl/src/transliteration.c, revision 1.40

1.1       bertrand    1: /*
                      2: ================================================================================
1.37      bertrand    3:   RPL/2 (R) version 4.1.3
1.25      bertrand    4:   Copyright (C) 1989-2011 Dr. BERTRAND Joël
1.1       bertrand    5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
                     22: 
1.14      bertrand   23: #include "rpl-conv.h"
                     24: #include "tex-conv.h"
1.5       bertrand   25: 
1.1       bertrand   26: #include <stdarg.h>
1.5       bertrand   27: 
1.1       bertrand   28: #undef fprintf
                     29: #undef printf
                     30: 
                     31: 
                     32: /*
                     33: ================================================================================
                     34:   Fonction de translitération
                     35: ================================================================================
                     36:   Entrées :
                     37: --------------------------------------------------------------------------------
                     38:   Sorties :
                     39: --------------------------------------------------------------------------------
                     40:   Effets de bord : néant
                     41: ================================================================================
                     42: */
                     43: 
                     44: unsigned char *
                     45: transliteration(struct_processus *s_etat_processus,
                     46:        unsigned char *chaine_entree,
                     47:        unsigned char *codage_entree,
                     48:        unsigned char *codage_sortie)
                     49: {
                     50:    unsigned char       *codage_sortie_transliteral;
                     51:    unsigned char       *tampon;
                     52: 
                     53:    if ((codage_sortie_transliteral = malloc((strlen(codage_sortie)
                     54:            + strlen("//TRANSLIT") + 1) * sizeof(unsigned char))) == NULL)
                     55:    {
                     56:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                     57:        return(NULL);
                     58:    }
                     59: 
                     60:    sprintf(codage_sortie_transliteral, "%s//TRANSLIT", codage_sortie);
                     61: 
                     62:    tampon = reencodage(s_etat_processus, chaine_entree,
                     63:            codage_entree, codage_sortie_transliteral);
                     64:    free(codage_sortie_transliteral);
                     65: 
                     66:    return(tampon);
                     67: }
                     68: 
                     69: 
                     70: unsigned char *
                     71: reencodage(struct_processus *s_etat_processus,
                     72:        unsigned char *chaine_entree,
                     73:        unsigned char *codage_entree,
                     74:        unsigned char *codage_sortie)
                     75: {
                     76: #  define              d_LONGUEUR  1024
                     77: 
                     78:    iconv_t             transcodage;
                     79: 
                     80:    size_t              ios;
                     81:    size_t              longueur_entree;
                     82:    size_t              longueur_sortie;
                     83: 
                     84:    unsigned char       *buffer_entree;
                     85:    unsigned char       *buffer_sortie;
                     86:    unsigned char       *chaine_sortie;
                     87:    unsigned char       *pointeur;
                     88:    unsigned char       *tampon;
                     89: 
                     90:    if ((transcodage = iconv_open(codage_sortie, codage_entree)) ==
                     91:            (iconv_t) -1)
                     92:    {
                     93:        (*s_etat_processus).erreur_execution = d_ex_erreur_transcodage;
                     94:        return(NULL);
                     95:    }
                     96: 
                     97:    buffer_entree = chaine_entree;
                     98:    longueur_entree = strlen(chaine_entree);
                     99: 
                    100:    if ((chaine_sortie = malloc(sizeof(unsigned char))) == NULL)
                    101:    {
                    102:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    103:        return(NULL);
                    104:    }
                    105: 
                    106:    chaine_sortie[0] = d_code_fin_chaine;
                    107: 
1.39      bertrand  108:    if ((buffer_sortie = malloc((d_LONGUEUR + 1) * sizeof(unsigned char)))
                    109:            == NULL)
1.1       bertrand  110:    {
                    111:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    112:        return(NULL);
                    113:    }
                    114: 
                    115:    do
                    116:    {
                    117:        longueur_sortie = d_LONGUEUR;
                    118:        pointeur = buffer_sortie;
                    119: 
                    120:        if ((ios = iconv(transcodage, (char **) &buffer_entree,
                    121:                &longueur_entree, (char **) &pointeur, &longueur_sortie))
                    122:                == (size_t) -1)
                    123:        {
                    124:            // On autorise les erreurs EINVAL et EILSEQ
                    125:            if (errno == EILSEQ)
                    126:            {
                    127:                free(buffer_sortie);
1.3       bertrand  128:                free(chaine_sortie);
                    129: 
1.1       bertrand  130:                (*s_etat_processus).erreur_execution = d_ex_erreur_transcodage;
                    131:                return(NULL);
                    132:            }
                    133:        }
                    134: 
1.38      bertrand  135:        tampon = chaine_sortie;
1.1       bertrand  136:        (*pointeur) = d_code_fin_chaine;
                    137: 
                    138:        if ((chaine_sortie = malloc((strlen(tampon) + strlen(buffer_sortie) + 1)
                    139:                * sizeof(unsigned char))) == NULL)
                    140:        {
                    141:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    142:            return(NULL);
                    143:        }
                    144: 
                    145:        sprintf(chaine_sortie, "%s%s", tampon, buffer_sortie);
                    146:        free(tampon);
                    147:    } while((*buffer_entree) != d_code_fin_chaine);
                    148: 
                    149:    free(buffer_sortie);
                    150:    iconv_close(transcodage);
                    151: 
                    152:    return(chaine_sortie);
                    153: }
                    154: 
                    155: 
                    156: /*
                    157: ================================================================================
                    158:   Fonctions spécifiques
                    159: ================================================================================
                    160:   Entrées :
                    161: --------------------------------------------------------------------------------
1.26      bertrand  162:   Sorties :
1.1       bertrand  163: --------------------------------------------------------------------------------
                    164:   Effets de bord : néant
                    165: ================================================================================
                    166: */
                    167: 
                    168: void
                    169: localisation_courante(struct_processus *s_etat_processus)
                    170: {
                    171:    char                        **arguments;
                    172: 
                    173:    int                         ios;
                    174:    int                         pipes_entree[2];
                    175:    int                         pipes_erreur[2];
                    176:    int                         pipes_sortie[2];
                    177:    int                         status;
                    178: 
                    179:    long                        i;
                    180:    long                        nombre_arguments;
                    181: 
                    182:    pid_t                       pid;
                    183: 
                    184:    sigset_t                    oldset;
                    185:    sigset_t                    set;
                    186: 
                    187:    struct sigaction            action_passee;
                    188: 
                    189:    unsigned char               *tampon;
                    190: 
                    191:    unsigned long               longueur_lecture;
                    192:    unsigned long               nombre_iterations;
                    193:    unsigned long               pointeur;
                    194: 
                    195:    if ((arguments = malloc(3 * sizeof(char **))) == NULL)
                    196:    {
                    197:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    198:        return;
                    199:    }
                    200: 
                    201:    if ((arguments[0] = malloc((strlen("locale") + 1) * sizeof(char))) == NULL)
                    202:    {
                    203:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    204:        return;
                    205:    }
                    206: 
                    207:    if ((arguments[1] = malloc((strlen("charmap") + 1) * sizeof(char))) == NULL)
                    208:    {
                    209:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    210:        return;
                    211:    }
                    212: 
                    213:    strcpy(arguments[0], "locale");
                    214:    strcpy(arguments[1], "charmap");
                    215:    arguments[2] = NULL;
                    216: 
                    217:    nombre_arguments = 2;
                    218: 
                    219:    if (pipe(pipes_entree) != 0)
                    220:    {
                    221:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    222:        return;
                    223:    }
                    224:        
                    225:    if (pipe(pipes_sortie) != 0)
                    226:    {
                    227:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    228:        return;
                    229:    }
                    230: 
                    231:    if (pipe(pipes_erreur) != 0)
                    232:    {
                    233:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    234:        return;
                    235:    }
                    236: 
                    237:    sigfillset(&set);
                    238:    pthread_sigmask(SIG_BLOCK, &set, &oldset);
                    239: 
                    240:    verrouillage_threads_concurrents(s_etat_processus);
                    241:    pid = fork();
                    242:    deverrouillage_threads_concurrents(s_etat_processus);
                    243: 
                    244:    pthread_sigmask(SIG_SETMASK, &oldset, NULL);
                    245:    sigpending(&set);
                    246: 
                    247:    if (pid < 0)
                    248:    {
                    249:        if (close(pipes_entree[0]) != 0)
                    250:        {
                    251:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    252:            return;
                    253:        }
                    254: 
                    255:        if (close(pipes_entree[1]) != 0)
                    256:        {
                    257:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    258:            return;
                    259:        }
                    260: 
                    261:        if (close(pipes_sortie[0]) != 0)
                    262:        {
                    263:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    264:            return;
                    265:        }
                    266: 
                    267:        if (close(pipes_sortie[1]) != 0)
                    268:        {
                    269:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    270:            return;
                    271:        }
                    272: 
                    273:        if (close(pipes_erreur[0]) != 0)
                    274:        {
                    275:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    276:            return;
                    277:        }
                    278: 
                    279:        if (close(pipes_erreur[1]) != 0)
                    280:        {
                    281:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    282:            return;
                    283:        }
                    284: 
                    285:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    286:        return;
                    287:    }
                    288:    else if (pid == 0)
                    289:    {
                    290:        if (close(pipes_entree[1]) != 0)
                    291:        {
                    292:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    293:            return;
                    294:        }
                    295: 
                    296:        if (close(pipes_sortie[0]) != 0)
                    297:        {
                    298:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    299:            return;
                    300:        }
                    301: 
                    302:        if (close(pipes_erreur[0]) != 0)
                    303:        {
                    304:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    305:            return;
                    306:        }
                    307: 
                    308:        if (pipes_entree[0] != STDIN_FILENO)
                    309:        {
                    310:            if (dup2(pipes_entree[0], STDIN_FILENO) == -1)
                    311:            {
                    312:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    313:                return;
                    314:            }
                    315:        }
                    316: 
                    317:        if (pipes_sortie[1] != STDOUT_FILENO)
                    318:        {
                    319:            if (dup2(pipes_sortie[1], STDOUT_FILENO) == -1)
                    320:            {
                    321:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    322:                return;
                    323:            }
                    324:        }
                    325: 
                    326:        if (pipes_sortie[1] != STDERR_FILENO)
                    327:        {
                    328:            if (dup2(pipes_sortie[1], STDERR_FILENO) == -1)
                    329:            {
                    330:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    331:                return;
                    332:            }
                    333:        }
                    334: 
                    335:        if (nombre_arguments != 0)
                    336:        {
                    337:            execvp(arguments[0], arguments);
                    338:        }
                    339:        else
                    340:        {
                    341:            exit(EXIT_SUCCESS);
                    342:        }
                    343: 
                    344:        /*
                    345:         * L'appel système execvp() a généré une erreur et n'a pu exécuter
                    346:         * argument[0] (fichier non exécutable ou inexistant).
                    347:         */
                    348: 
                    349:        close(pipes_entree[0]);
                    350:        close(pipes_sortie[1]);
                    351: 
                    352:        for(i = 0; i < nombre_arguments; i++)
                    353:        {
                    354:            free(arguments[i]);
                    355:        }
                    356: 
                    357:        free(arguments);
                    358:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    359: 
                    360:        /*
                    361:         * Envoi d'une erreur dans le pipe idoine. On ne regarde pas
                    362:         * le nombre d'octets écrits car l'erreur ne pourra de toute
                    363:         * façon pas être traitée.
                    364:         */
                    365: 
                    366:        write_atomic(s_etat_processus, pipes_erreur[1], " ", 1);
                    367:        close(pipes_erreur[1]);
                    368: 
                    369:        exit(EXIT_SUCCESS);
                    370:    }
                    371:    else
                    372:    {
                    373:        if (close(pipes_entree[0]) != 0)
                    374:        {
                    375:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    376:            return;
                    377:        }
                    378: 
                    379:        if (close(pipes_sortie[1]) != 0)
                    380:        {
                    381:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    382:            return;
                    383:        }
                    384: 
                    385:        if (close(pipes_erreur[1]) != 0)
                    386:        {
                    387:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    388:            return;
                    389:        }
                    390: 
                    391:        if (close(pipes_entree[1]) != 0)
                    392:        {
                    393:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    394:            return;
                    395:        }
                    396: 
                    397:        do
                    398:        {
                    399:            if (kill(pid, 0) != 0)
                    400:            {
                    401:                break;
                    402:            }
                    403: 
                    404:            /*
                    405:             * Récupération de la valeur de retour du processus détaché
                    406:             */
                    407: 
1.40    ! bertrand  408:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex_fork)) != 0)
1.1       bertrand  409:            {
                    410:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    411:                return;
                    412:            }
                    413: 
                    414:            if (waitpid(pid, &status, 0) == -1)
                    415:            {
1.40    ! bertrand  416:                if (pthread_mutex_lock(&((*s_etat_processus).mutex_fork)) != 0)
1.1       bertrand  417:                {
1.40    ! bertrand  418:                    (*s_etat_processus).erreur_systeme = d_es_processus;
        !           419:                    return;
1.1       bertrand  420:                }
                    421: 
                    422:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    423:                return;
                    424:            }
                    425: 
1.40    ! bertrand  426:            if (pthread_mutex_lock(&((*s_etat_processus).mutex_fork)) != 0)
1.1       bertrand  427:            {
1.40    ! bertrand  428:                (*s_etat_processus).erreur_systeme = d_es_processus;
        !           429:                return;
1.1       bertrand  430:            }
                    431:        } while((!WIFEXITED(status)) && (!WIFSIGNALED(status)));
                    432: 
                    433:        longueur_lecture = 256;
                    434:        pointeur = 0;
                    435:        nombre_iterations = 1;
                    436: 
                    437:        if ((tampon = malloc((longueur_lecture + 1) *
                    438:                sizeof(unsigned char))) == NULL)
                    439:        {
                    440:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    441:            return;
                    442:        }
                    443: 
1.18      bertrand  444:        tampon[0] = d_code_fin_chaine;
                    445: 
1.40    ! bertrand  446:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex_fork)) != 0)
1.1       bertrand  447:        {
                    448:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    449:            return;
                    450:        }
                    451: 
                    452:        while((ios = read_atomic(s_etat_processus,
                    453:                pipes_sortie[0], &(tampon[pointeur]),
                    454:                longueur_lecture)) > 0)
                    455:        {
1.40    ! bertrand  456:            if (pthread_mutex_lock(&((*s_etat_processus).mutex_fork)) != 0)
1.1       bertrand  457:            {
1.40    ! bertrand  458:                (*s_etat_processus).erreur_systeme = d_es_processus;
        !           459:                return;
1.1       bertrand  460:            }
                    461: 
                    462:            tampon[pointeur + ios] = d_code_fin_chaine;
                    463:            pointeur += longueur_lecture;
                    464:            nombre_iterations++;
                    465: 
                    466:            if ((tampon = realloc(tampon,
                    467:                    ((nombre_iterations * longueur_lecture) + 1) *
                    468:                    sizeof(unsigned char))) == NULL)
                    469:            {
                    470:                (*s_etat_processus).erreur_systeme =
                    471:                        d_es_allocation_memoire;
                    472:                return;
                    473:            }
                    474: 
1.40    ! bertrand  475:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex_fork)) != 0)
1.1       bertrand  476:            {
                    477:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    478:                return;
                    479:            }
                    480:        }
                    481: 
1.40    ! bertrand  482:        if (pthread_mutex_lock(&((*s_etat_processus).mutex_fork)) != 0)
1.1       bertrand  483:        {
1.40    ! bertrand  484:            (*s_etat_processus).erreur_systeme = d_es_processus;
        !           485:            return;
1.1       bertrand  486:        }
                    487: 
                    488:        if (strlen(tampon) == 0)
                    489:        {
                    490:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    491:            return;
                    492:        }
                    493: 
                    494:        tampon[strlen(tampon) - 1] = d_code_fin_chaine;
                    495: 
                    496:        if (ios == -1)
                    497:        {
                    498:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    499:            return;
                    500:        }
                    501: 
                    502:        if (close(pipes_sortie[0]) != 0)
                    503:        {
                    504:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    505:            return;
                    506:        }
                    507: 
1.17      bertrand  508:        if (strlen(tampon) > 0)
                    509:        {
                    510:            (*s_etat_processus).localisation = tampon;
                    511:        }
                    512:        else
                    513:        {
                    514:            free(tampon);
                    515: 
                    516:            if (((*s_etat_processus).localisation = malloc((strlen(d_locale)
                    517:                    + 1) * sizeof(unsigned char))) == NULL)
                    518:            {
                    519:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    520:                return;
                    521:            }
                    522: 
                    523:            strcpy((*s_etat_processus).localisation, d_locale);
                    524:        }
1.1       bertrand  525: 
                    526:        if (sigaction(SIGINT, &action_passee, NULL) != 0)
                    527:        {
                    528:            for(i = 0; i < nombre_arguments; i++)
                    529:            {
                    530:                free(arguments[i]);
                    531:            }
                    532: 
                    533:            free(arguments);
                    534:            (*s_etat_processus).erreur_systeme = d_es_signal;
                    535:            return;
                    536:        }
                    537: 
                    538:        for(i = 0; i < nombre_arguments; i++)
                    539:        {
                    540:            free(arguments[i]);
                    541:        }
                    542: 
                    543:        free(arguments);
                    544: 
1.40    ! bertrand  545:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex_fork)) != 0)
1.1       bertrand  546:        {
                    547:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    548:            return;
                    549:        }
                    550: 
                    551:        if (read_atomic(s_etat_processus, pipes_erreur[0], tampon, 1) > 0)
                    552:        {
                    553:            // Le processus fils renvoie une erreur.
                    554: 
1.18      bertrand  555:            free(tampon);
                    556: 
                    557:            if (((*s_etat_processus).localisation = malloc((strlen(d_locale)
                    558:                    + 1) * sizeof(unsigned char))) == NULL)
1.1       bertrand  559:            {
1.18      bertrand  560:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    561:                return;
1.1       bertrand  562:            }
                    563: 
1.18      bertrand  564:            strcpy((*s_etat_processus).localisation, d_locale);
1.1       bertrand  565:        }
                    566: 
1.40    ! bertrand  567:        if (pthread_mutex_lock(&((*s_etat_processus).mutex_fork)) != 0)
1.1       bertrand  568:        {
1.40    ! bertrand  569:            (*s_etat_processus).erreur_systeme = d_es_processus;
        !           570:            return;
1.1       bertrand  571:        }
                    572: 
                    573:        if (close(pipes_erreur[0]) != 0)
                    574:        {
                    575:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    576:            return;
                    577:        }
                    578:    }
                    579: 
                    580:    return;
                    581: }
                    582: 
                    583: 
                    584: int
                    585: transliterated_fprintf(struct_processus *s_etat_processus, file *flux,
                    586:        const char *format, ...)
                    587: {
                    588:    int             ios;
1.5       bertrand  589: 
                    590:    unsigned char   *tampon;
1.1       bertrand  591:    unsigned char   *tampon2;
1.5       bertrand  592: 
1.1       bertrand  593:    va_list         arguments;
                    594: 
                    595:    va_start(arguments, format);
                    596: 
1.17      bertrand  597: #  ifdef OS2
                    598:    unsigned char       *ptr_e;;
                    599:    unsigned char       *ptr_l;;
                    600:    unsigned char       *tampon3;
                    601: 
                    602:    unsigned long       i;
                    603: #  endif
                    604: 
1.5       bertrand  605:    if (valsprintf(&tampon, format, arguments) < 0)
1.1       bertrand  606:    {
                    607:        va_end(arguments);
                    608: 
                    609:        if (s_etat_processus != NULL)
                    610:        {
                    611:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    612:        }
                    613: 
                    614:        return(-1);
                    615:    }
                    616: 
                    617:    va_end(arguments);
                    618: 
                    619:    if (s_etat_processus != NULL)
                    620:    {
                    621:        if ((tampon2 = transliteration(s_etat_processus, tampon,
                    622:                d_locale, (*s_etat_processus).localisation)) == NULL)
                    623:        {
                    624:            free(tampon);
                    625:            return(-1);
                    626:        }
                    627: 
                    628:        free(tampon);
                    629:    }
                    630:    else
                    631:    {
                    632:        tampon2 = tampon;
                    633:    }
                    634: 
1.17      bertrand  635: #  ifdef OS2
1.23      bertrand  636:    if ((flux == stdin) || (flux == stdout))
                    637:    {
                    638:        i = 0;
                    639:        ptr_l = tampon2;
1.17      bertrand  640: 
1.23      bertrand  641:        while((*ptr_l) != d_code_fin_chaine)
1.17      bertrand  642:        {
1.23      bertrand  643:            if ((*ptr_l) == '\n')
                    644:            {
                    645:                i++;
                    646:            }
                    647: 
                    648:            ptr_l++;
1.17      bertrand  649:        }
                    650: 
1.23      bertrand  651:        if ((tampon3 = malloc((strlen(tampon2) + i + 1) *
                    652:                sizeof(unsigned char))) == NULL)
                    653:        {
                    654:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    655:            return(NULL);
                    656:        }
1.17      bertrand  657: 
1.23      bertrand  658:        ptr_e = tampon3;
                    659:        ptr_l = tampon2;
1.17      bertrand  660: 
1.23      bertrand  661:        while((*ptr_l) != d_code_fin_chaine)
                    662:        {
                    663:            (*ptr_e) = (*ptr_l);
1.17      bertrand  664: 
1.23      bertrand  665:            if ((*ptr_l) == '\n')
                    666:            {
                    667:                (*(++ptr_e)) = '\r';
                    668:                ptr_e++;
                    669:                ptr_l++;
                    670:            }
                    671:            else
                    672:            {
                    673:                ptr_e++;
                    674:                ptr_l++;
                    675:            }
1.17      bertrand  676:        }
                    677: 
1.23      bertrand  678:        (*ptr_e) = d_code_fin_chaine;
1.17      bertrand  679: 
1.23      bertrand  680:        free(tampon2);
                    681:        tampon2 = tampon3;
                    682:    }
1.17      bertrand  683: #  endif
                    684: 
1.1       bertrand  685: #  ifdef SunOS
                    686:    while((ios = fprintf(flux, "%s", tampon2)) < 0)
                    687:    {
                    688:        if ((errno != EINTR) && (errno != 0))
                    689:        {
                    690:            break;
                    691:        }
                    692:    }
                    693: #  else
                    694:    ios = fprintf(flux, "%s", tampon2);
                    695: #  endif
                    696: 
                    697:    free(tampon2);
                    698: 
                    699:    return(ios);
                    700: }
                    701: 
1.5       bertrand  702: 
                    703: int
                    704: tex_fprintf(struct_processus *s_etat_processus,
                    705:        file *flux, const char *format, ...)
                    706: {
                    707:    int             ios;
                    708: 
                    709:    unsigned char   *tampon;
                    710:    unsigned char   *tampon2;
                    711: 
                    712:    va_list         arguments;
                    713: 
                    714:    va_start(arguments, format);
                    715: 
                    716:    if (valsprintf(&tampon, format, arguments) < 0)
                    717:    {
                    718:        va_end(arguments);
                    719: 
                    720:        if (s_etat_processus != NULL)
                    721:        {
                    722:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    723:        }
                    724: 
                    725:        return(-1);
                    726:    }
                    727: 
                    728:    va_end(arguments);
                    729: 
                    730:    if ((tampon2 = transliteration(s_etat_processus, tampon,
                    731:            d_locale, ds_tex_encodage_3)) == NULL)
                    732:    {
                    733:        free(tampon);
                    734:        return(-1);
                    735:    }
                    736: 
                    737:    free(tampon);
                    738: 
                    739: #  ifdef SunOS
                    740:    while((ios = fprintf(flux, "%s", tampon2)) < 0)
                    741:    {
                    742:        if ((errno != EINTR) && (errno != 0))
                    743:        {
                    744:            break;
                    745:        }
                    746:    }
                    747: #  else
                    748:    ios = fprintf(flux, "%s", tampon2);
                    749: #  endif
                    750: 
                    751:    free(tampon2);
                    752: 
                    753:    return(ios);
                    754: }
                    755: 
1.21      bertrand  756: #undef readline
1.19      bertrand  757: 
                    758: unsigned char *
                    759: readline_wrapper(unsigned char *invite)
                    760: {
                    761:    unsigned char       *chaine;
                    762: 
                    763:    chaine = readline(invite);
                    764:    printf("\r");
                    765: 
                    766:    return(chaine);
                    767: }
                    768: 
                    769: 
1.1       bertrand  770: #define fprintf NULL
                    771: #define printf NULL
                    772: 
                    773: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>