Annotation of rpl/src/instructions_w1.c, revision 1.75

1.1       bertrand    1: /*
                      2: ================================================================================
1.72      bertrand    3:   RPL/2 (R) version 4.1.13
1.71      bertrand    4:   Copyright (C) 1989-2013 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.20      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Fonction 'while'
                     29: ================================================================================
                     30:   Entrées :
                     31: --------------------------------------------------------------------------------
                     32:   Sorties :
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: void
                     39: instruction_while(struct_processus *s_etat_processus)
                     40: {
                     41:    (*s_etat_processus).erreur_execution = d_ex;
                     42: 
                     43:    if ((*s_etat_processus).affichage_arguments == 'Y')
                     44:    {
                     45:        printf("\n  WHILE ");
                     46: 
                     47:        if ((*s_etat_processus).langue == 'F')
                     48:        {
                     49:            printf("(structure de contrôle)\n\n");
                     50:            printf("  Utilisation :\n\n");
                     51:        }
                     52:        else
                     53:        {
                     54:            printf("(control statement)\n\n");
                     55:            printf("  Usage:\n\n");
                     56:        }
                     57: 
                     58:        printf("    WHILE\n");
                     59:        printf("        (clause)\n");
                     60:        printf("    REPEAT\n");
                     61:        printf("        (expression 1)\n");
                     62:        printf("        EXIT\n");
                     63:        printf("        (expression 2)\n");
                     64:        printf("    END\n\n");
                     65: 
                     66:        printf("    WHILE\n");
                     67:        printf("        (clause)\n");
                     68:        printf("    REPEAT\n");
                     69:        printf("        (expression)\n");
                     70:        printf("    END\n");
                     71: 
                     72:        return;
                     73:    }
                     74:    else if ((*s_etat_processus).test_instruction == 'Y')
                     75:    {
                     76:        (*s_etat_processus).nombre_arguments = -1;
                     77:        return;
                     78:    }
                     79: 
                     80:    empilement_pile_systeme(s_etat_processus);
                     81: 
                     82:    if ((*s_etat_processus).erreur_systeme != d_es)
                     83:    {
                     84:        return;
                     85:    }
                     86: 
                     87:    (*(*s_etat_processus).l_base_pile_systeme).type_cloture = 'W';
                     88:    (*(*s_etat_processus).l_base_pile_systeme).clause = 'W';
                     89: 
                     90:    if ((*s_etat_processus).mode_execution_programme == 'Y')
                     91:    {
                     92:        (*(*s_etat_processus).l_base_pile_systeme).adresse_retour =
                     93:                (*s_etat_processus).position_courante;
                     94:    }
                     95:    else
                     96:    {
                     97:        if ((*s_etat_processus).expression_courante == NULL)
                     98:        {
                     99:            (*s_etat_processus).erreur_execution =
                    100:                    d_ex_erreur_traitement_boucle;
                    101:            return;
                    102:        }
                    103: 
                    104:        (*(*s_etat_processus).l_base_pile_systeme).pointeur_objet_retour =
                    105:                (*s_etat_processus).expression_courante;
                    106:    }
                    107: 
                    108:    return;
                    109: }
                    110: 
                    111: 
                    112: /*
                    113: ================================================================================
                    114:   Fonction 'warranty'
                    115: ================================================================================
                    116:   Entrées :
                    117: --------------------------------------------------------------------------------
                    118:   Sorties :
                    119: --------------------------------------------------------------------------------
                    120:   Effets de bord : néant
                    121: ================================================================================
                    122: */
                    123: 
                    124: void
                    125: instruction_warranty(struct_processus *s_etat_processus)
                    126: {
1.20      bertrand  127: #  include                 "garanties-conv.h"
1.1       bertrand  128: 
                    129:    (*s_etat_processus).erreur_execution = d_ex;
                    130: 
                    131:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    132:    {
                    133:        printf("\n  WARRANTY ");
                    134: 
                    135:        if ((*s_etat_processus).langue == 'F')
                    136:        {
                    137:            printf("(garantie)\n\n");
                    138:            printf("  Aucun argument\n");
                    139:        }
                    140:        else
                    141:        {
                    142:            printf("(warranty)\n\n");
                    143:            printf("  No argument\n");
                    144:        }
                    145: 
                    146:        return;
                    147:    }
                    148:    else if ((*s_etat_processus).test_instruction == 'Y')
                    149:    {
                    150:        (*s_etat_processus).nombre_arguments = -1;
                    151:        return;
                    152:    }
                    153: 
                    154:    printf("%s\n", warranty);
                    155: 
                    156:    if ((*s_etat_processus).hauteur_pile_operationnelle == 0)
                    157:    {
                    158:        printf("\n");
                    159:    }
                    160: 
                    161:    return;
                    162: }
                    163: 
                    164: 
                    165: /*
                    166: ================================================================================
                    167:   Fonction 'wait'
                    168: ================================================================================
                    169:   Entrées :
                    170: --------------------------------------------------------------------------------
                    171:   Sorties :
                    172: --------------------------------------------------------------------------------
                    173:   Effets de bord : néant
                    174: ================================================================================
                    175: */
                    176: 
                    177: void
                    178: instruction_wait(struct_processus *s_etat_processus)
                    179: {
                    180:    int                         code_retour;
                    181:    int                         erreur;
                    182: 
                    183:    real8                       attente;
                    184: 
                    185:    struct_objet                *s_objet;
                    186: 
                    187:    struct timespec             temporisation;
                    188: 
                    189:    (*s_etat_processus).erreur_execution = d_ex;
                    190: 
                    191:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    192:    {
                    193:        printf("\n  WAIT ");
                    194: 
                    195:        if ((*s_etat_processus).langue == 'F')
                    196:        {
                    197:            printf("(attente exprimée en secondes)\n\n");
                    198:        }
                    199:        else
                    200:        {
                    201:            printf("(wait a number of seconds)\n\n");
                    202:        }
                    203: 
                    204:        printf("    1: %s, %s\n", d_INT, d_REL);
                    205: 
                    206:        return;
                    207:    }
                    208:    else if ((*s_etat_processus).test_instruction == 'Y')
                    209:    {
                    210:        (*s_etat_processus).nombre_arguments = -1;
                    211:        return;
                    212:    }
                    213: 
                    214:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    215:    {
                    216:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    217:        {
                    218:            return;
                    219:        }
                    220:    }
                    221: 
                    222:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    223:            &s_objet) == d_erreur)
                    224:    {
                    225:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    226:        return;
                    227:    }
                    228:    
1.30      bertrand  229:    if (((*s_objet).type == INT) || ((*s_objet).type == REL))
1.1       bertrand  230:    {
                    231:        if ((*s_objet).type == INT)
                    232:        {
                    233:            attente = (real8) (*((integer8 *) (*s_objet).objet));
                    234:        }
                    235:        else
                    236:        {
                    237:            attente = (*((real8 *) (*s_objet).objet));
                    238:        }
                    239: 
                    240:        if (attente < 0)
                    241:        {
                    242:            liberation(s_etat_processus, s_objet);
                    243: 
                    244:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    245:            return;
                    246:        }
                    247: 
                    248:        temporisation.tv_sec = (long) floor((double) attente);
                    249:        temporisation.tv_nsec = (attente - temporisation.tv_sec) *
                    250:                (long) 1000000000;
                    251: 
                    252:        if ((*s_etat_processus).profilage == d_vrai)
                    253:        {
                    254:            profilage(s_etat_processus, "Sleep function (WAIT)");
                    255: 
                    256:            if ((*s_etat_processus).erreur_systeme != d_es)
                    257:            {
                    258:                return;
                    259:            }
                    260:        }
                    261: 
                    262:        do
                    263:        {
1.51      bertrand  264: #          ifndef SEMAPHORES_NOMMES
                    265:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    266: #          else
                    267:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    268: #          endif
1.1       bertrand  269:            {
                    270:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    271:                return;
                    272:            }
                    273: 
                    274:            code_retour = nanosleep(&temporisation, &temporisation);
                    275:            erreur = errno;
                    276: 
1.51      bertrand  277: #          ifndef SEMAPHORES_NOMMES
                    278:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    279: #          else
                    280:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    281: #          endif
1.1       bertrand  282:            {
1.50      bertrand  283:                if (errno != EINTR)
                    284:                {
                    285:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    286:                    return;
                    287:                }
1.1       bertrand  288:            }
1.28      bertrand  289: 
                    290:            scrutation_injection(s_etat_processus);
                    291: 
                    292:            if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                    293:            {
                    294:                affectation_interruptions_logicielles(s_etat_processus);
                    295:            }
                    296: 
                    297:            if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                    298:            {
                    299:                traitement_interruptions_logicielles(s_etat_processus);
                    300:            }
1.1       bertrand  301:        } while(((code_retour == -1) && (erreur == EINTR))
                    302:                && ((*s_etat_processus).var_volatile_requete_arret == 0));
                    303: 
                    304:        if ((*s_etat_processus).profilage == d_vrai)
                    305:        {
                    306:            profilage(s_etat_processus, NULL);
                    307:        }
                    308:    }
                    309:    else
                    310:    {
                    311:        liberation(s_etat_processus, s_objet);
                    312: 
                    313:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    314:        return;
                    315:    }
                    316: 
                    317:    liberation(s_etat_processus, s_objet);
                    318: 
                    319:    return;
                    320: }
                    321: 
                    322: 
                    323: /*
                    324: ================================================================================
                    325:   Fonction 'wireframe' (passe en mode d'affichage échantillonné)
                    326: ================================================================================
                    327:   Entrées : structure processus
                    328: --------------------------------------------------------------------------------
                    329:   Sorties :
                    330: --------------------------------------------------------------------------------
                    331:   Effets de bord : néant
                    332: ================================================================================
                    333: */
                    334: 
                    335: void
                    336: instruction_wireframe(struct_processus *s_etat_processus)
                    337: {
                    338:    (*s_etat_processus).erreur_execution = d_ex;
                    339: 
                    340:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    341:    {
                    342:        printf("\n  WIREFRAME ");
                    343: 
                    344:        if ((*s_etat_processus).langue == 'F')
                    345:        {
                    346:            printf("(graphique tridimensionnel grillagé)\n\n");
                    347:            printf("  Aucun argument\n");
                    348:        }
                    349:        else
                    350:        {
                    351:            printf("(wireframe 3D graph)\n\n");
                    352:            printf("  No argument\n");
                    353:        }
                    354: 
                    355:        return;
                    356:    }
                    357:    else if ((*s_etat_processus).test_instruction == 'Y')
                    358:    {
                    359:        (*s_etat_processus).nombre_arguments = -1;
                    360:        return;
                    361:    }
                    362: 
                    363:    strcpy((*s_etat_processus).type_trace_eq, "GRILLE 3D");
                    364: 
                    365:    return;
                    366: }
                    367: 
                    368: 
                    369: /*
                    370: ================================================================================
                    371:   Fonction 'write'
                    372: ================================================================================
                    373:   Entrées : structure processus
                    374: --------------------------------------------------------------------------------
                    375:   Sorties :
                    376: --------------------------------------------------------------------------------
                    377:   Effets de bord : néant
                    378: ================================================================================
                    379: */
                    380: 
                    381: void
                    382: instruction_write(struct_processus *s_etat_processus)
                    383: {
1.6       bertrand  384:    const char                          *queue;
                    385: 
1.1       bertrand  386:    int                                 adresse[16];
                    387:    int                                 port;
1.70      bertrand  388:    int                                 sqlite_status;
1.1       bertrand  389: 
1.8       bertrand  390:    integer8                            clef;
                    391:    integer8                            compteur;
                    392:    integer8                            id;
                    393:    integer8                            ordre;
                    394: 
1.64      bertrand  395:    logical1                            format_degenere;
1.8       bertrand  396:    logical1                            mise_a_jour;
                    397: 
1.64      bertrand  398:    long                                longueur;
1.1       bertrand  399:    long                                longueur_effective;
                    400:    long                                recursivite;
                    401: 
1.6       bertrand  402:    sqlite3_stmt                        *ppStmt;
                    403: 
1.1       bertrand  404:    ssize_t                             ios;
                    405: 
1.5       bertrand  406:    struct_descripteur_fichier          *descripteur;
                    407: 
1.8       bertrand  408:    struct_liste_chainee                *l_element_courant;
                    409:    struct_liste_chainee                *l_element_courant_format;
                    410: 
                    411:    struct_objet                        *s_format;
                    412:    struct_objet                        *s_element;
1.6       bertrand  413:    struct_objet                        *s_objet_argument_1;
1.1       bertrand  414:    struct_objet                        *s_objet_argument_2;
1.6       bertrand  415:    struct_objet                        *s_objet_argument_3;
1.1       bertrand  416: 
                    417:    struct sigaction                    action;
                    418:    struct sigaction                    registre;
                    419: 
                    420:    struct sockaddr_in                  adresse_ipv4;
1.20      bertrand  421: #  ifdef IPV6
1.1       bertrand  422:    struct sockaddr_in6                 adresse_ipv6;
1.20      bertrand  423: #  endif
1.1       bertrand  424:    struct sockaddr_un                  adresse_unix;
                    425: 
                    426:    struct flock                        lock;
                    427: 
1.70      bertrand  428:    struct timespec                     attente;
                    429: 
1.1       bertrand  430:    uint32_t                            calcul_adresse;
                    431: 
                    432:    unsigned char                       *chaine;
1.5       bertrand  433:    unsigned char                       *chaine_utf8;
1.8       bertrand  434:    unsigned char                       *clef_utf8;
1.6       bertrand  435:    unsigned char                       *commande;
1.64      bertrand  436:    unsigned char                       *format_chaine;
1.1       bertrand  437: 
                    438:    unsigned long                       i;
                    439: 
                    440:    (*s_etat_processus).erreur_execution = d_ex;
                    441: 
                    442:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    443:    {
                    444:        printf("\n  WRITE ");
                    445: 
                    446:        if ((*s_etat_processus).langue == 'F')
                    447:        {
                    448:            printf("(écriture d'un enregistrement d'un fichier)\n\n");
                    449:        }
                    450:        else
                    451:        {
                    452:            printf("(write a record of a file)\n\n");
                    453:        }
                    454: 
                    455:        printf("    2: %s\n", d_LST);
1.6       bertrand  456:        printf("    1: %s, %s\n\n", d_FCH, d_SCK);
1.1       bertrand  457: 
1.6       bertrand  458:        printf("    3: %s\n", d_LST);
1.8       bertrand  459:        printf("    2: %s\n", d_INT);
1.6       bertrand  460:        printf("    1: %s\n", d_FCH);
1.1       bertrand  461:        return;
                    462:    }
                    463:    else if ((*s_etat_processus).test_instruction == 'Y')
                    464:    {
                    465:        (*s_etat_processus).nombre_arguments = -1;
                    466:        return;
                    467:    }
                    468: 
                    469:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    470:    {
1.6       bertrand  471:        if ((*s_etat_processus).l_base_pile == NULL)
1.1       bertrand  472:        {
1.6       bertrand  473:            (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1.1       bertrand  474:            return;
                    475:        }
1.6       bertrand  476: 
                    477:        if ((*(*(*s_etat_processus).l_base_pile).donnee).type == FCH)
                    478:        {
                    479:            if ((*((struct_fichier *) (*(*(*s_etat_processus).l_base_pile)
1.9       bertrand  480:                    .donnee).objet)).acces == 'D')
1.6       bertrand  481:            {
1.9       bertrand  482:                if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
1.6       bertrand  483:                {
                    484:                    return;
                    485:                }
                    486:            }
                    487:            else
                    488:            {
1.9       bertrand  489:                if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
1.6       bertrand  490:                {
                    491:                    return;
                    492:                }
                    493:            }
                    494:        }
                    495:        else
                    496:        {
                    497:            if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    498:            {
                    499:                return;
                    500:            }
                    501:        }
1.1       bertrand  502:    }
                    503: 
                    504:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    505:            &s_objet_argument_1) == d_erreur)
                    506:    {
                    507:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    508:        return;
                    509:    }
                    510:    
                    511:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    512:            &s_objet_argument_2) == d_erreur)
                    513:    {
                    514:        liberation(s_etat_processus, s_objet_argument_1);
                    515: 
                    516:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    517:        return;
                    518:    }
                    519:    
1.6       bertrand  520:    if ((*s_objet_argument_1).type == FCH)
1.1       bertrand  521:    {
1.5       bertrand  522:        if ((descripteur = descripteur_fichier(s_etat_processus,
                    523:                (struct_fichier *) (*s_objet_argument_1).objet)) == NULL)
                    524:        {
                    525:            return;
                    526:        }
                    527: 
1.1       bertrand  528:        /*
                    529:         * Vérification des verrous
                    530:         */
                    531: 
                    532:        lock.l_type = F_WRLCK;
                    533:        lock.l_whence = SEEK_SET;
                    534:        lock.l_start = 0;
                    535:        lock.l_len = 0;
                    536:        lock.l_pid = getpid();
                    537:        recursivite = 0;
                    538: 
1.5       bertrand  539:        if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
                    540:                == -1)
