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

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

CVSweb interface <joel.bertrand@systella.fr>