Annotation of rpl/src/instructions_s9.c, revision 1.81

1.1       bertrand    1: /*
                      2: ================================================================================
1.81    ! bertrand    3:   RPL/2 (R) version 4.1.29
        !             4:   Copyright (C) 1989-2018 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.17      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Fonction 'sort'
                     29: ================================================================================
                     30:   Entrées :
                     31: --------------------------------------------------------------------------------
                     32:   Sorties :
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: void
                     39: instruction_sort(struct_processus *s_etat_processus)
                     40: {
                     41:    integer8                    i;
                     42:    integer8                    j;
                     43:    integer8                    nombre_elements;
                     44: 
                     45:    logical1                    condition;
                     46:    logical1                    inversion;
                     47:    logical1                    presence_nom;
                     48:    logical1                    terminaison_boucle_1;
                     49:    logical1                    terminaison_boucle_2;
                     50:    logical1                    terminaison_boucle_3;
                     51:    logical1                    variable_partagee;
                     52: 
                     53:    struct_liste_chainee        *l_element_courant;
                     54:    struct_liste_chainee        *l_element_precedent;
                     55:    struct_liste_chainee        *l_element_tampon;
                     56: 
                     57:    struct_objet                *s_objet_copie;
                     58:    struct_objet                *s_objet_critere;
                     59:    struct_objet                *s_objet_liste;
1.16      bertrand   60:    struct_objet                *s_objet_registre;
1.1       bertrand   61:    struct_objet                *s_objet_test;
                     62: 
1.60      bertrand   63:    integer8                    ecartement;
                     64:    integer8                    indice_i;
                     65:    integer8                    indice_j;
                     66:    integer8                    indice_k;
                     67:    integer8                    indice_l;
1.1       bertrand   68: 
                     69:    (*s_etat_processus).erreur_execution = d_ex;
                     70: 
                     71:    if ((*s_etat_processus).affichage_arguments == 'Y')
                     72:    {
                     73:        printf("\n  SORT ");
                     74: 
                     75:        if ((*s_etat_processus).langue == 'F')
                     76:        {
                     77:            printf("(trie une liste selon un critère paramétrable)\n\n");
                     78:        }
                     79:        else
                     80:        {
                     81:            printf("(sort a list)\n\n");
                     82:        }
                     83: 
                     84:        printf("    2: %s\n", d_LST);
                     85:        printf("    1: %s\n", d_RPN);
                     86:        printf("->  1: %s\n\n", d_LST);
                     87: 
                     88:        printf("    2: %s\n", d_TAB);
                     89:        printf("    1: %s\n", d_RPN);
                     90:        printf("->  1: %s\n\n", d_LST);
                     91: 
                     92:        printf("    2: %s\n", d_NOM);
                     93:        printf("    1: %s\n", d_RPN);
                     94: 
                     95:        return;
                     96:    }
                     97:    else if ((*s_etat_processus).test_instruction == 'Y')
                     98:    {
                     99:        (*s_etat_processus).nombre_arguments = -1;
                    100:        return;
                    101:    }
                    102:    
                    103:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    104:    {
                    105:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    106:        {
                    107:            return;
                    108:        }
                    109:    }
                    110: 
                    111:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    112:            &s_objet_critere) == d_erreur)
                    113:    {
                    114:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    115:        return;
                    116:    }
                    117: 
                    118:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    119:            &s_objet_liste) == d_erreur)
                    120:    {
                    121:        liberation(s_etat_processus, s_objet_critere);
                    122: 
                    123:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    124:        return;
                    125:    }
                    126: 
                    127:    variable_partagee = d_faux;
                    128: 
                    129:    if ((*s_objet_liste).type == NOM)
                    130:    {
                    131:        if (recherche_variable(s_etat_processus, (*((struct_nom *)
                    132:                (*s_objet_liste).objet)).nom) == d_faux)
                    133:        {
                    134:            (*s_etat_processus).erreur_systeme = d_es;
                    135:            (*s_etat_processus).erreur_execution = d_ex_variable_non_definie;
                    136: 
                    137:            liberation(s_etat_processus, s_objet_critere);
                    138:            liberation(s_etat_processus, s_objet_liste);
                    139: 
                    140:            return;
                    141:        }
                    142: 
1.27      bertrand  143:        if ((*(*s_etat_processus).pointeur_variable_courante)
                    144:                .variable_verrouillee == d_vrai)
1.1       bertrand  145:        {
                    146:            (*s_etat_processus).erreur_execution = d_ex_variable_verrouillee;
                    147: 
                    148:            liberation(s_etat_processus, s_objet_critere);
                    149:            liberation(s_etat_processus, s_objet_liste);
                    150: 
                    151:            return;
                    152:        }
                    153: 
1.27      bertrand  154:        if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL)
1.1       bertrand  155:        {
                    156:            if (recherche_variable_partagee(s_etat_processus,
1.27      bertrand  157:                    (*(*s_etat_processus).pointeur_variable_courante).nom,
                    158:                    (*(*s_etat_processus).pointeur_variable_courante)
                    159:                    .variable_partagee, (*(*s_etat_processus)
1.55      bertrand  160:                    .pointeur_variable_courante).origine) == NULL)
1.1       bertrand  161:            {
                    162:                (*s_etat_processus).erreur_execution =
                    163:                        d_ex_erreur_type_argument;
                    164: 
                    165:                liberation(s_etat_processus, s_objet_critere);
                    166:                liberation(s_etat_processus, s_objet_liste);
                    167: 
                    168:                return;
                    169:            }
                    170: 
1.54      bertrand  171:            if (((*(*(*s_etat_processus).pointeur_variable_partagee_courante)
                    172:                    .objet).type != LST) && ((*(*(*s_etat_processus)
                    173:                    .pointeur_variable_partagee_courante).objet).type != TBL))
1.1       bertrand  174:            {
                    175:                if (pthread_mutex_unlock(&((*(*s_etat_processus)
1.54      bertrand  176:                        .pointeur_variable_partagee_courante).mutex)) != 0)
1.1       bertrand  177:                {
                    178:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    179:                    return;
                    180:                }
                    181: 
                    182:                (*s_etat_processus).erreur_execution =
                    183:                        d_ex_erreur_type_argument;
                    184: 
                    185:                liberation(s_etat_processus, s_objet_critere);
                    186:                liberation(s_etat_processus, s_objet_liste);
                    187: 
                    188:                return;
                    189:            }
                    190: 
                    191:            liberation(s_etat_processus, s_objet_liste);
                    192: 
1.54      bertrand  193:            s_objet_liste = (*(*s_etat_processus)
                    194:                    .pointeur_variable_partagee_courante).objet;
1.1       bertrand  195: 
                    196:            if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste,
                    197:                    'N')) == NULL)
                    198:            {
                    199:                if (pthread_mutex_unlock(&((*(*s_etat_processus)
1.54      bertrand  200:                        .pointeur_variable_partagee_courante).mutex)) != 0)
1.1       bertrand  201:                {
                    202:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    203:                    return;
                    204:                }
                    205: 
                    206:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    207:                return;
                    208:            }
                    209: 
                    210:            variable_partagee = d_vrai;
                    211:        }
                    212:        else
                    213:        {
1.27      bertrand  214:            if (((*(*(*s_etat_processus).pointeur_variable_courante).objet)
                    215:                    .type != LST) && ((*(*(*s_etat_processus)
                    216:                    .pointeur_variable_courante).objet).type != TBL))
1.1       bertrand  217:            {
                    218:                (*s_etat_processus).erreur_execution =
                    219:                        d_ex_erreur_type_argument;
                    220: 
                    221:                liberation(s_etat_processus, s_objet_critere);
                    222:                liberation(s_etat_processus, s_objet_liste);
                    223: 
                    224:                return;
                    225:            }
                    226: 
                    227:            liberation(s_etat_processus, s_objet_liste);
                    228: 
1.27      bertrand  229:            s_objet_liste = (*(*s_etat_processus).pointeur_variable_courante)
                    230:                    .objet;
1.1       bertrand  231: 
                    232:            if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste,
                    233:                    'N')) == NULL)
                    234:            {
                    235:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    236:                return;
                    237:            }
                    238:        }
                    239: 
                    240:        liberation(s_etat_processus, s_objet_liste);
                    241:        s_objet_liste = s_objet_copie;
1.27      bertrand  242:        (*(*s_etat_processus).pointeur_variable_courante).objet = s_objet_liste;
1.1       bertrand  243:        presence_nom = d_vrai;
                    244:    }
                    245:    else
                    246:    {
                    247:        if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste, 'N'))
                    248:                == NULL)
                    249:        {
                    250:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    251:            return;
                    252:        }
                    253: 
                    254:        liberation(s_etat_processus, s_objet_liste);
                    255:        s_objet_liste = s_objet_copie;
                    256:        presence_nom = d_faux;
                    257:    }
                    258: 
                    259:    if (((*s_objet_liste).type == LST) &&
                    260:            ((*s_objet_critere).type == RPN))
                    261:    {
                    262:        /*
                    263:         * Tri bulle de la liste chaînée. On se contente d'un tri bulle
                    264:         * car on travaille sur une liste chaînée et non sur un tableau
                    265:         * sur lequel on pourrait accéder directement aux données grâce à
                    266:         * leur indice.
                    267:         */
                    268: 
                    269:        nombre_elements = 0;
                    270:        l_element_courant = (*s_objet_liste).objet;
                    271: 
                    272:        while(l_element_courant != NULL)
                    273:        {
                    274:            l_element_courant = (*l_element_courant).suivant;
                    275:            nombre_elements++;
                    276:        }
                    277: 
                    278:        // Si la liste est vide, on considère qu'elle est triée.
                    279:        // De la même manière, on considère qu'une liste d'un
                    280:        // seul élément est toujours triée.
                    281: 
                    282:        if (nombre_elements > 1)
                    283:        {
                    284:            j = nombre_elements;
                    285: 
                    286:            do
                    287:            {
                    288:                inversion = d_faux;
                    289: 
                    290:                l_element_courant = (*s_objet_liste).objet;
                    291:                l_element_precedent = NULL;
                    292: 
                    293:                for(i = 0; i < j - 1; i++)
                    294:                {
                    295:                    // Test des éléments adjacents. Pour cela, on
                    296:                    // empile les deux éléments adjacents dans la pile dans
                    297:                    // l'ordre [i] [i+1] et on évalue le critère d'ordre.
                    298: 
                    299:                    if ((s_objet_copie = copie_objet(s_etat_processus,
                    300:                            (*l_element_courant).donnee, 'P')) == NULL)
                    301:                    {
                    302:                        (*s_etat_processus).erreur_systeme =
                    303:                                d_es_allocation_memoire;
                    304:                        return;
                    305:                    }
                    306: 
                    307:                    if (empilement(s_etat_processus,
                    308:                            &((*s_etat_processus).l_base_pile),
                    309:                            s_objet_copie) == d_erreur)
                    310:                    {
                    311:                        return;
                    312:                    }
                    313: 
                    314:                    if ((s_objet_copie = copie_objet(s_etat_processus,
                    315:                            (*(*l_element_courant)
                    316:                            .suivant).donnee, 'P')) == NULL)
                    317:                    {
                    318:                        (*s_etat_processus).erreur_systeme =
                    319:                                d_es_allocation_memoire;
                    320:                        return;
                    321:                    }
                    322: 
                    323:                    if (empilement(s_etat_processus,
                    324:                            &((*s_etat_processus).l_base_pile),
                    325:                            s_objet_copie) == d_erreur)
                    326:                    {
                    327:                        return;
                    328:                    }
                    329: 
                    330:                    if (evaluation(s_etat_processus, s_objet_critere, 'N')
                    331:                            == d_erreur)
                    332:                    {
                    333:                        liberation(s_etat_processus, s_objet_critere);
                    334:                        liberation(s_etat_processus, s_objet_liste);
                    335: 
                    336:                        return;
                    337:                    }
                    338: 
                    339:                    if (depilement(s_etat_processus,
                    340:                            &((*s_etat_processus).l_base_pile), &s_objet_test)
                    341:                            == d_erreur)
                    342:                    {
                    343:                        liberation(s_etat_processus, s_objet_critere);
                    344:                        liberation(s_etat_processus, s_objet_liste);
                    345: 
                    346:                        (*s_etat_processus).erreur_execution =
                    347:                                d_ex_manque_argument;
                    348:                        return;
                    349:                    }
                    350: 
                    351:                    if ((*s_objet_test).type == INT)
                    352:                    {
                    353:                        condition = ((*((integer8 *) (*s_objet_test).objet))
                    354:                                == 0) ? d_faux : d_vrai;
                    355:                    }
                    356:                    else if ((*s_objet_test).type == REL)
                    357:                    {
                    358:                        condition = ((*((real8 *) (*s_objet_test).objet))
                    359:                                == 0) ? d_faux : d_vrai;
                    360:                    }
                    361:                    else
                    362:                    {
                    363:                        liberation(s_etat_processus, s_objet_critere);
                    364:                        liberation(s_etat_processus, s_objet_liste);
                    365:                        liberation(s_etat_processus, s_objet_test);
                    366: 
                    367:                        (*s_etat_processus).erreur_execution =
                    368:                                d_ex_erreur_type_argument;
                    369:                        return;
                    370:                    }
                    371: 
                    372:                    liberation(s_etat_processus, s_objet_test);
                    373: 
                    374:                    if (condition == d_faux)
                    375:                    {
                    376:                        // On échange les deux éléments adjacents
                    377: 
                    378:                        inversion = d_vrai;
                    379: 
                    380:                        if (l_element_precedent == NULL)
                    381:                        {
                    382:                            // Échange des deux premiers éléments
                    383:                            // de la liste.
                    384: 
                    385:                            l_element_tampon = (*(*l_element_courant)
                    386:                                    .suivant).suivant;
                    387:                            (*s_objet_liste).objet = (*l_element_courant)
                    388:                                    .suivant;
                    389:                            (*((struct_liste_chainee *) (*s_objet_liste)
                    390:                                    .objet)).suivant = l_element_courant;
                    391:                            (*l_element_courant).suivant =
                    392:                                    l_element_tampon;
                    393:                            l_element_courant = (*s_objet_liste).objet;
                    394:                        }
                    395:                        else
                    396:                        {
                    397:                            // Échange de deux éléments quelconques de la
                    398:                            // liste.
                    399: 
                    400:                            l_element_tampon = (*l_element_courant).suivant;
                    401:                            (*l_element_courant).suivant =
                    402:                                    (*(*l_element_courant).suivant).suivant;
                    403:                            (*l_element_precedent).suivant = l_element_tampon;
                    404:                            (*l_element_tampon).suivant = l_element_courant;
                    405: 
                    406:                            l_element_courant = l_element_tampon;
                    407:                        }
                    408:                    }
                    409: 
                    410:                    l_element_precedent = l_element_courant;
                    411:                    l_element_courant = (*l_element_courant).suivant;
                    412:                }
                    413: 
                    414:                j--;
                    415:            } while(inversion != d_faux);
                    416:        }
                    417:    }
                    418:    else if (((*s_objet_liste).type == TBL) &&
                    419:            ((*s_objet_critere).type == RPN))
                    420:    {
                    421:        /*
                    422:         * Tri Shell-Metzner d'une table
                    423:         */
                    424: 
                    425:        ecartement = (*((struct_tableau *) (*s_objet_liste).objet))
                    426:                .nombre_elements;
                    427:        terminaison_boucle_1 = d_faux;
                    428: 
                    429:        do
                    430:        {
                    431:            ecartement = ecartement / 2;
                    432: 
                    433:            if (ecartement >= 1)
                    434:            {
                    435:                indice_j = 0;
                    436:                indice_k = (*((struct_tableau *) (*s_objet_liste).objet))
                    437:                        .nombre_elements - ecartement;
                    438:                terminaison_boucle_2 = d_faux;
                    439: 
                    440:                do
                    441:                {
                    442:                    indice_i = indice_j;
                    443:                    terminaison_boucle_3 = d_faux;
                    444: 
                    445:                    do
                    446:                    {
                    447:                        indice_l = indice_i + ecartement;
                    448: 
                    449:                        if ((indice_i > 0) && (indice_l > 0))
                    450:                        {
                    451:                            if ((s_objet_copie = copie_objet(s_etat_processus,
                    452:                                    (*((struct_tableau *) (*s_objet_liste)
                    453:                                    .objet)).elements[indice_i - 1], 'P'))
                    454:                                    == NULL)
                    455:                            {
                    456:                                (*s_etat_processus).erreur_systeme =
                    457:                                        d_es_allocation_memoire;
                    458:                                return;
                    459:                            }
                    460: 
                    461:                            if (empilement(s_etat_processus,
                    462:                                    &((*s_etat_processus).l_base_pile),
                    463:                                    s_objet_copie) == d_erreur)
                    464:                            {
                    465:                                return;
                    466:                            }
                    467: 
                    468:                            if ((s_objet_copie = copie_objet(s_etat_processus,
                    469:                                    (*((struct_tableau *) (*s_objet_liste)
                    470:                                    .objet)).elements[indice_l - 1], 'P'))
                    471:                                    == NULL)
                    472:                            {
                    473:                                (*s_etat_processus).erreur_systeme =
                    474:                                        d_es_allocation_memoire;
                    475:                                return;
                    476:                            }
                    477: 
                    478:                            if (empilement(s_etat_processus,
                    479:                                    &((*s_etat_processus).l_base_pile),
                    480:                                    s_objet_copie) == d_erreur)
                    481:                            {
                    482:                                return;
                    483:                            }
                    484: 
                    485:                            if (evaluation(s_etat_processus, s_objet_critere,
                    486:                                    'N') == d_erreur)
                    487:                            {
                    488:                                liberation(s_etat_processus, s_objet_critere);
                    489:                                liberation(s_etat_processus, s_objet_liste);
                    490: 
                    491:                                return;
                    492:                            }
                    493: 
                    494:                            if (depilement(s_etat_processus,
                    495:                                    &((*s_etat_processus).l_base_pile),
                    496:                                    &s_objet_test) == d_erreur)
                    497:                            {
                    498:                                liberation(s_etat_processus, s_objet_critere);
                    499:                                liberation(s_etat_processus, s_objet_liste);
                    500: 
                    501:                                (*s_etat_processus).erreur_execution =
                    502:                                        d_ex_manque_argument;
                    503:                                return;
                    504:                            }
                    505: 
                    506:                            if ((*s_objet_test).type == INT)
                    507:                            {
                    508:                                condition = ((*((integer8 *) (*s_objet_test)
                    509:                                        .objet)) == 0) ? d_faux : d_vrai;
                    510:                            }
                    511:                            else if ((*s_objet_test).type == REL)
                    512:                            {
                    513:                                condition = ((*((real8 *) (*s_objet_test)
                    514:                                        .objet)) == 0) ? d_faux : d_vrai;
                    515:                            }
                    516:                            else
                    517:                            {
                    518:                                liberation(s_etat_processus, s_objet_critere);
                    519:                                liberation(s_etat_processus, s_objet_liste);
                    520:                                liberation(s_etat_processus, s_objet_test);
                    521: 
                    522:                                (*s_etat_processus).erreur_execution =
                    523:                                        d_ex_erreur_type_argument;
                    524:                                return;
                    525:                            }
                    526: 
                    527:                            liberation(s_etat_processus, s_objet_test);
                    528: 
                    529:                            if (condition == d_faux)
                    530:                            {
1.16      bertrand  531:                                s_objet_registre =
                    532:                                        (*((struct_tableau *)
1.14      bertrand  533:                                        (*s_objet_liste).objet)).elements
1.16      bertrand  534:                                        [indice_i - 1];
                    535:                                (*((struct_tableau *) (*s_objet_liste).objet))
                    536:                                        .elements[indice_i - 1] =
                    537:                                        (*((struct_tableau *) (*s_objet_liste)
                    538:                                        .objet)).elements[indice_l - 1];
                    539:                                (*((struct_tableau *) (*s_objet_liste)
                    540:                                        .objet)).elements[indice_l - 1] =
                    541:                                        s_objet_registre;
1.1       bertrand  542: 
                    543:                                indice_i -= ecartement;
                    544: 
                    545:                                if (indice_i < 1)
                    546:                                {
                    547:                                    terminaison_boucle_3 = d_vrai;
                    548:                                }
                    549:                            }
                    550:                            else
                    551:                            {
                    552:                                terminaison_boucle_3 = d_vrai;
                    553:                            }
                    554:                        }
                    555:                        else
                    556:                        {
                    557:                            terminaison_boucle_3 = d_vrai;
                    558:                        }
                    559:                    } while(terminaison_boucle_3 == d_faux);
                    560: 
                    561:                    indice_j++;
                    562: 
                    563:                    if (indice_j > indice_k)
                    564:                    {
                    565:                        terminaison_boucle_2 = d_vrai;
                    566:                    }
                    567:                } while(terminaison_boucle_2 == d_faux);
                    568:            }
                    569:            else
                    570:            {
                    571:                terminaison_boucle_1 = d_vrai;
                    572:            }
                    573:        } while(terminaison_boucle_1 == d_faux);
                    574:    }
                    575:    else
                    576:    {
                    577:        if (pthread_mutex_unlock(&((*(*s_etat_processus)
1.54      bertrand  578:                .pointeur_variable_partagee_courante).mutex)) != 0)
1.1       bertrand  579:        {
                    580:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    581:            return;
                    582:        }
                    583: 
                    584:        liberation(s_etat_processus, s_objet_liste);
                    585:        liberation(s_etat_processus, s_objet_critere);
                    586: 
                    587:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    588:        return;
                    589:    }
                    590: 
                    591:    if (presence_nom == d_faux)
                    592:    {
                    593:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    594:                s_objet_liste) == d_erreur)
                    595:        {
                    596:            return;
                    597:        }
                    598:    }
                    599:    else
                    600:    {
                    601:        if (variable_partagee == d_vrai)
                    602:        {
1.54      bertrand  603:            (*(*s_etat_processus).pointeur_variable_partagee_courante).objet =
                    604:                    s_objet_liste;
1.1       bertrand  605: 
                    606:            if (pthread_mutex_unlock(&((*(*s_etat_processus)
1.54      bertrand  607:                    .pointeur_variable_partagee_courante).mutex)) != 0)
1.1       bertrand  608:            {
                    609:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    610:                return;
                    611:            }
                    612:        }
                    613:    }
                    614: 
                    615:    liberation(s_etat_processus, s_objet_critere);
                    616: 
                    617:    return;
                    618: }
                    619: 
                    620: 
                    621: /*
                    622: ================================================================================
                    623:   Fonction 'save'
                    624: ================================================================================
                    625:   Entrées : structure processus
                    626: --------------------------------------------------------------------------------
                    627:   Sorties :
                    628: --------------------------------------------------------------------------------
                    629:   Effets de bord : néant
                    630: ================================================================================
                    631: */
                    632: 
                    633: void
                    634: instruction_save(struct_processus *s_etat_processus)
                    635: {
                    636:    struct_objet                        *s_objet_1;
                    637:    struct_objet                        *s_objet_2;
                    638: 
                    639:    struct_variable                     s_variable;
                    640: 
                    641:    (*s_etat_processus).erreur_execution = d_ex;
                    642: 
                    643:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    644:    {
                    645:        printf("\n  SAVE ");
                    646: 
                    647:        if ((*s_etat_processus).langue == 'F')
                    648:        {
                    649:            printf("(affecte un objet à une variable globale)\n\n");
                    650:        }
                    651:        else
                    652:        {
                    653:            printf("(store an object in a global variable)\n\n");
                    654:        }
                    655: 
                    656:        printf("    2: %s, %s, %s, %s, %s, %s,\n"
                    657:                "       %s, %s, %s, %s, %s,\n"
                    658:                "       %s, %s, %s, %s, %s,\n"
                    659:                "       %s, %s, %s, %s,\n"
                    660:                "       %s, %s\n",
                    661:                d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX,
                    662:                d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK,
                    663:                d_SQL, d_SLB, d_PRC, d_MTX);
                    664:        printf("    1: %s\n", d_NOM);
                    665: 
                    666:        return;
                    667:    }
                    668:    else if ((*s_etat_processus).test_instruction == 'Y')
                    669:    {
                    670:        (*s_etat_processus).nombre_arguments = -1;
                    671:        return;
                    672:    }
                    673:    
                    674:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    675:    {
                    676:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    677:        {
                    678:            return;
                    679:        }
                    680:    }
                    681: 
                    682:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    683:            &s_objet_1) == d_erreur)
                    684:    {
                    685:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    686:        return;
                    687:    }
                    688: 
                    689:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    690:            &s_objet_2) == d_erreur)
                    691:    {
                    692:        liberation(s_etat_processus, s_objet_1);
                    693: 
                    694:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    695:        return;
                    696:    }
                    697: 
                    698:    if ((*s_objet_1).type != NOM)
                    699:    {
                    700:        liberation(s_etat_processus, s_objet_1);
                    701:        liberation(s_etat_processus, s_objet_2);
                    702: 
                    703:        (*s_etat_processus).erreur_execution = d_ex_nom_invalide;
                    704:        return;
                    705:    }
                    706: 