1.1       bertrand  541:        {
                    542:            liberation(s_etat_processus, s_objet_argument_2);
                    543:            liberation(s_etat_processus, s_objet_argument_1);
                    544: 
                    545:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    546:            return;
                    547:        }
                    548: 
                    549:        if (lock.l_type != F_UNLCK)
                    550:        {
                    551:            liberation(s_etat_processus, s_objet_argument_2);
                    552:            liberation(s_etat_processus, s_objet_argument_1);
                    553: 
                    554:            (*s_etat_processus).erreur_execution =
                    555:                    d_ex_fichier_verrouille;
                    556:            return;
                    557:        }
                    558: 
                    559:        /*
                    560:         * Vérification de l'autorisation d'écriture
                    561:         */
                    562: 
                    563:        if ((*((struct_fichier *) (*s_objet_argument_1).objet))
                    564:                .protection == 'R')
                    565:        {
                    566:            liberation(s_etat_processus, s_objet_argument_2);
                    567:            liberation(s_etat_processus, s_objet_argument_1);
                    568: 
                    569:            (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
                    570:            return;
                    571:        }
                    572: 
                    573:        if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire == 'N')
                    574:        {
                    575:            /*
                    576:             * Fichiers formatés
                    577:             */
                    578: 
1.6       bertrand  579:            if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                    580:                    == 'S')
1.1       bertrand  581:            {
1.6       bertrand  582:                if ((*s_objet_argument_2).type != LST)
                    583:                {
                    584:                    liberation(s_etat_processus, s_objet_argument_2);
                    585:                    liberation(s_etat_processus, s_objet_argument_1);
                    586: 
                    587:                    (*s_etat_processus).erreur_execution =
                    588:                            d_ex_erreur_type_argument;
                    589:                    return;
                    590:                }
                    591: 
                    592:                if ((chaine = formateur_fichier(s_etat_processus,
                    593:                        s_objet_argument_2, (*((struct_fichier *)
                    594:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
1.75    ! bertrand  595:                        &longueur_effective, &recursivite, d_vrai)) == NULL)
1.6       bertrand  596:                {
                    597:                    liberation(s_etat_processus, s_objet_argument_2);
                    598:                    liberation(s_etat_processus, s_objet_argument_1);
1.1       bertrand  599: 
1.6       bertrand  600:                    return;
                    601:                }
1.1       bertrand  602: 
1.5       bertrand  603:                BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
                    604: 
                    605:                if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
                    606:                        != 0)
1.1       bertrand  607:                {
                    608:                    liberation(s_etat_processus, s_objet_argument_2);
                    609:                    liberation(s_etat_processus, s_objet_argument_1);
                    610: 
                    611:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    612:                    return;
                    613:                }
                    614: 
1.5       bertrand  615:                if ((chaine_utf8 = transliteration(s_etat_processus,
                    616:                        chaine, d_locale, "UTF-8")) == NULL)
                    617:                {
1.6       bertrand  618:                    free(chaine);
                    619: 
1.5       bertrand  620:                    liberation(s_etat_processus, s_objet_argument_2);
                    621:                    liberation(s_etat_processus, s_objet_argument_1);
                    622: 
                    623:                    return;
                    624:                }
                    625: 
1.6       bertrand  626:                free(chaine);
                    627: 
1.7       bertrand  628:                if (fprintf((*descripteur).descripteur_c, "%s\n", chaine_utf8)
                    629:                        < 0)
1.1       bertrand  630:                {
1.5       bertrand  631:                    free(chaine_utf8);
                    632: 
1.1       bertrand  633:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    634:                    return;
                    635:                }
1.5       bertrand  636: 
                    637:                free(chaine_utf8);
1.1       bertrand  638:            }
                    639:            else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                    640:                    == 'D')
                    641:            {
1.6       bertrand  642:                BUG(((*descripteur).type != 'S'), uprintf("Bad filetype !\n"));
                    643: 
                    644:                if ((*s_objet_argument_2).type != INT)
                    645:                {
                    646:                    liberation(s_etat_processus, s_objet_argument_2);
                    647:                    liberation(s_etat_processus, s_objet_argument_1);
                    648: 
                    649:                    (*s_etat_processus).erreur_execution =
                    650:                            d_ex_erreur_type_argument;
                    651:                    return;
                    652:                }
                    653: 
                    654:                if (depilement(s_etat_processus, &((*s_etat_processus)
                    655:                        .l_base_pile), &s_objet_argument_3) == d_erreur)
                    656:                {
                    657:                    (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    658:                    return;
                    659:                }
                    660: 
                    661:                if ((*s_objet_argument_3).type != LST)
                    662:                {
                    663:                    liberation(s_etat_processus, s_objet_argument_3);
                    664:                    liberation(s_etat_processus, s_objet_argument_2);
                    665:                    liberation(s_etat_processus, s_objet_argument_1);
                    666: 
                    667:                    (*s_etat_processus).erreur_execution =
                    668:                            d_ex_erreur_type_argument;
                    669:                    return;
                    670:                }
                    671: 
1.8       bertrand  672:                // Modification ou création d'un nouvel enregistrement
                    673: 
                    674:                if ((chaine = formateur_fichier(s_etat_processus,
                    675:                        s_objet_argument_3, (*((struct_fichier *)
                    676:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ',
1.75    ! bertrand  677:                        'F', &longueur_effective, &recursivite, d_vrai))
        !           678:                        == NULL)
1.8       bertrand  679:                {
                    680:                    liberation(s_etat_processus, s_objet_argument_3);
                    681:                    liberation(s_etat_processus, s_objet_argument_2);
                    682:                    liberation(s_etat_processus, s_objet_argument_1);
                    683: 
                    684:                    return;
                    685:                }
                    686: 
                    687:                if ((chaine_utf8 = transliteration(s_etat_processus,
                    688:                        chaine, d_locale, "UTF-8")) == NULL)
                    689:                {
                    690:                    free(chaine);
                    691: 
                    692:                    liberation(s_etat_processus, s_objet_argument_3);
                    693:                    liberation(s_etat_processus, s_objet_argument_2);
                    694:                    liberation(s_etat_processus, s_objet_argument_1);
                    695: 
                    696:                    return;
                    697:                }
                    698: 
                    699:                free(chaine);
                    700: 
                    701:                if (alsprintf(&commande, "insert or replace into data "
                    702:                        "(id, data) values (%lld, '%s')", (*((integer8 *)
                    703:                        (*s_objet_argument_2).objet)), chaine_utf8) < 0)
                    704:                {
1.9       bertrand  705:                    (*s_etat_processus).erreur_systeme =
                    706:                            d_es_allocation_memoire;
1.8       bertrand  707:                    return;
                    708:                }
                    709: 
                    710:                free(chaine_utf8);
                    711: 
                    712:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                    713:                        commande, strlen(commande), &ppStmt, &queue)
                    714:                        != SQLITE_OK)
                    715:                {
                    716:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    717:                    return;
                    718:                }
                    719: 
                    720:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    721:                {
                    722:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    723:                    return;
                    724:                }
                    725: 
                    726:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    727:                {
                    728:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    729:                    return;
                    730:                }
                    731: 
                    732:                liberation(s_etat_processus, s_objet_argument_3);
                    733:                free(commande);
                    734:            }
                    735:            else // Fichiers indexés
                    736:            {
                    737:                BUG(((*descripteur).type != 'S'), uprintf("Bad filetype !\n"));
                    738: 
                    739:                if ((*s_objet_argument_2).type != LST)
                    740:                {
                    741:                    liberation(s_etat_processus, s_objet_argument_2);
                    742:                    liberation(s_etat_processus, s_objet_argument_1);
                    743: 
                    744:                    (*s_etat_processus).erreur_execution =
                    745:                            d_ex_erreur_type_argument;
                    746:                    return;
                    747:                }
                    748: 
1.9       bertrand  749:                // Récupération de la position de la clef
1.8       bertrand  750: 
                    751:                if (alsprintf(&commande, "select key from control "
                    752:                        "where id = 1") < 0)
                    753:                {
1.9       bertrand  754:                    (*s_etat_processus).erreur_systeme =
                    755:                            d_es_allocation_memoire;
1.8       bertrand  756:                    return;
                    757:                }
                    758: 
                    759:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                    760:                        commande, strlen(commande), &ppStmt, &queue)
                    761:                        != SQLITE_OK)
                    762:                {
1.9       bertrand  763:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  764:                    return;
                    765:                }
                    766: 
1.70      bertrand  767:                attente.tv_sec = 0;
                    768:                attente.tv_nsec = GRANULARITE_us * 1000;
                    769: 
                    770:                do
1.8       bertrand  771:                {
1.70      bertrand  772:                    sqlite_status = sqlite3_step(ppStmt);
                    773: 
                    774:                    if (sqlite_status == SQLITE_ROW)
                    775:                    {
                    776:                        break;
                    777:                    }
                    778:                    else if ((sqlite_status == SQLITE_BUSY) ||
                    779:                            (sqlite_status == SQLITE_LOCKED))
                    780:                    {
                    781:                        nanosleep(&attente, NULL);
                    782:                        INCR_GRANULARITE(attente.tv_nsec);
                    783:                    }
                    784:                    else
                    785:                    {
                    786:                        (*s_etat_processus).erreur_systeme =
                    787:                                d_es_erreur_fichier;
                    788:                        return;
                    789:                    }
                    790:                } while(sqlite_status != SQLITE_ROW);
1.8       bertrand  791: 
                    792:                if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
                    793:                {
1.9       bertrand  794:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  795:                    return;
                    796:                }
                    797: 
                    798:                clef = sqlite3_column_int64(ppStmt, 0);
                    799: 
                    800:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    801:                {
1.9       bertrand  802:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  803:                    return;
                    804:                }
                    805: 
                    806:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    807:                {
1.9       bertrand  808:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  809:                    return;
                    810:                }
                    811: 
                    812:                free(commande);
                    813: 
                    814:                l_element_courant = (struct_liste_chainee *)
                    815:                        (*s_objet_argument_2).objet;
                    816:                l_element_courant_format = (struct_liste_chainee *)
                    817:                        (*(*((struct_fichier *) (*s_objet_argument_1).objet))
                    818:                        .format).objet;
                    819:                compteur = 1;
                    820: 
                    821:                while((l_element_courant != NULL) &&
                    822:                        (l_element_courant_format != NULL))
                    823:                {
                    824:                    if (compteur == clef)
                    825:                    {
                    826:                        break;
                    827:                    }
                    828: 
                    829:                    l_element_courant = (*l_element_courant).suivant;
                    830:                    l_element_courant_format = (*l_element_courant_format)
                    831:                            .suivant;
                    832:                    compteur++;
                    833:                }
                    834: 
                    835:                if ((l_element_courant == NULL) ||
                    836:                        (l_element_courant_format == NULL))
                    837:                {
                    838:                    (*s_etat_processus).erreur_execution =
                    839:                            d_ex_clef_inexistante;
                    840:                        
                    841:                    liberation(s_etat_processus, s_objet_argument_2);
                    842:                    liberation(s_etat_processus, s_objet_argument_1);
                    843: 
                    844:                    return;
                    845:                }
                    846: 
                    847:                if ((s_element = allocation(s_etat_processus, LST)) == NULL)
                    848:                {
                    849:                    (*s_etat_processus).erreur_systeme =
                    850:                            d_es_allocation_memoire;
                    851:                    return;
                    852:                }
                    853: 
                    854:                if (((*s_element).objet = allocation_maillon(s_etat_processus))
                    855:                        == NULL)
                    856:                {
                    857:                    (*s_etat_processus).erreur_systeme =
                    858:                            d_es_allocation_memoire;
                    859:                    return;
                    860:                }
                    861: 
                    862:                (*((struct_liste_chainee *) (*s_element).objet)).suivant = NULL;
                    863: 
                    864:                if (((*((struct_liste_chainee *) (*s_element).objet))
                    865:                        .donnee = copie_objet(s_etat_processus,
                    866:                        (*l_element_courant).donnee, 'N')) == NULL)
                    867:                {
                    868:                    (*s_etat_processus).erreur_systeme =
                    869:                            d_es_allocation_memoire;
                    870:                    return;
                    871:                }
                    872: 
                    873:                if ((s_format = allocation(s_etat_processus, LST)) == NULL)
                    874:                {
                    875:                    (*s_etat_processus).erreur_systeme =
                    876:                            d_es_allocation_memoire;
                    877:                    return;
                    878:                }
                    879: 
                    880:                if (((*s_format).objet = allocation_maillon(s_etat_processus))
                    881:                        == NULL)
                    882:                {
                    883:                    (*s_etat_processus).erreur_systeme =
                    884:                            d_es_allocation_memoire;
                    885:                    return;
                    886:                }
                    887: 
                    888:                (*((struct_liste_chainee *) (*s_format).objet)).suivant = NULL;
                    889: 
                    890:                if (((*((struct_liste_chainee *) (*s_format).objet))
                    891:                        .donnee = copie_objet(s_etat_processus,
                    892:                        (*l_element_courant_format).donnee, 'N')) == NULL)
                    893:                {
                    894:                    (*s_etat_processus).erreur_systeme =
                    895:                            d_es_allocation_memoire;
                    896:                    return;
                    897:                }
                    898: 
                    899:                if ((chaine = formateur_fichier(s_etat_processus,
                    900:                        s_element, s_format, 0, 0, ' ',
1.75    ! bertrand  901:                        'F', &longueur_effective, &recursivite, d_vrai))
        !           902:                        == NULL)
1.8       bertrand  903:                {
                    904:                    liberation(s_etat_processus, s_element);
                    905:                    liberation(s_etat_processus, s_format);
                    906:                    liberation(s_etat_processus, s_objet_argument_2);
                    907:                    liberation(s_etat_processus, s_objet_argument_1);
                    908: 
                    909:                    return;
                    910:                }
                    911: 
                    912:                liberation(s_etat_processus, s_element);
                    913:                liberation(s_etat_processus, s_format);
                    914: 
                    915:                if ((clef_utf8 = transliteration(s_etat_processus,
                    916:                        chaine, d_locale, "UTF-8")) == NULL)
                    917:                {
                    918:                    liberation(s_etat_processus, s_objet_argument_2);
                    919:                    liberation(s_etat_processus, s_objet_argument_1);
                    920: 
                    921:                    return;
                    922:                }
                    923: 
                    924:                free(chaine);
                    925: 
                    926:                // Récupération de l'identifiant de la clef
                    927: 
                    928:                if (alsprintf(&commande, "select id from key where key = "
                    929:                        "'%s'", clef_utf8) < 0)
                    930:                {
1.9       bertrand  931:                    (*s_etat_processus).erreur_systeme =
                    932:                            d_es_allocation_memoire;
1.8       bertrand  933:                    return;
                    934:                }
                    935: 
                    936:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                    937:                        commande, strlen(commande), &ppStmt, &queue)
                    938:                        != SQLITE_OK)
                    939:                {
1.9       bertrand  940:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  941:                    return;
                    942:                }
                    943: 
1.70      bertrand  944:                attente.tv_sec = 0;
                    945:                attente.tv_nsec = GRANULARITE_us * 1000;
                    946: 
                    947:                do
1.8       bertrand  948:                {
1.70      bertrand  949:                    switch(sqlite_status = sqlite3_step(ppStmt))
1.8       bertrand  950:                    {
1.70      bertrand  951:                        case SQLITE_ROW:
                    952:                        {
                    953:                            // Une clef existe.
                    954: 
                    955:                            mise_a_jour = d_vrai;
                    956:                            break;
                    957:                        }
1.8       bertrand  958: 
1.70      bertrand  959:                        case SQLITE_DONE:
                    960:                        {
                    961:                            // Aucune clef n'existe.
                    962: 
                    963:                            mise_a_jour = d_faux;
1.8       bertrand  964: 
1.70      bertrand  965:                            if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    966:                            {
                    967:                                (*s_etat_processus).erreur_systeme =
                    968:                                        d_es_erreur_fichier;
                    969:                                return;
                    970:                            }
1.8       bertrand  971: 
1.70      bertrand  972:                            free(commande);
1.8       bertrand  973: 
1.70      bertrand  974:                            if (alsprintf(&commande, "insert into key "
                    975:                                    "(key) values ('%s')", clef_utf8) < 0)
                    976:                            {
                    977:                                (*s_etat_processus).erreur_systeme =
                    978:                                        d_es_allocation_memoire;
                    979:                                return;
                    980:                            }
1.8       bertrand  981: 
1.70      bertrand  982:                            if (sqlite3_prepare_v2((*descripteur)
                    983:                                    .descripteur_sqlite,
                    984:                                    commande, strlen(commande), &ppStmt, &queue)
                    985:                                    != SQLITE_OK)
                    986:                            {
                    987:                                (*s_etat_processus).erreur_systeme =
                    988:                                        d_es_erreur_fichier;
                    989:                                return;
                    990:                            }
1.8       bertrand  991: 
1.70      bertrand  992:                            if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    993:                            {
                    994:                                (*s_etat_processus).erreur_systeme =
                    995:                                        d_es_erreur_fichier;
                    996:                                return;
                    997:                            }
1.8       bertrand  998: 
1.70      bertrand  999:                            if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1000:                            {
                   1001:                                (*s_etat_processus).erreur_systeme =
                   1002:                                        d_es_erreur_fichier;
                   1003:                                return;
                   1004:                            }
1.8       bertrand 1005: 
1.70      bertrand 1006:                            free(commande);
1.8       bertrand 1007: 
1.70      bertrand 1008:                            if (alsprintf(&commande, "select id from key "
                   1009:                                    "where key = '%s'", clef_utf8) < 0)
                   1010:                            {
                   1011:                                (*s_etat_processus).erreur_systeme =
                   1012:                                        d_es_allocation_memoire;
                   1013:                                return;
                   1014:                            }
1.8       bertrand 1015: 
1.70      bertrand 1016:                            if (sqlite3_prepare_v2((*descripteur)
                   1017:                                    .descripteur_sqlite,
                   1018:                                    commande, strlen(commande), &ppStmt, &queue)
                   1019:                                    != SQLITE_OK)
                   1020:                            {
                   1021:                                (*s_etat_processus).erreur_systeme =
                   1022:                                        d_es_erreur_fichier;
                   1023:                                return;
                   1024:                            }
1.8       bertrand 1025: 
1.70      bertrand 1026:                            break;
1.8       bertrand 1027:                        }
                   1028: 
1.70      bertrand 1029:                        case SQLITE_BUSY:
                   1030:                        case SQLITE_LOCKED:
1.8       bertrand 1031:                        {
1.70      bertrand 1032:                            nanosleep(&attente, NULL);
                   1033:                            INCR_GRANULARITE(attente.tv_nsec);
                   1034:                            break;
1.8       bertrand 1035:                        }
                   1036: 
1.70      bertrand 1037:                        default:
1.8       bertrand 1038:                        {
                   1039:                            (*s_etat_processus).erreur_systeme =
                   1040:                                    d_es_erreur_fichier;
                   1041:                            return;
                   1042:                        }
                   1043:                    }
1.70      bertrand 1044:                } while(sqlite_status != SQLITE_ROW);
1.8       bertrand 1045: 
                   1046:                if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
                   1047:                {
1.9       bertrand 1048:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1049:                    return;
                   1050:                }
                   1051: 
                   1052:                id = sqlite3_column_int64(ppStmt, 0);
                   1053: 
                   1054:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
