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

1.1       bertrand    1: /*
                      2: ================================================================================
1.10    ! bertrand    3:   RPL/2 (R) version 4.0.13
1.1       bertrand    4:   Copyright (C) 1989-2010 Dr. BERTRAND Joël
                      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: 
                     23: #include "rpl.conv.h"
                     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: {
                    127: #  include                 "garanties.conv.h"
                    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:    
                    229:    if (((*s_objet).type == INT) ||
                    230:            ((*s_objet).type == REL))
                    231:    {
                    232:        if ((*s_objet).type == INT)
                    233:        {
                    234:            attente = (real8) (*((integer8 *) (*s_objet).objet));
                    235:        }
                    236:        else
                    237:        {
                    238:            attente = (*((real8 *) (*s_objet).objet));
                    239:        }
                    240: 
                    241:        if (attente < 0)
                    242:        {
                    243:            liberation(s_etat_processus, s_objet);
                    244: 
                    245:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    246:            return;
                    247:        }
                    248: 
                    249:        temporisation.tv_sec = (long) floor((double) attente);
                    250:        temporisation.tv_nsec = (attente - temporisation.tv_sec) *
                    251:                (long) 1000000000;
                    252: 
                    253:        if ((*s_etat_processus).profilage == d_vrai)
                    254:        {
                    255:            profilage(s_etat_processus, "Sleep function (WAIT)");
                    256: 
                    257:            if ((*s_etat_processus).erreur_systeme != d_es)
                    258:            {
                    259:                return;
                    260:            }
                    261:        }
                    262: 
                    263:        do
                    264:        {
                    265:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    266:            {
                    267:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    268:                return;
                    269:            }
                    270: 
                    271:            code_retour = nanosleep(&temporisation, &temporisation);
                    272:            erreur = errno;
                    273: 
                    274:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                    275:            {
                    276:                if (errno != EINTR)
                    277:                {
                    278:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    279:                    return;
                    280:                }
                    281:            }
                    282: 
                    283:            scrutation_injection(s_etat_processus);
                    284: 
                    285:            if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                    286:            {
                    287:                affectation_interruptions_logicielles(s_etat_processus);
                    288:            }
                    289: 
                    290:            if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                    291:            {
                    292:                traitement_interruptions_logicielles(s_etat_processus);
                    293:            }
                    294:        } while(((code_retour == -1) && (erreur == EINTR))
                    295:                && ((*s_etat_processus).var_volatile_requete_arret == 0));
                    296: 
                    297:        if ((*s_etat_processus).profilage == d_vrai)
                    298:        {
                    299:            profilage(s_etat_processus, NULL);
                    300:        }
                    301:    }
                    302:    else
                    303:    {
                    304:        liberation(s_etat_processus, s_objet);
                    305: 
                    306:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    307:        return;
                    308:    }
                    309: 
                    310:    liberation(s_etat_processus, s_objet);
                    311: 
                    312:    return;
                    313: }
                    314: 
                    315: 
                    316: /*
                    317: ================================================================================
                    318:   Fonction 'wireframe' (passe en mode d'affichage échantillonné)
                    319: ================================================================================
                    320:   Entrées : structure processus
                    321: --------------------------------------------------------------------------------
                    322:   Sorties :
                    323: --------------------------------------------------------------------------------
                    324:   Effets de bord : néant
                    325: ================================================================================
                    326: */
                    327: 
                    328: void
                    329: instruction_wireframe(struct_processus *s_etat_processus)
                    330: {
                    331:    (*s_etat_processus).erreur_execution = d_ex;
                    332: 
                    333:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    334:    {
                    335:        printf("\n  WIREFRAME ");
                    336: 
                    337:        if ((*s_etat_processus).langue == 'F')
                    338:        {
                    339:            printf("(graphique tridimensionnel grillagé)\n\n");
                    340:            printf("  Aucun argument\n");
                    341:        }
                    342:        else
                    343:        {
                    344:            printf("(wireframe 3D graph)\n\n");
                    345:            printf("  No argument\n");
                    346:        }
                    347: 
                    348:        return;
                    349:    }
                    350:    else if ((*s_etat_processus).test_instruction == 'Y')
                    351:    {
                    352:        (*s_etat_processus).nombre_arguments = -1;
                    353:        return;
                    354:    }
                    355: 
                    356:    strcpy((*s_etat_processus).type_trace_eq, "GRILLE 3D");
                    357: 
                    358:    return;
                    359: }
                    360: 
                    361: 
                    362: /*
                    363: ================================================================================
                    364:   Fonction 'write'
                    365: ================================================================================
                    366:   Entrées : structure processus
                    367: --------------------------------------------------------------------------------
                    368:   Sorties :
                    369: --------------------------------------------------------------------------------
                    370:   Effets de bord : néant
                    371: ================================================================================
                    372: */
                    373: 
                    374: void
                    375: instruction_write(struct_processus *s_etat_processus)
                    376: {
1.6       bertrand  377:    const char                          *queue;
                    378: 
1.1       bertrand  379:    int                                 adresse[16];
                    380:    int                                 port;
                    381: 
1.8       bertrand  382:    integer8                            clef;
                    383:    integer8                            compteur;
                    384:    integer8                            id;
                    385:    integer8                            ordre;
                    386: 
                    387:    logical1                            mise_a_jour;
                    388: 
1.1       bertrand  389:    long                                longueur_effective;
                    390:    long                                recursivite;
                    391: 
1.6       bertrand  392:    sqlite3_stmt                        *ppStmt;
                    393: 
1.1       bertrand  394:    ssize_t                             ios;
                    395: 
1.5       bertrand  396:    struct_descripteur_fichier          *descripteur;
                    397: 
1.8       bertrand  398:    struct_liste_chainee                *l_element_courant;
                    399:    struct_liste_chainee                *l_element_courant_format;
                    400: 
                    401:    struct_objet                        *s_format;
                    402:    struct_objet                        *s_element;
1.6       bertrand  403:    struct_objet                        *s_objet_argument_1;
1.1       bertrand  404:    struct_objet                        *s_objet_argument_2;
1.6       bertrand  405:    struct_objet                        *s_objet_argument_3;
1.1       bertrand  406: 
                    407:    struct sigaction                    action;
                    408:    struct sigaction                    registre;
                    409: 
                    410:    struct sockaddr_in                  adresse_ipv4;
                    411:    struct sockaddr_in6                 adresse_ipv6;
                    412:    struct sockaddr_un                  adresse_unix;
                    413: 
                    414:    struct flock                        lock;
                    415: 
                    416:    uint32_t                            calcul_adresse;
                    417: 
                    418:    unsigned char                       *chaine;
1.5       bertrand  419:    unsigned char                       *chaine_utf8;
1.8       bertrand  420:    unsigned char                       *clef_utf8;
1.6       bertrand  421:    unsigned char                       *commande;
1.1       bertrand  422: 
                    423:    unsigned long                       i;
                    424: 
                    425:    (*s_etat_processus).erreur_execution = d_ex;
                    426: 
                    427:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    428:    {
                    429:        printf("\n  WRITE ");
                    430: 
                    431:        if ((*s_etat_processus).langue == 'F')
                    432:        {
                    433:            printf("(écriture d'un enregistrement d'un fichier)\n\n");
                    434:        }
                    435:        else
                    436:        {
                    437:            printf("(write a record of a file)\n\n");
                    438:        }
                    439: 
                    440:        printf("    2: %s\n", d_LST);
1.6       bertrand  441:        printf("    1: %s, %s\n\n", d_FCH, d_SCK);
1.1       bertrand  442: 
1.6       bertrand  443:        printf("    3: %s\n", d_LST);
1.8       bertrand  444:        printf("    2: %s\n", d_INT);
1.6       bertrand  445:        printf("    1: %s\n", d_FCH);
1.1       bertrand  446:        return;
                    447:    }
                    448:    else if ((*s_etat_processus).test_instruction == 'Y')
                    449:    {
                    450:        (*s_etat_processus).nombre_arguments = -1;
                    451:        return;
                    452:    }
                    453: 
                    454:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    455:    {
1.6       bertrand  456:        if ((*s_etat_processus).l_base_pile == NULL)
1.1       bertrand  457:        {
1.6       bertrand  458:            (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1.1       bertrand  459:            return;
                    460:        }
1.6       bertrand  461: 
                    462:        if ((*(*(*s_etat_processus).l_base_pile).donnee).type == FCH)
                    463:        {
                    464:            if ((*((struct_fichier *) (*(*(*s_etat_processus).l_base_pile)
1.9       bertrand  465:                    .donnee).objet)).acces == 'D')
1.6       bertrand  466:            {
1.9       bertrand  467:                if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
1.6       bertrand  468:                {
                    469:                    return;
                    470:                }
                    471:            }
                    472:            else
                    473:            {
1.9       bertrand  474:                if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
1.6       bertrand  475:                {
                    476:                    return;
                    477:                }
                    478:            }
                    479:        }
                    480:        else
                    481:        {
                    482:            if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    483:            {
                    484:                return;
                    485:            }
                    486:        }
1.1       bertrand  487:    }
                    488: 
                    489:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    490:            &s_objet_argument_1) == d_erreur)
                    491:    {
                    492:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    493:        return;
                    494:    }
                    495:    
                    496:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    497:            &s_objet_argument_2) == d_erreur)
                    498:    {
                    499:        liberation(s_etat_processus, s_objet_argument_1);
                    500: 
                    501:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    502:        return;
                    503:    }
                    504:    
1.6       bertrand  505:    if ((*s_objet_argument_1).type == FCH)
1.1       bertrand  506:    {
1.5       bertrand  507:        if ((descripteur = descripteur_fichier(s_etat_processus,
                    508:                (struct_fichier *) (*s_objet_argument_1).objet)) == NULL)
                    509:        {
                    510:            return;
                    511:        }
                    512: 
1.1       bertrand  513:        /*
                    514:         * Vérification des verrous
                    515:         */
                    516: 
                    517:        lock.l_type = F_WRLCK;
                    518:        lock.l_whence = SEEK_SET;
                    519:        lock.l_start = 0;
                    520:        lock.l_len = 0;
                    521:        lock.l_pid = getpid();
                    522:        recursivite = 0;
                    523: 
1.5       bertrand  524:        if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
                    525:                == -1)
