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

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

CVSweb interface <joel.bertrand@systella.fr>