1.6       bertrand 1055:                {
1.9       bertrand 1056:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1057:                    return;
                   1058:                }
1.6       bertrand 1059: 
1.8       bertrand 1060:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1061:                {
1.9       bertrand 1062:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1063:                    return;
                   1064:                }
                   1065: 
                   1066:                free(commande);
                   1067: 
                   1068:                // Modification de la clef
                   1069: 
                   1070:                if (mise_a_jour == d_vrai)
                   1071:                {
                   1072:                    if (alsprintf(&commande, "update key set key = '%s' where "
                   1073:                            "id = %lld", clef_utf8, id) < 0)
1.6       bertrand 1074:                    {
1.9       bertrand 1075:                        (*s_etat_processus).erreur_systeme =
                   1076:                                d_es_allocation_memoire;
1.6       bertrand 1077:                        return;
                   1078:                    }
1.8       bertrand 1079: 
                   1080:                    if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                   1081:                            commande, strlen(commande), &ppStmt, &queue)
                   1082:                            != SQLITE_OK)
                   1083:                    {
                   1084:                        (*s_etat_processus).erreur_systeme =
                   1085:                                d_es_erreur_fichier;
                   1086:                        return;
                   1087:                    }
                   1088: 
                   1089:                    if (sqlite3_step(ppStmt) != SQLITE_DONE)
                   1090:                    {
                   1091:                        (*s_etat_processus).erreur_systeme =
                   1092:                                d_es_erreur_fichier;
                   1093:                        return;
                   1094:                    }
                   1095: 
                   1096:                    if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1097:                    {
                   1098:                        (*s_etat_processus).erreur_systeme =
                   1099:                                d_es_erreur_fichier;
                   1100:                        return;
                   1101:                    }
                   1102: 
                   1103:                    free(commande);
1.6       bertrand 1104:                }
1.8       bertrand 1105: 
                   1106:                // Effacement de l'enregistrement existant
                   1107: 
                   1108:                if (alsprintf(&commande, "delete from data where "
                   1109:                        "key_id = %lld", id) < 0)
                   1110:                {
1.9       bertrand 1111:                    (*s_etat_processus).erreur_systeme =
                   1112:                            d_es_allocation_memoire;
1.8       bertrand 1113:                    return;
                   1114:                }
                   1115: 
                   1116:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                   1117:                        commande, strlen(commande), &ppStmt, &queue)
                   1118:                        != SQLITE_OK)
                   1119:                {
1.9       bertrand 1120:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1121:                    return;
                   1122:                }
                   1123: 
                   1124:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
                   1125:                {
1.9       bertrand 1126:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1127:                    return;
                   1128:                }
                   1129: 
                   1130:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1131:                {
1.9       bertrand 1132:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1133:                    return;
                   1134:                }
                   1135: 
                   1136:                free(commande);
                   1137: 
                   1138:                // Modification ou création d'un nouvel enregistrement
                   1139: 
                   1140:                l_element_courant = (struct_liste_chainee *)
                   1141:                        (*s_objet_argument_2).objet;
                   1142:                l_element_courant_format = (struct_liste_chainee *)
                   1143:                        (*(*((struct_fichier *) (*s_objet_argument_1).objet))
                   1144:                        .format).objet;
                   1145:                compteur = 1;
                   1146:                ordre = 1;
                   1147: 
                   1148:                while((l_element_courant != NULL) &&
                   1149:                        (l_element_courant_format != NULL))
1.6       bertrand 1150:                {
1.8       bertrand 1151:                    if (compteur == clef)
                   1152:                    {
                   1153:                        l_element_courant = (*l_element_courant).suivant;
                   1154:                        l_element_courant_format = (*l_element_courant_format)
                   1155:                                .suivant;
                   1156:                        compteur++;
                   1157:                        continue;
                   1158:                    }
                   1159: 
                   1160:                    if ((s_element = allocation(s_etat_processus, LST)) == NULL)
                   1161:                    {
                   1162:                        (*s_etat_processus).erreur_systeme =
                   1163:                                d_es_allocation_memoire;
                   1164:                        return;
                   1165:                    }
                   1166: 
                   1167:                    if (((*s_element).objet =
                   1168:                            allocation_maillon(s_etat_processus)) == NULL)
                   1169:                    {
                   1170:                        (*s_etat_processus).erreur_systeme =
                   1171:                                d_es_allocation_memoire;
                   1172:                        return;
                   1173:                    }
                   1174: 
                   1175:                    (*((struct_liste_chainee *) (*s_element).objet)).suivant
                   1176:                            = NULL;
                   1177: 
                   1178:                    if ((s_format = allocation(s_etat_processus, LST)) == NULL)
                   1179:                    {
                   1180:                        (*s_etat_processus).erreur_systeme =
                   1181:                                d_es_allocation_memoire;
                   1182:                        return;
                   1183:                    }
                   1184: 
                   1185:                    if (((*s_format).objet =
                   1186:                            allocation_maillon(s_etat_processus)) == NULL)
                   1187:                    {
                   1188:                        (*s_etat_processus).erreur_systeme =
                   1189:                                d_es_allocation_memoire;
                   1190:                        return;
                   1191:                    }
                   1192: 
                   1193:                    (*((struct_liste_chainee *) (*s_format).objet)).suivant
                   1194:                            = NULL;
                   1195: 
                   1196:                    if (((*((struct_liste_chainee *) (*s_element).objet))
                   1197:                            .donnee = copie_objet(s_etat_processus,
                   1198:                            (*l_element_courant).donnee, 'N')) == NULL)
                   1199:                    {
                   1200:                        (*s_etat_processus).erreur_systeme =
                   1201:                                d_es_allocation_memoire;
                   1202:                        return;
                   1203:                    }
                   1204: 
                   1205:                    if (((*((struct_liste_chainee *) (*s_format).objet))
                   1206:                            .donnee = copie_objet(s_etat_processus,
                   1207:                            (*l_element_courant_format).donnee, 'N')) == NULL)
                   1208:                    {
                   1209:                        (*s_etat_processus).erreur_systeme =
                   1210:                                d_es_allocation_memoire;
                   1211:                        return;
                   1212:                    }
1.6       bertrand 1213: 
                   1214:                    if ((chaine = formateur_fichier(s_etat_processus,
1.8       bertrand 1215:                            s_element, s_format, 0, 0, ' ',
1.75    ! bertrand 1216:                            'F', &longueur_effective, &recursivite, d_vrai))
        !          1217:                            == NULL)
1.6       bertrand 1218:                    {
1.8       bertrand 1219:                        free(clef_utf8);
1.9       bertrand 1220: 
1.8       bertrand 1221:                        liberation(s_etat_processus, s_element);
                   1222:                        liberation(s_etat_processus, s_format);
1.6       bertrand 1223:                        liberation(s_etat_processus, s_objet_argument_2);
                   1224:                        liberation(s_etat_processus, s_objet_argument_1);
                   1225: 
                   1226:                        return;
                   1227:                    }
                   1228: 
                   1229:                    if ((chaine_utf8 = transliteration(s_etat_processus,
                   1230:                            chaine, d_locale, "UTF-8")) == NULL)
                   1231:                    {
1.8       bertrand 1232:                        free(clef_utf8);
1.6       bertrand 1233:                        free(chaine);
                   1234: 
                   1235:                        liberation(s_etat_processus, s_objet_argument_2);
                   1236:                        liberation(s_etat_processus, s_objet_argument_1);
                   1237: 
                   1238:                        return;
                   1239:                    }
                   1240: 
                   1241:                    free(chaine);
                   1242: 
1.8       bertrand 1243:                    if (alsprintf(&commande, "insert into data "
                   1244:                            "(data, key_id, sequence) values "
                   1245:                            "('%s', %lld, %lld)", chaine_utf8, id, ordre) < 0)
1.6       bertrand 1246:                    {
1.9       bertrand 1247:                        (*s_etat_processus).erreur_systeme =
                   1248:                                d_es_allocation_memoire;
1.6       bertrand 1249:                        return;
                   1250:                    }
                   1251: 
1.8       bertrand 1252:                    if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                   1253:                            commande, strlen(commande), &ppStmt, &queue)
                   1254:                            != SQLITE_OK)
                   1255:                    {
                   1256:                        (*s_etat_processus).erreur_systeme =
                   1257:                                d_es_erreur_fichier;
                   1258:                        return;
                   1259:                    }
                   1260: 
                   1261:                    if (sqlite3_step(ppStmt) != SQLITE_DONE)
                   1262:                    {
                   1263:                        (*s_etat_processus).erreur_systeme =
                   1264:                                d_es_erreur_fichier;
                   1265:                        return;
                   1266:                    }
                   1267: 
                   1268:                    if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1269:                    {
                   1270:                        (*s_etat_processus).erreur_systeme =
                   1271:                                d_es_erreur_fichier;
                   1272:                        return;
                   1273:                    }
                   1274: 
                   1275:                    free(commande);
1.6       bertrand 1276:                    free(chaine_utf8);
1.8       bertrand 1277: 
                   1278:                    liberation(s_etat_processus, s_element);
                   1279:                    liberation(s_etat_processus, s_format);
                   1280: 
                   1281:                    l_element_courant = (*l_element_courant).suivant;
                   1282:                    l_element_courant_format = (*l_element_courant_format)
                   1283:                            .suivant;
                   1284: 
                   1285:                    compteur++;
                   1286:                    ordre++;
1.6       bertrand 1287:                }
                   1288: 
1.8       bertrand 1289:                free(clef_utf8);
1.6       bertrand 1290: 
1.8       bertrand 1291:                if ((l_element_courant != NULL) ||
                   1292:                        (l_element_courant_format != NULL))
1.6       bertrand 1293:                {
1.8       bertrand 1294:                    liberation(s_etat_processus, s_objet_argument_1);
                   1295:                    liberation(s_etat_processus, s_objet_argument_2);
1.6       bertrand 1296: 
1.8       bertrand 1297:                    (*s_etat_processus).erreur_execution =
                   1298:                            d_ex_erreur_format_fichier;
1.6       bertrand 1299:                    return;
                   1300:                }
1.1       bertrand 1301:            }
                   1302:        }
                   1303:        else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire
                   1304:                == 'Y')
                   1305:        {
                   1306:            /*
                   1307:             * Fichiers non formatés
                   1308:             */
                   1309: 
1.75    ! bertrand 1310:            if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
        !          1311:                    == 'S')
