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

1.1       bertrand    1: /*
                      2: ================================================================================
1.53      bertrand    3:   RPL/2 (R) version 4.1.9
1.48      bertrand    4:   Copyright (C) 1989-2012 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: 
1.54    ! bertrand  120:        if ((ios = iconv(transcodage, (const char **) &buffer_entree,
1.1       bertrand  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:    struct sigaction            action_passee;
                    185: 
                    186:    unsigned char               *tampon;
                    187: 
                    188:    unsigned long               longueur_lecture;
                    189:    unsigned long               nombre_iterations;
                    190:    unsigned long               pointeur;
                    191: 
                    192:    if ((arguments = malloc(3 * sizeof(char **))) == NULL)
                    193:    {
                    194:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    195:        return;
                    196:    }
                    197: 
                    198:    if ((arguments[0] = malloc((strlen("locale") + 1) * sizeof(char))) == NULL)
                    199:    {
                    200:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    201:        return;
                    202:    }
                    203: 
                    204:    if ((arguments[1] = malloc((strlen("charmap") + 1) * sizeof(char))) == NULL)
                    205:    {
                    206:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    207:        return;
                    208:    }
                    209: 
                    210:    strcpy(arguments[0], "locale");
                    211:    strcpy(arguments[1], "charmap");
                    212:    arguments[2] = NULL;
                    213: 
                    214:    nombre_arguments = 2;
                    215: 
                    216:    if (pipe(pipes_entree) != 0)
                    217:    {
                    218:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    219:        return;
                    220:    }
                    221:        
                    222:    if (pipe(pipes_sortie) != 0)
                    223:    {
                    224:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    225:        return;
                    226:    }
                    227: 
                    228:    if (pipe(pipes_erreur) != 0)
                    229:    {
                    230:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    231:        return;
                    232:    }
                    233: 
                    234:    verrouillage_threads_concurrents(s_etat_processus);
                    235:    pid = fork();
                    236:    deverrouillage_threads_concurrents(s_etat_processus);
                    237: 
                    238:    if (pid < 0)
                    239:    {
                    240:        if (close(pipes_entree[0]) != 0)
                    241:        {
                    242:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    243:            return;
                    244:        }
                    245: 
                    246:        if (close(pipes_entree[1]) != 0)
                    247:        {
                    248:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    249:            return;
                    250:        }
                    251: 
                    252:        if (close(pipes_sortie[0]) != 0)
                    253:        {
                    254:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    255:            return;
                    256:        }
                    257: 
                    258:        if (close(pipes_sortie[1]) != 0)
                    259:        {
                    260:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    261:            return;
                    262:        }
                    263: 
                    264:        if (close(pipes_erreur[0]) != 0)
                    265:        {
                    266:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    267:            return;
                    268:        }
                    269: 
                    270:        if (close(pipes_erreur[1]) != 0)
                    271:        {
                    272:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    273:            return;
                    274:        }
                    275: 
                    276:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    277:        return;
                    278:    }
                    279:    else if (pid == 0)
                    280:    {
                    281:        if (close(pipes_entree[1]) != 0)
                    282:        {
                    283:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    284:            return;
                    285:        }
                    286: 
                    287:        if (close(pipes_sortie[0]) != 0)
                    288:        {
                    289:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    290:            return;
                    291:        }
                    292: 
                    293:        if (close(pipes_erreur[0]) != 0)
                    294:        {
                    295:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    296:            return;
                    297:        }
                    298: 
                    299:        if (pipes_entree[0] != STDIN_FILENO)
                    300:        {
                    301:            if (dup2(pipes_entree[0], STDIN_FILENO) == -1)
                    302:            {
                    303:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    304:                return;
                    305:            }
                    306:        }
                    307: 
                    308:        if (pipes_sortie[1] != STDOUT_FILENO)
                    309:        {
                    310:            if (dup2(pipes_sortie[1], STDOUT_FILENO) == -1)
                    311:            {
                    312:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    313:                return;
                    314:            }
                    315:        }
                    316: 
                    317:        if (pipes_sortie[1] != STDERR_FILENO)
                    318:        {
                    319:            if (dup2(pipes_sortie[1], STDERR_FILENO) == -1)
                    320:            {
                    321:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    322:                return;
                    323:            }
                    324:        }
                    325: 
                    326:        if (nombre_arguments != 0)
                    327:        {
                    328:            execvp(arguments[0], arguments);
                    329:        }
                    330:        else
                    331:        {
                    332:            exit(EXIT_SUCCESS);
                    333:        }
                    334: 
                    335:        /*
                    336:         * L'appel système execvp() a généré une erreur et n'a pu exécuter
                    337:         * argument[0] (fichier non exécutable ou inexistant).
                    338:         */
                    339: 
                    340:        close(pipes_entree[0]);
                    341:        close(pipes_sortie[1]);
                    342: 
                    343:        for(i = 0; i < nombre_arguments; i++)
                    344:        {
                    345:            free(arguments[i]);
                    346:        }
                    347: 
                    348:        free(arguments);
                    349:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    350: 
                    351:        /*
                    352:         * Envoi d'une erreur dans le pipe idoine. On ne regarde pas
                    353:         * le nombre d'octets écrits car l'erreur ne pourra de toute
                    354:         * façon pas être traitée.
                    355:         */
                    356: 
                    357:        write_atomic(s_etat_processus, pipes_erreur[1], " ", 1);
                    358:        close(pipes_erreur[1]);
                    359: 
                    360:        exit(EXIT_SUCCESS);
                    361:    }
                    362:    else
                    363:    {
                    364:        if (close(pipes_entree[0]) != 0)
                    365:        {
                    366:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    367:            return;
                    368:        }
                    369: 
                    370:        if (close(pipes_sortie[1]) != 0)
                    371:        {
                    372:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    373:            return;
                    374:        }
                    375: 
                    376:        if (close(pipes_erreur[1]) != 0)
                    377:        {
                    378:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    379:            return;
                    380:        }
                    381: 
                    382:        if (close(pipes_entree[1]) != 0)
                    383:        {
                    384:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    385:            return;
                    386:        }
                    387: 
                    388:        do
                    389:        {
                    390:            if (kill(pid, 0) != 0)
                    391:            {
                    392:                break;
                    393:            }
                    394: 
                    395:            /*
                    396:             * Récupération de la valeur de retour du processus détaché
                    397:             */
                    398: 
1.44      bertrand  399: #          ifndef SEMAPHORES_NOMMES
                    400:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    401: #          else
                    402:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    403: #          endif
1.1       bertrand  404:            {
                    405:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    406:                return;
                    407:            }
                    408: 
                    409:            if (waitpid(pid, &status, 0) == -1)
                    410:            {
1.44      bertrand  411: #              ifndef SEMAPHORES_NOMMES
                    412:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    413: #              else
                    414:                    while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    415: #              endif
1.1       bertrand  416:                {
1.43      bertrand  417:                    if (errno != EINTR)
                    418:                    {
                    419:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                    420:                        return;
                    421:                    }
1.1       bertrand  422:                }
                    423: 
                    424:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    425:                return;
                    426:            }
                    427: 
1.44      bertrand  428: #          ifndef SEMAPHORES_NOMMES
                    429:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    430: #          else
                    431:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    432: #          endif
1.1       bertrand  433:            {
1.43      bertrand  434:                if (errno != EINTR)
                    435:                {
                    436:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    437:                    return;
                    438:                }
1.1       bertrand  439:            }
                    440:        } while((!WIFEXITED(status)) && (!WIFSIGNALED(status)));
                    441: 
                    442:        longueur_lecture = 256;
                    443:        pointeur = 0;
                    444:        nombre_iterations = 1;
                    445: 
                    446:        if ((tampon = malloc((longueur_lecture + 1) *
                    447:                sizeof(unsigned char))) == NULL)
                    448:        {
                    449:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    450:            return;
                    451:        }
                    452: 
1.18      bertrand  453:        tampon[0] = d_code_fin_chaine;
                    454: 
1.44      bertrand  455: #      ifndef SEMAPHORES_NOMMES
                    456:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    457: #      else
                    458:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    459: #      endif
1.1       bertrand  460:        {
                    461:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    462:            return;
                    463:        }
                    464: 
                    465:        while((ios = read_atomic(s_etat_processus,
                    466:                pipes_sortie[0], &(tampon[pointeur]),
                    467:                longueur_lecture)) > 0)
                    468:        {
1.44      bertrand  469: #          ifndef SEMAPHORES_NOMMES
                    470:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    471: #          else
                    472:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    473: #          endif
1.1       bertrand  474:            {
1.43      bertrand  475:                if (errno != EINTR)
                    476:                {
                    477:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    478:                    return;
                    479:                }
1.1       bertrand  480:            }
                    481: 
                    482:            tampon[pointeur + ios] = d_code_fin_chaine;
                    483:            pointeur += longueur_lecture;
                    484:            nombre_iterations++;
                    485: 
                    486:            if ((tampon = realloc(tampon,
                    487:                    ((nombre_iterations * longueur_lecture) + 1) *
                    488:                    sizeof(unsigned char))) == NULL)
                    489:            {
                    490:                (*s_etat_processus).erreur_systeme =
                    491:                        d_es_allocation_memoire;
                    492:                return;
                    493:            }
                    494: 
1.44      bertrand  495: #          ifndef SEMAPHORES_NOMMES
                    496:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    497: #          else
                    498:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    499: #          endif
1.1       bertrand  500:            {
                    501:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    502:                return;
                    503:            }
                    504:        }
                    505: 
1.44      bertrand  506: #      ifndef SEMAPHORES_NOMMES
                    507:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    508: #      else
                    509:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    510: #      endif
1.1       bertrand  511:        {
1.43      bertrand  512:            if (errno != EINTR)
                    513:            {
                    514:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    515:                return;
                    516:            }
1.1       bertrand  517:        }
                    518: 
                    519:        if (strlen(tampon) == 0)
                    520:        {
                    521:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    522:            return;
                    523:        }
                    524: 
                    525:        tampon[strlen(tampon) - 1] = d_code_fin_chaine;
                    526: 
                    527:        if (ios == -1)
                    528:        {
                    529:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    530:            return;
                    531:        }
                    532: 
                    533:        if (close(pipes_sortie[0]) != 0)
                    534:        {
                    535:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    536:            return;
                    537:        }
                    538: 
1.17      bertrand  539:        if (strlen(tampon) > 0)
                    540:        {
                    541:            (*s_etat_processus).localisation = tampon;
                    542:        }
                    543:        else
                    544:        {
                    545:            free(tampon);
                    546: 
                    547:            if (((*s_etat_processus).localisation = malloc((strlen(d_locale)
                    548:                    + 1) * sizeof(unsigned char))) == NULL)
                    549:            {
                    550:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    551:                return;
                    552:            }
                    553: 
                    554:            strcpy((*s_etat_processus).localisation, d_locale);
                    555:        }
1.1       bertrand  556: 
                    557:        if (sigaction(SIGINT, &action_passee, NULL) != 0)
                    558:        {
                    559:            for(i = 0; i < nombre_arguments; i++)
                    560:            {
                    561:                free(arguments[i]);
                    562:            }
                    563: 
                    564:            free(arguments);
                    565:            (*s_etat_processus).erreur_systeme = d_es_signal;
                    566:            return;
                    567:        }
                    568: 
                    569:        for(i = 0; i < nombre_arguments; i++)
                    570:        {
                    571:            free(arguments[i]);
                    572:        }
                    573: 
                    574:        free(arguments);
                    575: 
1.44      bertrand  576: #      ifndef SEMAPHORES_NOMMES
                    577:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    578: #      else
                    579:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    580: #      endif
1.1       bertrand  581:        {
                    582:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    583:            return;
                    584:        }
                    585: 
                    586:        if (read_atomic(s_etat_processus, pipes_erreur[0], tampon, 1) > 0)
                    587:        {
                    588:            // Le processus fils renvoie une erreur.
                    589: 
1.18      bertrand  590:            free(tampon);
                    591: 
                    592:            if (((*s_etat_processus).localisation = malloc((strlen(d_locale)
                    593:                    + 1) * sizeof(unsigned char))) == NULL)
1.1       bertrand  594:            {
1.18      bertrand  595:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    596:                return;
1.1       bertrand  597:            }
                    598: 
1.18      bertrand  599:            strcpy((*s_etat_processus).localisation, d_locale);
1.1       bertrand  600:        }
                    601: 
1.44      bertrand  602: #      ifndef SEMAPHORES_NOMMES
                    603:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    604: #      else
                    605:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    606: #      endif
1.1       bertrand  607:        {
1.43      bertrand  608:            if (errno != EINTR)
                    609:            {
                    610:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    611:                return;
                    612:            }
1.1       bertrand  613:        }
                    614: 
                    615:        if (close(pipes_erreur[0]) != 0)
                    616:        {
                    617:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    618:            return;
                    619:        }
                    620:    }
                    621: 
                    622:    return;
                    623: }
                    624: 
                    625: 
                    626: int
                    627: transliterated_fprintf(struct_processus *s_etat_processus, file *flux,
                    628:        const char *format, ...)
                    629: {
                    630:    int             ios;
1.5       bertrand  631: 
                    632:    unsigned char   *tampon;
1.1       bertrand  633:    unsigned char   *tampon2;
1.5       bertrand  634: 
1.1       bertrand  635:    va_list         arguments;
                    636: 
                    637:    va_start(arguments, format);
                    638: 
1.17      bertrand  639: #  ifdef OS2
                    640:    unsigned char       *ptr_e;;
                    641:    unsigned char       *ptr_l;;
                    642:    unsigned char       *tampon3;
                    643: 
                    644:    unsigned long       i;
                    645: #  endif
                    646: 
1.5       bertrand  647:    if (valsprintf(&tampon, format, arguments) < 0)
1.1       bertrand  648:    {
                    649:        va_end(arguments);
                    650: 
                    651:        if (s_etat_processus != NULL)
                    652:        {
                    653:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    654:        }
                    655: 
                    656:        return(-1);
                    657:    }
                    658: 
                    659:    va_end(arguments);
                    660: 
                    661:    if (s_etat_processus != NULL)
                    662:    {
                    663:        if ((tampon2 = transliteration(s_etat_processus, tampon,
                    664:                d_locale, (*s_etat_processus).localisation)) == NULL)
                    665:        {
                    666:            free(tampon);
                    667:            return(-1);
                    668:        }
                    669: 
                    670:        free(tampon);
                    671:    }
                    672:    else
                    673:    {
                    674:        tampon2 = tampon;
                    675:    }
                    676: 
1.17      bertrand  677: #  ifdef OS2
1.46      bertrand  678:    if ((flux == stderr) || (flux == stdout))
1.23      bertrand  679:    {
                    680:        i = 0;
                    681:        ptr_l = tampon2;
1.17      bertrand  682: 
1.23      bertrand  683:        while((*ptr_l) != d_code_fin_chaine)
1.17      bertrand  684:        {
1.23      bertrand  685:            if ((*ptr_l) == '\n')
                    686:            {
                    687:                i++;
                    688:            }
                    689: 
                    690:            ptr_l++;
1.17      bertrand  691:        }
                    692: 
1.23      bertrand  693:        if ((tampon3 = malloc((strlen(tampon2) + i + 1) *
                    694:                sizeof(unsigned char))) == NULL)
                    695:        {
                    696:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1.46      bertrand  697:            return(-1);
1.23      bertrand  698:        }
1.17      bertrand  699: 
1.23      bertrand  700:        ptr_e = tampon3;
                    701:        ptr_l = tampon2;
1.17      bertrand  702: 
1.23      bertrand  703:        while((*ptr_l) != d_code_fin_chaine)
                    704:        {
                    705:            (*ptr_e) = (*ptr_l);
1.17      bertrand  706: 
1.23      bertrand  707:            if ((*ptr_l) == '\n')
                    708:            {
                    709:                (*(++ptr_e)) = '\r';
                    710:                ptr_e++;
                    711:                ptr_l++;
                    712:            }
                    713:            else
                    714:            {
                    715:                ptr_e++;
                    716:                ptr_l++;
                    717:            }
1.17      bertrand  718:        }
                    719: 
1.23      bertrand  720:        (*ptr_e) = d_code_fin_chaine;
1.17      bertrand  721: 
1.23      bertrand  722:        free(tampon2);
                    723:        tampon2 = tampon3;
                    724:    }
1.17      bertrand  725: #  endif
                    726: 
1.1       bertrand  727: #  ifdef SunOS
                    728:    while((ios = fprintf(flux, "%s", tampon2)) < 0)
                    729:    {
                    730:        if ((errno != EINTR) && (errno != 0))
                    731:        {
                    732:            break;
                    733:        }
                    734:    }
                    735: #  else
                    736:    ios = fprintf(flux, "%s", tampon2);
                    737: #  endif
                    738: 
                    739:    free(tampon2);
                    740: 
                    741:    return(ios);
                    742: }
                    743: 