1.27      bertrand  707:    if (recherche_variable_globale(s_etat_processus, (*((struct_nom *)
1.1       bertrand  708:            (*s_objet_1).objet)).nom) == d_vrai)
                    709:    {
                    710:        /*
1.27      bertrand  711:         * Une variable est accessible.
1.1       bertrand  712:         */
                    713: 
1.27      bertrand  714:        if ((*(*s_etat_processus).pointeur_variable_courante)
                    715:                .variable_verrouillee == d_vrai)
1.1       bertrand  716:        {
1.27      bertrand  717:            liberation(s_etat_processus, s_objet_1);
                    718:            liberation(s_etat_processus, s_objet_2);
1.1       bertrand  719: 
1.27      bertrand  720:            (*s_etat_processus).erreur_execution = d_ex_variable_verrouillee;
                    721:            return;
                    722:        }
1.1       bertrand  723: 
1.27      bertrand  724:        if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL)
                    725:        {
                    726:            liberation(s_etat_processus, s_objet_1);
                    727:            liberation(s_etat_processus, s_objet_2);
1.1       bertrand  728: 
1.27      bertrand  729:            (*s_etat_processus).erreur_execution = d_ex_variable_partagee;
                    730:            return;
1.1       bertrand  731:        }
                    732: 
1.27      bertrand  733:        liberation(s_etat_processus,
                    734:                (*(*s_etat_processus).pointeur_variable_courante).objet);
                    735:        (*(*s_etat_processus).pointeur_variable_courante).objet = s_objet_2;