1.1       bertrand 1312:            {
1.75    ! bertrand 1313:                if ((chaine = formateur_fichier(s_etat_processus,
        !          1314:                        s_objet_argument_2, (*((struct_fichier *)
        !          1315:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
        !          1316:                        &longueur_effective, &recursivite, d_vrai)) == NULL)
        !          1317:                {
        !          1318:                    liberation(s_etat_processus, s_objet_argument_2);
        !          1319:                    liberation(s_etat_processus, s_objet_argument_1);
1.1       bertrand 1320: 
1.75    ! bertrand 1321:                    return;
        !          1322:                }
1.1       bertrand 1323: 
1.5       bertrand 1324:                BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
                   1325: 
                   1326:                if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
                   1327:                        != 0)
1.1       bertrand 1328:                {
                   1329:                    liberation(s_etat_processus, s_objet_argument_2);
                   1330:                    liberation(s_etat_processus, s_objet_argument_1);
                   1331: 
                   1332:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   1333:                    return;
                   1334:                }
                   1335: 
                   1336:                if (fwrite(chaine, sizeof(unsigned char), longueur_effective,
1.5       bertrand 1337:                        (*descripteur).descripteur_c) !=
                   1338:                        (size_t) longueur_effective)
1.1       bertrand 1339:                {
                   1340:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   1341:                    return;
                   1342:                }
                   1343:            }
                   1344:            else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                   1345:                    == 'D')
                   1346:            {
1.75    ! bertrand 1347:                if ((chaine = formateur_fichier(s_etat_processus,
        !          1348:                        s_objet_argument_2, (*((struct_fichier *)
        !          1349:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
        !          1350:                        &longueur_effective, &recursivite, d_faux)) == NULL)
        !          1351:                {
        !          1352:                    liberation(s_etat_processus, s_objet_argument_2);
        !          1353:                    liberation(s_etat_processus, s_objet_argument_1);
        !          1354: 
        !          1355:                    return;
        !          1356:                }
1.1       bertrand 1357:            }
1.75    ! bertrand 1358:            else // Fichiers indexés
1.1       bertrand 1359:            {
1.75    ! bertrand 1360:                if ((chaine = formateur_fichier(s_etat_processus,
        !          1361:                        s_objet_argument_2, (*((struct_fichier *)
        !          1362:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
        !          1363:                        &longueur_effective, &recursivite, d_faux)) == NULL)
        !          1364:                {
        !          1365:                    liberation(s_etat_processus, s_objet_argument_2);
        !          1366:                    liberation(s_etat_processus, s_objet_argument_1);
        !          1367: 
        !          1368:                    return;
        !          1369:                }
1.1       bertrand 1370:            }
                   1371: 
                   1372:            free(chaine);
                   1373:        }
                   1374:        else
                   1375:        {
                   1376:            /*
                   1377:             * Fichiers de type FLOW
                   1378:             */
1.33      bertrand 1379: 
                   1380:            if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                   1381:                    == 'S')
                   1382:            {
                   1383:                BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
                   1384: 
1.56      bertrand 1385:                if ((*s_objet_argument_2).type != LST)
                   1386:                {
                   1387:                    liberation(s_etat_processus, s_objet_argument_2);
                   1388:                    liberation(s_etat_processus, s_objet_argument_1);
                   1389: 
                   1390:                    (*s_etat_processus).erreur_execution =
                   1391:                            d_ex_erreur_type_argument;
                   1392:                    return;
                   1393:                }
                   1394: 
                   1395:                if ((*((struct_liste_chainee *) (*s_objet_argument_2).objet))
                   1396:                        .donnee == NULL)
                   1397:                {
                   1398:                    liberation(s_etat_processus, s_objet_argument_2);
                   1399:                    liberation(s_etat_processus, s_objet_argument_1);
                   1400: 
                   1401:                    (*s_etat_processus).erreur_execution =
                   1402:                            d_ex_erreur_type_argument;
                   1403:                    return;
                   1404:                }
                   1405: 
1.64      bertrand 1406:                l_element_courant = (*s_objet_argument_2).objet;
                   1407:                l_element_courant_format = (struct_liste_chainee *)
                   1408:                        (*(*((struct_fichier *) (*s_objet_argument_1).objet))
                   1409:                        .format).objet;
                   1410: 
                   1411:                while((l_element_courant != NULL) &&
                   1412:                        (l_element_courant_format != NULL))
1.33      bertrand 1413:                {
1.64      bertrand 1414:                    if ((*(*l_element_courant).donnee).type != CHN)
                   1415:                    {
                   1416:                        liberation(s_etat_processus, s_objet_argument_2);
                   1417:                        liberation(s_etat_processus, s_objet_argument_1);
                   1418: 
                   1419:                        (*s_etat_processus).erreur_execution =
                   1420:                                d_ex_erreur_type_argument;
                   1421:                        return;
                   1422:                    }
                   1423: 
                   1424:                    if ((*(*l_element_courant_format).donnee).type != CHN)
                   1425:                    {
                   1426:                        liberation(s_etat_processus, s_objet_argument_2);
                   1427:                        liberation(s_etat_processus, s_objet_argument_1);
                   1428: 
                   1429:                        (*s_etat_processus).erreur_execution =
                   1430:                                d_ex_erreur_type_argument;
                   1431:                        return;
                   1432:                    }
                   1433: 
                   1434:                    if ((format_chaine = conversion_majuscule((unsigned char *)
                   1435:                            (*(*l_element_courant_format).donnee).objet))
                   1436:                            == NULL)
                   1437:                    {
                   1438:                        (*s_etat_processus).erreur_systeme =
                   1439:                                d_es_allocation_memoire;
                   1440:                        return;
                   1441:                    }
                   1442: 
                   1443:                    if (strncmp("LENGTH*(", format_chaine, 8) != 0)
                   1444:                    {
                   1445:                        free(format_chaine);
                   1446: 
                   1447:                        liberation(s_etat_processus, s_objet_argument_2);
                   1448:                        liberation(s_etat_processus, s_objet_argument_1);
                   1449: 
                   1450:                        (*s_etat_processus).erreur_execution =
                   1451:                                d_ex_erreur_format_fichier;
                   1452:                        return;
                   1453:                    }
                   1454: 
                   1455:                    longueur = strlen(format_chaine);
                   1456: 
1.65      bertrand 1457:                    if (format_chaine[longueur - 1] != ')')
1.64      bertrand 1458:                    {
                   1459:                        free(format_chaine);
                   1460: 
                   1461:                        liberation(s_etat_processus, s_objet_argument_2);
                   1462:                        liberation(s_etat_processus, s_objet_argument_1);
                   1463: 
                   1464:                        (*s_etat_processus).erreur_execution =
                   1465:                                d_ex_erreur_format_fichier;
                   1466:                        return;
                   1467:                    }
                   1468: 
                   1469:                    format_chaine[longueur] = d_code_fin_chaine;
                   1470: 
                   1471:                    if (format_chaine[8] == '*')
                   1472:                    {
                   1473:                        format_degenere = d_vrai;
                   1474:                    }
                   1475:                    else
                   1476:                    {
                   1477:                        // Détermination de la longueur
                   1478:                        format_degenere = d_faux;
                   1479: 
                   1480:                        if (sscanf(&(format_chaine[8]), "%ld", &longueur) != 1)
                   1481:                        {
                   1482:                            free(format_chaine);
                   1483: 
                   1484:                            liberation(s_etat_processus, s_objet_argument_2);
                   1485:                            liberation(s_etat_processus, s_objet_argument_1);
1.33      bertrand 1486: 
1.64      bertrand 1487:                            (*s_etat_processus).erreur_execution =
                   1488:                                    d_ex_erreur_format_fichier;
                   1489:                            return;
                   1490:                        }
                   1491:                    }
1.33      bertrand 1492: 
1.64      bertrand 1493:                    free(format_chaine);
1.33      bertrand 1494: 
1.64      bertrand 1495:                    if ((chaine = formateur_flux(s_etat_processus,
                   1496:                            (unsigned char *) (*(*l_element_courant).donnee)
                   1497:                            .objet, &longueur_effective)) == NULL)
                   1498:                    {
                   1499:                        (*s_etat_processus).erreur_systeme =
                   1500:                                d_es_allocation_memoire;
                   1501:                        return;
                   1502:                    }
1.33      bertrand 1503: 
1.64      bertrand 1504:                    if ((format_degenere == d_vrai) ||
                   1505:                            (longueur_effective < longueur))
                   1506:                    {
                   1507:                        if (fwrite(chaine, sizeof(unsigned char),
                   1508:                                longueur_effective,
                   1509:                                (*descripteur).descripteur_c) !=
                   1510:                                (size_t) longueur_effective)
                   1511:                        {
                   1512:                            (*s_etat_processus).erreur_systeme =
                   1513:                                    d_es_erreur_fichier;
                   1514:                            return;
                   1515:                        }
                   1516:                    }
                   1517:                    else
                   1518:                    {
                   1519:                        if (fwrite(chaine, sizeof(unsigned char),
                   1520:                                longueur_effective,
                   1521:                                (*descripteur).descripteur_c) !=
                   1522:                                (size_t) longueur)
                   1523:                        {
                   1524:                            (*s_etat_processus).erreur_systeme =
                   1525:                                    d_es_erreur_fichier;
                   1526:                            return;
                   1527:                        }
                   1528:                    }
1.63      bertrand 1529: 
1.64      bertrand 1530:                    free(chaine);
1.63      bertrand 1531: 
1.64      bertrand 1532:                    l_element_courant = (*l_element_courant).suivant;
                   1533:                    l_element_courant_format = (*l_element_courant_format)
                   1534:                            .suivant;
                   1535:                }
1.63      bertrand 1536: 
1.64      bertrand 1537:                if ((l_element_courant_format != NULL) ||
                   1538:                        (l_element_courant != NULL))
1.63      bertrand 1539:                {
1.64      bertrand 1540:                    liberation(s_etat_processus, s_objet_argument_2);
                   1541:                    liberation(s_etat_processus, s_objet_argument_1);
                   1542: 
                   1543:                    (*s_etat_processus).erreur_execution =
                   1544:                            d_ex_erreur_format_fichier;
1.63      bertrand 1545:                    return;
                   1546:                }
1.33      bertrand 1547:            }
                   1548:            else
                   1549:            {
                   1550:                liberation(s_etat_processus, s_objet_argument_1);
                   1551:                liberation(s_etat_processus, s_objet_argument_2);
                   1552: 
                   1553:                (*s_etat_processus).erreur_execution =
                   1554:                        d_ex_erreur_type_fichier;
                   1555:                return;
                   1556:            }
1.1       bertrand 1557:        }
                   1558:    }
                   1559:    else if (((*s_objet_argument_2).type == LST) &&
                   1560:            ((*s_objet_argument_1).type == SCK))
                   1561:    {
                   1562:        /*
                   1563:         * Vérification de l'autorisation d'écriture
                   1564:         */
                   1565: 
                   1566:        if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1567:                .protection == 'R')
                   1568:        {
                   1569:            liberation(s_etat_processus, s_objet_argument_2);
                   1570:            liberation(s_etat_processus, s_objet_argument_1);
                   1571: 
                   1572:            (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
                   1573:            return;
                   1574:        }
                   1575: 
                   1576:        if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
                   1577:        {
                   1578:            /*
                   1579:             * Sockets formatées
                   1580:             */
                   1581: 
                   1582:            if ((chaine = formateur_fichier(s_etat_processus,
                   1583:                    s_objet_argument_2, (*((struct_socket *)
                   1584:                    (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
1.75    ! bertrand 1585:                    &longueur_effective, &recursivite, d_faux)) == NULL)
1.1       bertrand 1586:            {
                   1587:                liberation(s_etat_processus, s_objet_argument_2);
                   1588:                liberation(s_etat_processus, s_objet_argument_1);
                   1589: 
                   1590:                return;
                   1591:            }
1.33      bertrand 1592:        }
                   1593:        else if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire
                   1594:                == 'Y')
                   1595:        {
                   1596:            /*
                   1597:             * Sockets non formatées
                   1598:             */
1.38      bertrand 1599: 
                   1600:            chaine = NULL;
1.33      bertrand 1601:        }
                   1602:        else
                   1603:        {
                   1604:            /*
                   1605:             *  Sockets de type FLOW
                   1606:             */
                   1607: 
                   1608:            if ((*((*((struct_liste_chainee *) (*s_objet_argument_2).objet))
                   1609:                    .donnee)).type != CHN)
                   1610:            {
                   1611:                liberation(s_etat_processus, s_objet_argument_2);
                   1612:                liberation(s_etat_processus, s_objet_argument_1);
                   1613: 
                   1614:                (*s_etat_processus).erreur_execution =
                   1615:                        d_ex_erreur_type_argument;
                   1616:                return;
                   1617:            }
                   1618: 
                   1619:            if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
                   1620:                    (*((*((struct_liste_chainee *) (*s_objet_argument_2)
                   1621:                    .objet)).donnee)).objet, &longueur_effective)) == NULL)
                   1622:            {
                   1623:                liberation(s_etat_processus, s_objet_argument_2);
                   1624:                liberation(s_etat_processus, s_objet_argument_1);
                   1625: 
                   1626:                return;
                   1627:            }
                   1628:        }
1.1       bertrand 1629: 
1.33      bertrand 1630:        if ((strcmp((*((struct_socket *) (*s_objet_argument_1).objet)).type,
                   1631:                "STREAM") == 0) || (strcmp((*((struct_socket *)
                   1632:                (*s_objet_argument_1).objet)).type,
                   1633:                "SEQUENTIAL DATAGRAM") == 0))
                   1634:        { // Sockets connectées
                   1635: 
                   1636:            action.sa_handler = SIG_IGN;
                   1637:            action.sa_flags = SA_ONSTACK;
                   1638: 
                   1639:            if (sigaction(SIGPIPE, &action, &registre) != 0)
                   1640:            {
                   1641:                (*s_etat_processus).erreur_systeme = d_es_signal;
                   1642:                return;
                   1643:            }
                   1644: 
1.51      bertrand 1645: #          ifndef SEMAPHORES_NOMMES
                   1646:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1647: #          else
                   1648:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1649: #          endif
1.33      bertrand 1650:            {
                   1651:                if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1652:                {
                   1653:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                   1654:                    return;
                   1655:                }
                   1656: 
                   1657:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1658:                return;
                   1659:            }
1.1       bertrand 1660: 
1.33      bertrand 1661:            if (send((*((struct_socket *) (*s_objet_argument_1).objet))
                   1662:                    .socket, chaine, longueur_effective, 0) < 0)
                   1663:            {
                   1664:                ios = errno;
1.1       bertrand 1665: 
1.33      bertrand 1666:                if (sigaction(SIGPIPE, &registre, NULL) != 0)
1.1       bertrand 1667:                {
                   1668:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                   1669:                    return;
                   1670:                }
                   1671: 
1.51      bertrand 1672: #              ifndef SEMAPHORES_NOMMES
                   1673:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1674: #              else
                   1675:                    while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1676: #              endif
1.1       bertrand 1677:                {
1.50      bertrand 1678:                    if (errno != EINTR)
                   1679:                    {
                   1680:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1681:                        return;
                   1682:                    }
1.33      bertrand 1683:                }
1.1       bertrand 1684: 
1.33      bertrand 1685:                if ((ios == EPIPE) || (ios == ECONNRESET))
                   1686:                {
                   1687:                    (*s_etat_processus).erreur_execution =
                   1688:                            d_ex_erreur_acces_fichier;
1.1       bertrand 1689:                    return;
                   1690:                }
                   1691: 
1.33      bertrand 1692:                (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   1693:                return;
                   1694:            }
                   1695: 
1.51      bertrand 1696: #          ifndef SEMAPHORES_NOMMES
                   1697:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1698: #          else
                   1699:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1700: #          endif
1.33      bertrand 1701:            {
                   1702:                if (errno != EINTR)
1.1       bertrand 1703:                {
                   1704:                    if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1705:                    {
                   1706:                        (*s_etat_processus).erreur_systeme = d_es_signal;
                   1707:                        return;
                   1708:                    }
                   1709: 
1.33      bertrand 1710:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1711:                    return;
                   1712:                }
                   1713:            }
                   1714: 
                   1715:            if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1716:            {
                   1717:                (*s_etat_processus).erreur_systeme = d_es_signal;
                   1718:                return;
                   1719:            }
                   1720:        }
                   1721:        else
                   1722:        { // Sockets non connectées
                   1723: 
                   1724:            /*
                   1725:             * Vérification de l'adresse distante
                   1726:             */
                   1727: 
                   1728:            if (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
                   1729:                    .adresse_distante, "") == 0)
                   1730:            {
                   1731:                liberation(s_etat_processus, s_objet_argument_1);
                   1732:                liberation(s_etat_processus, s_objet_argument_2);
                   1733: 
                   1734:                (*s_etat_processus).erreur_execution =
                   1735:                        d_ex_erreur_acces_fichier;
                   1736:                return;
                   1737:            }
                   1738: 
                   1739:            /*
                   1740:             * Création de l'adresse logique
                   1741:             */
                   1742: 
                   1743:            if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1744:                    .domaine == PF_UNIX)
                   1745:            {
                   1746:                adresse_unix.sun_family = AF_UNIX;
                   1747:                strncpy(adresse_unix.sun_path, (*((struct_socket *)
                   1748:                        (*s_objet_argument_1).objet)).adresse_distante,
                   1749:                        UNIX_PATH_MAX);
                   1750:                adresse_unix.sun_path[UNIX_PATH_MAX - 1] =
                   1751:                        d_code_fin_chaine;
                   1752: 
1.51      bertrand 1753: #              ifndef SEMAPHORES_NOMMES
                   1754:                    if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1755: #              else
                   1756:                    if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1757: #              endif
1.33      bertrand 1758:                {
                   1759:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1760:                    return;
                   1761:                }
                   1762: 
                   1763:                if (sendto((*((struct_socket *)
                   1764:                        (*s_objet_argument_1).objet)).socket, chaine,
                   1765:                        longueur_effective, 0, (struct sockaddr *)
                   1766:                        &adresse_unix, sizeof(adresse_unix)) < 0)
                   1767:                {
1.38      bertrand 1768:                    ios = errno;
                   1769: 
1.51      bertrand 1770: #                  ifndef SEMAPHORES_NOMMES
                   1771:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   1772:                                != 0)
                   1773: #                  else
                   1774:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1775: #                  endif
1.1       bertrand 1776:                    {
1.50      bertrand 1777:                        if (errno != EINTR)
                   1778:                        {
                   1779:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1780:                            return;
                   1781:                        }
1.1       bertrand 1782:                    }
                   1783: 
1.34      bertrand 1784:                    if ((ios == EPIPE) || (ios == ECONNRESET))
                   1785:                    {
                   1786:                        (*s_etat_processus).erreur_execution =
                   1787:                                d_ex_erreur_acces_fichier;
                   1788:                        return;
                   1789:                    }
                   1790: 
1.73      bertrand 1791:                    if (ios == EMSGSIZE)
                   1792:                    {
                   1793:                        (*s_etat_processus).erreur_execution =
                   1794:                                d_ex_taille_message;
1.74      bertrand 1795:                        return;
1.73      bertrand 1796:                    }
1.34      bertrand 1797: 
                   1798:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.1       bertrand 1799:                    return;
                   1800:                }
                   1801: 
1.51      bertrand 1802: #              ifndef SEMAPHORES_NOMMES
                   1803:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1804: #              else
                   1805:                    while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1806: #              endif
1.1       bertrand 1807:                {
1.50      bertrand 1808:                    if (errno != EINTR)
                   1809:                    {
                   1810:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1811:                        return;
                   1812:                    }
1.1       bertrand 1813:                }
                   1814:            }
1.33      bertrand 1815:            else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1816:                    .domaine == PF_INET)
                   1817:            {
                   1818:                if (sscanf((*((struct_socket *)
                   1819:                        (*s_objet_argument_1).objet))
                   1820:                        .adresse_distante, "%d.%d.%d.%d(%d)",
                   1821:                        &(adresse[0]), &(adresse[1]), &(adresse[2]),
                   1822:                        &(adresse[3]), &port) == 5)
                   1823:                { // Adresse IPv4
                   1824:                    calcul_adresse = 0;
                   1825:                    for(i = 0; i < 4; calcul_adresse =
                   1826:                            (256 * calcul_adresse) + adresse[i++]);
                   1827: 
                   1828:                    memset(&adresse_ipv4, 0, sizeof(adresse_ipv4));
                   1829:                    adresse_ipv4.sin_family = AF_INET;
                   1830:                    adresse_ipv4.sin_port = htons(port);
                   1831:                    adresse_ipv4.sin_addr.s_addr = htonl(calcul_adresse);
1.1       bertrand 1832: 
1.51      bertrand 1833: #                  ifndef SEMAPHORES_NOMMES
                   1834:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   1835:                                != 0)
                   1836: #                  else
                   1837:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1838: #                  endif
1.1       bertrand 1839:                    {
                   1840:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1841:                        return;
                   1842:                    }
                   1843: 
                   1844:                    if (sendto((*((struct_socket *)
                   1845:                            (*s_objet_argument_1).objet)).socket, chaine,
1.33      bertrand 1846:                            longueur_effective, 0, (struct sockaddr *)
                   1847:                            &adresse_ipv4, sizeof(adresse_ipv4)) < 0)
1.1       bertrand 1848:                    {
1.74      bertrand 1849:                        ios = errno;
                   1850: 
1.51      bertrand 1851: #                      ifndef SEMAPHORES_NOMMES
                   1852:                            while(sem_wait(&((*s_etat_processus)
                   1853:                                    .semaphore_fork)) != 0)
                   1854: #                      else
                   1855:                            while(sem_wait((*s_etat_processus)
                   1856:                                    .semaphore_fork) != 0)
                   1857: #                      endif
1.1       bertrand 1858:                        {
1.50      bertrand 1859:                            if (errno != EINTR)
                   1860:                            {
                   1861:                                (*s_etat_processus).erreur_systeme =
                   1862:                                        d_es_processus;
                   1863:                                return;
                   1864:                            }
1.1       bertrand 1865:                        }
                   1866: 
1.74      bertrand 1867:                        if ((ios == EPIPE) || (ios == ECONNRESET))
                   1868:                        {
                   1869:                            (*s_etat_processus).erreur_execution =
                   1870:                                    d_ex_erreur_acces_fichier;
                   1871:                            return;
                   1872:                        }
                   1873: 
                   1874:                        if (ios == EMSGSIZE)
                   1875:                        {
                   1876:                            (*s_etat_processus).erreur_execution =
                   1877:                                    d_ex_taille_message;
                   1878:                            return;
                   1879:                        }
                   1880: 
1.1       bertrand 1881:                        (*s_etat_processus).erreur_systeme =
                   1882:                                d_es_erreur_fichier;
                   1883:                        return;
                   1884:                    }
                   1885: 
1.51      bertrand 1886: #                  ifndef SEMAPHORES_NOMMES
                   1887:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   1888:                                != 0)
                   1889: #                  else
                   1890:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1891: #                  endif