1.1       bertrand  526:        {
                    527:            liberation(s_etat_processus, s_objet_argument_2);
                    528:            liberation(s_etat_processus, s_objet_argument_1);
                    529: 
                    530:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    531:            return;
                    532:        }
                    533: 
                    534:        if (lock.l_type != F_UNLCK)
                    535:        {
                    536:            liberation(s_etat_processus, s_objet_argument_2);
                    537:            liberation(s_etat_processus, s_objet_argument_1);
                    538: 
                    539:            (*s_etat_processus).erreur_execution =
                    540:                    d_ex_fichier_verrouille;
                    541:            return;
                    542:        }
                    543: 
                    544:        /*
                    545:         * Vérification de l'autorisation d'écriture
                    546:         */
                    547: 
                    548:        if ((*((struct_fichier *) (*s_objet_argument_1).objet))
                    549:                .protection == 'R')
                    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 = d_ex_erreur_acces_fichier;
                    555:            return;
                    556:        }
                    557: 
                    558:        if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire == 'N')
                    559:        {
                    560:            /*
                    561:             * Fichiers formatés
                    562:             */
                    563: 
1.6       bertrand  564:            if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                    565:                    == 'S')
1.1       bertrand  566:            {
1.6       bertrand  567:                if ((*s_objet_argument_2).type != LST)
                    568:                {
                    569:                    liberation(s_etat_processus, s_objet_argument_2);
                    570:                    liberation(s_etat_processus, s_objet_argument_1);
                    571: 
                    572:                    (*s_etat_processus).erreur_execution =
                    573:                            d_ex_erreur_type_argument;
                    574:                    return;
                    575:                }
                    576: 
                    577:                if ((chaine = formateur_fichier(s_etat_processus,
                    578:                        s_objet_argument_2, (*((struct_fichier *)
                    579:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
                    580:                        &longueur_effective, &recursivite)) == NULL)
                    581:                {
                    582:                    liberation(s_etat_processus, s_objet_argument_2);
                    583:                    liberation(s_etat_processus, s_objet_argument_1);
1.1       bertrand  584: 
1.6       bertrand  585:                    return;
                    586:                }
1.1       bertrand  587: 
1.5       bertrand  588:                BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
                    589: 
                    590:                if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
                    591:                        != 0)
1.1       bertrand  592:                {
                    593:                    liberation(s_etat_processus, s_objet_argument_2);
                    594:                    liberation(s_etat_processus, s_objet_argument_1);
                    595: 
                    596:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    597:                    return;
                    598:                }
                    599: 
1.5       bertrand  600:                if ((chaine_utf8 = transliteration(s_etat_processus,
                    601:                        chaine, d_locale, "UTF-8")) == NULL)
                    602:                {
1.6       bertrand  603:                    free(chaine);
                    604: 
1.5       bertrand  605:                    liberation(s_etat_processus, s_objet_argument_2);
                    606:                    liberation(s_etat_processus, s_objet_argument_1);
                    607: 
                    608:                    return;
                    609:                }
                    610: 
1.6       bertrand  611:                free(chaine);
                    612: 
1.7       bertrand  613:                if (fprintf((*descripteur).descripteur_c, "%s\n", chaine_utf8)
                    614:                        < 0)
1.1       bertrand  615:                {
1.5       bertrand  616:                    free(chaine_utf8);
                    617: 
1.1       bertrand  618:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    619:                    return;
                    620:                }
1.5       bertrand  621: 
                    622:                free(chaine_utf8);
1.1       bertrand  623:            }
                    624:            else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                    625:                    == 'D')
                    626:            {
1.6       bertrand  627:                BUG(((*descripteur).type != 'S'), uprintf("Bad filetype !\n"));
                    628: 
                    629:                if ((*s_objet_argument_2).type != INT)
                    630:                {
                    631:                    liberation(s_etat_processus, s_objet_argument_2);
                    632:                    liberation(s_etat_processus, s_objet_argument_1);
                    633: 
                    634:                    (*s_etat_processus).erreur_execution =
                    635:                            d_ex_erreur_type_argument;
                    636:                    return;
                    637:                }
                    638: 
                    639:                if (depilement(s_etat_processus, &((*s_etat_processus)
                    640:                        .l_base_pile), &s_objet_argument_3) == d_erreur)
                    641:                {
                    642:                    (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    643:                    return;
                    644:                }
                    645: 
                    646:                if ((*s_objet_argument_3).type != LST)
                    647:                {
                    648:                    liberation(s_etat_processus, s_objet_argument_3);
                    649:                    liberation(s_etat_processus, s_objet_argument_2);
                    650:                    liberation(s_etat_processus, s_objet_argument_1);
                    651: 
                    652:                    (*s_etat_processus).erreur_execution =
                    653:                            d_ex_erreur_type_argument;
                    654:                    return;
                    655:                }
                    656: 
1.8       bertrand  657:                // Modification ou création d'un nouvel enregistrement
                    658: 
                    659:                if ((chaine = formateur_fichier(s_etat_processus,
                    660:                        s_objet_argument_3, (*((struct_fichier *)
                    661:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ',
                    662:                        'F', &longueur_effective, &recursivite)) == NULL)
                    663:                {
                    664:                    liberation(s_etat_processus, s_objet_argument_3);
                    665:                    liberation(s_etat_processus, s_objet_argument_2);
                    666:                    liberation(s_etat_processus, s_objet_argument_1);
                    667: 
                    668:                    return;
                    669:                }
                    670: 
                    671:                if ((chaine_utf8 = transliteration(s_etat_processus,
                    672:                        chaine, d_locale, "UTF-8")) == NULL)
                    673:                {
                    674:                    free(chaine);
                    675: 
                    676:                    liberation(s_etat_processus, s_objet_argument_3);
                    677:                    liberation(s_etat_processus, s_objet_argument_2);
                    678:                    liberation(s_etat_processus, s_objet_argument_1);
                    679: 
                    680:                    return;
                    681:                }
                    682: 
                    683:                free(chaine);
                    684: 
                    685:                if (alsprintf(&commande, "insert or replace into data "
                    686:                        "(id, data) values (%lld, '%s')", (*((integer8 *)
                    687:                        (*s_objet_argument_2).objet)), chaine_utf8) < 0)
                    688:                {
1.9       bertrand  689:                    (*s_etat_processus).erreur_systeme =
                    690:                            d_es_allocation_memoire;
1.8       bertrand  691:                    return;
                    692:                }
                    693: 
                    694:                free(chaine_utf8);
                    695: 
                    696:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                    697:                        commande, strlen(commande), &ppStmt, &queue)
                    698:                        != SQLITE_OK)
                    699:                {
                    700:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    701:                    return;
                    702:                }
                    703: 
                    704:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    705:                {
                    706:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    707:                    return;
                    708:                }
                    709: 
                    710:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    711:                {
                    712:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    713:                    return;
                    714:                }
                    715: 
                    716:                liberation(s_etat_processus, s_objet_argument_3);
                    717:                free(commande);
                    718:            }
                    719:            else // Fichiers indexés
                    720:            {
                    721:                BUG(((*descripteur).type != 'S'), uprintf("Bad filetype !\n"));
                    722: 
                    723:                if ((*s_objet_argument_2).type != LST)
                    724:                {
                    725:                    liberation(s_etat_processus, s_objet_argument_2);
                    726:                    liberation(s_etat_processus, s_objet_argument_1);
                    727: 
                    728:                    (*s_etat_processus).erreur_execution =
                    729:                            d_ex_erreur_type_argument;
                    730:                    return;
                    731:                }
                    732: 
1.9       bertrand  733:                // Récupération de la position de la clef
1.8       bertrand  734: 
                    735:                if (alsprintf(&commande, "select key from control "
                    736:                        "where id = 1") < 0)
                    737:                {
1.9       bertrand  738:                    (*s_etat_processus).erreur_systeme =
                    739:                            d_es_allocation_memoire;
1.8       bertrand  740:                    return;
                    741:                }
                    742: 
                    743:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                    744:                        commande, strlen(commande), &ppStmt, &queue)
                    745:                        != SQLITE_OK)
                    746:                {
1.9       bertrand  747:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  748:                    return;
                    749:                }
                    750: 
                    751:                if (sqlite3_step(ppStmt) != SQLITE_ROW)
                    752:                {
1.9       bertrand  753:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  754:                    return;
                    755:                }
                    756: 
                    757:                if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
                    758:                {
1.9       bertrand  759:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  760:                    return;
                    761:                }
                    762: 
                    763:                clef = sqlite3_column_int64(ppStmt, 0);
                    764: 
                    765:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    766:                {
1.9       bertrand  767:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  768:                    return;
                    769:                }
                    770: 
                    771:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    772:                {
1.9       bertrand  773:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  774:                    return;
                    775:                }
                    776: 
                    777:                free(commande);
                    778: 
                    779:                l_element_courant = (struct_liste_chainee *)
                    780:                        (*s_objet_argument_2).objet;
                    781:                l_element_courant_format = (struct_liste_chainee *)
                    782:                        (*(*((struct_fichier *) (*s_objet_argument_1).objet))
                    783:                        .format).objet;
                    784:                compteur = 1;
                    785: 
                    786:                while((l_element_courant != NULL) &&
                    787:                        (l_element_courant_format != NULL))
                    788:                {
                    789:                    if (compteur == clef)
                    790:                    {
                    791:                        break;
                    792:                    }
                    793: 
                    794:                    l_element_courant = (*l_element_courant).suivant;
                    795:                    l_element_courant_format = (*l_element_courant_format)
                    796:                            .suivant;
                    797:                    compteur++;
                    798:                }
                    799: 
                    800:                if ((l_element_courant == NULL) ||
                    801:                        (l_element_courant_format == NULL))
                    802:                {
                    803:                    (*s_etat_processus).erreur_execution =
                    804:                            d_ex_clef_inexistante;
                    805:                        
                    806:                    liberation(s_etat_processus, s_objet_argument_2);
                    807:                    liberation(s_etat_processus, s_objet_argument_1);
                    808: 
                    809:                    return;
                    810:                }
                    811: 
                    812:                if ((s_element = allocation(s_etat_processus, LST)) == NULL)
                    813:                {
                    814:                    (*s_etat_processus).erreur_systeme =
                    815:                            d_es_allocation_memoire;
                    816:                    return;
                    817:                }
                    818: 
                    819:                if (((*s_element).objet = allocation_maillon(s_etat_processus))
                    820:                        == NULL)
                    821:                {
                    822:                    (*s_etat_processus).erreur_systeme =
                    823:                            d_es_allocation_memoire;
                    824:                    return;
                    825:                }
                    826: 
                    827:                (*((struct_liste_chainee *) (*s_element).objet)).suivant = NULL;
                    828: 
                    829:                if (((*((struct_liste_chainee *) (*s_element).objet))
                    830:                        .donnee = copie_objet(s_etat_processus,
                    831:                        (*l_element_courant).donnee, 'N')) == NULL)
                    832:                {
                    833:                    (*s_etat_processus).erreur_systeme =
                    834:                            d_es_allocation_memoire;
                    835:                    return;
                    836:                }
                    837: 
                    838:                if ((s_format = allocation(s_etat_processus, LST)) == NULL)
                    839:                {
                    840:                    (*s_etat_processus).erreur_systeme =
                    841:                            d_es_allocation_memoire;
                    842:                    return;
                    843:                }
                    844: 
                    845:                if (((*s_format).objet = allocation_maillon(s_etat_processus))
                    846:                        == NULL)
                    847:                {
                    848:                    (*s_etat_processus).erreur_systeme =
                    849:                            d_es_allocation_memoire;
                    850:                    return;
                    851:                }
                    852: 
                    853:                (*((struct_liste_chainee *) (*s_format).objet)).suivant = NULL;
                    854: 
                    855:                if (((*((struct_liste_chainee *) (*s_format).objet))
                    856:                        .donnee = copie_objet(s_etat_processus,
                    857:                        (*l_element_courant_format).donnee, 'N')) == NULL)
                    858:                {
                    859:                    (*s_etat_processus).erreur_systeme =
                    860:                            d_es_allocation_memoire;
                    861:                    return;
                    862:                }
                    863: 
                    864:                if ((chaine = formateur_fichier(s_etat_processus,
                    865:                        s_element, s_format, 0, 0, ' ',
                    866:                        'F', &longueur_effective, &recursivite)) == NULL)
                    867:                {
                    868:                    liberation(s_etat_processus, s_element);
                    869:                    liberation(s_etat_processus, s_format);
                    870:                    liberation(s_etat_processus, s_objet_argument_2);
                    871:                    liberation(s_etat_processus, s_objet_argument_1);
                    872: 
                    873:                    return;
                    874:                }
                    875: 
                    876:                liberation(s_etat_processus, s_element);
                    877:                liberation(s_etat_processus, s_format);
                    878: 
                    879:                if ((clef_utf8 = transliteration(s_etat_processus,
                    880:                        chaine, d_locale, "UTF-8")) == NULL)
                    881:                {
                    882:                    liberation(s_etat_processus, s_objet_argument_2);
                    883:                    liberation(s_etat_processus, s_objet_argument_1);
                    884: 
                    885:                    return;
                    886:                }
                    887: 
                    888:                free(chaine);
                    889: 
                    890:                // Récupération de l'identifiant de la clef
                    891: 
                    892:                if (alsprintf(&commande, "select id from key where key = "
                    893:                        "'%s'", clef_utf8) < 0)
                    894:                {
1.9       bertrand  895:                    (*s_etat_processus).erreur_systeme =
                    896:                            d_es_allocation_memoire;
1.8       bertrand  897:                    return;
                    898:                }
                    899: 
                    900:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                    901:                        commande, strlen(commande), &ppStmt, &queue)
                    902:                        != SQLITE_OK)
                    903:                {
1.9       bertrand  904:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  905:                    return;
                    906:                }
                    907: 
                    908:                switch(sqlite3_step(ppStmt))
                    909:                {
                    910:                    case SQLITE_ROW:
                    911:                    {
                    912:                        // Une clef existe.
                    913: 
                    914:                        mise_a_jour = d_vrai;
                    915:                        break;
                    916:                    }
                    917: 
                    918:                    case SQLITE_DONE:
                    919:                    {
                    920:                        // Aucune clef n'existe.
                    921: 
                    922:                        mise_a_jour = d_faux;
                    923: 
                    924:                        if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    925:                        {
                    926:                            (*s_etat_processus).erreur_systeme =
                    927:                                    d_es_erreur_fichier;
                    928:                            return;
                    929:                        }
                    930: 
                    931:                        free(commande);
                    932: 
                    933:                        if (alsprintf(&commande, "insert into key "
                    934:                                "(key) values ('%s')", clef_utf8) < 0)
                    935:                        {
1.9       bertrand  936:                            (*s_etat_processus).erreur_systeme =
                    937:                                    d_es_allocation_memoire;
1.8       bertrand  938:                            return;
                    939:                        }
                    940: 
                    941:                        if (sqlite3_prepare_v2((*descripteur)
                    942:                                .descripteur_sqlite,
                    943:                                commande, strlen(commande), &ppStmt, &queue)
                    944:                                != SQLITE_OK)
                    945:                        {
                    946:                            (*s_etat_processus).erreur_systeme =
                    947:                                    d_es_erreur_fichier;
                    948:                            return;
                    949:                        }
                    950: 
                    951:                        if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    952:                        {
                    953:                            (*s_etat_processus).erreur_systeme =
                    954:                                    d_es_erreur_fichier;
                    955:                            return;
                    956:                        }
                    957: 
                    958:                        if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    959:                        {
                    960:                            (*s_etat_processus).erreur_systeme =
                    961:                                    d_es_erreur_fichier;
                    962:                            return;
                    963:                        }
                    964: 
                    965:                        free(commande);
                    966: 
                    967:                        if (alsprintf(&commande, "select id from key "
                    968:                                "where key = '%s'", clef_utf8) < 0)
                    969:                        {
1.9       bertrand  970:                            (*s_etat_processus).erreur_systeme =
                    971:                                    d_es_allocation_memoire;
1.8       bertrand  972:                            return;
                    973:                        }
                    974: 
                    975:                        if (sqlite3_prepare_v2((*descripteur)
                    976:                                .descripteur_sqlite,
                    977:                                commande, strlen(commande), &ppStmt, &queue)
                    978:                                != SQLITE_OK)
                    979:                        {
                    980:                            (*s_etat_processus).erreur_systeme =
                    981:                                    d_es_erreur_fichier;
                    982:                            return;
                    983:                        }
                    984: 
                    985:                        if (sqlite3_step(ppStmt) != SQLITE_ROW)
                    986:                        {
                    987:                            (*s_etat_processus).erreur_systeme =
                    988:                                    d_es_erreur_fichier;
                    989:                            return;
                    990:                        }
                    991: 
                    992:                        break;
                    993:                    }
                    994: 
                    995:                    default:
                    996:                    {
                    997:                        (*s_etat_processus).erreur_systeme =
                    998:                                d_es_erreur_fichier;
                    999:                        return;
                   1000:                    }
                   1001:                }
                   1002: 
                   1003:                if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
                   1004:                {
1.9       bertrand 1005:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1006:                    return;
                   1007:                }
                   1008: 
                   1009:                id = sqlite3_column_int64(ppStmt, 0);
                   1010: 
                   1011:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
