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

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

CVSweb interface <joel.bertrand@systella.fr>