1.1       bertrand 1892:                    {
1.50      bertrand 1893:                        if (errno != EINTR)
                   1894:                        {
                   1895:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1896:                            return;
                   1897:                        }
1.1       bertrand 1898:                    }
                   1899:                }
1.33      bertrand 1900:                else
1.1       bertrand 1901:                {
1.33      bertrand 1902:                    liberation(s_etat_processus, s_objet_argument_1);
                   1903:                    liberation(s_etat_processus, s_objet_argument_2);
1.1       bertrand 1904: 
1.33      bertrand 1905:                    (*s_etat_processus).erreur_execution =
                   1906:                            d_ex_erreur_parametre_fichier;
                   1907:                    return;
                   1908:                }
                   1909:            }
                   1910:            else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1911:                    .domaine == PF_INET6)
                   1912:            {
                   1913:                if (sscanf((*((struct_socket *) (*s_objet_argument_1)
                   1914:                        .objet)).adresse_distante, "%X:%X:%X:%X:%X:"
                   1915:                        "%X:%X:%X:%X:%X:%X:%X:%X:%X:%X:%X(%d)",
                   1916:                        &(adresse[0]), &(adresse[1]), &(adresse[2]),
                   1917:                        &(adresse[3]), &(adresse[4]), &(adresse[5]),
                   1918:                        &(adresse[6]), &(adresse[7]), &(adresse[8]),
                   1919:                        &(adresse[9]), &(adresse[10]), &(adresse[11]),
                   1920:                        &(adresse[12]), &(adresse[13]), &(adresse[14]),
                   1921:                        &(adresse[15]), &port)== 17)
                   1922:                { // Adresse IPv6
                   1923: #                  ifdef IPV6
                   1924:                    memset(&adresse_ipv6, 0, sizeof(adresse_ipv6));
                   1925:                    adresse_ipv6.sin6_family = AF_INET6;
                   1926:                    adresse_ipv6.sin6_port = htons((uint16_t) port);
                   1927: 
                   1928:                    for(i = 0; i < 16;
                   1929:                            adresse_ipv6.sin6_addr.s6_addr[i] =
                   1930:                            adresse[i], i++);
1.1       bertrand 1931: 
1.51      bertrand 1932: #                  ifndef SEMAPHORES_NOMMES
                   1933:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   1934:                                != 0)
                   1935: #                  else
                   1936:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1937: #                  endif
1.33      bertrand 1938:                    {
                   1939:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1940:                        return;
                   1941:                    }
1.1       bertrand 1942: 
1.33      bertrand 1943:                    if (sendto((*((struct_socket *)
                   1944:                            (*s_objet_argument_1).objet)).socket, chaine,
                   1945:                            longueur_effective, 0, (struct sockaddr *)
                   1946:                            &adresse_ipv6, sizeof(adresse_ipv6)) < 0)
                   1947:                    {
1.74      bertrand 1948:                        ios = errno;
                   1949: 
1.51      bertrand 1950: #                      ifndef SEMAPHORES_NOMMES
                   1951:                            while(sem_wait(&((*s_etat_processus)
                   1952:                                    .semaphore_fork)) != 0)
                   1953: #                      else
                   1954:                            while(sem_wait((*s_etat_processus)
                   1955:                                    .semaphore_fork) != 0)
                   1956: #                      endif
1.1       bertrand 1957:                        {
1.50      bertrand 1958:                            if (errno != EINTR)
                   1959:                            {
                   1960:                                (*s_etat_processus).erreur_systeme =
                   1961:                                        d_es_processus;
                   1962:                                return;
                   1963:                            }
1.1       bertrand 1964:                        }
                   1965: 
1.74      bertrand 1966:                        if ((ios == EPIPE) || (ios == ECONNRESET))
                   1967:                        {
                   1968:                            (*s_etat_processus).erreur_execution =
                   1969:                                    d_ex_erreur_acces_fichier;
                   1970:                            return;
                   1971:                        }
                   1972: 
                   1973:                        if (ios == EMSGSIZE)
                   1974:                        {
                   1975:                            (*s_etat_processus).erreur_execution =
                   1976:                                    d_ex_taille_message;
                   1977:                            return;
                   1978:                        }
                   1979: 
1.33      bertrand 1980:                        (*s_etat_processus).erreur_systeme =
                   1981:                                d_es_erreur_fichier;
1.1       bertrand 1982:                        return;
                   1983:                    }
                   1984: 
1.51      bertrand 1985: #                  ifndef SEMAPHORES_NOMMES
                   1986:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   1987:                                != 0)
                   1988: #                  else
                   1989:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1990: #                  endif
1.33      bertrand 1991:                    {
1.50      bertrand 1992:                        if (errno != EINTR)
                   1993:                        {
                   1994:                            (*s_etat_processus).erreur_systeme =
                   1995:                                    d_es_processus;
                   1996:                            return;
                   1997:                        }
1.33      bertrand 1998:                    }
                   1999: #                  else
                   2000:                    if ((*s_etat_processus).langue == 'F')
                   2001:                    {
                   2002:                        printf("+++Attention : Support du protocole"
                   2003:                                " IPv6 indisponible\n");
1.1       bertrand 2004:                    }
                   2005:                    else
                   2006:                    {
1.33      bertrand 2007:                        printf("+++Warning : IPv6 support "
                   2008:                                "unavailable\n");
1.1       bertrand 2009:                    }
1.33      bertrand 2010: #                  endif
1.1       bertrand 2011:                }
1.33      bertrand 2012:                else
1.1       bertrand 2013:                {
                   2014:                    liberation(s_etat_processus, s_objet_argument_1);
                   2015:                    liberation(s_etat_processus, s_objet_argument_2);
                   2016: 
                   2017:                    (*s_etat_processus).erreur_execution =
                   2018:                            d_ex_erreur_parametre_fichier;
                   2019:                    return;
                   2020:                }
                   2021:            }
1.33      bertrand 2022:            else 
                   2023:            {
                   2024:                liberation(s_etat_processus, s_objet_argument_1);
                   2025:                liberation(s_etat_processus, s_objet_argument_2);
1.1       bertrand 2026: 
1.33      bertrand 2027:                (*s_etat_processus).erreur_execution =
                   2028:                        d_ex_erreur_parametre_fichier;
                   2029:                return;
                   2030:            }
1.1       bertrand 2031:        }
1.33      bertrand 2032: 
                   2033:        free(chaine);
1.1       bertrand 2034:    }
                   2035:    else
                   2036:    {
                   2037:        liberation(s_etat_processus, s_objet_argument_2);
                   2038:        liberation(s_etat_processus, s_objet_argument_1);
                   2039: 
                   2040:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2041:        return;
                   2042:    }
                   2043: 
                   2044:    liberation(s_etat_processus, s_objet_argument_2);
                   2045:    liberation(s_etat_processus, s_objet_argument_1);
                   2046: 
                   2047:    return;
                   2048: }
                   2049: 
                   2050: 
                   2051: /*
                   2052: ================================================================================
                   2053:   Fonction 'wflock'
                   2054: ================================================================================
                   2055:   Entrées : pointeur sur une structure struct_processus
                   2056: --------------------------------------------------------------------------------
                   2057:   Sorties :
                   2058: --------------------------------------------------------------------------------
                   2059:   Effets de bord : néant
                   2060: ================================================================================
                   2061: */
                   2062: 
                   2063: void
                   2064: instruction_wflock(struct_processus *s_etat_processus)
                   2065: {
                   2066:    logical1                    drapeau;
                   2067: 
                   2068:    struct flock                lock;
                   2069: 
                   2070:    struct timespec             attente;
                   2071: 
1.5       bertrand 2072:    struct_descripteur_fichier  *descripteur;
                   2073: 
1.1       bertrand 2074:    struct_objet                *s_objet_argument_1;
                   2075:    struct_objet                *s_objet_argument_2;
                   2076: 
                   2077:    unsigned char               *chaine;
                   2078:    unsigned char               registre_instruction_valide;
                   2079: 
                   2080:    attente.tv_sec = 0;
                   2081:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2082: 
                   2083:    (*s_etat_processus).erreur_execution = d_ex;
                   2084: 
                   2085:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2086:    {
                   2087:        printf("\n  WFLOCK ");
                   2088:        
                   2089:        if ((*s_etat_processus).langue == 'F')
                   2090:        {
                   2091:            printf("(attente du positionnement d'un verrou sur un fichier)"
                   2092:                    "\n\n");
                   2093:        }
                   2094:        else
                   2095:        {
                   2096:            printf("(wait for file lock)\n\n");
                   2097:        }
                   2098: 
                   2099:        printf("    2: %s\n", d_FCH);
                   2100:        printf("    1: %s (READ/WRITE/NONE)\n", d_CHN);
                   2101: 
                   2102:        return;
                   2103:    }
                   2104:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2105:    {
                   2106:        (*s_etat_processus).nombre_arguments = -1;
                   2107:        return;
                   2108:    }
                   2109: 
                   2110:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2111:    {
                   2112:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                   2113:        {
                   2114:            return;
                   2115:        }
                   2116:    }
                   2117: 
                   2118:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2119:            &s_objet_argument_1) == d_erreur)
                   2120:    {
                   2121:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2122:        return;
                   2123:    }
                   2124: 
                   2125:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2126:            &s_objet_argument_2) == d_erreur)
                   2127:    {
                   2128:        liberation(s_etat_processus, s_objet_argument_1);
                   2129: 
                   2130:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2131:        return;
                   2132:    }
                   2133: 
                   2134:    if (((*s_objet_argument_2).type == FCH) &&
                   2135:            ((*s_objet_argument_1).type == CHN))
                   2136:    {
                   2137:        drapeau = d_faux;
                   2138: 
                   2139:        do
                   2140:        {
                   2141:            if ((chaine = conversion_majuscule((unsigned char *)
                   2142:                    (*s_objet_argument_1).objet)) == NULL)
                   2143:            {
                   2144:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2145:                return;
                   2146:            }
                   2147: 
                   2148:            if (strcmp(chaine, "WRITE") == 0)
                   2149:            {
                   2150:                lock.l_type = F_WRLCK;
                   2151:            }
                   2152:            else if (strcmp(chaine, "READ") == 0)
                   2153:            {
                   2154:                lock.l_type = F_RDLCK;
                   2155:            }
                   2156:            else if (strcmp(chaine, "NONE") == 0)
                   2157:            {
                   2158:                lock.l_type = F_UNLCK;
                   2159:            }
                   2160:            else
                   2161:            {
                   2162:                free(chaine);
                   2163: 
                   2164:                liberation(s_etat_processus, s_objet_argument_1);
                   2165:                liberation(s_etat_processus, s_objet_argument_2);
                   2166: 
                   2167:                (*s_etat_processus).erreur_execution = d_ex_verrou_indefini;
                   2168:                return;
                   2169:            }
                   2170: 
                   2171:            free(chaine);
                   2172: 
                   2173:            lock.l_whence = SEEK_SET;
                   2174:            lock.l_start = 0;
                   2175:            lock.l_len = 0;
                   2176:            lock.l_pid = getpid();
                   2177: 
                   2178:            if ((descripteur = descripteur_fichier(s_etat_processus,
                   2179:                    (struct_fichier *) (*s_objet_argument_2).objet)) == NULL)
                   2180:            {
                   2181:                return;
                   2182:            }
                   2183: 
1.5       bertrand 2184:            if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
                   2185:                    == -1)
1.1       bertrand 2186:            {
                   2187:                liberation(s_etat_processus, s_objet_argument_1);
                   2188:                liberation(s_etat_processus, s_objet_argument_2);
                   2189: 
                   2190:                (*s_etat_processus).erreur_execution = d_ex_fichier_verrouille;
                   2191:                return;
                   2192:            }
                   2193: 
1.51      bertrand 2194: #          ifndef SEMAPHORES_NOMMES
                   2195:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2196: #          else
                   2197:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2198: #          endif
1.1       bertrand 2199:            {
                   2200:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   2201:                return;
                   2202:            }
1.47      bertrand 2203: 
1.51      bertrand 2204: #          ifndef SEMAPHORES_NOMMES
                   2205:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   2206: #          else
                   2207:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   2208: #          endif
1.12      bertrand 2209:            {
1.50      bertrand 2210:                if (errno != EINTR)
                   2211:                {
                   2212:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2213:                    return;
                   2214:                }
1.12      bertrand 2215:            }
1.1       bertrand 2216: 
                   2217:            if (lock.l_type == F_UNLCK)
                   2218:            {
                   2219:                drapeau = d_vrai;
                   2220:            }
                   2221:            else
                   2222:            {
                   2223:                if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   2224:                {
                   2225:                    affectation_interruptions_logicielles(s_etat_processus);
                   2226:                }
                   2227: 
                   2228:                if ((*s_etat_processus).nombre_interruptions_en_queue
                   2229:                        != 0)
                   2230:                {
                   2231:                    registre_instruction_valide =
                   2232:                            (*s_etat_processus).instruction_valide;
                   2233:                    traitement_interruptions_logicielles(
                   2234:                            s_etat_processus);
                   2235:                    (*s_etat_processus).instruction_valide =
                   2236:                            registre_instruction_valide;
                   2237:                }
                   2238: 
                   2239:                nanosleep(&attente, NULL);
                   2240:                scrutation_injection(s_etat_processus);
                   2241: 
                   2242:                INCR_GRANULARITE(attente.tv_nsec);
                   2243:            }
                   2244:        } while((drapeau == d_faux) && ((*s_etat_processus)
                   2245:                .var_volatile_requete_arret != -1));
                   2246:    }
                   2247:    else
                   2248:    {
                   2249:        liberation(s_etat_processus, s_objet_argument_1);
                   2250:        liberation(s_etat_processus, s_objet_argument_2);
                   2251: 
                   2252:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2253:        return;
                   2254:    }
                   2255: 
                   2256:    return;
                   2257: }
                   2258: 
                   2259: 
                   2260: /*
                   2261: ================================================================================
                   2262:   Fonction 'wfproc'
                   2263: ================================================================================
                   2264:   Entrées : pointeur sur une structure struct_processus
                   2265: --------------------------------------------------------------------------------
                   2266:   Sorties :
                   2267: --------------------------------------------------------------------------------
                   2268:   Effets de bord : néant
                   2269: ================================================================================
                   2270: */
                   2271: 
                   2272: void
                   2273: instruction_wfproc(struct_processus *s_etat_processus)
                   2274: {
                   2275:    logical1                    drapeau_fin;
                   2276: 
                   2277:    struct_liste_chainee        *l_element_courant;
                   2278: 
                   2279:    struct_objet                *s_objet_argument;
                   2280: 
                   2281:    struct timespec             attente;
                   2282: 
                   2283:    unsigned char               registre_instruction_valide;
                   2284: 
                   2285:    (*s_etat_processus).erreur_execution = d_ex;
                   2286: 
                   2287:    attente.tv_sec = 0;
                   2288:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2289: 
                   2290:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2291:    {
                   2292:        printf("\n  WFPROC ");
                   2293: 
                   2294:        if ((*s_etat_processus).langue == 'F')
                   2295:        {
                   2296:            printf("(attente de la fin d'un processus fils)\n\n");
                   2297:        }
                   2298:        else
                   2299:        {
                   2300:            printf("(wait for child process end)\n\n");
                   2301:        }
                   2302: 
                   2303:        printf("    1: %s\n", d_PRC);
                   2304: 
                   2305:        return;
                   2306:    }
                   2307:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2308:    {
                   2309:        (*s_etat_processus).nombre_arguments = -1;
                   2310:        return;
                   2311:    }
                   2312: 
                   2313:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2314:    {
                   2315:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2316:        {
                   2317:            return;
                   2318:        }
                   2319:    }
                   2320: 
                   2321:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2322:            &s_objet_argument) == d_erreur)
                   2323:    {
                   2324:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2325:        return;
                   2326:    }
                   2327: 
                   2328:    if ((*s_objet_argument).type == PRC)
                   2329:    {
                   2330:        drapeau_fin = d_faux;
                   2331: 
                   2332:        if ((*s_etat_processus).profilage == d_vrai)
                   2333:        {
                   2334:            profilage(s_etat_processus, "Interprocess or interthread "
                   2335:                    "communications (WFPROC)");
                   2336: 
                   2337:            if ((*s_etat_processus).erreur_systeme != d_es)
                   2338:            {
                   2339:                return;
                   2340:            }
                   2341:        }
                   2342: 
                   2343:        if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   2344:        {
                   2345:            if ((*s_etat_processus).profilage == d_vrai)
                   2346:            {
                   2347:                profilage(s_etat_processus, NULL);
                   2348:            }
                   2349: 
                   2350:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2351:            return;
                   2352:        }
                   2353: 
                   2354:        while(drapeau_fin == d_faux)
                   2355:        {
                   2356:            l_element_courant = (struct_liste_chainee *)
                   2357:                    (*s_etat_processus).l_base_pile_processus;
                   2358: 
                   2359:            while(l_element_courant != NULL)
                   2360:            {
                   2361:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2362:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   2363:                {
                   2364:                    if ((*(*((struct_processus_fils *)
                   2365:                            (*s_objet_argument).objet)).thread)
                   2366:                            .processus_detache == d_vrai)
                   2367:                    {
                   2368:                        if ((*(*((struct_processus_fils *)
                   2369:                                (*(*l_element_courant)
                   2370:                                .donnee).objet)).thread).pid ==
                   2371:                                (*(*((struct_processus_fils *)
                   2372:                                (*s_objet_argument).objet)).thread).pid)
                   2373:                        {
                   2374:                            break;
                   2375:                        }
                   2376:                    }
                   2377:                }
                   2378:                else
                   2379:                {
                   2380:                    if ((*(*((struct_processus_fils *)
                   2381:                            (*s_objet_argument).objet)).thread)
                   2382:                            .processus_detache == d_faux)
                   2383:                    {
                   2384:                        if ((pthread_equal((*(*((struct_processus_fils *)
                   2385:                                (*(*l_element_courant).donnee).objet)).thread)
                   2386:                                .tid, (*(*((struct_processus_fils *)
                   2387:                                (*s_objet_argument).objet)).thread).tid) != 0)
                   2388:                                && ((*(*((struct_processus_fils *)
                   2389:                                (*(*l_element_courant).donnee).objet)).thread)
                   2390:                                .pid == (*(*((struct_processus_fils *)
                   2391:                                (*s_objet_argument).objet)).thread).pid))
                   2392:                        {
                   2393:                            break;
                   2394:                        }
                   2395:                    }
                   2396:                }
                   2397: 
                   2398:                l_element_courant = (*l_element_courant).suivant;
                   2399:            }
                   2400: 
                   2401:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2402:            {
                   2403:                if ((*s_etat_processus).profilage == d_vrai)
                   2404:                {
                   2405:                    profilage(s_etat_processus, NULL);
                   2406:                }
                   2407: 
                   2408:                if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2409:                {
                   2410:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2411:                    return;
                   2412:                }
                   2413: 
                   2414:                liberation(s_etat_processus, s_objet_argument);
                   2415:                return;
                   2416:            }
                   2417: 
                   2418:            if (l_element_courant == NULL)
                   2419:            {
                   2420:                /*
                   2421:                 * Si l_element_courant vaut NULL, le processus n'existe plus.
                   2422:                 */
                   2423: 
                   2424:                drapeau_fin = d_vrai;
                   2425:            }
                   2426:            else
                   2427:            {
                   2428:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2429:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   2430:                {
1.48      bertrand 2431:                    if (envoi_signal_processus((*(*((struct_processus_fils *)
1.1       bertrand 2432:                            (*(*l_element_courant).donnee).objet)).thread).pid,
1.48      bertrand 2433:                            rpl_signull) != 0)
1.1       bertrand 2434:                    {
                   2435:                        drapeau_fin = d_vrai;
                   2436:                    }
                   2437:                    else
                   2438:                    {
                   2439:                        drapeau_fin = d_faux;
                   2440:                    }
                   2441:                }
                   2442:                else
                   2443:                {
                   2444:                    if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
                   2445:                            (*(*l_element_courant).donnee).objet)).thread)
                   2446:                            .mutex)) != 0)
                   2447:                    {
                   2448:                        if ((*s_etat_processus).profilage == d_vrai)
                   2449:                        {
                   2450:                            profilage(s_etat_processus, NULL);
                   2451:                        }
                   2452: 
                   2453:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2454:                        return;
                   2455:                    }
                   2456: 
                   2457:                    if ((*(*((struct_processus_fils *)
                   2458:                            (*(*l_element_courant).donnee).objet)).thread)
                   2459:                            .thread_actif == d_faux)
                   2460:                    {
                   2461:                        drapeau_fin = d_vrai;
                   2462:                    }
                   2463:                    else
                   2464:                    {
                   2465:                        drapeau_fin = d_faux;
                   2466:                    }
                   2467: 
                   2468:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2469:                            (*(*l_element_courant).donnee).objet)).thread)
                   2470:                            .mutex)) != 0)
                   2471:                    {
                   2472:                        if ((*s_etat_processus).profilage == d_vrai)
                   2473:                        {
                   2474:                            profilage(s_etat_processus, NULL);
                   2475:                        }
                   2476: 
                   2477:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2478:                        return;
                   2479:                    }
                   2480:                }
                   2481: 
                   2482:                if (drapeau_fin == d_faux)
                   2483:                {
                   2484:                    /*
                   2485:                     * Le processus n'est pas terminé
                   2486:                     */
                   2487: 
                   2488:                    if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2489:                    {
                   2490:                        if ((*s_etat_processus).profilage == d_vrai)
                   2491:                        {
                   2492:                            profilage(s_etat_processus, NULL);
                   2493:                        }
                   2494: 
                   2495:                        (*s_etat_processus).erreur_systeme =
                   2496:                                d_es_processus;
                   2497:                        return;
                   2498:                    }
                   2499: 
                   2500:                    if ((*s_etat_processus).nombre_interruptions_non_affectees
                   2501:                            != 0)
                   2502:                    {
                   2503:                        affectation_interruptions_logicielles(s_etat_processus);
                   2504:                    }
                   2505: 
                   2506:                    if ((*s_etat_processus).nombre_interruptions_en_queue
                   2507:                            != 0)
                   2508:                    {
                   2509:                        registre_instruction_valide =
                   2510:                                (*s_etat_processus).instruction_valide;
                   2511:                        traitement_interruptions_logicielles(
                   2512:                                s_etat_processus);
                   2513:                        (*s_etat_processus).instruction_valide =
                   2514:                                registre_instruction_valide;
                   2515:                    }
                   2516: 
1.51      bertrand 2517: #                  ifndef SEMAPHORES_NOMMES
                   2518:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   2519:                                != 0)
                   2520: #                  else
                   2521:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2522: #                  endif