1.5       bertrand  744: 
                    745: int
                    746: tex_fprintf(struct_processus *s_etat_processus,
                    747:        file *flux, const char *format, ...)
                    748: {
                    749:    int             ios;
                    750: 
                    751:    unsigned char   *tampon;
                    752:    unsigned char   *tampon2;
                    753: 
                    754:    va_list         arguments;
                    755: 
                    756:    va_start(arguments, format);
                    757: 
                    758:    if (valsprintf(&tampon, format, arguments) < 0)
                    759:    {
                    760:        va_end(arguments);
                    761: 
                    762:        if (s_etat_processus != NULL)
                    763:        {
                    764:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    765:        }
                    766: 
                    767:        return(-1);
                    768:    }
                    769: 
                    770:    va_end(arguments);
                    771: 
                    772:    if ((tampon2 = transliteration(s_etat_processus, tampon,
                    773:            d_locale, ds_tex_encodage_3)) == NULL)
                    774:    {
                    775:        free(tampon);
                    776:        return(-1);
                    777:    }
                    778: 
                    779:    free(tampon);
                    780: 
                    781: #  ifdef SunOS
                    782:    while((ios = fprintf(flux, "%s", tampon2)) < 0)
                    783:    {
                    784:        if ((errno != EINTR) && (errno != 0))
                    785:        {
                    786:            break;
                    787:        }
                    788:    }
                    789: #  else
                    790:    ios = fprintf(flux, "%s", tampon2);
                    791: #  endif
                    792: 
                    793:    free(tampon2);
                    794: 
                    795:    return(ios);
                    796: }
                    797: 
1.21      bertrand  798: #undef readline
1.19      bertrand  799: 
                    800: unsigned char *
                    801: readline_wrapper(unsigned char *invite)
                    802: {
                    803:    unsigned char       *chaine;
                    804: 
                    805:    chaine = readline(invite);
                    806:    printf("\r");
                    807: 
                    808:    return(chaine);
                    809: }
                    810: 
                    811: 
1.1       bertrand  812: #define fprintf NULL
                    813: #define printf NULL
                    814: 
                    815: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>