1.1       bertrand  736:    }
                    737:    else
                    738:    {
                    739:        /*
                    740:         * Aucune variable n'est accessible (ni locale, ni globale).
                    741:         */
                    742: 
1.53      bertrand  743:        if (((*s_etat_processus).autorisation_nom_implicite == 'N') &&
                    744:                ((*((struct_nom *) (*s_objet_1).objet)).symbole == d_faux))
                    745:        {
                    746:            liberation(s_etat_processus, s_objet_1);
                    747:            liberation(s_etat_processus, s_objet_2);
                    748: 
                    749:            (*s_etat_processus).erreur_systeme = d_es;
                    750:            (*s_etat_processus).erreur_execution =
                    751:                    d_ex_creation_variable_globale;
                    752:            return;
                    753:        }
                    754: 
1.1       bertrand  755:        if ((s_variable.nom = malloc((strlen((*((struct_nom *)
                    756:                (*s_objet_1).objet)).nom) + 1) * sizeof(unsigned char)))
                    757:                == NULL)
                    758:        {
                    759:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    760:            return;
                    761:        }
                    762: 
                    763:        strcpy(s_variable.nom, (*((struct_nom *) (*s_objet_1).objet)).nom);
                    764:        s_variable.niveau = 1;
                    765: 
                    766:        /*
                    767:         * Le niveau 0 correspond aux définitions. Les variables
                    768:         * commencent à 1 car elles sont toujours incluses dans
                    769:         * une définition.
                    770:         */
                    771: 
                    772:        s_variable.objet = s_objet_2;
                    773: 
                    774:        if (creation_variable(s_etat_processus, &s_variable, 'V', 'P')
                    775:                == d_erreur)
                    776:        {
                    777:            return;
                    778:        }
                    779: 
                    780:        (*s_etat_processus).erreur_systeme = d_es;
                    781:    }
                    782: 
                    783:    liberation(s_etat_processus, s_objet_1);
                    784: 
                    785:    return;
                    786: }
                    787: 
                    788: 
                    789: /*
                    790: ================================================================================
                    791:   Fonction 'suspend'
                    792: ================================================================================
                    793:   Entrées : structure processus
                    794: --------------------------------------------------------------------------------
                    795:   Sorties :
                    796: --------------------------------------------------------------------------------
                    797:   Effets de bord : néant
                    798: ================================================================================
                    799: */
                    800: 
                    801: void
                    802: instruction_suspend(struct_processus *s_etat_processus)
                    803: {
1.37      bertrand  804:    struct timespec             attente;
1.1       bertrand  805: 
                    806:    (*s_etat_processus).erreur_execution = d_ex;
                    807: 
                    808:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    809:    {
                    810:        printf("\n  SUSPEND ");
                    811: 
                    812:        if ((*s_etat_processus).langue == 'F')
                    813:        {
1.37      bertrand  814:            printf("(attend un signal RPL/SIGCONT)\n\n");
1.1       bertrand  815:            printf("  Aucun argument\n");
                    816:        }
                    817:        else
                    818:        {
1.37      bertrand  819:            printf("(wait for RPL/SIGCONT signal)\n\n");
1.1       bertrand  820:            printf("  No argument\n");
                    821:        }
                    822: 
                    823:        return;
                    824:    }
                    825:    else if ((*s_etat_processus).test_instruction == 'Y')
                    826:    {
                    827:        (*s_etat_processus).nombre_arguments = -1;
                    828:        return;
                    829:    }
                    830: 
                    831:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    832:    {
                    833:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                    834:        {
                    835:            return;
                    836:        }
                    837:    }
                    838: 
                    839:    if ((*s_etat_processus).profilage == d_vrai)
                    840:    {
                    841:        profilage(s_etat_processus, "Suspend");
                    842: 
                    843:        if ((*s_etat_processus).erreur_systeme != d_es)
                    844:        {
                    845:            return;
                    846:        }
                    847:    }
                    848: 
1.42      bertrand  849: #  ifndef SEMAPHORES_NOMMES
                    850:        if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    851: #  else
                    852:        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    853: #  endif
1.1       bertrand  854:    {
                    855:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    856:        return;
                    857:    }
                    858: 
1.37      bertrand  859:    for((*s_etat_processus).redemarrage_processus = d_faux;;)
                    860:    {
                    861:        scrutation_interruptions(s_etat_processus);
                    862: 
                    863:        if ((*s_etat_processus).redemarrage_processus == d_vrai)
                    864:        {
                    865:            break;
                    866:        }
                    867: 
                    868:        nanosleep(&attente, NULL);
                    869:        INCR_GRANULARITE(attente.tv_nsec);
                    870:    }
1.1       bertrand  871: 
1.42      bertrand  872: #  ifndef SEMAPHORES_NOMMES
                    873:        while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    874: #  else
                    875:        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    876: #  endif
1.1       bertrand  877:    {
1.41      bertrand  878:        if (errno != EINTR)
                    879:        {
                    880:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    881:            return;
                    882:        }
1.1       bertrand  883:    }
                    884: 
                    885:    if ((*s_etat_processus).profilage == d_vrai)
                    886:    {
                    887:        profilage(s_etat_processus, NULL);
                    888:    }
                    889: 
                    890:    return;
                    891: }
                    892: 
                    893: 
                    894: /*
                    895: ================================================================================
                    896:   Fonction 'static'
                    897: ================================================================================
                    898:   Entrées : structure processus
                    899: --------------------------------------------------------------------------------
                    900:   Sorties :
                    901: --------------------------------------------------------------------------------
                    902:   Effets de bord : néant
                    903: ================================================================================
                    904: */
                    905: 
                    906: void
                    907: instruction_static(struct_processus *s_etat_processus)
                    908: {
                    909:    (*s_etat_processus).erreur_execution = d_ex;
                    910: 
                    911:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    912:    {
                    913:        printf("\n  STATIC ");
                    914: 
                    915:        if ((*s_etat_processus).langue == 'F')
                    916:        {
                    917:            printf("(déclaration de variables statiques)\n\n");
                    918:            printf("  Aucun argument\n");
                    919:        }
                    920:        else
                    921:        {
                    922:            printf("(static variables declaration)\n\n");
                    923:            printf("  No argument\n");
                    924:        }
                    925: 
                    926:        return;
                    927:    }
                    928:    else if ((*s_etat_processus).test_instruction == 'Y')
                    929:    {
                    930:        (*s_etat_processus).nombre_arguments = -1;
                    931:        return;
                    932:    }
                    933:    
                    934:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    935:    {
                    936:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                    937:        {
                    938:            return;
                    939:        }
                    940:    }
                    941: 
                    942:    if ((*s_etat_processus).creation_variables_partagees == d_vrai)
                    943:    {
                    944:        (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee;
                    945:        return;
                    946:    }
                    947: 
                    948:    (*s_etat_processus).creation_variables_statiques = d_vrai;
                    949: 
                    950:    return;
                    951: }
                    952: 
                    953: 
                    954: /*
                    955: ================================================================================
                    956:   Fonction 'shared'
                    957: ================================================================================
                    958:   Entrées : structure processus
                    959: --------------------------------------------------------------------------------
                    960:   Sorties :
                    961: --------------------------------------------------------------------------------
                    962:   Effets de bord : néant
                    963: ================================================================================
                    964: */
                    965: 
                    966: void
                    967: instruction_shared(struct_processus *s_etat_processus)
                    968: {
                    969:    (*s_etat_processus).erreur_execution = d_ex;
                    970: 
                    971:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    972:    {
                    973:        printf("\n  SHARED ");
                    974: 
                    975:        if ((*s_etat_processus).langue == 'F')
                    976:        {
                    977:            printf("(déclaration de variables partagées)\n\n");
                    978:            printf("  Aucun argument\n");
                    979:        }
                    980:        else
                    981:        {
                    982:            printf("(shared variables declaration)\n\n");
                    983:            printf("  No argument\n");
                    984:        }
                    985: 
                    986:        return;
                    987:    }
                    988:    else if ((*s_etat_processus).test_instruction == 'Y')
                    989:    {
                    990:        (*s_etat_processus).nombre_arguments = -1;
                    991:        return;
                    992:    }
                    993:    
                    994:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    995:    {
                    996:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                    997:        {
                    998:            return;
                    999:        }
                   1000:    }
                   1001: 
                   1002:    if ((*s_etat_processus).creation_variables_partagees == d_vrai)
                   1003:    {
                   1004:        (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee;
                   1005:        return;
                   1006:    }
                   1007: 
                   1008:    (*s_etat_processus).creation_variables_partagees = d_vrai;
                   1009: 
                   1010:    return;
                   1011: }
                   1012: 
                   1013: 
                   1014: /*
                   1015: ================================================================================
                   1016:   Fonction 'stoswi'
                   1017: ================================================================================
                   1018:   Entrées : structure processus
                   1019: --------------------------------------------------------------------------------
                   1020:   Sorties :
                   1021: --------------------------------------------------------------------------------
                   1022:   Effets de bord : néant
                   1023: ================================================================================
                   1024: */
                   1025: 
                   1026: void
                   1027: instruction_stoswi(struct_processus *s_etat_processus)
                   1028: {
                   1029:    integer8                    interruption;
                   1030: 
                   1031:    struct_objet                *s_objet_argument_1;
                   1032:    struct_objet                *s_objet_argument_2;
                   1033: 
                   1034:    (*s_etat_processus).erreur_execution = d_ex;
                   1035: 
                   1036:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1037:    {
                   1038:        printf("\n  STOSWI ");
                   1039: 
                   1040:        if ((*s_etat_processus).langue == 'F')
                   1041:        {
                   1042:            printf("(définition d'une interruption logicielle)\n\n");
                   1043:        }
                   1044:        else
                   1045:        {
                   1046:            printf("(software interrupt definition)\n\n");
                   1047:        }
                   1048: 
                   1049:        printf("    2: %s, %s\n", d_NOM, d_RPN);
                   1050:        printf("    1: %s\n", d_INT);
                   1051: 
                   1052:        return;
                   1053:    }
                   1054:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1055:    {
                   1056:        (*s_etat_processus).nombre_arguments = -1;
                   1057:        return;
                   1058:    }
                   1059: 
                   1060:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1061:    {
                   1062:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                   1063:        {
                   1064:            return;
                   1065:        }
                   1066:    }
                   1067: 
                   1068:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1069:            &s_objet_argument_1) == d_erreur)
                   1070:    {
                   1071:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1072:        return;
                   1073:    }
                   1074: 
                   1075:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1076:            &s_objet_argument_2) == d_erreur)
                   1077:    {
                   1078:        liberation(s_etat_processus, s_objet_argument_1);
                   1079: 
                   1080:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1081:        return;
                   1082:    }
                   1083: 
                   1084:    if ((*s_objet_argument_1).type == INT)
                   1085:    {
                   1086:        interruption = (*((integer8 *) (*s_objet_argument_1).objet));
                   1087: 
                   1088:        if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   1089:        {
                   1090:            liberation(s_etat_processus, s_objet_argument_1);
                   1091:            liberation(s_etat_processus, s_objet_argument_2);
                   1092: 
                   1093:            (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
                   1094:            return;
                   1095:        }
                   1096: 
                   1097:        if ((*s_objet_argument_2).type == NOM)
                   1098:        {
                   1099:            liberation(s_etat_processus, (*s_etat_processus).corps_interruptions
                   1100:                    [interruption - 1]);
                   1101:            (*s_etat_processus).corps_interruptions[interruption - 1] =
                   1102:                    s_objet_argument_2;
                   1103:        }
                   1104:        else if((*s_objet_argument_2).type == RPN)
                   1105:        {
                   1106:            liberation(s_etat_processus, (*s_etat_processus).corps_interruptions
                   1107:                    [interruption - 1]);
                   1108:            (*s_etat_processus).corps_interruptions[interruption - 1] =
                   1109:                    s_objet_argument_2;
                   1110:        }
                   1111:        else
                   1112:        {
                   1113:            liberation(s_etat_processus, s_objet_argument_1);
                   1114:            liberation(s_etat_processus, s_objet_argument_2);
                   1115: 
                   1116:            (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1117:            return;
                   1118:        }
                   1119:    }
                   1120:    else
                   1121:    {
                   1122:        liberation(s_etat_processus, s_objet_argument_1);
                   1123:        liberation(s_etat_processus, s_objet_argument_2);
                   1124: 
                   1125:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1126:        return;
                   1127:    }
                   1128: 
                   1129:    liberation(s_etat_processus, s_objet_argument_1);
                   1130: 
                   1131:    return;
                   1132: }
                   1133: 
                   1134: 
                   1135: /*
                   1136: ================================================================================
                   1137:   Fonction 'swi'
                   1138: ================================================================================
                   1139:   Entrées : structure processus
                   1140: --------------------------------------------------------------------------------
                   1141:   Sorties :
                   1142: --------------------------------------------------------------------------------
                   1143:   Effets de bord : néant
                   1144: ================================================================================
                   1145: */
                   1146: 
                   1147: void
                   1148: instruction_swi(struct_processus *s_etat_processus)
                   1149: {
                   1150:    int                         interruption_reduite;
                   1151: 
                   1152:    integer8                    interruption;
                   1153: 
                   1154:    sig_atomic_t                registre;
                   1155: 
                   1156:    ssize_t                     longueur_ecriture;
                   1157: 
                   1158:    struct_objet                *s_objet_argument;
                   1159: 
                   1160:    struct timespec             attente;
                   1161: 
1.62      bertrand 1162:    unsigned char               caractere;
1.1       bertrand 1163:    unsigned char               tampon;
                   1164: 
                   1165:    (*s_etat_processus).erreur_execution = d_ex;
                   1166: 
                   1167:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1168:    {
                   1169:        printf("\n  SWI ");
                   1170: 
                   1171:        if ((*s_etat_processus).langue == 'F')
                   1172:        {
                   1173:            printf("(interruption logicielle)\n\n");
                   1174:        }
                   1175:        else
                   1176:        {
                   1177:            printf("(software interrupt)\n\n");
                   1178:        }
                   1179: 
                   1180:        printf("    1: %s\n", d_INT);
                   1181: 
                   1182:        return;
                   1183:    }
                   1184:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1185:    {
                   1186:        (*s_etat_processus).nombre_arguments = -1;
                   1187:        return;
                   1188:    }
                   1189: 
                   1190:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1191:    {
                   1192:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   1193:        {
                   1194:            return;
                   1195:        }
                   1196:    }
                   1197: 
                   1198:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1199:            &s_objet_argument) == d_erreur)
                   1200:    {
                   1201:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1202:        return;
                   1203:    }
                   1204: 
                   1205:    if ((*s_objet_argument).type == INT)
                   1206:    {
                   1207:        interruption = (*((integer8 *) (*s_objet_argument).objet));
                   1208: 
                   1209:        if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   1210:        {
                   1211:            liberation(s_etat_processus, s_objet_argument);
                   1212: 
                   1213:            (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
                   1214:            return;
                   1215:        }
                   1216: 
                   1217:        if ((*s_etat_processus).presence_pipes == d_faux)
                   1218:        {
                   1219:            liberation(s_etat_processus, s_objet_argument);
                   1220: 
                   1221:            (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                   1222:            return;
                   1223:        }
                   1224: 
                   1225:        // Envoi d'un PID invalide (-1) pour ne pas bloquer le thread
                   1226:        // de surveillance.
                   1227: 
                   1228:        registre = (*s_etat_processus).var_volatile_traitement_retarde_stop;
                   1229:        (*s_etat_processus).var_volatile_traitement_retarde_stop = 1;
                   1230: 
1.60      bertrand 1231:        interruption_reduite = (int) interruption;
1.1       bertrand 1232: 
                   1233:        attente.tv_sec = 0;
                   1234:        attente.tv_nsec = GRANULARITE_us * 1000;
                   1235: 
1.42      bertrand 1236: #      ifndef SEMAPHORES_NOMMES
                   1237:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1238: #      else
                   1239:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1240: #      endif
1.8       bertrand 1241:        {
                   1242:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1243:            return;
                   1244:        }
1.1       bertrand 1245: 
                   1246:        while((longueur_ecriture = write_atomic(s_etat_processus,
                   1247:                (*s_etat_processus).pipe_interruptions,
                   1248:                &interruption_reduite, sizeof(interruption_reduite)))
                   1249:                != sizeof(interruption_reduite))
                   1250:        {
1.42      bertrand 1251: #          ifndef SEMAPHORES_NOMMES
                   1252:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1253: #          else
                   1254:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1255: #          endif
1.1       bertrand 1256:            {
1.41      bertrand 1257:                if (errno != EINTR)
                   1258:                {
                   1259:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1260:                    return;
                   1261:                }
1.1       bertrand 1262:            }
                   1263: 
                   1264:            if (longueur_ecriture == -1)
                   1265:            {
                   1266:                if (registre == 0)
                   1267:                {
                   1268:                    if ((*s_etat_processus)
                   1269:                            .var_volatile_traitement_retarde_stop == -1)
                   1270:                    {
                   1271:                        (*s_etat_processus).var_volatile_requete_arret = -1;
                   1272:                    }
                   1273: 
                   1274:                    (*s_etat_processus)
                   1275:                            .var_volatile_traitement_retarde_stop
                   1276:                            = registre;
                   1277:                }
                   1278: 
                   1279:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1280:                return;
                   1281:            }
                   1282: 
                   1283:            nanosleep(&attente, NULL);
                   1284:            INCR_GRANULARITE(attente.tv_nsec);
                   1285: 
1.42      bertrand 1286: #          ifndef SEMAPHORES_NOMMES
                   1287:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1288: #          else
                   1289:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1290: #          endif
1.8       bertrand 1291:            {
                   1292:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1293:                return;
                   1294:            }
1.39      bertrand 1295: 
                   1296:            scrutation_interruptions(s_etat_processus);
1.1       bertrand 1297:        }
                   1298: 
1.42      bertrand 1299: #      ifndef SEMAPHORES_NOMMES
                   1300:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1301: #      else
                   1302:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1303: #      endif
1.1       bertrand 1304:        {
1.41      bertrand 1305:            if (errno != EINTR)
                   1306:            {
                   1307:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1308:                return;
                   1309:            }
1.1       bertrand 1310:        }
                   1311: 
                   1312:        if ((*s_etat_processus).processus_detache == d_vrai)
                   1313:        {
1.62      bertrand 1314:            caractere = 2;
1.1       bertrand 1315: 
                   1316:            attente.tv_sec = 0;
                   1317:            attente.tv_nsec = GRANULARITE_us * 1000;
                   1318: 
1.42      bertrand 1319: #          ifndef SEMAPHORES_NOMMES
                   1320:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1321: #          else
                   1322:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1323: #          endif
1.8       bertrand 1324:            {
                   1325:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1326:                return;
                   1327:            }
1.1       bertrand 1328: 
                   1329:            while((longueur_ecriture = write_atomic(s_etat_processus,
1.62      bertrand 1330:                    (*s_etat_processus).pipe_nombre_elements_attente,
                   1331:                    &caractere, sizeof(caractere))) != sizeof(caractere))
1.1       bertrand 1332:            {
1.42      bertrand 1333: #              ifndef SEMAPHORES_NOMMES
                   1334:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1335: #              else
                   1336:                    while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1337: #              endif
1.1       bertrand 1338:                {
1.41      bertrand 1339:                    if (errno != EINTR)
                   1340:                    {
                   1341:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1342:                        return;
                   1343:                    }
1.1       bertrand 1344:                }
                   1345: 
                   1346:                if (longueur_ecriture == -1)
                   1347:                {
                   1348:                    if (registre == 0)
                   1349:                    {
                   1350:                        if ((*s_etat_processus)
                   1351:                                .var_volatile_traitement_retarde_stop == -1)
                   1352:                        {
                   1353:                            (*s_etat_processus).var_volatile_requete_arret = -1;
                   1354:                        }
                   1355: 
                   1356:                        (*s_etat_processus)
                   1357:                                .var_volatile_traitement_retarde_stop
                   1358:                                = registre;
                   1359:                    }
                   1360: 
                   1361:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1362:                    return;
                   1363:                }
                   1364: 
                   1365:                nanosleep(&attente, NULL);
                   1366:                INCR_GRANULARITE(attente.tv_nsec);
                   1367: 
1.42      bertrand 1368: #              ifndef SEMAPHORES_NOMMES
                   1369:                    if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1370: #              else
                   1371:                    if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1372: #              endif
1.8       bertrand 1373:                {
                   1374:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1375:                    return;
                   1376:                }
1.39      bertrand 1377: 
                   1378:                scrutation_interruptions(s_etat_processus);
1.1       bertrand 1379:            }
                   1380: 
1.42      bertrand 1381: #          ifndef SEMAPHORES_NOMMES
                   1382:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1383: #          else
                   1384:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1385: #          endif
1.1       bertrand 1386:            {
1.41      bertrand 1387:                if (errno != EINTR)
                   1388:                {
                   1389:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1390:                    return;
                   1391:                }
1.1       bertrand 1392:            }
                   1393:        }
                   1394:        else
                   1395:        {
1.62      bertrand 1396:            caractere = 2;
1.1       bertrand 1397: 
1.42      bertrand 1398: #          ifndef SEMAPHORES_NOMMES
                   1399:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1400: #          else
                   1401:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1402: #          endif
1.8       bertrand 1403:            {
                   1404:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1405:                return;
                   1406:            }
1.1       bertrand 1407: 
                   1408:            while((longueur_ecriture = write_atomic(s_etat_processus,
1.62      bertrand 1409:                    (*s_etat_processus).pipe_nombre_elements_attente,
                   1410:                    &caractere, sizeof(caractere))) != sizeof(caractere))
1.1       bertrand 1411:            {
1.42      bertrand 1412: #              ifndef SEMAPHORES_NOMMES
                   1413:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1414: #              else
                   1415:                    while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1416: #              endif
1.1       bertrand 1417:                {
1.41      bertrand 1418:                    if (errno != EINTR)
                   1419:                    {
                   1420:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1421:                        return;
                   1422:                    }
1.1       bertrand 1423:                }
                   1424: 
                   1425:                if (longueur_ecriture == -1)
                   1426:                {
                   1427:                    if (registre == 0)
                   1428:                    {
                   1429:                        if ((*s_etat_processus)
                   1430:                                .var_volatile_traitement_retarde_stop == -1)
                   1431:                        {
                   1432:                            (*s_etat_processus).var_volatile_requete_arret = -1;
                   1433:                        }
                   1434: 
                   1435:                        (*s_etat_processus)
                   1436:                                .var_volatile_traitement_retarde_stop
                   1437:                                = registre;
                   1438:                    }
                   1439: 
                   1440:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1441:                    return;
                   1442:                }
                   1443: 
                   1444:                nanosleep(&attente, NULL);
                   1445:                INCR_GRANULARITE(attente.tv_nsec);
                   1446: 
1.42      bertrand 1447: #              ifndef SEMAPHORES_NOMMES
                   1448:                    if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1449: #              else
                   1450:                    if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1451: #              endif
1.1       bertrand 1452:                {
                   1453:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1454:                    return;
                   1455:                }
1.39      bertrand 1456: 
                   1457:                scrutation_interruptions(s_etat_processus);
1.1       bertrand 1458:            }
                   1459: 
1.42      bertrand 1460: #          ifndef SEMAPHORES_NOMMES
                   1461:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1462: #          else
                   1463:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1464: #          endif
1.1       bertrand 1465:            {
1.41      bertrand 1466:                if (errno != EINTR)
                   1467:                {
                   1468:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1469:                    return;
                   1470:                }
1.1       bertrand 1471:            }
                   1472:        }
                   1473: 
                   1474:        attente.tv_sec = 0;
                   1475:        attente.tv_nsec = GRANULARITE_us * 1000;
                   1476: 
1.42      bertrand 1477: #      ifndef SEMAPHORES_NOMMES
                   1478:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1479: #      else
                   1480:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1481: #      endif
1.1       bertrand 1482:        {
                   1483:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1484:            return;
                   1485:        }
                   1486: 
                   1487:        while(read_atomic(s_etat_processus,
                   1488:                (*s_etat_processus).pipe_acquittement,
                   1489:                &tampon, sizeof(unsigned char)) != sizeof(unsigned char))
                   1490:        {
1.42      bertrand 1491: #          ifndef SEMAPHORES_NOMMES
                   1492:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1493: #          else
                   1494:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1495: #          endif
1.1       bertrand 1496:            {
1.41      bertrand 1497:                if (errno != EINTR)
                   1498:                {
                   1499:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1500:                    return;
                   1501:                }
1.1       bertrand 1502:            }
                   1503: 
                   1504:            nanosleep(&attente, NULL);
                   1505:            INCR_GRANULARITE(attente.tv_nsec);
                   1506: 
1.42      bertrand 1507: #          ifndef SEMAPHORES_NOMMES
                   1508:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1509: #          else
                   1510:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1511: #          endif
1.1       bertrand 1512:            {
                   1513:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1514:                return;
                   1515:            }
1.39      bertrand 1516: 
                   1517:            scrutation_interruptions(s_etat_processus);
1.1       bertrand 1518:        }
                   1519: 
1.42      bertrand 1520: #      ifndef SEMAPHORES_NOMMES
                   1521:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1522: #      else
                   1523:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1524: #      endif
1.1       bertrand 1525:        {
1.41      bertrand 1526:            if (errno != EINTR)
                   1527:            {
                   1528:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1529:                return;
                   1530:            }
1.1       bertrand 1531:        }
                   1532: 
                   1533:        if (registre == 0)
                   1534:        {
                   1535:            if ((*s_etat_processus).var_volatile_traitement_retarde_stop == -1)
                   1536:            {
                   1537:                (*s_etat_processus).var_volatile_requete_arret = -1;
                   1538:            }
                   1539: 
                   1540:            (*s_etat_processus).var_volatile_traitement_retarde_stop = registre;
                   1541:        }
                   1542:    }
                   1543:    else
                   1544:    {
                   1545:        liberation(s_etat_processus, s_objet_argument);
                   1546: 
                   1547:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1548:        return;
                   1549:    }
                   1550: 
                   1551:    liberation(s_etat_processus, s_objet_argument);
                   1552: 
                   1553:    return;
                   1554: }
                   1555: 
                   1556: 
                   1557: /*
                   1558: ================================================================================
                   1559:   Fonction 'swilock'
                   1560: ================================================================================
                   1561:   Entrées : structure processus
                   1562: --------------------------------------------------------------------------------
                   1563:   Sorties :
                   1564: --------------------------------------------------------------------------------
                   1565:   Effets de bord : néant
                   1566: ================================================================================
                   1567: */
                   1568: 
                   1569: void
                   1570: instruction_swilock(struct_processus *s_etat_processus)
                   1571: {
                   1572:    integer8                    interruption;
                   1573: 
                   1574:    struct_liste_chainee        *l_element_courant;
                   1575: 
                   1576:    struct_objet                *s_objet_argument;
                   1577: 
                   1578:    (*s_etat_processus).erreur_execution = d_ex;
                   1579: 
                   1580:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1581:    {
                   1582:        printf("\n  SWILOCK ");
                   1583: 
                   1584:        if ((*s_etat_processus).langue == 'F')
                   1585:        {
                   1586:            printf("(verrouillage des interruptions logicielles)\n\n");
                   1587:        }
                   1588:        else
                   1589:        {
                   1590:            printf("(software interrupt lock)\n\n");
                   1591:        }
                   1592: 
                   1593:        printf("    1: %s, %s\n", d_INT, d_LST);
                   1594: 
                   1595:        return;
                   1596:    }
                   1597:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1598:    {
                   1599:        (*s_etat_processus).nombre_arguments = -1;
                   1600:        return;
                   1601:    }
                   1602: 
                   1603:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1604:    {
                   1605:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   1606:        {
                   1607:            return;
                   1608:        }
                   1609:    }
                   1610: 
                   1611:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1612:            &s_objet_argument) == d_erreur)
                   1613:    {
                   1614:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1615:        return;
                   1616:    }
                   1617: 
                   1618:    if ((*s_objet_argument).type == INT)
                   1619:    {
                   1620:        interruption = (*((integer8 *) (*s_objet_argument).objet));
                   1621: 
                   1622:        if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   1623:        {
                   1624:            liberation(s_etat_processus, s_objet_argument);
                   1625: 
                   1626:            (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
                   1627:            return;
                   1628:        }
                   1629: 
                   1630:        (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
                   1631:    }
                   1632:    else if ((*s_objet_argument).type == LST)
                   1633:    {
                   1634:        l_element_courant = (*s_objet_argument).objet;
                   1635: 
                   1636:        while(l_element_courant)
                   1637:        {
                   1638:            if ((*(*l_element_courant).donnee).type != INT)
                   1639:            {
                   1640:                liberation(s_etat_processus, s_objet_argument);
                   1641: 
                   1642:                (*s_etat_processus).erreur_execution =
                   1643:                        d_ex_erreur_type_argument;
                   1644:                return;
                   1645:            }
                   1646: 
                   1647:            interruption = (*((integer8 *) (*(*l_element_courant)
                   1648:                    .donnee).objet));
                   1649: 
                   1650:            if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   1651:            {
                   1652:                liberation(s_etat_processus, s_objet_argument);
                   1653: 
                   1654:                (*s_etat_processus).erreur_execution =
                   1655:                        d_ex_interruption_invalide;
                   1656:                return;
                   1657:            }
                   1658: 
                   1659:            (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
                   1660:            l_element_courant = (*l_element_courant).suivant;
                   1661:        }
                   1662:    }
                   1663:    else
                   1664:    {
                   1665:        liberation(s_etat_processus, s_objet_argument);
                   1666: 
                   1667:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1668:        return;
                   1669:    }
                   1670: 
                   1671:    liberation(s_etat_processus, s_objet_argument);
                   1672: 
                   1673:    return;
                   1674: }
                   1675: 
                   1676: 
                   1677: /*
                   1678: ================================================================================
                   1679:   Fonction 'swistatus'
                   1680: ================================================================================
                   1681:   Entrées : structure processus
                   1682: --------------------------------------------------------------------------------
                   1683:   Sorties :
                   1684: --------------------------------------------------------------------------------
                   1685:   Effets de bord : néant
                   1686: ================================================================================
                   1687: */
                   1688: 
                   1689: void
                   1690: instruction_swistatus(struct_processus *s_etat_processus)
                   1691: {
                   1692:    int                         i;
                   1693: 
                   1694:    struct_liste_chainee        *l_element_courant;
                   1695:    struct_liste_chainee        *l_element_futur;
                   1696:    struct_liste_chainee        *l_element_liste;
                   1697: 
                   1698:    struct_objet                *s_objet_resultat;
                   1699: 
                   1700:    (*s_etat_processus).erreur_execution = d_ex;
                   1701: 
                   1702:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1703:    {
                   1704:        printf("\n  SWISTATUS ");
                   1705: 
                   1706:        if ((*s_etat_processus).langue == 'F')
                   1707:        {
                   1708:            printf("(état des interruptions logicielles)\n\n");
                   1709:        }
                   1710:        else
                   1711:        {
                   1712:            printf("(software interrupts status)\n\n");
                   1713:        }
                   1714: 
                   1715:        printf("->  1: %s\n\n", d_LST);
                   1716: 
                   1717:        if ((*s_etat_processus).langue == 'F')
                   1718:        {
                   1719:            printf("  Utilisation :\n\n");
                   1720:        }
                   1721:        else
                   1722:        {
                   1723:            printf("  Usage:\n\n");
                   1724:        }
                   1725: 
                   1726:        printf("    { { initialized interrupts }\n"
                   1727:                "      { unlocked interrupts }\n"
                   1728:                "      { queued interrupts }\n"
                   1729:                "      { locked interrupts } }\n");
                   1730:        return;
                   1731:    }
                   1732:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1733:    {
                   1734:        (*s_etat_processus).nombre_arguments = -1;
                   1735:        return;
                   1736:    }
                   1737: 
                   1738:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1739:    {
                   1740:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                   1741:        {
                   1742:            return;
                   1743:        }
                   1744:    }
                   1745: 
                   1746:    if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL)
                   1747:    {
                   1748:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1749:        return;
                   1750:    }
                   1751: 
                   1752:    if (((*s_objet_resultat).objet =
                   1753:            allocation_maillon(s_etat_processus)) == NULL)
                   1754:    {
                   1755:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1756:        return;
                   1757:    }
                   1758: 
                   1759:    l_element_courant = (struct_liste_chainee *) (*s_objet_resultat).objet;
                   1760: 
                   1761:    if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
                   1762:            == NULL)
                   1763:    {
                   1764:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1765:        return;
                   1766:    }
                   1767: 
                   1768:    l_element_liste = NULL;
                   1769:    l_element_futur = NULL;
                   1770: 
                   1771:    for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
                   1772:    {
                   1773:        if ((*s_etat_processus).corps_interruptions[i] != NULL)
                   1774:        {
                   1775:            if (l_element_liste == NULL)
                   1776:            {
                   1777:                if ((l_element_liste =
                   1778:                        allocation_maillon(s_etat_processus)) == NULL)
                   1779:                {
                   1780:                    (*s_etat_processus).erreur_systeme =
                   1781:                            d_es_allocation_memoire;
                   1782:                    return;
                   1783:                }
                   1784: 
                   1785:                l_element_futur = l_element_liste;
                   1786:            }
                   1787:            else
                   1788:            {
                   1789:                if (((*l_element_liste).suivant =
                   1790:                        allocation_maillon(s_etat_processus)) == NULL)
                   1791:                {
                   1792:                    (*s_etat_processus).erreur_systeme =
                   1793:                            d_es_allocation_memoire;
                   1794:                    return;
                   1795:                }
                   1796: 
                   1797:                l_element_liste = (*l_element_liste).suivant;
                   1798:            }
                   1799: 
                   1800:            (*l_element_liste).suivant = NULL;
                   1801: 
                   1802:            if (((*l_element_liste).donnee = allocation(s_etat_processus,
                   1803:                    INT)) == NULL)
                   1804:            {
                   1805:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1806:                return;
                   1807:            }
                   1808: 
                   1809:            (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
                   1810:        }
                   1811:    }
                   1812: 
                   1813:    (*(*l_element_courant).donnee).objet = l_element_futur;
                   1814: 
                   1815:    if (((*l_element_courant).suivant =
                   1816:            allocation_maillon(s_etat_processus)) == NULL)
                   1817:    {
                   1818:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1819:        return;
                   1820:    }
                   1821: 
                   1822:    l_element_courant = (*l_element_courant).suivant;
                   1823: 
                   1824:    if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
                   1825:            == NULL)
                   1826:    {
                   1827:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1828:        return;
                   1829:    }
                   1830: 
                   1831:    l_element_liste = NULL;
                   1832:    l_element_futur = NULL;
                   1833: 
                   1834:    for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
                   1835:    {
                   1836:        if ((*s_etat_processus).masque_interruptions[i] == 'N')
                   1837:        {
                   1838:            if (l_element_liste == NULL)
                   1839:            {
                   1840:                if ((l_element_liste =
                   1841:                        allocation_maillon(s_etat_processus)) == NULL)
                   1842:                {
                   1843:                    (*s_etat_processus).erreur_systeme =
                   1844:                            d_es_allocation_memoire;
                   1845:                    return;
                   1846:                }
                   1847: 
                   1848:                l_element_futur = l_element_liste;
                   1849:            }
                   1850:            else
                   1851:            {
                   1852:                if (((*l_element_liste).suivant =
                   1853:                        allocation_maillon(s_etat_processus)) == NULL)
                   1854:                {
                   1855:                    (*s_etat_processus).erreur_systeme =
                   1856:                            d_es_allocation_memoire;
                   1857:                    return;
                   1858:                }
                   1859: 
                   1860:                l_element_liste = (*l_element_liste).suivant;
                   1861:            }
                   1862: 
                   1863:            (*l_element_liste).suivant = NULL;
                   1864: 
                   1865:            if (((*l_element_liste).donnee = allocation(s_etat_processus,
                   1866:                    INT)) == NULL)
                   1867:            {
                   1868:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1869:                return;
                   1870:            }
                   1871: 
                   1872:            (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
                   1873:        }
                   1874:    }
                   1875: 
                   1876:    (*(*l_element_courant).donnee).objet = l_element_futur;
                   1877: 
                   1878:    if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
                   1879:            == NULL)
                   1880:    {
                   1881:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1882:        return;
                   1883:    }
                   1884: 
                   1885:    l_element_courant = (*l_element_courant).suivant;
                   1886: 
                   1887:    if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
                   1888:            == NULL)
                   1889:    {
                   1890:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1891:        return;
                   1892:    }
                   1893: 
                   1894:    l_element_liste = NULL;
                   1895:    l_element_futur = NULL;
                   1896: 
                   1897:    for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
                   1898:    {
                   1899:        if ((*s_etat_processus).masque_interruptions[i] == 'Q')
                   1900:        {
                   1901:            if (l_element_liste == NULL)
                   1902:            {
                   1903:                if ((l_element_liste =
                   1904:                        allocation_maillon(s_etat_processus)) == NULL)
                   1905:                {
                   1906:                    (*s_etat_processus).erreur_systeme =
                   1907:                            d_es_allocation_memoire;
                   1908:                    return;
                   1909:                }
                   1910: 
                   1911:                l_element_futur = l_element_liste;
                   1912:            }
                   1913:            else
                   1914:            {
                   1915:                if (((*l_element_liste).suivant =
                   1916:                        allocation_maillon(s_etat_processus)) == NULL)
                   1917:                {
                   1918:                    (*s_etat_processus).erreur_systeme =
                   1919:                            d_es_allocation_memoire;
                   1920:                    return;
                   1921:                }
                   1922: 
                   1923:                l_element_liste = (*l_element_liste).suivant;
                   1924:            }
                   1925: 
                   1926:            (*l_element_liste).suivant = NULL;
                   1927: 
                   1928:            if (((*l_element_liste).donnee = allocation(s_etat_processus,
                   1929:                    INT)) == NULL)
                   1930:            {
                   1931:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1932:                return;
                   1933:            }
                   1934: 
                   1935:            (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
                   1936:        }
                   1937:    }
                   1938: 
                   1939:    (*(*l_element_courant).donnee).objet = l_element_futur;
                   1940: 
                   1941:    if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
                   1942:            == NULL)
                   1943:    {
                   1944:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1945:        return;
                   1946:    }
                   1947: 
                   1948:    l_element_courant = (*l_element_courant).suivant;
                   1949: 
                   1950:    if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
                   1951:            == NULL)
                   1952:    {
                   1953:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1954:        return;
                   1955:    }
                   1956: 
                   1957:    l_element_liste = NULL;
                   1958:    l_element_futur = NULL;
                   1959: 
                   1960:    for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
                   1961:    {
                   1962:        if ((*s_etat_processus).masque_interruptions[i] == 'I')
                   1963:        {
                   1964:            if (l_element_liste == NULL)
                   1965:            {
                   1966:                if ((l_element_liste =
                   1967:                        allocation_maillon(s_etat_processus)) == NULL)
                   1968:                {
                   1969:                    (*s_etat_processus).erreur_systeme =
                   1970:                            d_es_allocation_memoire;
                   1971:                    return;
                   1972:                }
                   1973: 
                   1974:                l_element_futur = l_element_liste;
                   1975:            }
                   1976:            else
                   1977:            {
                   1978:                if (((*l_element_liste).suivant =
                   1979:                        allocation_maillon(s_etat_processus)) == NULL)
                   1980:                {
                   1981:                    (*s_etat_processus).erreur_systeme =
                   1982:                            d_es_allocation_memoire;
                   1983:                    return;
                   1984:                }
                   1985: 
                   1986:                l_element_liste = (*l_element_liste).suivant;
                   1987:            }
                   1988: 
                   1989:            (*l_element_liste).suivant = NULL;
                   1990: 
                   1991:            if (((*l_element_liste).donnee = allocation(s_etat_processus,
                   1992:                    INT)) == NULL)
                   1993:            {
                   1994:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1995:                return;
                   1996:            }
                   1997: 
                   1998:            (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
                   1999:        }
                   2000:    }
                   2001: 
                   2002:    (*(*l_element_courant).donnee).objet = l_element_futur;
                   2003: 
                   2004:    (*l_element_courant).suivant = NULL;
                   2005: 
                   2006:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2007:            s_objet_resultat) == d_erreur)
                   2008:    {
                   2009:        return;
                   2010:    }
                   2011: 
                   2012:    return;
                   2013: }
                   2014: 
                   2015: 
                   2016: /*
                   2017: ================================================================================
                   2018:   Fonction 'swiunlock'
                   2019: ================================================================================
                   2020:   Entrées : structure processus
                   2021: --------------------------------------------------------------------------------
                   2022:   Sorties :
                   2023: --------------------------------------------------------------------------------
                   2024:   Effets de bord : néant
                   2025: ================================================================================
                   2026: */
                   2027: 
                   2028: void
                   2029: instruction_swiunlock(struct_processus *s_etat_processus)
                   2030: {
                   2031:    integer8                    interruption;
                   2032: 
                   2033:    struct_liste_chainee        *l_element_courant;
                   2034: 
                   2035:    struct_objet                *s_objet_argument;
                   2036: 
                   2037:    (*s_etat_processus).erreur_execution = d_ex;
                   2038: 
                   2039:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2040:    {
                   2041:        printf("\n  SWIUNLOCK ");
                   2042: 
                   2043:        if ((*s_etat_processus).langue == 'F')
                   2044:        {
                   2045:            printf("(déverrouillage des interruptions logicielles)\n\n");
                   2046:        }
                   2047:        else
                   2048:        {
                   2049:            printf("(software interrupt unlock)\n\n");
                   2050:        }
                   2051: 
                   2052:        printf("    1: %s, %s\n", d_INT, d_LST);
                   2053: 
                   2054:        return;
                   2055:    }
                   2056:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2057:    {
                   2058:        (*s_etat_processus).nombre_arguments = -1;
                   2059:        return;
                   2060:    }
                   2061: 
                   2062:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2063:    {
                   2064:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2065:        {
                   2066:            return;
                   2067:        }
                   2068:    }
                   2069: 
                   2070:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2071:            &s_objet_argument) == d_erreur)
                   2072:    {
                   2073:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2074:        return;
                   2075:    }
                   2076: 
                   2077:    if ((*s_objet_argument).type == INT)
                   2078:    {
                   2079:        interruption = (*((integer8 *) (*s_objet_argument).objet));
                   2080: 
                   2081:        if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   2082:        {
                   2083:            liberation(s_etat_processus, s_objet_argument);
                   2084: 
                   2085:            (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
                   2086:            return;
                   2087:        }
                   2088: 
                   2089:        (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
                   2090:    }
                   2091:    else if ((*s_objet_argument).type == LST)
                   2092:    {
                   2093:        l_element_courant = (*s_objet_argument).objet;
                   2094: 
                   2095:        while(l_element_courant)
                   2096:        {
                   2097:            if ((*(*l_element_courant).donnee).type != INT)
                   2098:            {
                   2099:                liberation(s_etat_processus, s_objet_argument);
                   2100: 
                   2101:                (*s_etat_processus).erreur_execution =
                   2102:                        d_ex_erreur_type_argument;
                   2103:                return;
                   2104:            }
                   2105: 
                   2106:            interruption = (*((integer8 *) (*(*l_element_courant)
                   2107:                    .donnee).objet));
                   2108: 
                   2109:            if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   2110:            {
                   2111:                liberation(s_etat_processus, s_objet_argument);
                   2112: 
                   2113:                (*s_etat_processus).erreur_execution =
                   2114:                        d_ex_interruption_invalide;
                   2115:                return;
                   2116:            }
                   2117: 
                   2118:            (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
                   2119:            l_element_courant = (*l_element_courant).suivant;
                   2120:        }
                   2121:    }
                   2122:    else
                   2123:    {
                   2124:        liberation(s_etat_processus, s_objet_argument);
                   2125: 
                   2126:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2127:        return;
                   2128:    }
                   2129: 
                   2130:    liberation(s_etat_processus, s_objet_argument);
                   2131: 
                   2132:    return;
                   2133: }
                   2134: 
                   2135: 
                   2136: /*
                   2137: ================================================================================
                   2138:   Fonction 'swiqueue'
                   2139: ================================================================================
                   2140:   Entrées : structure processus
                   2141: --------------------------------------------------------------------------------
                   2142:   Sorties :
                   2143: --------------------------------------------------------------------------------
                   2144:   Effets de bord : néant
                   2145: ================================================================================
                   2146: */
                   2147: 
                   2148: void
                   2149: instruction_swiqueue(struct_processus *s_etat_processus)
                   2150: {
                   2151:    integer8                    interruption;
                   2152: 
                   2153:    struct_liste_chainee        *l_element_courant;
                   2154: 
                   2155:    struct_objet                *s_objet_argument;
                   2156: 
                   2157:    (*s_etat_processus).erreur_execution = d_ex;
                   2158: 
                   2159:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2160:    {
                   2161:        printf("\n  SWIQUEUE ");
                   2162: 
                   2163:        if ((*s_etat_processus).langue == 'F')
                   2164:        {
                   2165:            printf("(enregistre des interruptions logicielles)\n\n");
                   2166:        }
                   2167:        else
                   2168:        {
                   2169:            printf("(software interrupt record)\n\n");
                   2170:        }
                   2171: 
                   2172:        printf("    1: %s, %s\n", d_INT, d_LST);
                   2173: 
                   2174:        return;
                   2175:    }
                   2176:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2177:    {
                   2178:        (*s_etat_processus).nombre_arguments = -1;
                   2179:        return;
                   2180:    }
                   2181: 
                   2182:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2183:    {
                   2184:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2185:        {
                   2186:            return;
                   2187:        }
                   2188:    }
                   2189: 
                   2190:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2191:            &s_objet_argument) == d_erreur)
                   2192:    {
                   2193:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2194:        return;
                   2195:    }
                   2196: 
                   2197:    if ((*s_objet_argument).type == INT)
                   2198:    {
                   2199:        interruption = (*((integer8 *) (*s_objet_argument).objet));
                   2200: 
                   2201:        if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   2202:        {
                   2203:            liberation(s_etat_processus, s_objet_argument);
                   2204: 
                   2205:            (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
                   2206:            return;
                   2207:        }
                   2208: 
                   2209:        (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
                   2210:    }
                   2211:    else if ((*s_objet_argument).type == LST)
                   2212:    {
                   2213:        l_element_courant = (*s_objet_argument).objet;
                   2214: 
                   2215:        while(l_element_courant)
                   2216:        {
                   2217:            if ((*(*l_element_courant).donnee).type != INT)
                   2218:            {
                   2219:                liberation(s_etat_processus, s_objet_argument);
                   2220: 
                   2221:                (*s_etat_processus).erreur_execution =
                   2222:                        d_ex_erreur_type_argument;
                   2223:                return;
                   2224:            }
                   2225: 
                   2226:            interruption = (*((integer8 *) (*(*l_element_courant)
                   2227:                    .donnee).objet));
                   2228: 
                   2229:            if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   2230:            {
                   2231:                liberation(s_etat_processus, s_objet_argument);
                   2232: 
                   2233:                (*s_etat_processus).erreur_execution =
                   2234:                        d_ex_interruption_invalide;
                   2235:                return;
                   2236:            }
                   2237: 
                   2238:            (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
                   2239:            l_element_courant = (*l_element_courant).suivant;
                   2240:        }
                   2241:    }
                   2242:    else
                   2243:    {
                   2244:        liberation(s_etat_processus, s_objet_argument);
                   2245: 
                   2246:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2247:        return;
                   2248:    }
                   2249: 
                   2250:    liberation(s_etat_processus, s_objet_argument);
                   2251: 
                   2252:    return;
                   2253: }
                   2254: 
                   2255: 
                   2256: /*
                   2257: ================================================================================
                   2258:   Fonction 'sched'
                   2259: ================================================================================
                   2260:   Entrées : structure processus
                   2261: --------------------------------------------------------------------------------
                   2262:   Sorties :
                   2263: --------------------------------------------------------------------------------
                   2264:   Effets de bord : néant
                   2265: ================================================================================
                   2266: */
                   2267: 
                   2268: void
                   2269: instruction_sched(struct_processus *s_etat_processus)
                   2270: {
                   2271:    real8                       pourcentage;
                   2272: 
                   2273:    struct_objet                *s_objet_argument;
                   2274: 
                   2275:    (*s_etat_processus).erreur_execution = d_ex;
                   2276: 
                   2277:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2278:    {
                   2279:        printf("\n  SCHED ");
                   2280: 
                   2281:        if ((*s_etat_processus).langue == 'F')
                   2282:        {
                   2283:            printf("(limitation des ressources de calcul)\n\n");
                   2284:        }
                   2285:        else
                   2286:        {
                   2287:            printf("(CPU ressources limitation)\n\n");
                   2288:        }
                   2289: 
                   2290:        printf("    1: %s, %s\n", d_INT, d_REL);
                   2291: 
                   2292:        return;
                   2293:    }
                   2294:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2295:    {
                   2296:        (*s_etat_processus).nombre_arguments = -1;
                   2297:        return;
                   2298:    }
                   2299: 
                   2300:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2301:    {
                   2302:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2303:        {
                   2304:            return;
                   2305:        }
                   2306:    }
                   2307: 
                   2308:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2309:            &s_objet_argument) == d_erreur)
                   2310:    {
                   2311:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2312:        return;
                   2313:    }
                   2314: 
                   2315:    if ((*s_objet_argument).type == INT)
                   2316:    {
                   2317:        pourcentage = (real8) (*((integer8 *) (*s_objet_argument).objet));
                   2318:    }
                   2319:    else if ((*s_objet_argument).type == REL)
                   2320:    {
                   2321:        pourcentage = (*((real8 *) (*s_objet_argument).objet));
                   2322:    }
                   2323:    else
                   2324:    {
                   2325:        liberation(s_etat_processus, s_objet_argument);
                   2326: 
                   2327:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2328:        return;
                   2329:    }
                   2330: 
                   2331:    liberation(s_etat_processus, s_objet_argument);
                   2332: 
                   2333:    if ((pourcentage <= 0) || (pourcentage > 100))
                   2334:    {
                   2335:        (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                   2336:        return;
                   2337:    }
                   2338: 
                   2339:    (*s_etat_processus).pourcentage_maximal_cpu = pourcentage;
                   2340: 
                   2341:    return;
                   2342: }
                   2343: 
                   2344: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>