1.1       bertrand 2523:                    {
                   2524:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2525:                        return;
                   2526:                    }
                   2527: 
                   2528:                    nanosleep(&attente, NULL);
                   2529: 
1.51      bertrand 2530: #                  ifndef SEMAPHORES_NOMMES
                   2531:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   2532:                                != 0)
                   2533: #                  else
                   2534:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   2535: #                  endif
1.1       bertrand 2536:                    {
1.50      bertrand 2537:                        if (errno != EINTR)
                   2538:                        {
                   2539:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2540:                            return;
                   2541:                        }
1.1       bertrand 2542:                    }
                   2543: 
                   2544:                    scrutation_injection(s_etat_processus);
                   2545: 
                   2546:                    if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   2547:                    {
                   2548:                        if ((*s_etat_processus).profilage == d_vrai)
                   2549:                        {
                   2550:                            profilage(s_etat_processus, NULL);
                   2551:                        }
                   2552: 
                   2553:                        (*s_etat_processus).erreur_systeme =
                   2554:                                d_es_processus;
                   2555:                        return;
                   2556:                    }
                   2557:                }
                   2558:            }
                   2559: 
                   2560:            INCR_GRANULARITE(attente.tv_nsec);
                   2561:        }
                   2562: 
                   2563:        if ((*s_etat_processus).profilage == d_vrai)
                   2564:        {
                   2565:            profilage(s_etat_processus, NULL);
                   2566:        }
                   2567: 
                   2568:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2569:        {
                   2570:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2571:            return;
                   2572:        }
                   2573:    }
                   2574:    else
                   2575:    {
                   2576:        liberation(s_etat_processus, s_objet_argument);
                   2577: 
                   2578:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2579:        return;
                   2580:    }
                   2581: 
                   2582:    liberation(s_etat_processus, s_objet_argument);
                   2583: 
                   2584:    return;
                   2585: }
                   2586: 
                   2587: 
                   2588: /*
                   2589: ================================================================================
                   2590:   Fonction 'wfdata'
                   2591: ================================================================================
                   2592:   Entrées : pointeur sur une structure struct_processus
                   2593: --------------------------------------------------------------------------------
                   2594:   Sorties :
                   2595: --------------------------------------------------------------------------------
                   2596:   Effets de bord : néant
                   2597: ================================================================================
                   2598: */
                   2599: 
                   2600: void
                   2601: instruction_wfdata(struct_processus *s_etat_processus)
                   2602: {
                   2603:    logical1                    drapeau_fin;
                   2604: 
                   2605:    struct_liste_chainee        *l_element_courant;
                   2606: 
                   2607:    struct_objet                *s_objet_argument;
                   2608: 
                   2609:    struct timespec             attente;
                   2610: 
                   2611:    unsigned char               registre_instruction_valide;
                   2612: 
                   2613:    (*s_etat_processus).erreur_execution = d_ex;
                   2614: 
                   2615:    attente.tv_sec = 0;
                   2616:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2617: 
                   2618:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2619:    {
                   2620:        printf("\n  WFDATA ");
                   2621: 
                   2622:        if ((*s_etat_processus).langue == 'F')
                   2623:        {
                   2624:            printf("(attente de données d'un processus fils)\n\n");
                   2625:        }
                   2626:        else
                   2627:        {
                   2628:            printf("(wait for data from child process)\n\n");
                   2629:        }
                   2630: 
                   2631:        printf("    1: %s\n", d_PRC);
                   2632: 
                   2633:        return;
                   2634:    }
                   2635:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2636:    {
                   2637:        (*s_etat_processus).nombre_arguments = -1;
                   2638:        return;
                   2639:    }
                   2640: 
                   2641:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2642:    {
                   2643:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2644:        {
                   2645:            return;
                   2646:        }
                   2647:    }
                   2648: 
                   2649:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2650:            &s_objet_argument) == d_erreur)
                   2651:    {
                   2652:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2653:        return;
                   2654:    }
                   2655: 
                   2656:    if ((*s_objet_argument).type == PRC)
                   2657:    {
                   2658:        drapeau_fin = d_faux;
                   2659: 
                   2660:        if ((*s_etat_processus).profilage == d_vrai)
                   2661:        {
                   2662:            profilage(s_etat_processus, "Interprocess or interthread "
                   2663:                    "communications (WFDATA)");
                   2664: 
                   2665:            if ((*s_etat_processus).erreur_systeme != d_es)
                   2666:            {
                   2667:                return;
                   2668:            }
                   2669:        }
                   2670: 
                   2671:        if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   2672:        {
                   2673:            if ((*s_etat_processus).profilage == d_vrai)
                   2674:            {
                   2675:                profilage(s_etat_processus, NULL);
                   2676:            }
                   2677: 
                   2678:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2679:            return;
                   2680:        }
                   2681: 
                   2682:        while(drapeau_fin == d_faux)
                   2683:        {
                   2684:            l_element_courant = (struct_liste_chainee *)
                   2685:                    (*s_etat_processus).l_base_pile_processus;
                   2686: 
                   2687:            while(l_element_courant != NULL)
                   2688:            {
                   2689:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2690:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   2691:                {
                   2692:                    if (((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2693:                            .donnee).objet)).thread).pid ==
                   2694:                            (*(*((struct_processus_fils *)
                   2695:                            (*s_objet_argument).objet)).thread).pid)
                   2696:                            && ((*(*((struct_processus_fils *)
                   2697:                            (*s_objet_argument).objet)).thread)
                   2698:                            .processus_detache == d_vrai))
                   2699:                    {
                   2700:                        break;
                   2701:                    }
                   2702:                }
                   2703:                else
                   2704:                {
                   2705:                    if ((pthread_equal((*(*((struct_processus_fils *)
                   2706:                            (*(*l_element_courant).donnee).objet)).thread).tid,
                   2707:                            (*(*((struct_processus_fils *) (*s_objet_argument)
                   2708:                            .objet)).thread).tid) != 0) &&
                   2709:                            ((*(*((struct_processus_fils *)
                   2710:                            (*(*l_element_courant).donnee).objet)).thread).pid
                   2711:                            == (*(*((struct_processus_fils *)
                   2712:                            (*s_objet_argument).objet)).thread).pid) &&
                   2713:                            ((*(*((struct_processus_fils *)
                   2714:                            (*s_objet_argument).objet)).thread)
                   2715:                            .processus_detache == d_faux))
                   2716:                    {
                   2717:                        break;
                   2718:                    }
                   2719:                }
                   2720: 
                   2721:                l_element_courant = (*l_element_courant).suivant;
                   2722:            }
                   2723: 
                   2724:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2725:            {
                   2726:                if ((*s_etat_processus).profilage == d_vrai)
                   2727:                {
                   2728:                    profilage(s_etat_processus, NULL);
                   2729:                }
                   2730: 
                   2731:                if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2732:                {
                   2733:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2734:                    return;
                   2735:                }
                   2736: 
                   2737:                liberation(s_etat_processus, s_objet_argument);
                   2738:                return;
                   2739:            }
                   2740: 
                   2741:            if (l_element_courant != NULL)
                   2742:            {
                   2743:                if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
                   2744:                        (*(*l_element_courant).donnee).objet)).thread).mutex))
                   2745:                        != 0)
                   2746:                {
                   2747:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2748:                    return;
                   2749:                }
                   2750: 
                   2751:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2752:                        .donnee).objet)).thread).nombre_objets_dans_pipe != 0)
                   2753:                {
                   2754:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2755:                            (*(*l_element_courant).donnee).objet)).thread)
                   2756:                            .mutex)) != 0)
                   2757:                    {
                   2758:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2759:                        return;
                   2760:                    }
                   2761: 
                   2762:                    drapeau_fin = d_vrai;
                   2763:                }
                   2764:                else
                   2765:                {
                   2766:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2767:                            (*(*l_element_courant).donnee).objet)).thread)
                   2768:                            .mutex)) != 0)
                   2769:                    {
                   2770:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2771:                        return;
                   2772:                    }
                   2773: 
                   2774:                    if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2775:                    {
                   2776:                        if ((*s_etat_processus).profilage == d_vrai)
                   2777:                        {
                   2778:                            profilage(s_etat_processus, NULL);
                   2779:                        }
                   2780: 
                   2781:                        (*s_etat_processus).erreur_systeme =
                   2782:                                d_es_processus;
                   2783:                        return;
                   2784:                    }
                   2785: 
1.51      bertrand 2786: #                  ifndef SEMAPHORES_NOMMES
                   2787:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   2788:                                != 0)
                   2789: #                  else
                   2790:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2791: #                  endif
1.12      bertrand 2792:                    {
                   2793:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2794:                        return;
                   2795:                    }
1.1       bertrand 2796: 
                   2797:                    nanosleep(&attente, NULL);
                   2798: 
1.51      bertrand 2799: #                  ifndef SEMAPHORES_NOMMES
                   2800:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   2801:                                != 0)
                   2802: #                  else
                   2803:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   2804: #                  endif
