Annotation of rpl/src/instructions_r4.c, revision 1.78

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

CVSweb interface <joel.bertrand@systella.fr>