1.6       bertrand 1012:                {
1.9       bertrand 1013:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1014:                    return;
                   1015:                }
1.6       bertrand 1016: 
1.8       bertrand 1017:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1018:                {
1.9       bertrand 1019:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1020:                    return;
                   1021:                }
                   1022: 
                   1023:                free(commande);
                   1024: 
                   1025:                // Modification de la clef
                   1026: 
                   1027:                if (mise_a_jour == d_vrai)
                   1028:                {
                   1029:                    if (alsprintf(&commande, "update key set key = '%s' where "
                   1030:                            "id = %lld", clef_utf8, id) < 0)
1.6       bertrand 1031:                    {
1.9       bertrand 1032:                        (*s_etat_processus).erreur_systeme =
                   1033:                                d_es_allocation_memoire;
1.6       bertrand 1034:                        return;
                   1035:                    }
1.8       bertrand 1036: 
                   1037:                    if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                   1038:                            commande, strlen(commande), &ppStmt, &queue)
                   1039:                            != SQLITE_OK)
                   1040:                    {
                   1041:                        (*s_etat_processus).erreur_systeme =
                   1042:                                d_es_erreur_fichier;
                   1043:                        return;
                   1044:                    }
                   1045: 
                   1046:                    if (sqlite3_step(ppStmt) != SQLITE_DONE)
                   1047:                    {
                   1048:                        (*s_etat_processus).erreur_systeme =
                   1049:                                d_es_erreur_fichier;
                   1050:                        return;
                   1051:                    }
                   1052: 
                   1053:                    if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1054:                    {
                   1055:                        (*s_etat_processus).erreur_systeme =
                   1056:                                d_es_erreur_fichier;
                   1057:                        return;
                   1058:                    }
                   1059: 
                   1060:                    free(commande);
1.6       bertrand 1061:                }
1.8       bertrand 1062: 
                   1063:                // Effacement de l'enregistrement existant
                   1064: 
                   1065:                if (alsprintf(&commande, "delete from data where "
                   1066:                        "key_id = %lld", id) < 0)
                   1067:                {
1.9       bertrand 1068:                    (*s_etat_processus).erreur_systeme =
                   1069:                            d_es_allocation_memoire;
1.8       bertrand 1070:                    return;
                   1071:                }
                   1072: 
                   1073:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                   1074:                        commande, strlen(commande), &ppStmt, &queue)
                   1075:                        != SQLITE_OK)
                   1076:                {
1.9       bertrand 1077:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1078:                    return;
                   1079:                }
                   1080: 
                   1081:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
                   1082:                {
1.9       bertrand 1083:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1084:                    return;
                   1085:                }
                   1086: 
                   1087:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1088:                {
1.9       bertrand 1089:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1090:                    return;
                   1091:                }
                   1092: 
                   1093:                free(commande);
                   1094: 
                   1095:                // Modification ou création d'un nouvel enregistrement
                   1096: 
                   1097:                l_element_courant = (struct_liste_chainee *)
                   1098:                        (*s_objet_argument_2).objet;
                   1099:                l_element_courant_format = (struct_liste_chainee *)
                   1100:                        (*(*((struct_fichier *) (*s_objet_argument_1).objet))
                   1101:                        .format).objet;
                   1102:                compteur = 1;
                   1103:                ordre = 1;
                   1104: 
                   1105:                while((l_element_courant != NULL) &&
                   1106:                        (l_element_courant_format != NULL))
1.6       bertrand 1107:                {
1.8       bertrand 1108:                    if (compteur == clef)
                   1109:                    {
                   1110:                        l_element_courant = (*l_element_courant).suivant;
                   1111:                        l_element_courant_format = (*l_element_courant_format)
                   1112:                                .suivant;
                   1113:                        compteur++;
                   1114:                        continue;
                   1115:                    }
                   1116: 
                   1117:                    if ((s_element = allocation(s_etat_processus, LST)) == NULL)
                   1118:                    {
                   1119:                        (*s_etat_processus).erreur_systeme =
                   1120:                                d_es_allocation_memoire;
                   1121:                        return;
                   1122:                    }
                   1123: 
                   1124:                    if (((*s_element).objet =
                   1125:                            allocation_maillon(s_etat_processus)) == NULL)
                   1126:                    {
                   1127:                        (*s_etat_processus).erreur_systeme =
                   1128:                                d_es_allocation_memoire;
                   1129:                        return;
                   1130:                    }
                   1131: 
                   1132:                    (*((struct_liste_chainee *) (*s_element).objet)).suivant
                   1133:                            = NULL;
                   1134: 
                   1135:                    if ((s_format = allocation(s_etat_processus, LST)) == NULL)
                   1136:                    {
                   1137:                        (*s_etat_processus).erreur_systeme =
                   1138:                                d_es_allocation_memoire;
                   1139:                        return;
                   1140:                    }
                   1141: 
                   1142:                    if (((*s_format).objet =
                   1143:                            allocation_maillon(s_etat_processus)) == NULL)
                   1144:                    {
                   1145:                        (*s_etat_processus).erreur_systeme =
                   1146:                                d_es_allocation_memoire;
                   1147:                        return;
                   1148:                    }
                   1149: 
                   1150:                    (*((struct_liste_chainee *) (*s_format).objet)).suivant
                   1151:                            = NULL;
                   1152: 
                   1153:                    if (((*((struct_liste_chainee *) (*s_element).objet))
                   1154:                            .donnee = copie_objet(s_etat_processus,
                   1155:                            (*l_element_courant).donnee, 'N')) == NULL)
                   1156:                    {
                   1157:                        (*s_etat_processus).erreur_systeme =
                   1158:                                d_es_allocation_memoire;
                   1159:                        return;
                   1160:                    }
                   1161: 
                   1162:                    if (((*((struct_liste_chainee *) (*s_format).objet))
                   1163:                            .donnee = copie_objet(s_etat_processus,
                   1164:                            (*l_element_courant_format).donnee, 'N')) == NULL)
                   1165:                    {
                   1166:                        (*s_etat_processus).erreur_systeme =
                   1167:                                d_es_allocation_memoire;
                   1168:                        return;
                   1169:                    }
1.6       bertrand 1170: 
                   1171:                    if ((chaine = formateur_fichier(s_etat_processus,
1.8       bertrand 1172:                            s_element, s_format, 0, 0, ' ',
1.6       bertrand 1173:                            'F', &longueur_effective, &recursivite)) == NULL)
                   1174:                    {
1.8       bertrand 1175:                        free(clef_utf8);
1.9       bertrand 1176: 
1.8       bertrand 1177:                        liberation(s_etat_processus, s_element);
                   1178:                        liberation(s_etat_processus, s_format);
1.6       bertrand 1179:                        liberation(s_etat_processus, s_objet_argument_2);
                   1180:                        liberation(s_etat_processus, s_objet_argument_1);
                   1181: 
                   1182:                        return;
                   1183:                    }
                   1184: 
                   1185:                    if ((chaine_utf8 = transliteration(s_etat_processus,
                   1186:                            chaine, d_locale, "UTF-8")) == NULL)
                   1187:                    {
1.8       bertrand 1188:                        free(clef_utf8);
1.6       bertrand 1189:                        free(chaine);
                   1190: 
                   1191:                        liberation(s_etat_processus, s_objet_argument_2);
                   1192:                        liberation(s_etat_processus, s_objet_argument_1);
                   1193: 
                   1194:                        return;
                   1195:                    }
                   1196: 
                   1197:                    free(chaine);
                   1198: 
1.8       bertrand 1199:                    if (alsprintf(&commande, "insert into data "
                   1200:                            "(data, key_id, sequence) values "
                   1201:                            "('%s', %lld, %lld)", chaine_utf8, id, ordre) < 0)
1.6       bertrand 1202:                    {
1.9       bertrand 1203:                        (*s_etat_processus).erreur_systeme =
                   1204:                                d_es_allocation_memoire;
1.6       bertrand 1205:                        return;
                   1206:                    }
                   1207: 
1.8       bertrand 1208:                    if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
                   1209:                            commande, strlen(commande), &ppStmt, &queue)
                   1210:                            != SQLITE_OK)
                   1211:                    {
                   1212:                        (*s_etat_processus).erreur_systeme =
                   1213:                                d_es_erreur_fichier;
                   1214:                        return;
                   1215:                    }
                   1216: 
                   1217:                    if (sqlite3_step(ppStmt) != SQLITE_DONE)
                   1218:                    {
                   1219:                        (*s_etat_processus).erreur_systeme =
                   1220:                                d_es_erreur_fichier;
                   1221:                        return;
                   1222:                    }
                   1223: 
                   1224:                    if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1225:                    {
                   1226:                        (*s_etat_processus).erreur_systeme =
                   1227:                                d_es_erreur_fichier;
                   1228:                        return;
                   1229:                    }
                   1230: 
                   1231:                    free(commande);
1.6       bertrand 1232:                    free(chaine_utf8);
1.8       bertrand 1233: 
                   1234:                    liberation(s_etat_processus, s_element);
                   1235:                    liberation(s_etat_processus, s_format);
                   1236: 
                   1237:                    l_element_courant = (*l_element_courant).suivant;
                   1238:                    l_element_courant_format = (*l_element_courant_format)
                   1239:                            .suivant;
                   1240: 
                   1241:                    compteur++;
                   1242:                    ordre++;
1.6       bertrand 1243:                }
                   1244: 
1.8       bertrand 1245:                free(clef_utf8);
1.6       bertrand 1246: 
1.8       bertrand 1247:                if ((l_element_courant != NULL) ||
                   1248:                        (l_element_courant_format != NULL))
1.6       bertrand 1249:                {
1.8       bertrand 1250:                    liberation(s_etat_processus, s_objet_argument_1);
                   1251:                    liberation(s_etat_processus, s_objet_argument_2);
1.6       bertrand 1252: 
1.8       bertrand 1253:                    (*s_etat_processus).erreur_execution =
                   1254:                            d_ex_erreur_format_fichier;
1.6       bertrand 1255:                    return;
                   1256:                }