1.1       bertrand 2805:                    {
1.50      bertrand 2806:                        if (errno != EINTR)
                   2807:                        {
                   2808:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2809:                            return;
                   2810:                        }
1.1       bertrand 2811:                    }
                   2812: 
                   2813:                    scrutation_injection(s_etat_processus);
                   2814: 
                   2815:                    if ((*s_etat_processus).nombre_interruptions_non_affectees
                   2816:                            != 0)
                   2817:                    {
                   2818:                        affectation_interruptions_logicielles(s_etat_processus);
                   2819:                    }
                   2820: 
                   2821:                    if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   2822:                    {
                   2823:                        registre_instruction_valide =
                   2824:                                (*s_etat_processus).instruction_valide;
                   2825:                        traitement_interruptions_logicielles(s_etat_processus);
                   2826:                        (*s_etat_processus).instruction_valide =
                   2827:                                registre_instruction_valide;
                   2828:                    }
                   2829: 
                   2830:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2831:                    {
                   2832:                        if ((*s_etat_processus).profilage == d_vrai)
                   2833:                        {
                   2834:                            profilage(s_etat_processus, NULL);
                   2835:                        }
                   2836: 
                   2837:                        return;
                   2838:                    }
                   2839: 
                   2840:                    if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   2841:                    {
                   2842:                        if ((*s_etat_processus).profilage == d_vrai)
                   2843:                        {
                   2844:                            profilage(s_etat_processus, NULL);
                   2845:                        }
                   2846: 
                   2847:                        (*s_etat_processus).erreur_systeme =
                   2848:                                d_es_processus;
                   2849:                        return;
                   2850:                    }
                   2851:                }
                   2852:            }
                   2853:            else
                   2854:            {
                   2855:                drapeau_fin = d_vrai;
                   2856:                (*s_etat_processus).erreur_execution = d_ex_processus;
                   2857:            }
                   2858: 
                   2859:            INCR_GRANULARITE(attente.tv_nsec);
                   2860:        }
                   2861: 
                   2862:        if ((*s_etat_processus).profilage == d_vrai)
                   2863:        {
                   2864:            profilage(s_etat_processus, NULL);
                   2865:        }
                   2866: 
                   2867:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2868:        {
                   2869:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2870:            return;
                   2871:        }
                   2872:    }
                   2873:    else
                   2874:    {
                   2875:        liberation(s_etat_processus, s_objet_argument);
                   2876: 
                   2877:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2878:        return;
                   2879:    }
                   2880: 
                   2881:    liberation(s_etat_processus, s_objet_argument);
                   2882: 
                   2883:    return;
                   2884: }
                   2885: 
                   2886: 
                   2887: /*
                   2888: ================================================================================
                   2889:   Fonction 'wfsock'
                   2890: ================================================================================
                   2891:   Entrées : pointeur sur une structure struct_processus
                   2892: --------------------------------------------------------------------------------
                   2893:   Sorties :
                   2894: --------------------------------------------------------------------------------
                   2895:   Effets de bord : néant
                   2896: ================================================================================
                   2897: */
                   2898: 
                   2899: void
                   2900: instruction_wfsock(struct_processus *s_etat_processus)
                   2901: {
                   2902:    int                     erreur;
                   2903: 
                   2904:    logical1                drapeau;
                   2905: 
                   2906:    socklen_t               longueur;
                   2907: 
                   2908:    struct_liste_chainee    *l_element_courant;
                   2909: 
                   2910:    struct_objet            *s_objet_argument;
                   2911:    struct_objet            *s_objet_resultat;
                   2912: 
1.54      bertrand 2913:    struct pollfd           s_poll;
                   2914: 
1.1       bertrand 2915:    struct sockaddr_in      adresse_ipv4;
1.20      bertrand 2916: #  ifdef IPV6
1.1       bertrand 2917:    struct sockaddr_in6     adresse_ipv6;
1.20      bertrand 2918: #  endif
1.1       bertrand 2919: 
                   2920:    unsigned long           i;
                   2921: 
                   2922:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2923:    {
                   2924:        printf("\n  WFSOCK ");
                   2925: 
                   2926:        if ((*s_etat_processus).langue == 'F')
                   2927:        {
                   2928:            printf("(attente d'une connexion sur une socket)\n\n");
                   2929:        }
                   2930:        else
                   2931:        {
                   2932:            printf("(wait for connection on a socket)\n\n");
                   2933:        }
                   2934: 
                   2935:        printf("    1: %s\n", d_SCK);
                   2936:        printf("->  2: %s\n", d_SCK);
                   2937:        printf("    1: %s\n", d_SCK);
                   2938: 
                   2939:        return;
                   2940:    }
                   2941:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2942:    {
                   2943:        (*s_etat_processus).nombre_arguments = -1;
                   2944:        return;
                   2945:    }
                   2946: 
                   2947:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2948:    {
                   2949:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2950:        {
                   2951:            return;
                   2952:        }
                   2953:    }
                   2954: 
                   2955:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2956:            &s_objet_argument) == d_erreur)
                   2957:    {
                   2958:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2959:        return;
                   2960:    }
                   2961: 
                   2962:    if ((*s_objet_argument).type == SCK)
                   2963:    {
                   2964:        if ((strcmp((*((struct_socket *) (*s_objet_argument).objet)).type,
                   2965:                "STREAM") != 0) && (strcmp((*((struct_socket *)
                   2966:                (*s_objet_argument).objet)).type, "SEQUENTIAL DATAGRAM") != 0))
                   2967:        {
1.54      bertrand 2968:            // Mode non connecté : l'attente se fait sur un poll()
                   2969: 
                   2970:            if ((s_objet_resultat = copie_objet(s_etat_processus,
                   2971:                    s_objet_argument, 'P')) == NULL)
                   2972:            {
                   2973:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2974:                return;
                   2975:            }
                   2976: 
                   2977:            s_poll.fd = (*((struct_socket *) (*s_objet_argument).objet)).socket;
                   2978:            s_poll.events = POLLIN;
                   2979:            s_poll.revents = 0;
                   2980: 
1.55      bertrand 2981:            do
1.54      bertrand 2982:            {
1.55      bertrand 2983:                drapeau = d_vrai;
                   2984: 
                   2985: #              ifndef SEMAPHORES_NOMMES
                   2986:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2987: #              else
                   2988:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2989: #              endif
                   2990:                {
                   2991:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2992:                    return;
                   2993:                }
                   2994: 
                   2995:                if (poll(&s_poll, 1, -1) < 0)
                   2996:                {
                   2997:                    erreur = errno;
                   2998: 
                   2999: #                  ifndef SEMAPHORES_NOMMES
                   3000:                    while(sem_wait(&((*s_etat_processus)
                   3001:                            .semaphore_fork)) != 0)
                   3002: #                  else
                   3003:                    while(sem_wait((*s_etat_processus).semaphore_fork)
                   3004:                            != 0)
                   3005: #                  endif
                   3006: 
                   3007:                    if (erreur != EINTR)
                   3008:                    {
                   3009:                        liberation(s_etat_processus, s_objet_argument);
                   3010:                        liberation(s_etat_processus, s_objet_resultat);
                   3011: 
                   3012:                        (*s_etat_processus).erreur_execution =
                   3013:                                d_ex_erreur_acces_fichier;
                   3014:                        return;
                   3015:                    }
                   3016: 
                   3017:                    scrutation_injection(s_etat_processus);
                   3018: 
                   3019:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3020:                    {
                   3021:                        drapeau = d_vrai;
                   3022:                    }
                   3023:                    else
                   3024:                    {
                   3025:                        drapeau = d_faux;
                   3026:                    }
                   3027:                }
                   3028:                else
1.54      bertrand 3029:                {
1.55      bertrand 3030: #                  ifndef SEMAPHORES_NOMMES
                   3031:                        while(sem_wait(&((*s_etat_processus)
                   3032:                                .semaphore_fork)) != 0)
                   3033: #                  else
                   3034:                        while(sem_wait((*s_etat_processus).semaphore_fork)
                   3035:                                != 0)
                   3036: #                  endif
                   3037:                    {
                   3038:                        if (errno != EINTR)
                   3039:                        {
                   3040:                            (*s_etat_processus).erreur_systeme =
                   3041:                                    d_es_processus;
                   3042:                            return;
                   3043:                        }
                   3044:                    }
1.54      bertrand 3045:                }
1.55      bertrand 3046:            } while(drapeau == d_faux);
1.54      bertrand 3047: 
                   3048:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3049:                    s_objet_argument) == d_erreur)
                   3050:            {
                   3051:                return;
                   3052:            }
1.1       bertrand 3053: 
1.54      bertrand 3054:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3055:                    s_objet_resultat) == d_erreur)
                   3056:            {
                   3057:                return;
                   3058:            }
1.1       bertrand 3059:        }
1.54      bertrand 3060:        else
1.1       bertrand 3061:        {
1.54      bertrand 3062:            // Mode connecté
1.1       bertrand 3063: 
1.54      bertrand 3064:            if ((s_objet_resultat = copie_objet(s_etat_processus,
                   3065:                    s_objet_argument, 'O')) == NULL)
                   3066:            {
                   3067:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3068:                return;
                   3069:            }
1.1       bertrand 3070: 
1.54      bertrand 3071:            (*((struct_socket *) (*s_objet_resultat).objet)).effacement = 'N';
                   3072:            (*((struct_socket *) (*s_objet_resultat).objet)).socket_en_ecoute
                   3073:                    = 'N';
1.1       bertrand 3074: 
1.54      bertrand 3075:            if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
                   3076:                    PF_INET)
1.1       bertrand 3077:            {
1.54      bertrand 3078:                longueur = sizeof(adresse_ipv4);
                   3079: 
                   3080:                do
                   3081:                {
                   3082:                    drapeau = d_vrai;
1.1       bertrand 3083: 
1.51      bertrand 3084: #              ifndef SEMAPHORES_NOMMES
1.54      bertrand 3085:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   3086:                                != 0)
1.51      bertrand 3087: #              else
1.54      bertrand 3088:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1.51      bertrand 3089: #              endif
1.54      bertrand 3090:                    {
                   3091:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   3092:                        return;
                   3093:                    }
1.1       bertrand 3094: 
1.54      bertrand 3095:                    if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3096:                            .socket = accept((*((struct_socket *)
                   3097:                            (*s_objet_argument).objet)).socket,
                   3098:                            (struct sockaddr *) &adresse_ipv4, &longueur))
                   3099:                            < 0)
                   3100:                    {
                   3101:                        erreur = errno;
1.1       bertrand 3102: 
1.55      bertrand 3103: #                      ifndef SEMAPHORES_NOMMES
                   3104:                        while(sem_wait(&((*s_etat_processus)
                   3105:                                .semaphore_fork)) != 0)
                   3106: #                      else
                   3107:                        while(sem_wait((*s_etat_processus).semaphore_fork)
                   3108:                                != 0)
                   3109: #                      endif
1.50      bertrand 3110:                        {
1.54      bertrand 3111:                            if (errno != EINTR)
                   3112:                            {
                   3113:                                (*s_etat_processus).erreur_systeme =
                   3114:                                        d_es_processus;
                   3115:                                return;
                   3116:                            }
1.50      bertrand 3117:                        }
1.1       bertrand 3118: 
1.54      bertrand 3119:                        if (erreur != EINTR)
                   3120:                        {
                   3121:                            liberation(s_etat_processus, s_objet_argument);
                   3122:                            liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3123: 
1.54      bertrand 3124:                            (*s_etat_processus).erreur_execution =
                   3125:                                    d_ex_erreur_acces_fichier;
                   3126:                            return;
                   3127:                        }
1.1       bertrand 3128: 
1.54      bertrand 3129:                        scrutation_injection(s_etat_processus);
1.1       bertrand 3130: 
1.54      bertrand 3131:                        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3132:                        {
                   3133:                            drapeau = d_vrai;
                   3134:                        }
                   3135:                        else
                   3136:                        {
                   3137:                            drapeau = d_faux;
                   3138:                        }
1.1       bertrand 3139:                    }
                   3140:                    else
                   3141:                    {
1.51      bertrand 3142: #                  ifndef SEMAPHORES_NOMMES
1.54      bertrand 3143:                            while(sem_wait(&((*s_etat_processus)
                   3144:                                    .semaphore_fork)) != 0)
1.51      bertrand 3145: #                  else
1.54      bertrand 3146:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3147:                                    != 0)
1.51      bertrand 3148: #                  endif
1.50      bertrand 3149:                        {
1.54      bertrand 3150:                            if (errno != EINTR)
                   3151:                            {
                   3152:                                (*s_etat_processus).erreur_systeme =
                   3153:                                        d_es_processus;
                   3154:                                return;
                   3155:                            }
1.50      bertrand 3156:                        }
1.1       bertrand 3157:                    }
1.54      bertrand 3158:                } while(drapeau == d_faux);
                   3159: 
                   3160:                if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3161:                        .adresse_distante = malloc(22 *
                   3162:                        sizeof(unsigned char))) == NULL)
                   3163:                {
                   3164:                    (*s_etat_processus).erreur_systeme =
                   3165:                            d_es_allocation_memoire;
                   3166:                    return;
1.1       bertrand 3167:                }
                   3168: 
1.54      bertrand 3169:                sprintf((*((struct_socket *) (*s_objet_resultat).objet))
                   3170:                        .adresse_distante, "%d.%d.%d.%d(%d)",
                   3171:                        (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF,
                   3172:                        (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF,
                   3173:                        (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF,
                   3174:                        ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF,
                   3175:                        ntohs(adresse_ipv4.sin_port));
                   3176:            }
                   3177:            else if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
                   3178:                    PF_INET6)
1.1       bertrand 3179:            {
1.20      bertrand 3180: #          ifdef IPV6
1.54      bertrand 3181:                longueur = sizeof(adresse_ipv6);
1.1       bertrand 3182: 
1.54      bertrand 3183:                do
                   3184:                {
                   3185:                    drapeau = d_vrai;
1.1       bertrand 3186: 
1.51      bertrand 3187: #              ifndef SEMAPHORES_NOMMES
1.54      bertrand 3188:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   3189:                                != 0)
1.51      bertrand 3190: #              else
1.54      bertrand 3191:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1.51      bertrand 3192: #              endif
1.54      bertrand 3193:                    {
                   3194:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   3195:                        return;
                   3196:                    }
1.1       bertrand 3197: 
1.54      bertrand 3198:                    if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3199:                            .socket = accept((*((struct_socket *)
                   3200:                            (*s_objet_argument).objet)).socket,
                   3201:                            (struct sockaddr *) &adresse_ipv6, &longueur)) < 0)
                   3202:                    {
                   3203:                        erreur = errno;
1.1       bertrand 3204: 
1.51      bertrand 3205: #                  ifndef SEMAPHORES_NOMMES
1.54      bertrand 3206:                            while(sem_wait(&((*s_etat_processus)
                   3207:                                    .semaphore_fork)) != 0)
1.51      bertrand 3208: #                  else
1.54      bertrand 3209:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3210:                                    != 0)
1.51      bertrand 3211: #                  endif
1.50      bertrand 3212:                        {
1.54      bertrand 3213:                            if (errno != EINTR)
                   3214:                            {
                   3215:                                (*s_etat_processus).erreur_systeme =
                   3216:                                        d_es_processus;
                   3217:                                return;
                   3218:                            }
1.50      bertrand 3219:                        }
1.1       bertrand 3220: 
1.54      bertrand 3221:                        if (erreur != EINTR)
                   3222:                        {
                   3223:                            liberation(s_etat_processus, s_objet_argument);
                   3224:                            liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3225: 
1.54      bertrand 3226:                            (*s_etat_processus).erreur_execution =
                   3227:                                    d_ex_erreur_acces_fichier;
                   3228:                            return;
                   3229:                        }
1.1       bertrand 3230: 
1.54      bertrand 3231:                        scrutation_injection(s_etat_processus);
1.1       bertrand 3232: 
1.54      bertrand 3233:                        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3234:                        {
                   3235:                            drapeau = d_vrai;
                   3236:                        }
                   3237:                        else
                   3238:                        {
                   3239:                            drapeau = d_faux;
                   3240:                        }
1.1       bertrand 3241:                    }
                   3242:                    else
                   3243:                    {
1.51      bertrand 3244: #                  ifndef SEMAPHORES_NOMMES
1.54      bertrand 3245:                            while(sem_wait(&((*s_etat_processus)
                   3246:                                    .semaphore_fork)) != 0)
1.51      bertrand 3247: #                  else
1.54      bertrand 3248:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3249:                                    != 0)
1.51      bertrand 3250: #                  endif
1.50      bertrand 3251:                        {
1.54      bertrand 3252:                            if (errno != EINTR)
                   3253:                            {
                   3254:                                (*s_etat_processus).erreur_systeme =
                   3255:                                        d_es_processus;
                   3256:                                return;
                   3257:                            }
1.50      bertrand 3258:                        }
1.1       bertrand 3259:                    }
1.54      bertrand 3260:                } while(drapeau == d_faux);
                   3261: 
                   3262:                if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3263:                        .adresse_distante = malloc(55 *
                   3264:                        sizeof(unsigned char))) == NULL)
                   3265:                {
                   3266:                    (*s_etat_processus).erreur_systeme =
                   3267:                            d_es_allocation_memoire;
                   3268:                    return;
1.1       bertrand 3269:                }
                   3270: 
1.54      bertrand 3271:                (*((struct_socket *) (*s_objet_resultat).objet))
                   3272:                        .adresse_distante = d_code_fin_chaine;
1.1       bertrand 3273: 
1.54      bertrand 3274:                for(i = 0; i < 16; i++)
                   3275:                {
                   3276:                    sprintf((*((struct_socket *) (*s_objet_resultat)
                   3277:                            .objet)).adresse_distante, (i == 0) ? "%s%X"
                   3278:                            : "%s:%X", (*((struct_socket *) (*s_objet_resultat)
                   3279:                            .objet)).adresse_distante,
                   3280:                            adresse_ipv6.sin6_addr.s6_addr[i]);
                   3281:                }
1.1       bertrand 3282: 
                   3283:                sprintf((*((struct_socket *) (*s_objet_resultat)
1.54      bertrand 3284:                        .objet)).adresse_distante, "%s(%u)",
1.1       bertrand 3285:                        (*((struct_socket *) (*s_objet_resultat)
                   3286:                        .objet)).adresse_distante,
1.54      bertrand 3287:                        ntohs(adresse_ipv6.sin6_port));
1.20      bertrand 3288: #          else
1.54      bertrand 3289:                if ((*s_etat_processus).langue == 'F')
                   3290:                {
                   3291:                    printf("+++Attention : Support du protocole"
                   3292:                            " IPv6 indisponible\n");
                   3293:                }
                   3294:                else
                   3295:                {
                   3296:                    printf("+++Warning : IPv6 support "
                   3297:                            "unavailable\n");
                   3298:                }
                   3299: #          endif
1.22      bertrand 3300:            }
                   3301:            else
                   3302:            {
1.54      bertrand 3303:                longueur = 0;
1.1       bertrand 3304: 
1.54      bertrand 3305:                do
                   3306:                {
                   3307:                    drapeau = d_vrai;
1.1       bertrand 3308: 
1.51      bertrand 3309: #              ifndef SEMAPHORES_NOMMES
1.54      bertrand 3310:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   3311:                                != 0)
1.51      bertrand 3312: #              else
1.54      bertrand 3313:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1.51      bertrand 3314: #              endif
1.54      bertrand 3315:                    {
                   3316:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   3317:                        return;
                   3318:                    }
1.1       bertrand 3319: 
1.54      bertrand 3320:                    if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3321:                            .socket = accept((*((struct_socket *)
                   3322:                            (*s_objet_argument).objet)).socket, NULL,
                   3323:                            &longueur)) < 0)
                   3324:                    {
                   3325:                        erreur = errno;
1.1       bertrand 3326: 
1.51      bertrand 3327: #                  ifndef SEMAPHORES_NOMMES
1.54      bertrand 3328:                            while(sem_wait(&((*s_etat_processus)
                   3329:                                    .semaphore_fork)) != 0)
1.51      bertrand 3330: #                  else
1.54      bertrand 3331:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3332:                                    != 0)
1.51      bertrand 3333: #                  endif
1.50      bertrand 3334:                        {
1.54      bertrand 3335:                            if (errno != EINTR)
                   3336:                            {
                   3337:                                (*s_etat_processus).erreur_systeme =
                   3338:                                        d_es_processus;
                   3339:                                return;
                   3340:                            }
1.50      bertrand 3341:                        }
1.1       bertrand 3342: 
1.54      bertrand 3343:                        if (erreur != EINTR)
                   3344:                        {
                   3345:                            liberation(s_etat_processus, s_objet_argument);
                   3346:                            liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3347: 
1.54      bertrand 3348:                            (*s_etat_processus).erreur_execution =
                   3349:                                    d_ex_erreur_acces_fichier;
                   3350:                            return;
                   3351:                        }
