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

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

CVSweb interface <joel.bertrand@systella.fr>