1.1       bertrand 1257:            }
                   1258:        }
                   1259:        else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire
                   1260:                == 'Y')
                   1261:        {
                   1262:            /*
                   1263:             * Fichiers non formatés
                   1264:             */
                   1265: 
                   1266:            if ((chaine = formateur_fichier(s_etat_processus,
                   1267:                    s_objet_argument_2, (*((struct_fichier *)
                   1268:                    (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
                   1269:                    &longueur_effective, &recursivite)) == NULL)
                   1270:            {
                   1271:                liberation(s_etat_processus, s_objet_argument_2);
                   1272:                liberation(s_etat_processus, s_objet_argument_1);
                   1273: 
                   1274:                return;
                   1275:            }
                   1276: 
                   1277:            if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                   1278:                    == 'S')
                   1279:            {
1.5       bertrand 1280:                BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
                   1281: 
                   1282:                if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
                   1283:                        != 0)
1.1       bertrand 1284:                {
                   1285:                    liberation(s_etat_processus, s_objet_argument_2);
                   1286:                    liberation(s_etat_processus, s_objet_argument_1);
                   1287: 
                   1288:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   1289:                    return;
                   1290:                }
                   1291: 
                   1292:                if (fwrite(chaine, sizeof(unsigned char), longueur_effective,
1.5       bertrand 1293:                        (*descripteur).descripteur_c) !=
                   1294:                        (size_t) longueur_effective)
1.1       bertrand 1295:                {
                   1296:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   1297:                    return;
                   1298:                }
                   1299:            }
                   1300:            else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                   1301:                    == 'D')
                   1302:            {
                   1303:            }
                   1304:            else
                   1305:            {
                   1306:                /* Fichiers indexés : panique totale ! */
                   1307:            }
                   1308: 
                   1309:            free(chaine);
                   1310:        }
                   1311:        else
                   1312:        {
                   1313:            /*
                   1314:             * Fichiers de type FLOW
                   1315:             */
                   1316:        }
                   1317:    }
                   1318:    else if (((*s_objet_argument_2).type == LST) &&
                   1319:            ((*s_objet_argument_1).type == SCK))
                   1320:    {
                   1321:        /*
                   1322:         * Vérification de l'autorisation d'écriture
                   1323:         */
                   1324: 
                   1325:        if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1326:                .protection == 'R')
                   1327:        {
                   1328:            liberation(s_etat_processus, s_objet_argument_2);
                   1329:            liberation(s_etat_processus, s_objet_argument_1);
                   1330: 
                   1331:            (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
                   1332:            return;
                   1333:        }
                   1334: 
                   1335:        if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
                   1336:        {
                   1337:            /*
                   1338:             * Sockets formatées
                   1339:             */
                   1340: 
                   1341:            if ((chaine = formateur_fichier(s_etat_processus,
                   1342:                    s_objet_argument_2, (*((struct_socket *)
                   1343:                    (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
                   1344:                    &longueur_effective, &recursivite)) == NULL)
                   1345:            {
                   1346:                liberation(s_etat_processus, s_objet_argument_2);
                   1347:                liberation(s_etat_processus, s_objet_argument_1);
                   1348: 
                   1349:                return;
                   1350:            }
                   1351: 
                   1352:            if ((strcmp((*((struct_socket *) (*s_objet_argument_1).objet)).type,
                   1353:                    "STREAM") == 0) || (strcmp((*((struct_socket *)
                   1354:                    (*s_objet_argument_1).objet)).type,
                   1355:                    "SEQUENTIAL DATAGRAM") == 0))
                   1356:            { // Sockets connectées
                   1357: 
                   1358:                action.sa_handler = SIG_IGN;
                   1359:                action.sa_flags = SA_ONSTACK;
                   1360: 
                   1361:                if (sigaction(SIGPIPE, &action, &registre) != 0)
                   1362:                {
                   1363:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                   1364:                    return;
                   1365:                }
                   1366: 
                   1367:                if (sem_post(&((*s_etat_processus).semaphore_fork))
                   1368:                        != 0)
                   1369:                {
                   1370:                    if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1371:                    {
                   1372:                        (*s_etat_processus).erreur_systeme = d_es_signal;
                   1373:                        return;
                   1374:                    }
                   1375: 
                   1376:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1377:                    return;
                   1378:                }
                   1379: 
                   1380:                if (send((*((struct_socket *) (*s_objet_argument_1).objet))
                   1381:                        .socket, chaine, strlen(chaine), 0) < 0)
                   1382:                {
                   1383:                    ios = errno;
                   1384: 
                   1385:                    if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1386:                    {
                   1387:                        (*s_etat_processus).erreur_systeme = d_es_signal;
                   1388:                        return;
                   1389:                    }
                   1390: 
                   1391:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   1392:                    {
                   1393:                        if (errno != EINTR)
                   1394:                        {
                   1395:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1396:                            return;
                   1397:                        }
                   1398:                    }
                   1399: 
                   1400:                    if (ios == EPIPE)
                   1401:                    {
                   1402:                        (*s_etat_processus).erreur_execution =
                   1403:                                d_ex_erreur_acces_fichier;
                   1404:                        return;
                   1405:                    }
                   1406: 
                   1407:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   1408:                    return;
                   1409:                }
                   1410: 
                   1411:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   1412:                {
                   1413:                    if (errno != EINTR)
                   1414:                    {
                   1415:                        if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1416:                        {
                   1417:                            (*s_etat_processus).erreur_systeme = d_es_signal;
                   1418:                            return;
                   1419:                        }
                   1420: 
                   1421:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1422:                        return;
                   1423:                    }
                   1424:                }
                   1425: 
                   1426:                if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1427:                {
                   1428:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                   1429:                    return;
                   1430:                }
                   1431:            }
                   1432:            else
                   1433:            { // Sockets non connectées
                   1434: 
                   1435:                /*
                   1436:                 * Vérification de l'adresse distante
                   1437:                 */
                   1438: 
                   1439:                if (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
                   1440:                        .adresse_distante, "") == 0)
                   1441:                {
                   1442:                    liberation(s_etat_processus, s_objet_argument_1);
                   1443:                    liberation(s_etat_processus, s_objet_argument_2);
                   1444: 
                   1445:                    (*s_etat_processus).erreur_execution =
                   1446:                            d_ex_erreur_acces_fichier;
                   1447:                    return;
                   1448:                }
                   1449: 
                   1450:                /*
                   1451:                 * Création de l'adresse logique
                   1452:                 */
                   1453: 
                   1454:                if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1455:                        .domaine == PF_UNIX)
                   1456:                {
                   1457:                    adresse_unix.sun_family = AF_UNIX;
                   1458:                    strncpy(adresse_unix.sun_path, (*((struct_socket *)
                   1459:                            (*s_objet_argument_1).objet)).adresse_distante,
                   1460:                            108);
                   1461:                    adresse_unix.sun_path[108 - 1] = d_code_fin_chaine;
                   1462: 
                   1463:                    if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1464:                    {
                   1465:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1466:                        return;
                   1467:                    }
                   1468: 
                   1469:                    if (sendto((*((struct_socket *)
                   1470:                            (*s_objet_argument_1).objet)).socket, chaine,
                   1471:                            strlen(chaine), 0, (struct sockaddr *)
                   1472:                            &adresse_unix, sizeof(adresse_unix)) < 0)
                   1473:                    {
                   1474:                        while(sem_wait(&((*s_etat_processus)
                   1475:                                .semaphore_fork)) == -1)
                   1476:                        {
                   1477:                            if (errno != EINTR)
                   1478:                            {
                   1479:                                (*s_etat_processus).erreur_systeme =
                   1480:                                        d_es_processus;
                   1481:                                return;
                   1482:                            }
                   1483:                        }
                   1484: 
                   1485:                        (*s_etat_processus).erreur_systeme =
                   1486:                                d_es_erreur_fichier;
                   1487:                        return;
                   1488:                    }
                   1489: 
                   1490:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   1491:                    {
                   1492:                        if (errno != EINTR)
                   1493:                        {
                   1494:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1495:                            return;
                   1496:                        }
                   1497:                    }
                   1498:                }
                   1499:                else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1500:                        .domaine == PF_INET)
                   1501:                {
                   1502:                    if (sscanf((*((struct_socket *)
                   1503:                            (*s_objet_argument_1).objet))
                   1504:                            .adresse_distante, "%d.%d.%d.%d(%d)",
                   1505:                            &(adresse[0]), &(adresse[1]), &(adresse[2]),
                   1506:                            &(adresse[3]), &port) == 5)
                   1507:                    { // Adresse IPv4
                   1508:                        calcul_adresse = 0;
                   1509:                        for(i = 0; i < 4; calcul_adresse =
                   1510:                                (256 * calcul_adresse) + adresse[i++]);
                   1511: 
                   1512:                        memset(&adresse_ipv4, 0, sizeof(adresse_ipv4));
                   1513:                        adresse_ipv4.sin_family = AF_INET;
                   1514:                        adresse_ipv4.sin_port = htons(port);
                   1515:                        adresse_ipv4.sin_addr.s_addr = htonl(calcul_adresse);
                   1516: 
                   1517:                        if (sem_post(&((*s_etat_processus)
                   1518:                                .semaphore_fork)) != 0)
                   1519:                        {
                   1520:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1521:                            return;
                   1522:                        }
                   1523: 
                   1524:                        if (sendto((*((struct_socket *)
                   1525:                                (*s_objet_argument_1).objet)).socket, chaine,
                   1526:                                strlen(chaine), 0, (struct sockaddr *)
                   1527:                                &adresse_ipv4, sizeof(adresse_ipv4)) < 0)
                   1528:                        {
                   1529:                            while(sem_wait(&((*s_etat_processus)
                   1530:                                    .semaphore_fork)) == -1)
                   1531:                            {
                   1532:                                if (errno != EINTR)
                   1533:                                {
                   1534:                                    (*s_etat_processus).erreur_systeme =
                   1535:                                            d_es_processus;
                   1536:                                    return;
                   1537:                                }
                   1538:                            }
                   1539: 
                   1540:                            (*s_etat_processus).erreur_systeme =
                   1541:                                    d_es_erreur_fichier;
                   1542:                            return;
                   1543:                        }
                   1544: 
                   1545:                        while(sem_wait(&((*s_etat_processus)
                   1546:                                .semaphore_fork)) == -1)
                   1547:                        {
                   1548:                            if (errno != EINTR)
                   1549:                            {
                   1550:                                (*s_etat_processus).erreur_systeme =
                   1551:                                        d_es_processus;
                   1552:                                return;
                   1553:                            }
                   1554:                        }
                   1555:                    }
                   1556:                    else
                   1557:                    {
                   1558:                        liberation(s_etat_processus, s_objet_argument_1);
                   1559:                        liberation(s_etat_processus, s_objet_argument_2);
                   1560: 
                   1561:                        (*s_etat_processus).erreur_execution =
                   1562:                                d_ex_erreur_parametre_fichier;
                   1563:                        return;
                   1564:                    }
                   1565:                }
                   1566:                else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1567:                        .domaine == PF_INET6)
                   1568:                {
                   1569:                    if (sscanf((*((struct_socket *) (*s_objet_argument_1)
                   1570:                            .objet)).adresse_distante, "%X:%X:%X:%X:%X:"
                   1571:                            "%X:%X:%X:%X:%X:%X:%X:%X:%X:%X:%X(%d)",
                   1572:                            &(adresse[0]), &(adresse[1]), &(adresse[2]),
                   1573:                            &(adresse[3]), &(adresse[4]), &(adresse[5]),
                   1574:                            &(adresse[6]), &(adresse[7]), &(adresse[8]),
                   1575:                            &(adresse[9]), &(adresse[10]), &(adresse[11]),
                   1576:                            &(adresse[12]), &(adresse[13]), &(adresse[14]),
                   1577:                            &(adresse[15]), &port)== 17)
                   1578:                    { // Adresse IPv6
                   1579:                        memset(&adresse_ipv6, 0, sizeof(adresse_ipv6));
                   1580:                        adresse_ipv6.sin6_family = AF_INET6;
                   1581:                        adresse_ipv6.sin6_port = htons((uint16_t) port);
                   1582: 
                   1583:                        for(i = 0; i < 16;
                   1584:                                adresse_ipv6.sin6_addr.s6_addr[i] =
                   1585:                                adresse[i], i++);
                   1586: 
                   1587:                        if (sem_post(&((*s_etat_processus)
                   1588:                                .semaphore_fork)) != 0)
                   1589:                        {
                   1590:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1591:                            return;
                   1592:                        }
                   1593: 
                   1594:                        if (sendto((*((struct_socket *)
                   1595:                                (*s_objet_argument_1).objet)).socket, chaine,
                   1596:                                strlen(chaine), 0, (struct sockaddr *)
                   1597:                                &adresse_ipv6, sizeof(adresse_ipv6)) < 0)
                   1598:                        {
                   1599:                            while(sem_wait(&((*s_etat_processus)
                   1600:                                    .semaphore_fork)) == -1)
                   1601:                            {
                   1602:                                if (errno != EINTR)
                   1603:                                {
                   1604:                                    (*s_etat_processus).erreur_systeme =
                   1605:                                            d_es_processus;
                   1606:                                    return;
                   1607:                                }
                   1608:                            }
                   1609: 
                   1610:                            (*s_etat_processus).erreur_systeme =
                   1611:                                    d_es_erreur_fichier;
                   1612:                            return;
                   1613:                        }
                   1614: 
                   1615:                        while(sem_wait(&((*s_etat_processus)
                   1616:                                .semaphore_fork)) == -1)
                   1617:                        {
                   1618:                            if (errno != EINTR)
                   1619:                            {
                   1620:                                (*s_etat_processus).erreur_systeme =
                   1621:                                        d_es_processus;
                   1622:                                return;
                   1623:                            }
                   1624:                        }
                   1625:                    }
                   1626:                    else
                   1627:                    {
                   1628:                        liberation(s_etat_processus, s_objet_argument_1);
                   1629:                        liberation(s_etat_processus, s_objet_argument_2);
                   1630: 
                   1631:                        (*s_etat_processus).erreur_execution =
                   1632:                                d_ex_erreur_parametre_fichier;
                   1633:                        return;
                   1634:                    }
                   1635:                }
                   1636:                else 
                   1637:                {
                   1638:                    liberation(s_etat_processus, s_objet_argument_1);
                   1639:                    liberation(s_etat_processus, s_objet_argument_2);
                   1640: 
                   1641:                    (*s_etat_processus).erreur_execution =
                   1642:                            d_ex_erreur_parametre_fichier;
                   1643:                    return;
                   1644:                }
                   1645:            }
                   1646: 
                   1647:            free(chaine);
                   1648:        }
                   1649:        else if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire
                   1650:                == 'Y')
                   1651:        {
                   1652:            /*
                   1653:             * Sockets non formatées
                   1654:             */
                   1655:        }
                   1656:        else
                   1657:        {
                   1658:            /*
                   1659:             *  Sockets de type FLOW
                   1660:             */
                   1661:        }
                   1662:    }
                   1663:    else
                   1664:    {
                   1665:        liberation(s_etat_processus, s_objet_argument_2);
                   1666:        liberation(s_etat_processus, s_objet_argument_1);
                   1667: 
                   1668:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1669:        return;
                   1670:    }
                   1671: 
                   1672:    liberation(s_etat_processus, s_objet_argument_2);
                   1673:    liberation(s_etat_processus, s_objet_argument_1);
                   1674: 
                   1675:    return;
                   1676: }
                   1677: 
                   1678: 
                   1679: /*
                   1680: ================================================================================
                   1681:   Fonction 'wflock'
                   1682: ================================================================================
                   1683:   Entrées : pointeur sur une structure struct_processus
                   1684: --------------------------------------------------------------------------------
                   1685:   Sorties :
                   1686: --------------------------------------------------------------------------------
                   1687:   Effets de bord : néant
                   1688: ================================================================================
                   1689: */
                   1690: 
                   1691: void
                   1692: instruction_wflock(struct_processus *s_etat_processus)
                   1693: {
                   1694:    logical1                    drapeau;
                   1695: 
                   1696:    struct flock                lock;
                   1697: 
                   1698:    struct timespec             attente;
                   1699: 
1.5       bertrand 1700:    struct_descripteur_fichier  *descripteur;
                   1701: 
1.1       bertrand 1702:    struct_objet                *s_objet_argument_1;
                   1703:    struct_objet                *s_objet_argument_2;
                   1704: 
                   1705:    unsigned char               *chaine;
                   1706:    unsigned char               registre_instruction_valide;
                   1707: 
                   1708:    attente.tv_sec = 0;
                   1709:    attente.tv_nsec = GRANULARITE_us * 1000;
                   1710: 
                   1711:    (*s_etat_processus).erreur_execution = d_ex;
                   1712: 
                   1713:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1714:    {
                   1715:        printf("\n  WFLOCK ");
                   1716:        
                   1717:        if ((*s_etat_processus).langue == 'F')
                   1718:        {
                   1719:            printf("(attente du positionnement d'un verrou sur un fichier)"
                   1720:                    "\n\n");
                   1721:        }
                   1722:        else
                   1723:        {
                   1724:            printf("(wait for file lock)\n\n");
                   1725:        }
                   1726: 
                   1727:        printf("    2: %s\n", d_FCH);
                   1728:        printf("    1: %s (READ/WRITE/NONE)\n", d_CHN);
                   1729: 
                   1730:        return;
                   1731:    }
                   1732:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1733:    {
                   1734:        (*s_etat_processus).nombre_arguments = -1;
                   1735:        return;
                   1736:    }
                   1737: 
                   1738:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1739:    {
                   1740:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                   1741:        {
                   1742:            return;
                   1743:        }
                   1744:    }
                   1745: 
                   1746:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1747:            &s_objet_argument_1) == d_erreur)
                   1748:    {
                   1749:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1750:        return;
                   1751:    }
                   1752: 
                   1753:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1754:            &s_objet_argument_2) == d_erreur)
                   1755:    {
                   1756:        liberation(s_etat_processus, s_objet_argument_1);
                   1757: 
                   1758:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1759:        return;
                   1760:    }
                   1761: 
                   1762:    if (((*s_objet_argument_2).type == FCH) &&
                   1763:            ((*s_objet_argument_1).type == CHN))
                   1764:    {
                   1765:        drapeau = d_faux;
                   1766: 
                   1767:        do
                   1768:        {
                   1769:            if ((chaine = conversion_majuscule((unsigned char *)
                   1770:                    (*s_objet_argument_1).objet)) == NULL)
                   1771:            {
                   1772:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1773:                return;
                   1774:            }
                   1775: 
                   1776:            if (strcmp(chaine, "WRITE") == 0)
                   1777:            {
                   1778:                lock.l_type = F_WRLCK;
                   1779:            }
                   1780:            else if (strcmp(chaine, "READ") == 0)
                   1781:            {
                   1782:                lock.l_type = F_RDLCK;
                   1783:            }
                   1784:            else if (strcmp(chaine, "NONE") == 0)
                   1785:            {
                   1786:                lock.l_type = F_UNLCK;
                   1787:            }
                   1788:            else
                   1789:            {
                   1790:                free(chaine);
                   1791: 
                   1792:                liberation(s_etat_processus, s_objet_argument_1);
                   1793:                liberation(s_etat_processus, s_objet_argument_2);
                   1794: 
                   1795:                (*s_etat_processus).erreur_execution = d_ex_verrou_indefini;
                   1796:                return;
                   1797:            }
                   1798: 
                   1799:            free(chaine);
                   1800: 
                   1801:            lock.l_whence = SEEK_SET;
                   1802:            lock.l_start = 0;
                   1803:            lock.l_len = 0;
                   1804:            lock.l_pid = getpid();
                   1805: 
                   1806:            if ((descripteur = descripteur_fichier(s_etat_processus,
                   1807:                    (struct_fichier *) (*s_objet_argument_2).objet)) == NULL)
                   1808:            {
                   1809:                return;
                   1810:            }
                   1811: 
1.5       bertrand 1812:            if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
                   1813:                    == -1)
1.1       bertrand 1814:            {
                   1815:                liberation(s_etat_processus, s_objet_argument_1);
                   1816:                liberation(s_etat_processus, s_objet_argument_2);
                   1817: 
                   1818:                (*s_etat_processus).erreur_execution = d_ex_fichier_verrouille;
                   1819:                return;
                   1820:            }
                   1821: 
                   1822:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1823:            {
                   1824:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1825:                return;
                   1826:            }
                   1827: 
                   1828:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   1829:            {
                   1830:                if (errno != EINTR)
                   1831:                {
                   1832:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1833:                    return;
                   1834:                }
                   1835:            }
                   1836: 
                   1837:            if (lock.l_type == F_UNLCK)
                   1838:            {
                   1839:                drapeau = d_vrai;
                   1840:            }
                   1841:            else
                   1842:            {
                   1843:                if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   1844:                {
                   1845:                    affectation_interruptions_logicielles(s_etat_processus);
                   1846:                }
                   1847: 
                   1848:                if ((*s_etat_processus).nombre_interruptions_en_queue
                   1849:                        != 0)
                   1850:                {
                   1851:                    registre_instruction_valide =
                   1852:                            (*s_etat_processus).instruction_valide;
                   1853:                    traitement_interruptions_logicielles(
                   1854:                            s_etat_processus);
                   1855:                    (*s_etat_processus).instruction_valide =
                   1856:                            registre_instruction_valide;
                   1857:                }
                   1858: 
                   1859:                nanosleep(&attente, NULL);
                   1860:                scrutation_injection(s_etat_processus);
                   1861: 
                   1862:                INCR_GRANULARITE(attente.tv_nsec);
                   1863:            }
                   1864:        } while((drapeau == d_faux) && ((*s_etat_processus)
                   1865:                .var_volatile_requete_arret != -1));
                   1866:    }
                   1867:    else
                   1868:    {
                   1869:        liberation(s_etat_processus, s_objet_argument_1);
                   1870:        liberation(s_etat_processus, s_objet_argument_2);
                   1871: 
                   1872:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1873:        return;
                   1874:    }
                   1875: 
                   1876:    return;
                   1877: }
                   1878: 
                   1879: 
                   1880: /*
                   1881: ================================================================================
                   1882:   Fonction 'wfproc'
                   1883: ================================================================================
                   1884:   Entrées : pointeur sur une structure struct_processus
                   1885: --------------------------------------------------------------------------------
                   1886:   Sorties :
                   1887: --------------------------------------------------------------------------------
                   1888:   Effets de bord : néant
                   1889: ================================================================================
                   1890: */
                   1891: 
                   1892: void
                   1893: instruction_wfproc(struct_processus *s_etat_processus)
                   1894: {
                   1895:    logical1                    drapeau_fin;
                   1896: 
                   1897:    struct_liste_chainee        *l_element_courant;
                   1898: 
                   1899:    struct_objet                *s_objet_argument;
                   1900: 
                   1901:    struct timespec             attente;
                   1902: 
                   1903:    unsigned char               registre_instruction_valide;
                   1904: 
                   1905:    (*s_etat_processus).erreur_execution = d_ex;
                   1906: 
                   1907:    attente.tv_sec = 0;
                   1908:    attente.tv_nsec = GRANULARITE_us * 1000;
                   1909: 
                   1910:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1911:    {
                   1912:        printf("\n  WFPROC ");
                   1913: 
                   1914:        if ((*s_etat_processus).langue == 'F')
                   1915:        {
                   1916:            printf("(attente de la fin d'un processus fils)\n\n");
                   1917:        }
                   1918:        else
                   1919:        {
                   1920:            printf("(wait for child process end)\n\n");
                   1921:        }
                   1922: 
                   1923:        printf("    1: %s\n", d_PRC);
                   1924: 
                   1925:        return;
                   1926:    }
                   1927:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1928:    {
                   1929:        (*s_etat_processus).nombre_arguments = -1;
                   1930:        return;
                   1931:    }
                   1932: 
                   1933:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1934:    {
                   1935:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   1936:        {
                   1937:            return;
                   1938:        }
                   1939:    }
                   1940: 
                   1941:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1942:            &s_objet_argument) == d_erreur)
                   1943:    {
                   1944:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1945:        return;
                   1946:    }
                   1947: 
                   1948:    if ((*s_objet_argument).type == PRC)
                   1949:    {
                   1950:        drapeau_fin = d_faux;
                   1951: 
                   1952:        if ((*s_etat_processus).profilage == d_vrai)
                   1953:        {
                   1954:            profilage(s_etat_processus, "Interprocess or interthread "
                   1955:                    "communications (WFPROC)");
                   1956: 
                   1957:            if ((*s_etat_processus).erreur_systeme != d_es)
                   1958:            {
                   1959:                return;
                   1960:            }
                   1961:        }
                   1962: 
                   1963:        if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   1964:        {
                   1965:            if ((*s_etat_processus).profilage == d_vrai)
                   1966:            {
                   1967:                profilage(s_etat_processus, NULL);
                   1968:            }
                   1969: 
                   1970:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1971:            return;
                   1972:        }
                   1973: 
                   1974:        while(drapeau_fin == d_faux)
                   1975:        {
                   1976:            l_element_courant = (struct_liste_chainee *)
                   1977:                    (*s_etat_processus).l_base_pile_processus;
                   1978: 
                   1979:            while(l_element_courant != NULL)
                   1980:            {
                   1981:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   1982:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   1983:                {
                   1984:                    if ((*(*((struct_processus_fils *)
                   1985:                            (*s_objet_argument).objet)).thread)
                   1986:                            .processus_detache == d_vrai)
                   1987:                    {
                   1988:                        if ((*(*((struct_processus_fils *)
                   1989:                                (*(*l_element_courant)
                   1990:                                .donnee).objet)).thread).pid ==
                   1991:                                (*(*((struct_processus_fils *)
                   1992:                                (*s_objet_argument).objet)).thread).pid)
                   1993:                        {
                   1994:                            break;
                   1995:                        }
                   1996:                    }
                   1997:                }
                   1998:                else
                   1999:                {
                   2000:                    if ((*(*((struct_processus_fils *)
                   2001:                            (*s_objet_argument).objet)).thread)
                   2002:                            .processus_detache == d_faux)
                   2003:                    {
                   2004:                        if ((pthread_equal((*(*((struct_processus_fils *)
                   2005:                                (*(*l_element_courant).donnee).objet)).thread)
                   2006:                                .tid, (*(*((struct_processus_fils *)
                   2007:                                (*s_objet_argument).objet)).thread).tid) != 0)
                   2008:                                && ((*(*((struct_processus_fils *)
                   2009:                                (*(*l_element_courant).donnee).objet)).thread)
                   2010:                                .pid == (*(*((struct_processus_fils *)
                   2011:                                (*s_objet_argument).objet)).thread).pid))
                   2012:                        {
                   2013:                            break;
                   2014:                        }
                   2015:                    }
                   2016:                }
                   2017: 
                   2018:                l_element_courant = (*l_element_courant).suivant;
                   2019:            }
                   2020: 
                   2021:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2022:            {
                   2023:                if ((*s_etat_processus).profilage == d_vrai)
                   2024:                {
                   2025:                    profilage(s_etat_processus, NULL);
                   2026:                }
                   2027: 
                   2028:                if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2029:                {
                   2030:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2031:                    return;
                   2032:                }
                   2033: 
                   2034:                liberation(s_etat_processus, s_objet_argument);
                   2035:                return;
                   2036:            }
                   2037: 
                   2038:            if (l_element_courant == NULL)
                   2039:            {
                   2040:                /*
                   2041:                 * Si l_element_courant vaut NULL, le processus n'existe plus.
                   2042:                 */
                   2043: 
                   2044:                drapeau_fin = d_vrai;
                   2045:            }
                   2046:            else
                   2047:            {
                   2048:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2049:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   2050:                {
                   2051:                    if (kill((*(*((struct_processus_fils *)
                   2052:                            (*(*l_element_courant).donnee).objet)).thread).pid,
                   2053:                            0) != 0)
                   2054:                    {
                   2055:                        drapeau_fin = d_vrai;
                   2056:                    }
                   2057:                    else
                   2058:                    {
                   2059:                        drapeau_fin = d_faux;
                   2060:                    }
                   2061:                }
                   2062:                else
                   2063:                {
                   2064:                    if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
                   2065:                            (*(*l_element_courant).donnee).objet)).thread)
                   2066:                            .mutex)) != 0)
                   2067:                    {
                   2068:                        if ((*s_etat_processus).profilage == d_vrai)
                   2069:                        {
                   2070:                            profilage(s_etat_processus, NULL);
                   2071:                        }
                   2072: 
                   2073:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2074:                        return;
                   2075:                    }
                   2076: 
                   2077:                    if ((*(*((struct_processus_fils *)
                   2078:                            (*(*l_element_courant).donnee).objet)).thread)
                   2079:                            .thread_actif == d_faux)
                   2080:                    {
                   2081:                        drapeau_fin = d_vrai;
                   2082:                    }
                   2083:                    else
                   2084:                    {
                   2085:                        drapeau_fin = d_faux;
                   2086:                    }
                   2087: 
                   2088:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2089:                            (*(*l_element_courant).donnee).objet)).thread)
                   2090:                            .mutex)) != 0)
                   2091:                    {
                   2092:                        if ((*s_etat_processus).profilage == d_vrai)
                   2093:                        {
                   2094:                            profilage(s_etat_processus, NULL);
                   2095:                        }
                   2096: 
                   2097:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2098:                        return;
                   2099:                    }
                   2100:                }
                   2101: 
                   2102:                if (drapeau_fin == d_faux)
                   2103:                {
                   2104:                    /*
                   2105:                     * Le processus n'est pas terminé
                   2106:                     */
                   2107: 
                   2108:                    if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2109:                    {
                   2110:                        if ((*s_etat_processus).profilage == d_vrai)
                   2111:                        {
                   2112:                            profilage(s_etat_processus, NULL);
                   2113:                        }
                   2114: 
                   2115:                        (*s_etat_processus).erreur_systeme =
                   2116:                                d_es_processus;
                   2117:                        return;
                   2118:                    }
                   2119: 
                   2120:                    if ((*s_etat_processus).nombre_interruptions_non_affectees
                   2121:                            != 0)
                   2122:                    {
                   2123:                        affectation_interruptions_logicielles(s_etat_processus);
                   2124:                    }
                   2125: 
                   2126:                    if ((*s_etat_processus).nombre_interruptions_en_queue
                   2127:                            != 0)
                   2128:                    {
                   2129:                        registre_instruction_valide =
                   2130:                                (*s_etat_processus).instruction_valide;
                   2131:                        traitement_interruptions_logicielles(
                   2132:                                s_etat_processus);
                   2133:                        (*s_etat_processus).instruction_valide =
                   2134:                                registre_instruction_valide;
                   2135:                    }
                   2136: 
                   2137:                    if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2138:                    {
                   2139:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2140:                        return;
                   2141:                    }
                   2142: 
                   2143:                    nanosleep(&attente, NULL);
                   2144: 
                   2145:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2146:                    {
                   2147:                        if (errno != EINTR)
                   2148:                        {
                   2149:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2150:                            return;
                   2151:                        }
                   2152:                    }
                   2153: 
                   2154:                    scrutation_injection(s_etat_processus);
                   2155: 
                   2156:                    if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   2157:                    {
                   2158:                        if ((*s_etat_processus).profilage == d_vrai)
                   2159:                        {
                   2160:                            profilage(s_etat_processus, NULL);
                   2161:                        }
                   2162: 
                   2163:                        (*s_etat_processus).erreur_systeme =
                   2164:                                d_es_processus;
                   2165:                        return;
                   2166:                    }
                   2167:                }
                   2168:            }
                   2169: 
                   2170:            INCR_GRANULARITE(attente.tv_nsec);
                   2171:        }
                   2172: 
                   2173:        if ((*s_etat_processus).profilage == d_vrai)
                   2174:        {
                   2175:            profilage(s_etat_processus, NULL);
                   2176:        }
                   2177: 
                   2178:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2179:        {
                   2180:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2181:            return;
                   2182:        }
                   2183:    }
                   2184:    else
                   2185:    {
                   2186:        liberation(s_etat_processus, s_objet_argument);
                   2187: 
                   2188:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2189:        return;
                   2190:    }
                   2191: 
                   2192:    liberation(s_etat_processus, s_objet_argument);
                   2193: 
                   2194:    return;
                   2195: }
                   2196: 
                   2197: 
                   2198: /*
                   2199: ================================================================================
                   2200:   Fonction 'wfdata'
                   2201: ================================================================================
                   2202:   Entrées : pointeur sur une structure struct_processus
                   2203: --------------------------------------------------------------------------------
                   2204:   Sorties :
                   2205: --------------------------------------------------------------------------------
                   2206:   Effets de bord : néant
                   2207: ================================================================================
                   2208: */
                   2209: 
                   2210: void
                   2211: instruction_wfdata(struct_processus *s_etat_processus)
                   2212: {
                   2213:    logical1                    drapeau_fin;
                   2214: 
                   2215:    struct_liste_chainee        *l_element_courant;
                   2216: 
                   2217:    struct_objet                *s_objet_argument;
                   2218: 
                   2219:    struct timespec             attente;
                   2220: 
                   2221:    unsigned char               registre_instruction_valide;
                   2222: 
                   2223:    (*s_etat_processus).erreur_execution = d_ex;
                   2224: 
                   2225:    attente.tv_sec = 0;
                   2226:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2227: 
                   2228:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2229:    {
                   2230:        printf("\n  WFDATA ");
                   2231: 
                   2232:        if ((*s_etat_processus).langue == 'F')
                   2233:        {
                   2234:            printf("(attente de données d'un processus fils)\n\n");
                   2235:        }
                   2236:        else
                   2237:        {
                   2238:            printf("(wait for data from child process)\n\n");
                   2239:        }
                   2240: 
                   2241:        printf("    1: %s\n", d_PRC);
                   2242: 
                   2243:        return;
                   2244:    }
                   2245:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2246:    {
                   2247:        (*s_etat_processus).nombre_arguments = -1;
                   2248:        return;
                   2249:    }
                   2250: 
                   2251:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2252:    {
                   2253:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2254:        {
                   2255:            return;
                   2256:        }
                   2257:    }
                   2258: 
                   2259:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2260:            &s_objet_argument) == d_erreur)
                   2261:    {
                   2262:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2263:        return;
                   2264:    }
                   2265: 
                   2266:    if ((*s_objet_argument).type == PRC)
                   2267:    {
                   2268:        drapeau_fin = d_faux;
                   2269: 
                   2270:        if ((*s_etat_processus).profilage == d_vrai)
                   2271:        {
                   2272:            profilage(s_etat_processus, "Interprocess or interthread "
                   2273:                    "communications (WFDATA)");
                   2274: 
                   2275:            if ((*s_etat_processus).erreur_systeme != d_es)
                   2276:            {
                   2277:                return;
                   2278:            }
                   2279:        }
                   2280: 
                   2281:        if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   2282:        {
                   2283:            if ((*s_etat_processus).profilage == d_vrai)
                   2284:            {
                   2285:                profilage(s_etat_processus, NULL);
                   2286:            }
                   2287: 
                   2288:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2289:            return;
                   2290:        }
                   2291: 
                   2292:        while(drapeau_fin == d_faux)
                   2293:        {
                   2294:            l_element_courant = (struct_liste_chainee *)
                   2295:                    (*s_etat_processus).l_base_pile_processus;
                   2296: 
                   2297:            while(l_element_courant != NULL)
                   2298:            {
                   2299:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2300:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   2301:                {
                   2302:                    if (((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2303:                            .donnee).objet)).thread).pid ==
                   2304:                            (*(*((struct_processus_fils *)
                   2305:                            (*s_objet_argument).objet)).thread).pid)
                   2306:                            && ((*(*((struct_processus_fils *)
                   2307:                            (*s_objet_argument).objet)).thread)
                   2308:                            .processus_detache == d_vrai))
                   2309:                    {
                   2310:                        break;
                   2311:                    }
                   2312:                }
                   2313:                else
                   2314:                {
                   2315:                    if ((pthread_equal((*(*((struct_processus_fils *)
                   2316:                            (*(*l_element_courant).donnee).objet)).thread).tid,
                   2317:                            (*(*((struct_processus_fils *) (*s_objet_argument)
                   2318:                            .objet)).thread).tid) != 0) &&
                   2319:                            ((*(*((struct_processus_fils *)
                   2320:                            (*(*l_element_courant).donnee).objet)).thread).pid
                   2321:                            == (*(*((struct_processus_fils *)
                   2322:                            (*s_objet_argument).objet)).thread).pid) &&
                   2323:                            ((*(*((struct_processus_fils *)
                   2324:                            (*s_objet_argument).objet)).thread)
                   2325:                            .processus_detache == d_faux))
                   2326:                    {
                   2327:                        break;
                   2328:                    }
                   2329:                }
                   2330: 
                   2331:                l_element_courant = (*l_element_courant).suivant;
                   2332:            }
                   2333: 
                   2334:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2335:            {
                   2336:                if ((*s_etat_processus).profilage == d_vrai)
                   2337:                {
                   2338:                    profilage(s_etat_processus, NULL);
                   2339:                }
                   2340: 
                   2341:                if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2342:                {
                   2343:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2344:                    return;
                   2345:                }
                   2346: 
                   2347:                liberation(s_etat_processus, s_objet_argument);
                   2348:                return;
                   2349:            }
                   2350: 
                   2351:            if (l_element_courant != NULL)
                   2352:            {
                   2353:                if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
                   2354:                        (*(*l_element_courant).donnee).objet)).thread).mutex))
                   2355:                        != 0)
                   2356:                {
                   2357:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2358:                    return;
                   2359:                }
                   2360: 
                   2361:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2362:                        .donnee).objet)).thread).nombre_objets_dans_pipe != 0)
                   2363:                {
                   2364:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2365:                            (*(*l_element_courant).donnee).objet)).thread)
                   2366:                            .mutex)) != 0)
                   2367:                    {
                   2368:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2369:                        return;
                   2370:                    }
                   2371: 
                   2372:                    drapeau_fin = d_vrai;
                   2373:                }
                   2374:                else
                   2375:                {
                   2376:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2377:                            (*(*l_element_courant).donnee).objet)).thread)
                   2378:                            .mutex)) != 0)
                   2379:                    {
                   2380:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2381:                        return;
                   2382:                    }
                   2383: 
                   2384:                    if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2385:                    {
                   2386:                        if ((*s_etat_processus).profilage == d_vrai)
                   2387:                        {
                   2388:                            profilage(s_etat_processus, NULL);
                   2389:                        }
                   2390: 
                   2391:                        (*s_etat_processus).erreur_systeme =
                   2392:                                d_es_processus;
                   2393:                        return;
                   2394:                    }
                   2395: 
                   2396:                    if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2397:                    {
                   2398:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2399:                        return;
                   2400:                    }
                   2401: 
                   2402:                    nanosleep(&attente, NULL);
                   2403: 
                   2404:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2405:                    {
                   2406:                        if (errno != EINTR)
                   2407:                        {
                   2408:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2409:                            return;
                   2410:                        }
                   2411:                    }
                   2412: 
                   2413:                    scrutation_injection(s_etat_processus);
                   2414: 
                   2415:                    if ((*s_etat_processus).nombre_interruptions_non_affectees
                   2416:                            != 0)
                   2417:                    {
                   2418:                        affectation_interruptions_logicielles(s_etat_processus);
                   2419:                    }
                   2420: 
                   2421:                    if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   2422:                    {
                   2423:                        registre_instruction_valide =
                   2424:                                (*s_etat_processus).instruction_valide;
                   2425:                        traitement_interruptions_logicielles(s_etat_processus);
                   2426:                        (*s_etat_processus).instruction_valide =
                   2427:                                registre_instruction_valide;
                   2428:                    }
                   2429: 
                   2430:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2431:                    {
                   2432:                        if ((*s_etat_processus).profilage == d_vrai)
                   2433:                        {
                   2434:                            profilage(s_etat_processus, NULL);
                   2435:                        }
                   2436: 
                   2437:                        return;
                   2438:                    }
                   2439: 
                   2440:                    if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   2441:                    {
                   2442:                        if ((*s_etat_processus).profilage == d_vrai)
                   2443:                        {
                   2444:                            profilage(s_etat_processus, NULL);
                   2445:                        }
                   2446: 
                   2447:                        (*s_etat_processus).erreur_systeme =
                   2448:                                d_es_processus;
                   2449:                        return;
                   2450:                    }
                   2451:                }
                   2452:            }
                   2453:            else
                   2454:            {
                   2455:                drapeau_fin = d_vrai;
                   2456:                (*s_etat_processus).erreur_execution = d_ex_processus;
                   2457:            }
                   2458: 
                   2459:            INCR_GRANULARITE(attente.tv_nsec);
                   2460:        }
                   2461: 
                   2462:        if ((*s_etat_processus).profilage == d_vrai)
                   2463:        {
                   2464:            profilage(s_etat_processus, NULL);
                   2465:        }
                   2466: 
                   2467:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2468:        {
                   2469:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2470:            return;
                   2471:        }
                   2472:    }
                   2473:    else
                   2474:    {
                   2475:        liberation(s_etat_processus, s_objet_argument);
                   2476: 
                   2477:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2478:        return;
                   2479:    }
                   2480: 
                   2481:    liberation(s_etat_processus, s_objet_argument);
                   2482: 
                   2483:    return;
                   2484: }
                   2485: 
                   2486: 
                   2487: /*
                   2488: ================================================================================
                   2489:   Fonction 'wfsock'
                   2490: ================================================================================
                   2491:   Entrées : pointeur sur une structure struct_processus
                   2492: --------------------------------------------------------------------------------
                   2493:   Sorties :
                   2494: --------------------------------------------------------------------------------
                   2495:   Effets de bord : néant
                   2496: ================================================================================
                   2497: */
                   2498: 
                   2499: void
                   2500: instruction_wfsock(struct_processus *s_etat_processus)
                   2501: {
                   2502:    int                     erreur;
                   2503: 
                   2504:    logical1                drapeau;
                   2505: 
                   2506:    socklen_t               longueur;
                   2507: 
                   2508:    struct_liste_chainee    *l_element_courant;
                   2509: 
                   2510:    struct_objet            *s_objet_argument;
                   2511:    struct_objet            *s_objet_resultat;
                   2512: 
                   2513:    struct sockaddr_in      adresse_ipv4;
                   2514:    struct sockaddr_in6     adresse_ipv6;
                   2515: 
                   2516:    unsigned long           i;
                   2517: 
                   2518:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2519:    {
                   2520:        printf("\n  WFSOCK ");
                   2521: 
                   2522:        if ((*s_etat_processus).langue == 'F')
                   2523:        {
                   2524:            printf("(attente d'une connexion sur une socket)\n\n");
                   2525:        }
                   2526:        else
                   2527:        {
                   2528:            printf("(wait for connection on a socket)\n\n");
                   2529:        }
                   2530: 
                   2531:        printf("    1: %s\n", d_SCK);
                   2532:        printf("->  2: %s\n", d_SCK);
                   2533:        printf("    1: %s\n", d_SCK);
                   2534: 
                   2535:        return;
                   2536:    }
                   2537:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2538:    {
                   2539:        (*s_etat_processus).nombre_arguments = -1;
                   2540:        return;
                   2541:    }
                   2542: 
                   2543:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2544:    {
                   2545:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2546:        {
                   2547:            return;
                   2548:        }
                   2549:    }
                   2550: 
                   2551:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2552:            &s_objet_argument) == d_erreur)
                   2553:    {
                   2554:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2555:        return;
                   2556:    }
                   2557: 
                   2558:    if ((*s_objet_argument).type == SCK)
                   2559:    {
                   2560:        if ((strcmp((*((struct_socket *) (*s_objet_argument).objet)).type,
                   2561:                "STREAM") != 0) && (strcmp((*((struct_socket *)
                   2562:                (*s_objet_argument).objet)).type, "SEQUENTIAL DATAGRAM") != 0))
                   2563:        {
                   2564:            liberation(s_etat_processus, s_objet_argument);
                   2565: 
                   2566:            (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
                   2567:            return;
                   2568:        }
                   2569: 
                   2570:        if ((s_objet_resultat = copie_objet(s_etat_processus, s_objet_argument,
                   2571:                'O')) == NULL)
                   2572:        {
                   2573:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2574:            return;
                   2575:        }
                   2576: 
                   2577:        (*((struct_socket *) (*s_objet_resultat).objet)).socket_en_ecoute = 'N';
                   2578:        (*((struct_socket *) (*s_objet_resultat).objet)).effacement = 'N';
                   2579: 
                   2580:        if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine == PF_INET)
                   2581:        {
                   2582:            longueur = sizeof(adresse_ipv4);
                   2583: 
                   2584:            do
                   2585:            {
                   2586:                drapeau = d_vrai;
                   2587: 
                   2588:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2589:                {
                   2590:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2591:                    return;
                   2592:                }
                   2593: 
                   2594:                if (((*((struct_socket *) (*s_objet_resultat).objet)).socket =
                   2595:                        accept((*((struct_socket *) (*s_objet_argument).objet))
                   2596:                        .socket, (struct sockaddr *) &adresse_ipv4, &longueur))
                   2597:                        < 0)
                   2598:                {
                   2599:                    erreur = errno;
                   2600: 
                   2601:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2602:                    {
                   2603:                        if (errno != EINTR)
                   2604:                        {
                   2605:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2606:                            return;
                   2607:                        }
                   2608:                    }
                   2609: 
                   2610:                    if (erreur != EINTR)
                   2611:                    {
                   2612:                        liberation(s_etat_processus, s_objet_argument);
                   2613:                        liberation(s_etat_processus, s_objet_resultat);
                   2614: 
                   2615:                        (*s_etat_processus).erreur_execution =
                   2616:                                d_ex_erreur_acces_fichier;
                   2617:                        return;
                   2618:                    }
                   2619: 
                   2620:                    scrutation_injection(s_etat_processus);
                   2621: 
                   2622:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2623:                    {
                   2624:                        drapeau = d_vrai;
                   2625:                    }
                   2626:                    else
                   2627:                    {
                   2628:                        drapeau = d_faux;
                   2629:                    }
                   2630:                }
                   2631:                else
                   2632:                {
                   2633:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2634:                    {
                   2635:                        if (errno != EINTR)
                   2636:                        {
                   2637:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2638:                            return;
                   2639:                        }
                   2640:                    }
                   2641:                }
                   2642:            } while(drapeau == d_faux);
                   2643: 
                   2644:            if (((*((struct_socket *) (*s_objet_resultat).objet))
                   2645:                    .adresse_distante = malloc(22 *
                   2646:                    sizeof(unsigned char))) == NULL)
                   2647:            {
                   2648:                (*s_etat_processus).erreur_systeme =
                   2649:                        d_es_allocation_memoire;
                   2650:                return;
                   2651:            }
                   2652: 
                   2653:            sprintf((*((struct_socket *) (*s_objet_resultat).objet))
                   2654:                    .adresse_distante, "%d.%d.%d.%d(%d)",
                   2655:                    (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF,
                   2656:                    (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF,
                   2657:                    (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF,
                   2658:                    ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF,
                   2659:                    ntohs(adresse_ipv4.sin_port));
                   2660:        }
                   2661:        else if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
                   2662:                PF_INET6)
                   2663:        {
                   2664:            longueur = sizeof(adresse_ipv6);
                   2665: 
                   2666:            do
                   2667:            {
                   2668:                drapeau = d_vrai;
                   2669: 
                   2670:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2671:                {
                   2672:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2673:                    return;
                   2674:                }
                   2675: 
                   2676:                if (((*((struct_socket *) (*s_objet_resultat).objet)).socket =
                   2677:                        accept((*((struct_socket *) (*s_objet_argument).objet))
                   2678:                        .socket, (struct sockaddr *) &adresse_ipv6, &longueur))
                   2679:                        < 0)
                   2680:                {
                   2681:                    erreur = errno;
                   2682: 
                   2683:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2684:                    {
                   2685:                        if (errno != EINTR)
                   2686:                        {
                   2687:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2688:                            return;
                   2689:                        }
                   2690:                    }
                   2691: 
                   2692:                    if (erreur != EINTR)
                   2693:                    {
                   2694:                        liberation(s_etat_processus, s_objet_argument);
                   2695:                        liberation(s_etat_processus, s_objet_resultat);
                   2696: 
                   2697:                        (*s_etat_processus).erreur_execution =
                   2698:                                d_ex_erreur_acces_fichier;
                   2699:                        return;
                   2700:                    }
                   2701: 
                   2702:                    scrutation_injection(s_etat_processus);
                   2703: 
                   2704:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2705:                    {
                   2706:                        drapeau = d_vrai;
                   2707:                    }
                   2708:                    else
                   2709:                    {
                   2710:                        drapeau = d_faux;
                   2711:                    }
                   2712:                }
                   2713:                else
                   2714:                {
                   2715:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2716:                    {
                   2717:                        if (errno != EINTR)
                   2718:                        {
                   2719:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2720:                            return;
                   2721:                        }
                   2722:                    }
                   2723:                }
                   2724:            } while(drapeau == d_faux);
                   2725: 
                   2726:            if (((*((struct_socket *) (*s_objet_resultat).objet))
                   2727:                    .adresse_distante = malloc(55 *
                   2728:                    sizeof(unsigned char))) == NULL)
                   2729:            {
                   2730:                (*s_etat_processus).erreur_systeme =
                   2731:                        d_es_allocation_memoire;
                   2732:                return;
                   2733:            }
                   2734: 
                   2735:            (*((struct_socket *) (*s_objet_resultat).objet))
                   2736:                    .adresse_distante = d_code_fin_chaine;
                   2737: 
                   2738:            for(i = 0; i < 16; i++)
                   2739:            {
                   2740:                sprintf((*((struct_socket *) (*s_objet_resultat)
                   2741:                        .objet)).adresse_distante, (i == 0) ? "%s%X" : "%s:%X",
                   2742:                        (*((struct_socket *) (*s_objet_resultat)
                   2743:                        .objet)).adresse_distante,
                   2744:                        adresse_ipv6.sin6_addr.s6_addr[i]);
                   2745:            }
                   2746: 
                   2747:            sprintf((*((struct_socket *) (*s_objet_resultat)
                   2748:                    .objet)).adresse_distante, "%s(%u)",
                   2749:                    (*((struct_socket *) (*s_objet_resultat)
                   2750:                    .objet)).adresse_distante, ntohs(adresse_ipv6.sin6_port));
                   2751:        }
                   2752:        else
                   2753:        {
                   2754:            longueur = 0;
                   2755: 
                   2756:            do
                   2757:            {
                   2758:                drapeau = d_vrai;
                   2759: 
                   2760:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2761:                {
                   2762:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2763:                    return;
                   2764:                }
                   2765: 
                   2766:                if (((*((struct_socket *) (*s_objet_resultat).objet)).socket =
                   2767:                        accept((*((struct_socket *) (*s_objet_argument).objet))
                   2768:                        .socket, NULL, &longueur)) < 0)
                   2769:                {
                   2770:                    erreur = errno;
                   2771: 
                   2772:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2773:                    {
                   2774:                        if (errno != EINTR)
                   2775:                        {
                   2776:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2777:                            return;
                   2778:                        }
                   2779:                    }
                   2780: 
                   2781:                    if (erreur != EINTR)
                   2782:                    {
                   2783:                        liberation(s_etat_processus, s_objet_argument);
                   2784:                        liberation(s_etat_processus, s_objet_resultat);
                   2785: 
                   2786:                        (*s_etat_processus).erreur_execution =
                   2787:                                d_ex_erreur_acces_fichier;
                   2788:                        return;
                   2789:                    }
                   2790: 
                   2791:                    scrutation_injection(s_etat_processus);
                   2792: 
                   2793:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2794:                    {
                   2795:                        drapeau = d_vrai;
                   2796:                    }
                   2797:                    else
                   2798:                    {
                   2799:                        drapeau = d_faux;
                   2800:                    }
                   2801:                }
                   2802:                else
                   2803:                {
                   2804:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2805:                    {
                   2806:                        if (errno != EINTR)
                   2807:                        {
                   2808:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2809:                            return;
                   2810:                        }
                   2811:                    }
                   2812:                }
                   2813:            } while(drapeau == d_faux);
                   2814:        }
                   2815: 
                   2816:        // Si accept() renvoie une erreur non récupérée, il ne peut s'agir
                   2817:        // que de EINTR sachant qu'une requête d'arrêt est en court de
                   2818:        // traitement.
                   2819: 
                   2820:        if ((*((struct_socket *) (*s_objet_resultat).objet)).socket >= 0)
                   2821:        {
                   2822:            l_element_courant = (*s_etat_processus).s_sockets;
                   2823: 
                   2824:            if (l_element_courant == NULL)
                   2825:            {
                   2826:                if (((*s_etat_processus).s_sockets =
                   2827:                        allocation_maillon(s_etat_processus)) == NULL)
                   2828:                {
                   2829:                    (*s_etat_processus).erreur_systeme =
                   2830:                            d_es_allocation_memoire;
                   2831:                    return;
                   2832:                }
                   2833: 
                   2834:                (*(*s_etat_processus).s_sockets).suivant = NULL;
                   2835:                l_element_courant = (*s_etat_processus).s_sockets;
                   2836:            }
                   2837:            else
                   2838:            {
                   2839:                /*
                   2840:                 * Ajout d'un élément à la fin de la liste chaînée
                   2841:                 */
                   2842: 
                   2843:                while((*l_element_courant).suivant != NULL)
                   2844:                {
                   2845:                    l_element_courant = (*l_element_courant).suivant;
                   2846:                }
                   2847: 
                   2848:                if (((*l_element_courant).suivant =
                   2849:                        allocation_maillon(s_etat_processus)) == NULL)
                   2850:                {
                   2851:                    (*s_etat_processus).erreur_systeme =
                   2852:                            d_es_allocation_memoire;
                   2853:                    return;
                   2854:                }
                   2855: 
                   2856:                l_element_courant = (*l_element_courant).suivant;
                   2857:                (*l_element_courant).suivant = NULL;
                   2858:            }
                   2859: 
                   2860:            if (((*l_element_courant).donnee = copie_objet(s_etat_processus,
                   2861:                    s_objet_resultat, 'O')) == NULL)
                   2862:            {
                   2863:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2864:                return;
                   2865:            }
                   2866:        }
                   2867: 
                   2868:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2869:                s_objet_argument) == d_erreur)
                   2870:        {
                   2871:            return;
                   2872:        }
                   2873: 
                   2874:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2875:                s_objet_resultat) == d_erreur)
                   2876:        {
                   2877:            return;
                   2878:        }
                   2879:    }
                   2880:    else
                   2881:    {
                   2882:        liberation(s_etat_processus, s_objet_argument);
                   2883: 
                   2884:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2885:        return;
                   2886:    }
                   2887: 
                   2888:    return;
                   2889: }
                   2890: 
                   2891: 
                   2892: /*
                   2893: ================================================================================
                   2894:   Fonction 'wfswi'
                   2895: ================================================================================
                   2896:   Entrées : pointeur sur une structure struct_processus
                   2897: --------------------------------------------------------------------------------
                   2898:   Sorties :
                   2899: --------------------------------------------------------------------------------
                   2900:   Effets de bord : néant
                   2901: ================================================================================
                   2902: */
                   2903: 
                   2904: void
                   2905: instruction_wfswi(struct_processus *s_etat_processus)
                   2906: {
                   2907:    integer8                    interruption;
                   2908: 
                   2909:    logical1                    drapeau_fin;
                   2910: 
                   2911:    struct_objet                *s_objet_argument;
                   2912: 
                   2913:    struct timespec             attente;
                   2914: 
                   2915:    (*s_etat_processus).erreur_execution = d_ex;
                   2916: 
                   2917:    attente.tv_sec = 0;
                   2918:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2919: 
                   2920:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2921:    {
                   2922:        printf("\n  WFSWI ");
                   2923: 
                   2924:        if ((*s_etat_processus).langue == 'F')
                   2925:        {
                   2926:            printf("(attente d'une interruption)\n\n");
                   2927:        }
                   2928:        else
                   2929:        {
                   2930:            printf("(wait for interrupt)\n\n");
                   2931:        }
                   2932: 
                   2933:        printf("    1: %s\n", d_INT);
                   2934: 
                   2935:        return;
                   2936:    }
                   2937:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2938:    {
                   2939:        (*s_etat_processus).nombre_arguments = -1;
                   2940:        return;
                   2941:    }
                   2942: 
                   2943:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2944:    {
                   2945:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2946:        {
                   2947:            return;
                   2948:        }
                   2949:    }
                   2950: 
                   2951:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2952:            &s_objet_argument) == d_erreur)
                   2953:    {
                   2954:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2955:        return;
                   2956:    }
                   2957: 
                   2958:    if ((*s_objet_argument).type == INT)
                   2959:    {
                   2960:        drapeau_fin = d_faux;
                   2961: 
                   2962:        interruption = (*((integer8 *) (*s_objet_argument).objet));
                   2963: 
                   2964:        if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   2965:        {
                   2966:            liberation(s_etat_processus, s_objet_argument);
                   2967: 
                   2968:            (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
                   2969:            return;
                   2970:        }
                   2971: 
                   2972:        while(drapeau_fin == d_faux)
                   2973:        {
                   2974:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2975:            {
                   2976:                liberation(s_etat_processus, s_objet_argument);
                   2977:                return;
                   2978:            }
                   2979: 
                   2980:            if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   2981:            {
                   2982:                affectation_interruptions_logicielles(s_etat_processus);
                   2983:            }
                   2984: 
                   2985:            if ((*s_etat_processus).queue_interruptions[interruption - 1] > 0)
                   2986:            {
                   2987:                drapeau_fin = d_vrai;
                   2988:            }
                   2989:            else
                   2990:            {
                   2991:                nanosleep(&attente, NULL);
                   2992:                scrutation_injection(s_etat_processus);
                   2993:                INCR_GRANULARITE(attente.tv_nsec);
                   2994:            }
                   2995:        }
                   2996:    }
                   2997:    else
                   2998:    {
                   2999:        liberation(s_etat_processus, s_objet_argument);
                   3000: 
                   3001:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   3002:        return;
                   3003:    }
                   3004: 
                   3005:    liberation(s_etat_processus, s_objet_argument);
                   3006: 
                   3007:    return;
                   3008: }
                   3009: 
                   3010: 
                   3011: /*
                   3012: ================================================================================
                   3013:   Fonction 'wfpoke'
                   3014: ================================================================================
                   3015:   Entrées : pointeur sur une structure struct_processus
                   3016: --------------------------------------------------------------------------------
                   3017:   Sorties :
                   3018: --------------------------------------------------------------------------------
                   3019:   Effets de bord : néant
                   3020: ================================================================================
                   3021: */
                   3022: 
                   3023: void
                   3024: instruction_wfpoke(struct_processus *s_etat_processus)
                   3025: {
                   3026:    struct timespec             attente;
                   3027: 
                   3028:    unsigned char               registre_instruction_valide;
                   3029: 
                   3030:    (*s_etat_processus).erreur_execution = d_ex;
                   3031: 
                   3032:    attente.tv_sec = 0;
                   3033:    attente.tv_nsec = GRANULARITE_us * 1000;
                   3034: 
                   3035:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   3036:    {
                   3037:        printf("\n  WFPOKE ");
                   3038: 
                   3039:        if ((*s_etat_processus).langue == 'F')
                   3040:        {
                   3041:            printf("(attente de données en provenance du processus père)\n\n");
                   3042:            printf("  Aucun argument\n");
                   3043:        }
                   3044:        else
                   3045:        {
                   3046:            printf("(wait for data from parent process)\n\n");
                   3047:            printf("  No argument\n");
                   3048:        }
                   3049: 
                   3050:        return;
                   3051:    }
                   3052:    else if ((*s_etat_processus).test_instruction == 'Y')
                   3053:    {
                   3054:        (*s_etat_processus).nombre_arguments = -1;
                   3055:        return;
                   3056:    }
                   3057: 
                   3058:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   3059:    {
                   3060:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                   3061:        {
                   3062:            return;
                   3063:        }
                   3064:    }
                   3065: 
                   3066:    if ((*s_etat_processus).presence_pipes == d_faux)
                   3067:    {
                   3068:        (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                   3069:        return;
                   3070:    }
                   3071: 
                   3072:    if ((*s_etat_processus).nombre_objets_injectes > 0)
                   3073:    {
                   3074:        return;
                   3075:    }
                   3076: 
                   3077:    if ((*s_etat_processus).profilage == d_vrai)
                   3078:    {
                   3079:        profilage(s_etat_processus, "Interprocess or interthread "
                   3080:                "communications (WFPOKE)");
                   3081: 
                   3082:        if ((*s_etat_processus).erreur_systeme != d_es)
                   3083:        {
                   3084:            return;
                   3085:        }
                   3086:    }
                   3087: 
                   3088:    do
                   3089:    {
                   3090:        if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   3091:        {
                   3092:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   3093:            return;
                   3094:        }
                   3095: 
                   3096:        nanosleep(&attente, NULL);
                   3097: 
                   3098:        while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   3099:        {
                   3100:            if (errno != EINTR)
                   3101:            {
                   3102:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3103:                return;
                   3104:            }
                   3105:        }
                   3106: 
                   3107:        scrutation_injection(s_etat_processus);
                   3108: 
                   3109:        if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   3110:        {
                   3111:            affectation_interruptions_logicielles(s_etat_processus);
                   3112:        }
                   3113: 
                   3114:        if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   3115:        {
                   3116:            registre_instruction_valide =
                   3117:                    (*s_etat_processus).instruction_valide;
                   3118:            traitement_interruptions_logicielles(s_etat_processus);
                   3119:            (*s_etat_processus).instruction_valide =
                   3120:                    registre_instruction_valide;
                   3121:        }
                   3122: 
                   3123:        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3124:        {
                   3125:            if ((*s_etat_processus).profilage == d_vrai)
                   3126:            {
                   3127:                profilage(s_etat_processus, NULL);
                   3128:            }
                   3129: 
                   3130:            return;
                   3131:        }
                   3132: 
                   3133:        INCR_GRANULARITE(attente.tv_nsec);
                   3134:    } while((*s_etat_processus).nombre_objets_injectes == 0);
                   3135: 
                   3136:    return;
                   3137: }
                   3138: 
                   3139: 
                   3140: /*
                   3141: ================================================================================
                   3142:   Fonction 'wfack'
                   3143: ================================================================================
                   3144:   Entrées : pointeur sur une structure struct_processus
                   3145: --------------------------------------------------------------------------------
                   3146:   Sorties :
                   3147: --------------------------------------------------------------------------------
                   3148:   Effets de bord : néant
                   3149: ================================================================================
                   3150: */
                   3151: 
                   3152: void
                   3153: instruction_wfack(struct_processus *s_etat_processus)
                   3154: {
                   3155:    struct timespec             attente;
                   3156: 
                   3157:    unsigned char               registre_instruction_valide;
                   3158: 
                   3159:    (*s_etat_processus).erreur_execution = d_ex;
                   3160: 
                   3161:    attente.tv_sec = 0;
                   3162:    attente.tv_nsec = GRANULARITE_us * 1000;
                   3163: 
                   3164:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   3165:    {
                   3166:        printf("\n  WFACK ");
                   3167: 
                   3168:        if ((*s_etat_processus).langue == 'F')
                   3169:        {
                   3170:            printf("(attente des acquittements de lecture)\n\n");
                   3171:            printf("  Aucun argument\n");
                   3172:        }
                   3173:        else
                   3174:        {
                   3175:            printf("(wait for reading of data acknowledgement)\n\n");
                   3176:            printf("  No argument\n");
                   3177:        }
                   3178: 
                   3179:        return;
                   3180:    }
                   3181:    else if ((*s_etat_processus).test_instruction == 'Y')
                   3182:    {
                   3183:        (*s_etat_processus).nombre_arguments = -1;
                   3184:        return;
                   3185:    }
                   3186: 
                   3187:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   3188:    {
                   3189:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                   3190:        {
                   3191:            return;
                   3192:        }
                   3193:    }
                   3194: 
                   3195:    if ((*s_etat_processus).presence_pipes == d_faux)
                   3196:    {
                   3197:        (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                   3198:        return;
                   3199:    }
                   3200: 
                   3201:    if ((*s_etat_processus).profilage == d_vrai)
                   3202:    {
                   3203:        profilage(s_etat_processus, "Interprocess or interthread communications"
                   3204:                " (WFACK)");
                   3205: 
                   3206:        if ((*s_etat_processus).erreur_systeme != d_es)
                   3207:        {
                   3208:            return;
                   3209:        }
                   3210:    }
                   3211: 
                   3212:    while((*s_etat_processus).nombre_objets_envoyes_non_lus != 0)
                   3213:    {
                   3214:        scrutation_injection(s_etat_processus);
                   3215: 
                   3216:        if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   3217:        {
                   3218:            affectation_interruptions_logicielles(s_etat_processus);
                   3219:        }
                   3220: 
                   3221:        if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   3222:        {
                   3223:            registre_instruction_valide =
                   3224:                    (*s_etat_processus).instruction_valide;
                   3225:            traitement_interruptions_logicielles(s_etat_processus);
                   3226:            (*s_etat_processus).instruction_valide =
                   3227:                    registre_instruction_valide;
                   3228:        }
                   3229: 
                   3230:        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3231:        {
                   3232:            if ((*s_etat_processus).profilage == d_vrai)
                   3233:            {
                   3234:                profilage(s_etat_processus, NULL);
                   3235:            }
                   3236: 
                   3237:            return;
                   3238:        }
                   3239: 
                   3240:        if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   3241:        {
                   3242:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   3243:            return;
                   3244:        }
                   3245: 
                   3246:        nanosleep(&attente, NULL);
                   3247:        INCR_GRANULARITE(attente.tv_nsec);
                   3248: 
                   3249:        while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   3250:        {
                   3251:            if (errno != EINTR)
                   3252:            {
                   3253:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3254:                return;
                   3255:            }
                   3256:        }
                   3257:    }
                   3258: 
                   3259:    if ((*s_etat_processus).profilage == d_vrai)
                   3260:    {
                   3261:        profilage(s_etat_processus, NULL);
                   3262:    }
                   3263: 
                   3264:    return;
                   3265: }
                   3266: 
                   3267: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>