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

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

CVSweb interface <joel.bertrand@systella.fr>