1.1       bertrand 3352: 
1.54      bertrand 3353:                        scrutation_injection(s_etat_processus);
1.1       bertrand 3354: 
1.54      bertrand 3355:                        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3356:                        {
                   3357:                            drapeau = d_vrai;
                   3358:                        }
                   3359:                        else
                   3360:                        {
                   3361:                            drapeau = d_faux;
                   3362:                        }
1.1       bertrand 3363:                    }
                   3364:                    else
                   3365:                    {
1.51      bertrand 3366: #                  ifndef SEMAPHORES_NOMMES
1.54      bertrand 3367:                            while(sem_wait(&((*s_etat_processus)
                   3368:                                    .semaphore_fork)) != 0)
1.51      bertrand 3369: #                  else
1.54      bertrand 3370:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3371:                                    != 0)
1.51      bertrand 3372: #                  endif
1.50      bertrand 3373:                        {
1.54      bertrand 3374:                            if (errno != EINTR)
                   3375:                            {
                   3376:                                (*s_etat_processus).erreur_systeme =
                   3377:                                        d_es_processus;
                   3378:                                return;
                   3379:                            }
1.50      bertrand 3380:                        }
1.1       bertrand 3381:                    }
1.54      bertrand 3382:                } while(drapeau == d_faux);
                   3383:            }
1.1       bertrand 3384: 
1.54      bertrand 3385:            // Si accept() renvoie une erreur non récupérée, il ne peut s'agir
                   3386:            // que de EINTR sachant qu'une requête d'arrêt est en court de
                   3387:            // traitement.
1.1       bertrand 3388: 
1.54      bertrand 3389:            if ((*((struct_socket *) (*s_objet_resultat).objet)).socket >= 0)
                   3390:            {
                   3391:                l_element_courant = (*s_etat_processus).s_sockets;
1.1       bertrand 3392: 
1.54      bertrand 3393:                if (l_element_courant == NULL)
1.1       bertrand 3394:                {
1.54      bertrand 3395:                    if (((*s_etat_processus).s_sockets =
                   3396:                            allocation_maillon(s_etat_processus)) == NULL)
                   3397:                    {
                   3398:                        (*s_etat_processus).erreur_systeme =
                   3399:                                d_es_allocation_memoire;
                   3400:                        return;
                   3401:                    }
                   3402: 
                   3403:                    (*(*s_etat_processus).s_sockets).suivant = NULL;
                   3404:                    l_element_courant = (*s_etat_processus).s_sockets;
1.1       bertrand 3405:                }
1.54      bertrand 3406:                else
                   3407:                {
                   3408:                    /*
                   3409:                     * Ajout d'un élément à la fin de la liste chaînée
                   3410:                     */
1.1       bertrand 3411: 
1.54      bertrand 3412:                    while((*l_element_courant).suivant != NULL)
                   3413:                    {
                   3414:                        l_element_courant = (*l_element_courant).suivant;
                   3415:                    }
                   3416: 
                   3417:                    if (((*l_element_courant).suivant =
                   3418:                            allocation_maillon(s_etat_processus)) == NULL)
                   3419:                    {
                   3420:                        (*s_etat_processus).erreur_systeme =
                   3421:                                d_es_allocation_memoire;
                   3422:                        return;
                   3423:                    }
1.1       bertrand 3424: 
                   3425:                    l_element_courant = (*l_element_courant).suivant;
1.54      bertrand 3426:                    (*l_element_courant).suivant = NULL;
1.1       bertrand 3427:                }
                   3428: 
1.54      bertrand 3429:                if (((*l_element_courant).donnee = copie_objet(s_etat_processus,
                   3430:                        s_objet_resultat, 'O')) == NULL)
1.1       bertrand 3431:                {
                   3432:                    (*s_etat_processus).erreur_systeme =
                   3433:                            d_es_allocation_memoire;
                   3434:                    return;
                   3435:                }
1.54      bertrand 3436:            }
1.1       bertrand 3437: 
1.54      bertrand 3438:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3439:                    s_objet_argument) == d_erreur)
                   3440:            {
                   3441:                return;
1.1       bertrand 3442:            }
                   3443: 
1.54      bertrand 3444:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3445:                    s_objet_resultat) == d_erreur)
1.1       bertrand 3446:            {
                   3447:                return;
                   3448:            }
                   3449:        }
                   3450:    }
                   3451:    else
                   3452:    {
                   3453:        liberation(s_etat_processus, s_objet_argument);
                   3454: 
                   3455:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   3456:        return;
                   3457:    }
                   3458: 
                   3459:    return;
                   3460: }
                   3461: 
                   3462: 
                   3463: /*
                   3464: ================================================================================
                   3465:   Fonction 'wfswi'
                   3466: ================================================================================
                   3467:   Entrées : pointeur sur une structure struct_processus
                   3468: --------------------------------------------------------------------------------
                   3469:   Sorties :
                   3470: --------------------------------------------------------------------------------
                   3471:   Effets de bord : néant
                   3472: ================================================================================
                   3473: */
                   3474: 
                   3475: void
                   3476: instruction_wfswi(struct_processus *s_etat_processus)
                   3477: {
                   3478:    integer8                    interruption;
                   3479: 
                   3480:    logical1                    drapeau_fin;
                   3481: 
                   3482:    struct_objet                *s_objet_argument;
                   3483: 
                   3484:    struct timespec             attente;
                   3485: 
                   3486:    (*s_etat_processus).erreur_execution = d_ex;
                   3487: 
                   3488:    attente.tv_sec = 0;
                   3489:    attente.tv_nsec = GRANULARITE_us * 1000;
                   3490: 
                   3491:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   3492:    {
                   3493:        printf("\n  WFSWI ");
                   3494: 
                   3495:        if ((*s_etat_processus).langue == 'F')
                   3496:        {
                   3497:            printf("(attente d'une interruption)\n\n");
                   3498:        }
                   3499:        else
                   3500:        {
                   3501:            printf("(wait for interrupt)\n\n");
                   3502:        }
                   3503: 
                   3504:        printf("    1: %s\n", d_INT);
                   3505: 
                   3506:        return;
                   3507:    }
                   3508:    else if ((*s_etat_processus).test_instruction == 'Y')
                   3509:    {
                   3510:        (*s_etat_processus).nombre_arguments = -1;
                   3511:        return;
                   3512:    }
                   3513: 
                   3514:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   3515:    {
                   3516:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   3517:        {
                   3518:            return;
                   3519:        }
                   3520:    }
                   3521: 
                   3522:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3523:            &s_objet_argument) == d_erreur)
                   3524:    {
                   3525:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   3526:        return;
                   3527:    }
                   3528: 
                   3529:    if ((*s_objet_argument).type == INT)
                   3530:    {
                   3531:        drapeau_fin = d_faux;
                   3532: 
                   3533:        interruption = (*((integer8 *) (*s_objet_argument).objet));
                   3534: 
                   3535:        if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   3536:        {
                   3537:            liberation(s_etat_processus, s_objet_argument);
                   3538: 
                   3539:            (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
                   3540:            return;
                   3541:        }
                   3542: 
                   3543:        while(drapeau_fin == d_faux)
                   3544:        {
                   3545:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3546:            {
                   3547:                liberation(s_etat_processus, s_objet_argument);
                   3548:                return;
                   3549:            }
                   3550: 
                   3551:            if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   3552:            {
                   3553:                affectation_interruptions_logicielles(s_etat_processus);
                   3554:            }
                   3555: 
                   3556:            if ((*s_etat_processus).queue_interruptions[interruption - 1] > 0)
                   3557:            {
                   3558:                drapeau_fin = d_vrai;
                   3559:            }
                   3560:            else
                   3561:            {
                   3562:                nanosleep(&attente, NULL);
                   3563:                scrutation_injection(s_etat_processus);
                   3564:                INCR_GRANULARITE(attente.tv_nsec);
                   3565:            }
                   3566:        }
                   3567:    }
                   3568:    else
                   3569:    {
                   3570:        liberation(s_etat_processus, s_objet_argument);
                   3571: 
                   3572:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   3573:        return;
                   3574:    }
                   3575: 
                   3576:    liberation(s_etat_processus, s_objet_argument);
                   3577: 
                   3578:    return;
                   3579: }
                   3580: 
                   3581: 
                   3582: /*
                   3583: ================================================================================
                   3584:   Fonction 'wfpoke'
                   3585: ================================================================================
                   3586:   Entrées : pointeur sur une structure struct_processus
                   3587: --------------------------------------------------------------------------------
                   3588:   Sorties :
                   3589: --------------------------------------------------------------------------------
                   3590:   Effets de bord : néant
                   3591: ================================================================================
                   3592: */
                   3593: 
                   3594: void
                   3595: instruction_wfpoke(struct_processus *s_etat_processus)
                   3596: {
                   3597:    struct timespec             attente;
                   3598: 
                   3599:    unsigned char               registre_instruction_valide;
                   3600: 
                   3601:    (*s_etat_processus).erreur_execution = d_ex;
                   3602: 
                   3603:    attente.tv_sec = 0;
                   3604:    attente.tv_nsec = GRANULARITE_us * 1000;
                   3605: 
                   3606:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   3607:    {
                   3608:        printf("\n  WFPOKE ");
                   3609: 
                   3610:        if ((*s_etat_processus).langue == 'F')
                   3611:        {
                   3612:            printf("(attente de données en provenance du processus père)\n\n");
                   3613:            printf("  Aucun argument\n");
                   3614:        }
                   3615:        else
                   3616:        {
                   3617:            printf("(wait for data from parent process)\n\n");
                   3618:            printf("  No argument\n");
                   3619:        }
                   3620: 
                   3621:        return;
                   3622:    }
                   3623:    else if ((*s_etat_processus).test_instruction == 'Y')
                   3624:    {
                   3625:        (*s_etat_processus).nombre_arguments = -1;
                   3626:        return;
                   3627:    }
                   3628: 
                   3629:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   3630:    {
                   3631:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                   3632:        {
                   3633:            return;
                   3634:        }
                   3635:    }
                   3636: 
                   3637:    if ((*s_etat_processus).presence_pipes == d_faux)
                   3638:    {
                   3639:        (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                   3640:        return;
                   3641:    }
                   3642: 
                   3643:    if ((*s_etat_processus).nombre_objets_injectes > 0)
                   3644:    {
                   3645:        return;
                   3646:    }
                   3647: 
                   3648:    if ((*s_etat_processus).profilage == d_vrai)
                   3649:    {
                   3650:        profilage(s_etat_processus, "Interprocess or interthread "
                   3651:                "communications (WFPOKE)");
                   3652: 
                   3653:        if ((*s_etat_processus).erreur_systeme != d_es)
                   3654:        {
                   3655:            return;
                   3656:        }
                   3657:    }
                   3658: 
                   3659:    do
                   3660:    {
1.51      bertrand 3661: #      ifndef SEMAPHORES_NOMMES
                   3662:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   3663: #      else
                   3664:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   3665: #      endif
1.1       bertrand 3666:        {
                   3667:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   3668:            return;
                   3669:        }
                   3670: 
                   3671:        nanosleep(&attente, NULL);
                   3672: 
1.51      bertrand 3673: #      ifndef SEMAPHORES_NOMMES
                   3674:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   3675: #      else
                   3676:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   3677: #      endif
1.1       bertrand 3678:        {
1.50      bertrand 3679:            if (errno != EINTR)
                   3680:            {
                   3681:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3682:                return;
                   3683:            }
1.1       bertrand 3684:        }
                   3685: 
                   3686:        scrutation_injection(s_etat_processus);
                   3687: 
                   3688:        if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   3689:        {
                   3690:            affectation_interruptions_logicielles(s_etat_processus);
                   3691:        }
                   3692: 
                   3693:        if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   3694:        {
                   3695:            registre_instruction_valide =
                   3696:                    (*s_etat_processus).instruction_valide;
                   3697:            traitement_interruptions_logicielles(s_etat_processus);
                   3698:            (*s_etat_processus).instruction_valide =
                   3699:                    registre_instruction_valide;
                   3700:        }
                   3701: 
                   3702:        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3703:        {
                   3704:            if ((*s_etat_processus).profilage == d_vrai)
                   3705:            {
                   3706:                profilage(s_etat_processus, NULL);
                   3707:            }
                   3708: 
                   3709:            return;
                   3710:        }
                   3711: 
                   3712:        INCR_GRANULARITE(attente.tv_nsec);
                   3713:    } while((*s_etat_processus).nombre_objets_injectes == 0);
                   3714: 
                   3715:    return;
                   3716: }
                   3717: 
                   3718: 
                   3719: /*
                   3720: ================================================================================
                   3721:   Fonction 'wfack'
                   3722: ================================================================================
                   3723:   Entrées : pointeur sur une structure struct_processus
                   3724: --------------------------------------------------------------------------------
                   3725:   Sorties :
                   3726: --------------------------------------------------------------------------------
                   3727:   Effets de bord : néant
                   3728: ================================================================================
                   3729: */
                   3730: 
                   3731: void
                   3732: instruction_wfack(struct_processus *s_etat_processus)
                   3733: {
                   3734:    struct timespec             attente;
                   3735: 
                   3736:    unsigned char               registre_instruction_valide;
                   3737: 
                   3738:    (*s_etat_processus).erreur_execution = d_ex;
                   3739: 
                   3740:    attente.tv_sec = 0;
                   3741:    attente.tv_nsec = GRANULARITE_us * 1000;
                   3742: 
                   3743:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   3744:    {
                   3745:        printf("\n  WFACK ");
                   3746: 
                   3747:        if ((*s_etat_processus).langue == 'F')
                   3748:        {
                   3749:            printf("(attente des acquittements de lecture)\n\n");
                   3750:            printf("  Aucun argument\n");
                   3751:        }
                   3752:        else
                   3753:        {
                   3754:            printf("(wait for reading of data acknowledgement)\n\n");
                   3755:            printf("  No argument\n");
                   3756:        }
                   3757: 
                   3758:        return;
                   3759:    }
                   3760:    else if ((*s_etat_processus).test_instruction == 'Y')
                   3761:    {
                   3762:        (*s_etat_processus).nombre_arguments = -1;
                   3763:        return;
                   3764:    }
                   3765: 
                   3766:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   3767:    {
                   3768:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                   3769:        {
                   3770:            return;
                   3771:        }
                   3772:    }
                   3773: 
                   3774:    if ((*s_etat_processus).presence_pipes == d_faux)
                   3775:    {
                   3776:        (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                   3777:        return;
                   3778:    }
                   3779: 
                   3780:    if ((*s_etat_processus).profilage == d_vrai)
                   3781:    {
                   3782:        profilage(s_etat_processus, "Interprocess or interthread communications"
                   3783:                " (WFACK)");
                   3784: 
                   3785:        if ((*s_etat_processus).erreur_systeme != d_es)
                   3786:        {
                   3787:            return;
                   3788:        }
                   3789:    }
                   3790: 
                   3791:    while((*s_etat_processus).nombre_objets_envoyes_non_lus != 0)
                   3792:    {
                   3793:        scrutation_injection(s_etat_processus);
                   3794: 
                   3795:        if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   3796:        {
                   3797:            affectation_interruptions_logicielles(s_etat_processus);
                   3798:        }
                   3799: 
                   3800:        if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   3801:        {
                   3802:            registre_instruction_valide =
                   3803:                    (*s_etat_processus).instruction_valide;
                   3804:            traitement_interruptions_logicielles(s_etat_processus);
                   3805:            (*s_etat_processus).instruction_valide =
                   3806:                    registre_instruction_valide;
                   3807:        }
                   3808: 
                   3809:        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3810:        {
                   3811:            if ((*s_etat_processus).profilage == d_vrai)
                   3812:            {
                   3813:                profilage(s_etat_processus, NULL);
                   3814:            }
                   3815: 
                   3816:            return;
                   3817:        }
                   3818: 
1.51      bertrand 3819: #      ifndef SEMAPHORES_NOMMES
                   3820:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   3821: #      else
                   3822:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   3823: #      endif
1.12      bertrand 3824:        {
                   3825:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   3826:            return;
                   3827:        }
1.1       bertrand 3828: 
                   3829:        nanosleep(&attente, NULL);
                   3830:        INCR_GRANULARITE(attente.tv_nsec);
                   3831: 
1.51      bertrand 3832: #      ifndef SEMAPHORES_NOMMES
                   3833:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   3834: #      else
                   3835:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   3836: #      endif
1.1       bertrand 3837:        {
1.50      bertrand 3838:            if (errno != EINTR)
                   3839:            {
                   3840:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3841:                return;
                   3842:            }
1.1       bertrand 3843:        }
                   3844:    }
                   3845: 
                   3846:    if ((*s_etat_processus).profilage == d_vrai)
                   3847:    {
                   3848:        profilage(s_etat_processus, NULL);
                   3849:    }
                   3850: 
                   3851:    return;
                   3852: }
                   3853: 
                   3854: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>