Annotation of rpl/src/sequenceur.c, revision 1.80

1.1       bertrand    1: /*
                      2: ================================================================================
1.80    ! bertrand    3:   RPL/2 (R) version 4.1.18
1.79      bertrand    4:   Copyright (C) 1989-2014 Dr. BERTRAND Joël
1.1       bertrand    5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
1.13      bertrand   22: 
1.20      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
1.60      bertrand   28:   Boucle principale de l'interprète RPL/2
1.1       bertrand   29: ================================================================================
1.60      bertrand   30:   Entrées : structure sur l'état du processus
1.1       bertrand   31: --------------------------------------------------------------------------------
1.60      bertrand   32:   Sorties : néant
1.1       bertrand   33: --------------------------------------------------------------------------------
1.60      bertrand   34:   Effets de bord : néant
1.1       bertrand   35: ================================================================================
                     36: */
                     37: 
                     38: logical1
                     39: sequenceur(struct_processus *s_etat_processus)
                     40: {
                     41:    struct_liste_chainee        *l_element_courant;
                     42: 
                     43:    struct_objet                *s_objet;
1.4       bertrand   44:    struct_objet                *s_objet_evaluation;
1.1       bertrand   45:    struct_objet                *s_sous_objet;
                     46: 
1.69      bertrand   47:    integer8                    niveau;
                     48:    integer8                    position_courante;
                     49: 
1.1       bertrand   50:    logical1                    drapeau_appel_definition;
                     51:    logical1                    drapeau_fin;
                     52:    logical1                    drapeau_then;
                     53:    logical1                    erreur;
1.56      bertrand   54:    logical1                    presence_compteur;
1.1       bertrand   55: 
                     56:    static logical1             completion_valide = d_faux;
                     57: 
                     58:    struct sigaction            action;
                     59:    struct sigaction            action_defaut;
                     60:    struct sigaction            action_defaut2;
                     61: 
                     62:    unsigned char               *instruction_majuscule;
                     63:    unsigned char               *ligne;
                     64:    unsigned char               *message;
                     65:    unsigned char               *registre;
                     66:    unsigned char               *tampon;
                     67:    unsigned char               *t_ligne;
                     68: 
1.49      bertrand   69:    Keymap                      ancien_keymap;
                     70:    Keymap                      nouveau_keymap;
                     71: 
1.1       bertrand   72:    (*s_etat_processus).retour_routine_evaluation = 'N';
                     73: 
                     74:    if ((*s_etat_processus).debug == d_vrai)
                     75:        if (((*s_etat_processus).type_debug &
                     76:                d_debug_appels_fonctions) != 0)
                     77:    {
                     78:        if ((*s_etat_processus).niveau_recursivite != 0)
                     79:        {
                     80:            if ((*s_etat_processus).langue == 'F')
                     81:            {
1.70      bertrand   82:                printf("[%d] Exécution récursive de niveau %lld\n",
1.1       bertrand   83:                        (int) getpid(), (*s_etat_processus).niveau_recursivite);
                     84:            }
                     85:            else
                     86:            {
1.70      bertrand   87:                printf("[%d] %lld level recursive execution\n",
1.1       bertrand   88:                        (int) getpid(), (*s_etat_processus).niveau_recursivite);
                     89:            }
                     90:        }
                     91:        else
                     92:        {
                     93:            if ((*s_etat_processus).langue == 'F')
                     94:            {
1.70      bertrand   95:                printf("[%d] Exécution\n", (int) getpid());
1.1       bertrand   96:            }
                     97:            else
                     98:            {
                     99:                printf("[%d] Execution\n", (int) getpid());
                    100:            }
                    101:        }
                    102: 
                    103:        fflush(stdout);
                    104:    }
                    105: 
                    106: /*
                    107: --------------------------------------------------------------------------------
1.60      bertrand  108:   Boucle de l'interprète RPL/2
1.1       bertrand  109:   On boucle tant qu'on n'a pas une bonne raison de sortir...
                    110: --------------------------------------------------------------------------------
                    111: */
                    112: 
                    113:    do
                    114:    {
                    115:        drapeau_appel_definition = d_faux;
                    116: 
                    117: /*
                    118: --------------------------------------------------------------------------------
1.60      bertrand  119:   Recherche de l'instruction suivante dans les définitions chaînées
1.1       bertrand  120: --------------------------------------------------------------------------------
                    121: */
                    122: 
                    123:        if ((erreur = recherche_instruction_suivante(s_etat_processus))
                    124:                == d_erreur)
                    125:        {
                    126:            return(d_erreur);
                    127:        }
                    128: 
                    129:        if (((*s_etat_processus).debug_programme == d_vrai) &&
                    130:                ((*s_etat_processus).niveau_recursivite == 0))
                    131:        {
                    132:            /*
                    133:             * Traitement de la commande HALT (debug)
                    134:             */
                    135: 
                    136:            action.sa_handler = SIG_IGN;
                    137:            action.sa_flags = SA_NODEFER | SA_ONSTACK;
                    138: 
                    139:            (*s_etat_processus).execution_pas_suivant = d_faux;
                    140:            (*s_etat_processus).traitement_instruction_halt = d_vrai;
                    141: 
                    142:            if (completion_valide == d_faux)
                    143:            {
                    144:                initialisation_completion();
                    145:                completion_valide = d_vrai;
                    146:            }
                    147: 
                    148:            while((*s_etat_processus).execution_pas_suivant == d_faux)
                    149:            {
                    150:                if ((*s_etat_processus).hauteur_pile_operationnelle != 0)
                    151:                {
                    152:                    fprintf(stdout, "\n");
                    153:                }
                    154: 
                    155:                affichage_pile(s_etat_processus, (*s_etat_processus)
                    156:                        .l_base_pile, 1);
                    157: 
                    158:                if ((*s_etat_processus).mode_interactif == 'N')
                    159:                {
                    160:                    printf("[%d] Instruction : %s\n", (int) getpid(),
                    161:                            (*s_etat_processus).instruction_courante);
                    162:                    fflush(stdout);
                    163:                }
                    164: 
                    165:                if (sigaction(SIGINT, &action, &action_defaut) != 0)
                    166:                {
                    167:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                    168:                    return(d_erreur);
                    169:                }
                    170: 
                    171:                if (sigaction(SIGTSTP, &action, &action_defaut2) != 0)
                    172:                {
                    173:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                    174:                    return(d_erreur);
                    175:                }
                    176: 
                    177:                (*s_etat_processus).var_volatile_requete_arret = 0;
                    178:                (*s_etat_processus).var_volatile_requete_arret2 = 0;
                    179: 
                    180:                flockfile(stdin);
                    181:                flockfile(stdout);
                    182: 
1.49      bertrand  183:                ancien_keymap = rl_get_keymap();
                    184:                nouveau_keymap = rl_copy_keymap(ancien_keymap);
                    185:                rl_set_keymap(nouveau_keymap);
                    186: 
1.50      bertrand  187:                rl_bind_key(NEWLINE, readline_analyse_syntaxique);
                    188:                rl_bind_key(RETURN, readline_analyse_syntaxique);
                    189:                rl_bind_key(CTRL('g'), readline_effacement);
1.49      bertrand  190:                rl_done = 0;
                    191: 
1.1       bertrand  192:                ligne = readline("RPL/2> ");
                    193: 
1.49      bertrand  194:                rl_set_keymap(ancien_keymap);
                    195:                rl_free(nouveau_keymap);
                    196: 
1.1       bertrand  197:                funlockfile(stdin);
                    198:                funlockfile(stdout);
                    199: 
                    200:                if ((*s_etat_processus).var_volatile_requete_arret != 0)
                    201:                {
                    202:                    (*s_etat_processus).requete_arret = 'Y';
                    203:                    break;
                    204:                }
                    205: 
                    206:                if (ligne != NULL)
                    207:                {
                    208:                    if ((t_ligne = transliteration(s_etat_processus, ligne,
                    209:                            (*s_etat_processus).localisation, d_locale))
                    210:                            == NULL)
                    211:                    {
1.27      bertrand  212:                        free((*s_etat_processus).instruction_courante);
1.1       bertrand  213:                        return(d_erreur);
                    214:                    }
                    215: 
                    216:                    free(ligne);
                    217:                    ligne = t_ligne;
                    218: 
                    219:                    if ((ligne = compactage(ligne)) == NULL)
                    220:                    {
                    221:                        (*s_etat_processus).erreur_systeme =
                    222:                                d_es_allocation_memoire;
                    223:                        return(d_erreur);
                    224:                    }
                    225:                }
                    226: 
                    227:                if (sigaction(SIGINT, &action_defaut, NULL) != 0)
                    228:                {
                    229:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                    230:                    return(d_erreur);
                    231:                }
                    232: 
                    233:                if (sigaction(SIGTSTP, &action_defaut2, NULL) != 0)
                    234:                {
                    235:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                    236:                    return(d_erreur);
                    237:                }
                    238: 
                    239:                if (ligne == NULL)
                    240:                {
                    241:                    if ((ligne = (unsigned char *) malloc(6 *
                    242:                            sizeof(unsigned char))) == NULL)
                    243:                    {
                    244:                        (*s_etat_processus).erreur_systeme =
                    245:                                d_es_allocation_memoire;
                    246:                        return(d_erreur);
                    247:                    }
                    248: 
                    249:                    sprintf(ligne, "abort");
                    250:                    fprintf(stdout, "%s\n", ligne);
                    251:                }
                    252:                else if (((*ligne) == d_code_fin_chaine) &&
                    253:                        ((*s_etat_processus).l_base_pile != NULL))
                    254:                {
                    255:                    free(ligne);
                    256: 
                    257:                    if ((ligne = (unsigned char *) malloc(4 *
                    258:                            sizeof(unsigned char))) == NULL)
                    259:                    {
                    260:                        (*s_etat_processus).erreur_systeme =
                    261:                                d_es_allocation_memoire;
                    262:                        return(d_erreur);
                    263:                    }
                    264: 
                    265:                    sprintf(ligne, "dup");
                    266:                }
                    267: 
                    268:                add_history(ligne);
                    269:                stifle_history(ds_longueur_historique);
                    270: 
                    271:                position_courante = (*s_etat_processus).position_courante;
                    272:                tampon = (*s_etat_processus).definitions_chainees;
                    273:                registre = (*s_etat_processus).instruction_courante;
                    274:                (*s_etat_processus).definitions_chainees = ligne;
                    275: 
                    276:                if (analyse_syntaxique(s_etat_processus) == d_absence_erreur)
                    277:                {
                    278:                    (*s_etat_processus).instruction_courante = registre;
                    279:                    (*s_etat_processus).position_courante = position_courante;
                    280:                    (*s_etat_processus).definitions_chainees = tampon;
                    281: 
                    282:                    if ((tampon = (unsigned char *) malloc((strlen(ligne) + 7) *
                    283:                            sizeof(unsigned char))) == NULL)
                    284:                    {
                    285:                        (*s_etat_processus).erreur_systeme =
                    286:                                d_es_allocation_memoire;
                    287:                        return(d_erreur);
                    288:                    }
                    289: 
                    290:                    sprintf(tampon, "<< %s >>", ligne);
                    291: 
                    292:                    free(ligne);
                    293:                    ligne = tampon;
                    294: 
                    295:                    tampon = (*s_etat_processus).instruction_courante;
                    296:                    (*s_etat_processus).instruction_courante = ligne;
1.6       bertrand  297: 
1.1       bertrand  298:                    recherche_type(s_etat_processus);
                    299: 
1.6       bertrand  300:                    (*s_etat_processus).instruction_courante = tampon;
                    301: 
1.1       bertrand  302:                    if ((((*s_etat_processus).erreur_execution != d_ex) ||
                    303:                            ((*s_etat_processus).erreur_systeme != d_es)) &&
                    304:                            ((*s_etat_processus).invalidation_message_erreur
                    305:                            == d_faux))
                    306:                    {
                    307:                        if ((*s_etat_processus).erreur_execution != d_ex)
                    308:                        {
                    309:                            (*s_etat_processus).erreur_scrutation = d_vrai;
                    310:                        }
                    311: 
                    312:                        if (test_cfsf(s_etat_processus, 51) == d_faux)
                    313:                        {
                    314:                            printf("%s", ds_beep);
                    315:                        }
                    316: 
                    317:                        if ((message = messages(s_etat_processus)) == NULL)
                    318:                        {
1.27      bertrand  319:                            free((*s_etat_processus).instruction_courante);
1.1       bertrand  320:                            return(d_erreur);
                    321:                        }
                    322: 
                    323:                        printf("%s [%d]\n", message, (int) getpid());
                    324: 
                    325:                        free(message);
                    326: 
                    327:                        (*s_etat_processus).erreur_execution = d_ex;
                    328: 
                    329:                        if ((*s_etat_processus).erreur_systeme != d_es)
                    330:                        {
                    331:                            return(d_erreur);
                    332:                        }
                    333:                    }
                    334:                    else
                    335:                    {
1.76      bertrand  336:                        position_courante =
                    337:                                (*s_etat_processus).position_courante;
1.74      bertrand  338:                        empilement_pile_systeme(s_etat_processus);
                    339: 
                    340:                        if ((*s_etat_processus).erreur_systeme != d_es)
                    341:                        {
                    342:                            return(d_erreur);
                    343:                        }
                    344: 
1.1       bertrand  345:                        (*(*s_etat_processus).l_base_pile_systeme)
                    346:                                .retour_definition = 'Y';
                    347: 
                    348:                        if (depilement(s_etat_processus, &((*s_etat_processus)
                    349:                            .l_base_pile), &s_objet) == d_erreur)
                    350:                        {
                    351:                            if (test_cfsf(s_etat_processus, 51) == d_faux)
                    352:                            {
                    353:                                printf("%s", ds_beep);
                    354:                            }
                    355: 
                    356:                            if ((*s_etat_processus).langue == 'F')
                    357:                            {
1.70      bertrand  358:                                printf("+++Erreur : Défaut d'argument\n");
1.1       bertrand  359:                            }
                    360:                            else
                    361:                            {
                    362:                                printf("+++Error : Too few arguments\n");
                    363:                            }
                    364: 
1.74      bertrand  365:                            depilement_pile_systeme(s_etat_processus);
                    366: 
                    367:                            if ((*s_etat_processus).erreur_systeme != d_es)
                    368:                            {
                    369:                                return(d_erreur);
                    370:                            }
1.1       bertrand  371: 
                    372:                            fflush(stdout);
                    373:                        }
                    374:                        else if (evaluation(s_etat_processus, s_objet, 'I') ==
                    375:                                d_erreur)
                    376:                        {
                    377:                            if ((*s_etat_processus).erreur_systeme != d_es)
                    378:                            {
                    379:                                if (test_cfsf(s_etat_processus, 51) == d_faux)
                    380:                                {
                    381:                                    printf("%s", ds_beep);
                    382:                                }
                    383: 
                    384:                                if ((message = messages(s_etat_processus))
                    385:                                        == NULL)
                    386:                                {
1.27      bertrand  387:                                    free((*s_etat_processus)
                    388:                                            .instruction_courante);
1.1       bertrand  389:                                    return(d_erreur);
                    390:                                }
                    391: 
                    392:                                printf("%s [%d]\n", message, (int) getpid());
1.27      bertrand  393: 
1.1       bertrand  394:                                free(message);
1.27      bertrand  395:                                free((*s_etat_processus).instruction_courante);
1.1       bertrand  396:                                return(d_erreur);
                    397:                            }
                    398:                            else if ((*s_etat_processus)
                    399:                                    .invalidation_message_erreur == d_faux)
                    400:                            {
                    401:                                (*s_etat_processus).erreur_execution =
                    402:                                        (*s_etat_processus)
                    403:                                        .derniere_erreur_evaluation;
                    404: 
                    405:                                if (test_cfsf(s_etat_processus, 51) == d_faux)
                    406:                                {
                    407:                                    printf("%s", ds_beep);
                    408:                                }
                    409: 
                    410:                                if ((message = messages(s_etat_processus))
                    411:                                        == NULL)
                    412:                                {
1.27      bertrand  413:                                    free((*s_etat_processus)
                    414:                                            .instruction_courante);
1.1       bertrand  415:                                    return(d_erreur);
                    416:                                }
                    417: 
                    418:                                printf("%s [%d]\n", message, (int) getpid());
                    419:                                free(message);
                    420: 
                    421:                                if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    422:                                {
                    423:                                    l_element_courant = (*s_etat_processus)
                    424:                                            .l_base_pile_last;
                    425: 
                    426:                                    while(l_element_courant != NULL)
                    427:                                    {
                    428:                                        if ((s_sous_objet = copie_objet(
                    429:                                                s_etat_processus,
                    430:                                                (*l_element_courant).donnee,
                    431:                                                'P')) == NULL)
                    432:                                        {
                    433:                                            (*s_etat_processus).erreur_systeme =
                    434:                                                    d_es_allocation_memoire;
                    435:                                            return(d_erreur);
                    436:                                        }
                    437: 
                    438:                                        if (empilement(s_etat_processus,
                    439:                                                &((*s_etat_processus)
                    440:                                                .l_base_pile),
                    441:                                                s_sous_objet) == d_erreur)
                    442:                                        {
                    443:                                            return(d_erreur);
                    444:                                        }
                    445: 
                    446:                                        l_element_courant = (*l_element_courant)
                    447:                                                .suivant;
                    448:                                    }
                    449:                                }
                    450: 
                    451:                                (*s_etat_processus).erreur_execution = d_ex;
                    452:                                (*s_etat_processus).exception = d_ep;
                    453:                            }
                    454: 
                    455:                            liberation(s_etat_processus, s_objet);
                    456:                        }
                    457:                        else
                    458:                        {   
                    459:                            liberation(s_etat_processus, s_objet);
                    460:                        }
1.76      bertrand  461: 
                    462:                        (*s_etat_processus).position_courante =
                    463:                                position_courante;
1.1       bertrand  464:                    }
                    465:                }
                    466:                else if ((*s_etat_processus).invalidation_message_erreur
                    467:                        == d_faux)
                    468:                {
                    469:                    (*s_etat_processus).instruction_courante = registre;
                    470:                    (*s_etat_processus).position_courante = position_courante;
                    471:                    (*s_etat_processus).definitions_chainees = tampon;
                    472: 
                    473:                    if (test_cfsf(s_etat_processus, 51) == d_faux)
                    474:                    {
                    475:                        printf("%s", ds_beep);
                    476:                    }
                    477: 
                    478:                    if ((message = messages(s_etat_processus)) == NULL)
                    479:                    {
1.27      bertrand  480:                        free((*s_etat_processus).instruction_courante);
1.1       bertrand  481:                        free(ligne);
                    482:                        return(d_erreur);
                    483:                    }
                    484: 
                    485:                    free(message);
                    486: 
                    487:                    if ((*s_etat_processus).langue == 'F')
                    488:                    {
                    489:                        printf("+++Erreur : Erreur de syntaxe\n");
                    490:                    }
                    491:                    else
                    492:                    {
                    493:                        printf("+++Error : Syntax error\n");
                    494:                    }
                    495: 
                    496:                    fflush(stdout);
                    497:                }
                    498: 
                    499:                free(ligne);
                    500:            }
                    501: 
                    502:            (*s_etat_processus).traitement_instruction_halt = d_faux;
                    503:        }
                    504: 
                    505:        if ((*s_etat_processus).debug == d_vrai)
                    506:            if (((*s_etat_processus).type_debug &
                    507:                    d_debug_fonctions_intrinseques) != 0)
                    508:        {
                    509:            if ((*s_etat_processus).langue == 'F')
                    510:            {
                    511:                printf("[%d] Instruction %s\n",
                    512:                        (int) getpid(),
                    513:                        (*s_etat_processus).instruction_courante);
                    514:            }
                    515:            else
                    516:            {
                    517:                printf("[%d] %s instruction\n",
                    518:                        (int) getpid(),
                    519:                        (*s_etat_processus).instruction_courante);
                    520:            }
                    521: 
                    522:            fflush(stdout);
                    523:        }
                    524: 
                    525: /*
                    526: --------------------------------------------------------------------------------
1.60      bertrand  527:   Dans le cas où une instruction est retournée, celle-ci est évaluée. Dans le
                    528:   cas contraire, l'interprète renvoie un message d'erreur et s'interrompt.
1.1       bertrand  529: --------------------------------------------------------------------------------
                    530: */
                    531: 
                    532:        if (erreur == d_absence_erreur)
                    533:        {
                    534: 
                    535: /*
                    536: --------------------------------------------------------------------------------
1.60      bertrand  537:   Scrutation des mots clef du langage RPL/2 et exécution le cas échéant
                    538:   de l'action associée.
1.1       bertrand  539: --------------------------------------------------------------------------------
                    540: */
                    541: 
                    542:            analyse(s_etat_processus, NULL);
                    543: 
                    544:            if ((*s_etat_processus).traitement_cycle_exit != 'N')
                    545:            {
                    546:                switch((*s_etat_processus).traitement_cycle_exit)
                    547:                {
                    548:                    case 'C' :
                    549:                    {
                    550:                        instruction_cycle(s_etat_processus);
                    551:                        break;
                    552:                    }
                    553: 
                    554:                    case 'E' :
                    555:                    {
                    556:                        instruction_exit(s_etat_processus);
                    557:                        break;
                    558:                    }
                    559:                }
                    560:            }
                    561: 
                    562:            if ((*s_etat_processus).instruction_valide == 'N')
                    563:            {
                    564:            
                    565: /*
                    566: --------------------------------------------------------------------------------
1.60      bertrand  567:   L'instruction ne correspond pas à l'un des mots clef du langage RPL/2.
1.1       bertrand  568: --------------------------------------------------------------------------------
                    569: */
                    570: 
                    571:                if ((recherche_variable(s_etat_processus,
                    572:                        (*s_etat_processus).instruction_courante) ==
                    573:                        d_vrai) && ((*s_etat_processus)
                    574:                        .autorisation_evaluation_nom == 'Y'))
                    575:                {
1.32      bertrand  576:                    if ((*(*s_etat_processus).pointeur_variable_courante)
                    577:                            .objet == NULL)
1.1       bertrand  578:                    {
                    579: 
                    580: /*
                    581: --------------------------------------------------------------------------------
1.60      bertrand  582:   L'instruction est une variable partagée
1.1       bertrand  583: --------------------------------------------------------------------------------
                    584: */
                    585: 
                    586:                        if ((*s_etat_processus).debug == d_vrai)
                    587:                            if (((*s_etat_processus).type_debug &
                    588:                                    d_debug_variables) != 0)
                    589:                        {
                    590:                            if ((*s_etat_processus).langue == 'F')
                    591:                            {
1.60      bertrand  592:                                printf("[%d] Évaluation de la variable "
                    593:                                        "partagée %s de type %d\n",
1.32      bertrand  594:                                        (int) getpid(), (*s_etat_processus)
1.1       bertrand  595:                                        .instruction_courante,
1.32      bertrand  596:                                        (*(*(*s_etat_processus)
                    597:                                        .pointeur_variable_courante).objet)
1.1       bertrand  598:                                        .type);
                    599:                            }
                    600:                            else
                    601:                            {
                    602:                                printf("[%d] Pushing %s as %d type shared "
1.70      bertrand  603:                                        "variable\n", (int) getpid(),
1.1       bertrand  604:                                        (*s_etat_processus)
                    605:                                        .instruction_courante,
1.32      bertrand  606:                                        (*(*(*s_etat_processus)
                    607:                                        .pointeur_variable_courante).objet)
1.1       bertrand  608:                                        .type);
                    609:                            }
                    610: 
                    611:                            fflush(stdout);
                    612:                        }
                    613: 
                    614:                        if (recherche_variable_partagee(s_etat_processus,
1.32      bertrand  615:                                (*(*s_etat_processus)
                    616:                                .pointeur_variable_courante).nom,
                    617:                                (*(*s_etat_processus)
                    618:                                .pointeur_variable_courante).variable_partagee,
1.62      bertrand  619:                                'P') != NULL)
1.1       bertrand  620:                        {
                    621:                            // La variable existe.
                    622: 
                    623:                            if ((s_objet = copie_objet(s_etat_processus,
                    624:                                    (*(*s_etat_processus)
1.61      bertrand  625:                                    .pointeur_variable_partagee_courante)
                    626:                                    .objet, 'P')) == NULL)
1.1       bertrand  627:                            {
                    628:                                (*s_etat_processus).erreur_systeme =
                    629:                                        d_es_allocation_memoire;
                    630:                                return(d_erreur);
                    631:                            }
                    632: 
                    633:                            if (pthread_mutex_unlock(&((*(*s_etat_processus)
1.61      bertrand  634:                                    .pointeur_variable_partagee_courante)
                    635:                                    .mutex)) != 0)
1.1       bertrand  636:                            {
                    637:                                (*s_etat_processus).erreur_systeme =
                    638:                                        d_es_processus;
                    639:                                return(d_erreur);
                    640:                            }
                    641: 
1.60      bertrand  642:                            if (evaluation(s_etat_processus, s_objet, 'E')
                    643:                                    == d_erreur)
1.1       bertrand  644:                            {
1.60      bertrand  645:                                liberation(s_etat_processus, s_objet);
1.1       bertrand  646:                                return(d_erreur);
                    647:                            }
1.60      bertrand  648: 
                    649:                            liberation(s_etat_processus, s_objet);
1.1       bertrand  650:                        }
                    651:                        else
                    652:                        {
                    653:                            // La variable n'existe plus.
                    654:                        }
                    655:                    }
                    656: 
                    657: /*
                    658: --------------------------------------------------------------------------------
1.60      bertrand  659:   L'instruction est une variable automatique (évaluation lors de l'empilement).
1.1       bertrand  660: --------------------------------------------------------------------------------
                    661: */
                    662: 
1.32      bertrand  663:                    else if ((*(*(*s_etat_processus).pointeur_variable_courante)
1.1       bertrand  664:                            .objet).type == ADR)
                    665:                    {
                    666: 
                    667: /*
                    668: --------------------------------------------------------------------------------
                    669:   L'instruction est une variable de type 'adresse' pointant sur une
1.60      bertrand  670:   définition. Un branchement est effectué à cette adresse.
1.1       bertrand  671: --------------------------------------------------------------------------------
                    672: */
                    673: 
                    674:                        if ((*s_etat_processus).debug == d_vrai)
                    675:                            if (((*s_etat_processus).type_debug &
                    676:                                    d_debug_appels_fonctions) != 0)
                    677:                        {
                    678:                            if ((*s_etat_processus).langue == 'F')
                    679:                            {
1.60      bertrand  680:                                printf("[%d] Branchement à la"
                    681:                                        " définition %s\n", (int) getpid(),
1.1       bertrand  682:                                        (*s_etat_processus)
                    683:                                        .instruction_courante);
                    684:                            }
                    685:                            else
                    686:                            {
                    687:                                printf("[%d] Execution : "
                    688:                                        "Branching at %s definition\n",
                    689:                                        (int) getpid(), (*s_etat_processus)
                    690:                                        .instruction_courante);
                    691:                            }
                    692: 
                    693:                            fflush(stdout);
                    694:                        }
                    695: 
                    696:                        (*s_etat_processus).autorisation_empilement_programme =
                    697:                                'N';
                    698: 
                    699:                        empilement_pile_systeme(s_etat_processus);
                    700: 
                    701:                        if ((*s_etat_processus).erreur_systeme != d_es)
                    702:                        {
                    703:                            erreur = d_erreur;
                    704:                        }
                    705:                        else
                    706:                        {
                    707:                            if ((*s_etat_processus).profilage == d_vrai)
                    708:                            {
                    709:                                profilage(s_etat_processus,
                    710:                                        (*s_etat_processus)
                    711:                                        .instruction_courante);
                    712: 
                    713:                                if ((*s_etat_processus).erreur_systeme != d_es)
                    714:                                {
                    715:                                    return(d_erreur);
                    716:                                }
                    717:                            }
                    718: 
                    719:                            (*(*s_etat_processus).l_base_pile_systeme)
                    720:                                    .adresse_retour = (*s_etat_processus)
                    721:                                    .position_courante;
                    722: 
                    723:                            (*(*s_etat_processus).l_base_pile_systeme)
                    724:                                    .retour_definition = 'Y';
                    725: 
                    726:                            (*(*s_etat_processus).l_base_pile_systeme)
                    727:                                    .niveau_courant = (*s_etat_processus)
                    728:                                    .niveau_courant;
                    729: 
                    730:                            (*s_etat_processus).position_courante =
1.69      bertrand  731:                                    (*((integer8 *)
1.32      bertrand  732:                                    ((*(*(*s_etat_processus)
                    733:                                    .pointeur_variable_courante)
                    734:                                    .objet).objet)));
1.1       bertrand  735: 
                    736:                            drapeau_appel_definition = d_vrai;
                    737:                        }
                    738:                    }
                    739:                    else
                    740:                    {
                    741:                        if ((*s_etat_processus).debug == d_vrai)
                    742:                            if (((*s_etat_processus).type_debug &
                    743:                                    d_debug_variables) != 0)
                    744:                        {
                    745:                            if ((*s_etat_processus).langue == 'F')
                    746:                            {
1.60      bertrand  747:                                printf("[%d] Évaluation de la variable "
1.1       bertrand  748:                                        "%s de type %d\n",
                    749:                                        (int) getpid(),
                    750:                                        (*s_etat_processus)
                    751:                                        .instruction_courante,
1.32      bertrand  752:                                        (*(*(*s_etat_processus)
                    753:                                        .pointeur_variable_courante).objet)
1.1       bertrand  754:                                        .type);
                    755:                            }
                    756:                            else
                    757:                            {
                    758:                                printf("[%d] Pushing %s as %d type variable "
                    759:                                        "\n", (int) getpid(),
                    760:                                        (*s_etat_processus)
                    761:                                        .instruction_courante,
1.32      bertrand  762:                                        (*(*(*s_etat_processus)
                    763:                                        .pointeur_variable_courante).objet)
1.1       bertrand  764:                                        .type);
                    765:                            }
                    766: 
                    767:                            fflush(stdout);
                    768:                        }
                    769: 
                    770:                        if ((s_objet = copie_objet(s_etat_processus,
1.32      bertrand  771:                                (*(*s_etat_processus)
                    772:                                .pointeur_variable_courante).objet, 'P'))
1.1       bertrand  773:                                == NULL)
                    774:                        {
                    775:                            (*s_etat_processus).erreur_systeme =
                    776:                                    d_es_allocation_memoire;
                    777:                            return(d_erreur);
                    778:                        }
                    779: 
1.60      bertrand  780:                        if (evaluation(s_etat_processus, s_objet, 'E')
                    781:                                == d_erreur)
1.1       bertrand  782:                        {
1.60      bertrand  783:                            liberation(s_etat_processus, s_objet);
1.1       bertrand  784:                            return(d_erreur);
                    785:                        }
1.60      bertrand  786: 
                    787:                        liberation(s_etat_processus, s_objet);
1.1       bertrand  788:                    }
                    789:                }
                    790:                else
                    791:                {
                    792: 
                    793: /*
                    794: --------------------------------------------------------------------------------
1.60      bertrand  795:   L'instruction est une donnée à empiler.
1.1       bertrand  796: --------------------------------------------------------------------------------
                    797: */
                    798: 
                    799:                    (*s_etat_processus).erreur_systeme = d_es;
                    800:                    recherche_type(s_etat_processus);
1.4       bertrand  801: 
1.9       bertrand  802:                    if ((*s_etat_processus).autorisation_nom_implicite == 'N')
                    803:                    {
                    804:                        if ((*s_etat_processus).l_base_pile == NULL)
                    805:                        {
1.37      bertrand  806:                            if ((*s_etat_processus).erreur_execution !=
                    807:                                    d_ex_nom_implicite)
                    808:                            {
                    809:                                (*s_etat_processus).erreur_execution =
                    810:                                        d_ex_manque_argument;
                    811:                            }
1.9       bertrand  812:                        }
1.12      bertrand  813:                        else if ((*(*(*s_etat_processus).l_base_pile).donnee)
                    814:                                .type == NOM)
1.9       bertrand  815:                        {
                    816:                            if ((*((struct_nom *) (*(*(*s_etat_processus)
                    817:                                    .l_base_pile).donnee).objet)).symbole
                    818:                                    == d_faux)
                    819:                            {
1.12      bertrand  820:                                (*s_etat_processus).erreur_execution =
                    821:                                        d_ex_nom_implicite;
                    822: 
1.60      bertrand  823:                                // Si le niveau de récursivité est non nul, on
1.12      bertrand  824:                                // arrive ici depuis la fonction
1.60      bertrand  825:                                // recherche_type(). On retourne à cette
                    826:                                // dernière en indiquant une erreur.
1.12      bertrand  827: 
                    828:                                if ((*s_etat_processus).niveau_recursivite != 0)
1.11      bertrand  829:                                {
1.12      bertrand  830:                                    free((*s_etat_processus)
                    831:                                            .instruction_courante);
1.11      bertrand  832:                                    return(d_erreur);
                    833:                                }
1.9       bertrand  834:                            }
                    835:                        }
                    836:                    }
                    837: 
1.60      bertrand  838:                    // Le séquenceur est appelé depuis la routine d'évaluation
1.4       bertrand  839: 
                    840:                    if ((*s_etat_processus).evaluation_forcee == 'Y')
                    841:                    {
                    842:                        if (depilement(s_etat_processus,
                    843:                                &((*s_etat_processus).l_base_pile),
                    844:                                &s_objet_evaluation) == d_erreur)
                    845:                        {
1.27      bertrand  846:                            free((*s_etat_processus).instruction_courante);
1.4       bertrand  847:                            (*s_etat_processus).erreur_execution =
                    848:                                    d_ex_manque_argument;
                    849:                            return(d_erreur);
                    850:                        }
                    851: 
                    852:                        if (evaluation(s_etat_processus, s_objet_evaluation,
                    853:                                'N') == d_erreur)
                    854:                        {
1.27      bertrand  855:                            free((*s_etat_processus).instruction_courante);
1.4       bertrand  856:                            liberation(s_etat_processus, s_objet_evaluation);
                    857:                            return(d_erreur);
                    858:                        }
                    859: 
                    860:                        liberation(s_etat_processus, s_objet_evaluation);
                    861:                    }
1.27      bertrand  862: 
1.60      bertrand  863:                    // Le séquenceur est appelé depuis la routine de
1.27      bertrand  864:                    // recherche de type
                    865: 
                    866:                    else if ((*s_etat_processus).recherche_type == 'Y')
                    867:                    {
                    868:                        if ((*s_etat_processus).erreur_execution != d_ex)
                    869:                        {
                    870:                            free((*s_etat_processus).instruction_courante);
                    871:                            return(d_erreur);
                    872:                        }
                    873:                    }
1.1       bertrand  874:                }
                    875:            }
                    876:            else if (((*s_etat_processus).test_instruction == 'Y') &&
                    877:                    ((*s_etat_processus).instruction_valide == 'Y'))
                    878:            {
                    879: 
                    880: /*
                    881: --------------------------------------------------------------------------------
                    882:   Permet de traiter les fonctions dans les objets de type liste
                    883: --------------------------------------------------------------------------------
                    884: */
                    885: 
                    886:                if ((instruction_majuscule = conversion_majuscule(
                    887:                        (*s_etat_processus).instruction_courante)) == NULL)
                    888:                {
                    889:                    (*s_etat_processus).erreur_systeme =
                    890:                            d_es_allocation_memoire;
                    891:                    return(d_erreur);
                    892:                }
                    893: 
                    894:                if ((strcmp((*s_etat_processus).instruction_courante, "<<")
                    895:                        != 0) && (strcmp((*s_etat_processus)
                    896:                        .instruction_courante, ">>") != 0))
                    897:                {
1.12      bertrand  898:                    if ((s_objet = allocation(s_etat_processus, FCT)) == NULL)
1.1       bertrand  899:                    {
                    900:                        (*s_etat_processus).erreur_systeme =
                    901:                                d_es_allocation_memoire;
                    902:                        return(d_erreur);
                    903:                    }
                    904: 
                    905:                    (*((struct_fonction *) (*s_objet).objet))
                    906:                            .nombre_arguments = 0;
                    907: 
                    908:                    if ((*s_etat_processus).instruction_intrinseque == 'Y')
                    909:                    {
                    910:                        if (((*((struct_fonction *) (*s_objet).objet))
                    911:                                .nom_fonction = conversion_majuscule(
                    912:                                (*s_etat_processus).instruction_courante))
                    913:                                == NULL)
                    914:                        {
                    915:                            (*s_etat_processus).erreur_systeme =
                    916:                                    d_es_allocation_memoire;
                    917:                            return(d_erreur);
                    918:                        }
                    919:                    }
                    920:                    else
                    921:                    {
                    922:                        if (((*((struct_fonction *) (*s_objet).objet))
                    923:                                .nom_fonction = (unsigned char *) malloc(
                    924:                                (strlen((*s_etat_processus)
                    925:                                .instruction_courante)
                    926:                                + 1) * sizeof(unsigned char))) == NULL)
                    927:                        {
                    928:                            (*s_etat_processus).erreur_systeme =
                    929:                                    d_es_allocation_memoire;
                    930:                            return(d_erreur);
                    931:                        }
                    932: 
                    933:                        strcpy((*((struct_fonction *) (*s_objet).objet))
                    934:                                .nom_fonction, (*s_etat_processus)
                    935:                                .instruction_courante);
                    936:                    }
                    937: 
                    938:                    (*((struct_fonction *) (*s_objet).objet)).fonction =
                    939:                            analyse_instruction(s_etat_processus,
                    940:                            (*s_etat_processus).instruction_courante);
                    941: 
                    942:                    if (empilement(s_etat_processus,
                    943:                            &((*s_etat_processus).l_base_pile), s_objet) ==
                    944:                            d_erreur)
                    945:                    {
                    946:                        (*s_etat_processus).erreur_systeme =
                    947:                                d_es_allocation_memoire;
                    948:                        return(d_erreur);
                    949:                    }
                    950:                }
                    951:                else
                    952:                {
                    953:                    (*s_etat_processus).test_instruction = 'N';
                    954:                    analyse(s_etat_processus, NULL);
                    955:                    (*s_etat_processus).test_instruction = 'Y';
                    956:                }
                    957: 
                    958:                free(instruction_majuscule);
                    959:            }
                    960: 
1.69      bertrand  961:            erreur = (logical1) (erreur | (((*s_etat_processus)
                    962:                    .erreur_execution != d_ex) ? d_erreur : d_absence_erreur));
1.1       bertrand  963:        }
                    964:        else
                    965:        {
                    966:            printf("\n");
                    967: 
                    968:            if ((*s_etat_processus).langue == 'F')
                    969:            {
                    970:                printf("+++Erreur : Argument %s invalide\n",
                    971:                        (*s_etat_processus).instruction_courante);
                    972:            }
                    973:            else
                    974:            {
                    975:                printf("+++Error : Invalid %s argument\n",
                    976:                        (*s_etat_processus).instruction_courante);
                    977:            }
                    978: 
                    979:            fflush(stdout);
                    980: 
1.27      bertrand  981:            free((*s_etat_processus).instruction_courante);
1.1       bertrand  982:            return(d_erreur);
                    983:        }
                    984: 
                    985: /*
                    986: --------------------------------------------------------------------------------
1.60      bertrand  987:   Traitement des arrêts simples
1.1       bertrand  988: --------------------------------------------------------------------------------
                    989: */
                    990: 
                    991:        if ((*s_etat_processus).var_volatile_requete_arret2 != 0)
                    992:        {
                    993:            if ((*s_etat_processus).debug_programme == d_vrai)
                    994:            {
                    995:                (*s_etat_processus).var_volatile_requete_arret2 = 0;
                    996:            }
                    997:            else
                    998:            {
                    999:                if ((*s_etat_processus).var_volatile_requete_arret2 == -1)
                   1000:                {
                   1001:                    if (strncmp(getenv("LANG"), "fr", 2) == 0)
                   1002:                    {
1.70      bertrand 1003:                        printf("[%d] Arrêt\n", (int) getpid());
1.1       bertrand 1004:                    }
                   1005:                    else
                   1006:                    {
                   1007:                        printf("[%d] Break\n", (int) getpid());
                   1008:                    }
                   1009: 
                   1010:                    (*s_etat_processus).var_volatile_requete_arret2 = 1;
                   1011: 
                   1012:                    fflush(stdout);
                   1013:                }
                   1014: 
                   1015:                if ((*s_etat_processus).niveau_recursivite == 0)
                   1016:                {
                   1017:                    (*s_etat_processus).debug_programme = d_vrai;
                   1018:                    (*s_etat_processus).var_volatile_requete_arret2 = 0;
                   1019:                }
                   1020:            }
                   1021:        }
                   1022: 
                   1023:        /*
                   1024:         * On ne sort pas du debugger en cas d'une erreur sur un programme
1.60      bertrand 1025:         * en cours de débogage.
1.1       bertrand 1026:         */
                   1027: 
                   1028:        if ((((*s_etat_processus).erreur_execution != d_ex) ||
                   1029:                ((*s_etat_processus).exception != d_ep)) &&
                   1030:                ((*s_etat_processus).debug_programme == d_vrai))
                   1031:        {
                   1032:            if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1033:            {
                   1034:                l_element_courant = (*s_etat_processus).l_base_pile_last;
                   1035: 
                   1036:                while(l_element_courant != NULL)
                   1037:                {
                   1038:                    if ((s_objet = copie_objet(s_etat_processus,
                   1039:                            (*l_element_courant).donnee, 'P')) == NULL)
                   1040:                    {
                   1041:                        (*s_etat_processus).erreur_systeme =
                   1042:                                d_es_allocation_memoire;
                   1043:                        return(d_erreur);
                   1044:                    }
                   1045: 
                   1046:                    if (empilement(s_etat_processus, &((*s_etat_processus)
                   1047:                            .l_base_pile), s_objet) == d_erreur)
                   1048:                    {
                   1049:                        return(d_erreur);
                   1050:                    }
                   1051: 
                   1052:                    l_element_courant = (*l_element_courant).suivant;
                   1053:                }
                   1054:            }
                   1055: 
                   1056:            if (test_cfsf(s_etat_processus, 51) == d_faux)
                   1057:            {
                   1058:                printf("%s", ds_beep);
                   1059:            }
                   1060: 
                   1061:            if ((message = messages(s_etat_processus)) == NULL)
                   1062:            {
1.27      bertrand 1063:                free((*s_etat_processus).instruction_courante);
1.1       bertrand 1064:                return(d_erreur);
                   1065:            }
                   1066: 
                   1067:            printf("%s [%d]\n", message, (int) getpid());
                   1068: 
                   1069:            free(message);
                   1070: 
                   1071:            (*s_etat_processus).erreur_execution = d_ex;
                   1072:            (*s_etat_processus).exception = d_ep;
                   1073:            erreur = d_absence_erreur;
                   1074: 
1.69      bertrand 1075:            (*s_etat_processus).position_courante -= (integer8)
1.1       bertrand 1076:                    strlen((*s_etat_processus).instruction_courante);
                   1077:        }
                   1078: 
                   1079: /*
                   1080: --------------------------------------------------------------------------------
1.60      bertrand 1081:   Test de fin d'exécution du programme RPL/2
1.1       bertrand 1082: --------------------------------------------------------------------------------
                   1083: */
                   1084: 
                   1085:        if (((*s_etat_processus).niveau_courant == 0) &&
                   1086:                (drapeau_appel_definition != d_vrai))
                   1087:        {
                   1088:            drapeau_fin = d_vrai;
                   1089:        }
                   1090:        else if ((*s_etat_processus).requete_arret == 'Y')
                   1091:        {
                   1092:            drapeau_fin = d_vrai;
                   1093:        }
                   1094:        else if (((*s_etat_processus).var_volatile_requete_arret != 0)
                   1095:                && ((*s_etat_processus).debug_programme == d_faux))
                   1096:        {
                   1097:            drapeau_fin = d_vrai;
                   1098: 
                   1099:            if ((*s_etat_processus).erreur_systeme == d_es)
                   1100:            {
                   1101:                erreur = d_absence_erreur;
                   1102:            }
                   1103:        }
                   1104:        else if ((*s_etat_processus).arret_si_exception == d_vrai)
                   1105:        {
                   1106:            drapeau_fin = d_faux;
                   1107: 
                   1108:            if ((*s_etat_processus).exception != d_ep)
                   1109:            {
                   1110:                erreur = d_erreur;
                   1111:            }
                   1112:            else if ((*s_etat_processus).erreur_systeme != d_es)
                   1113:            {
                   1114:                erreur = d_erreur;
                   1115:            }
                   1116:        }
                   1117:        else if ((*s_etat_processus).arret_si_exception == d_faux)
                   1118:        {
                   1119:            if ((message = messages(s_etat_processus)) == NULL)
                   1120:            {
                   1121:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1122:                return(d_erreur);
                   1123:            }
                   1124: 
                   1125:            free(message);
                   1126: 
                   1127:            drapeau_fin = d_faux;
                   1128: 
                   1129: /*
                   1130: --------------------------------------------------------------------------------
                   1131:   Traitement des exceptions
                   1132: --------------------------------------------------------------------------------
                   1133: */
                   1134: 
                   1135:            if ((*s_etat_processus).erreur_systeme != d_es)
                   1136:            {
                   1137:                erreur = d_erreur;
                   1138:            }
                   1139:            else if (((*s_etat_processus).exception != d_ep) ||
                   1140:                    ((*s_etat_processus).erreur_execution != d_ex))
                   1141:            {
                   1142:                tampon = (*s_etat_processus).instruction_courante;
                   1143: 
                   1144:                while((*(*s_etat_processus).l_base_pile_systeme).clause != 'R')
                   1145:                {
                   1146:                    erreur = recherche_instruction_suivante(s_etat_processus);
                   1147: 
                   1148:                    if (erreur == d_erreur)
                   1149:                    {
1.27      bertrand 1150:                        free((*s_etat_processus).instruction_courante);
1.1       bertrand 1151:                        return(d_erreur);
                   1152:                    }
                   1153: 
                   1154:                    if (recherche_variable(s_etat_processus,
                   1155:                            (*s_etat_processus).instruction_courante) == d_vrai)
                   1156:                    {
1.32      bertrand 1157:                        if ((*(*s_etat_processus).pointeur_variable_courante)
                   1158:                                .objet == NULL)
1.1       bertrand 1159:                        {
1.60      bertrand 1160:                            // Variable partagée
1.1       bertrand 1161:                        }
1.32      bertrand 1162:                        else if ((*(*(*s_etat_processus)
                   1163:                                .pointeur_variable_courante).objet).type == ADR)
1.1       bertrand 1164:                        {
                   1165:                            empilement_pile_systeme(s_etat_processus);
                   1166: 
                   1167:                            if ((*s_etat_processus).erreur_systeme != d_es)
                   1168:                            {
1.27      bertrand 1169:                                free((*s_etat_processus).instruction_courante);
1.1       bertrand 1170:                                return(d_erreur);
                   1171:                            }
                   1172: 
                   1173:                            (*(*s_etat_processus).l_base_pile_systeme)
                   1174:                                    .adresse_retour = (*s_etat_processus)
                   1175:                                    .position_courante;
                   1176: 
                   1177:                            (*(*s_etat_processus).l_base_pile_systeme)
                   1178:                                    .retour_definition = 'Y';
                   1179: 
                   1180:                            (*(*s_etat_processus).l_base_pile_systeme)
                   1181:                                    .niveau_courant = (*s_etat_processus)
                   1182:                                    .niveau_courant;
                   1183: 
                   1184:                            (*s_etat_processus).position_courante =
1.69      bertrand 1185:                                    (*((integer8 *)
1.32      bertrand 1186:                                    ((*(*(*s_etat_processus)
                   1187:                                    .pointeur_variable_courante)
                   1188:                                    .objet).objet)));
1.1       bertrand 1189: 
                   1190:                            (*s_etat_processus)
                   1191:                                    .autorisation_empilement_programme = 'N';
                   1192:                        }
                   1193:                    }
                   1194:                    else
                   1195:                    {
                   1196:                        (*s_etat_processus).erreur_systeme = d_es;
                   1197:                        instruction_majuscule = conversion_majuscule(
                   1198:                                (*s_etat_processus).instruction_courante);
                   1199: 
                   1200:                        if (instruction_majuscule == NULL)
                   1201:                        {
1.27      bertrand 1202:                            free((*s_etat_processus).instruction_courante);
1.1       bertrand 1203:                            return(d_erreur);
                   1204:                        }
                   1205: 
                   1206:                        /*
1.60      bertrand 1207:                         * Traitement de la pile système par les
                   1208:                         * différentes instructions.
1.1       bertrand 1209:                         */
                   1210: 
                   1211:                        if ((strcmp(instruction_majuscule, "IF") == 0) ||
                   1212:                                (strcmp(instruction_majuscule, "IFERR") == 0) ||
                   1213:                                (strcmp(instruction_majuscule, "DO") == 0) ||
                   1214:                                (strcmp(instruction_majuscule, "WHILE") == 0) ||
                   1215:                                (strcmp(instruction_majuscule, "FOR") == 0) ||
1.56      bertrand 1216:                                (strcmp(instruction_majuscule, "FORALL") == 0)
                   1217:                                ||
1.1       bertrand 1218:                                (strcmp(instruction_majuscule, "START") == 0) ||
                   1219:                                (strcmp(instruction_majuscule, "SELECT") == 0)
1.55      bertrand 1220:                                ||
                   1221:                                (strcmp(instruction_majuscule, "CRITICAL") == 0)
1.1       bertrand 1222:                                || (strcmp(instruction_majuscule, "CASE") == 0)
                   1223:                                || (strcmp(instruction_majuscule, "<<") == 0))
                   1224:                        {
                   1225:                            if (strcmp(instruction_majuscule, "<<") == 0)
                   1226:                            {
                   1227:                                analyse(s_etat_processus, NULL);
                   1228:                            }
1.56      bertrand 1229:                            else if ((strcmp(instruction_majuscule, "FOR") == 0)
1.57      bertrand 1230:                                    || (strcmp(instruction_majuscule, "FORALL")
                   1231:                                    == 0) || (strcmp(instruction_majuscule,
                   1232:                                    "START") == 0))
1.56      bertrand 1233:                            {
                   1234:                                empilement_pile_systeme(s_etat_processus);
                   1235: 
                   1236:                                if ((*s_etat_processus).erreur_systeme != d_es)
                   1237:                                {
                   1238:                                    return(d_erreur);
                   1239:                                }
                   1240: 
                   1241:                                (*(*s_etat_processus).l_base_pile_systeme)
                   1242:                                        .type_cloture = 'L';
                   1243:                            }
1.1       bertrand 1244:                            else
                   1245:                            {
                   1246:                                empilement_pile_systeme(s_etat_processus);
                   1247: 
                   1248:                                if ((*s_etat_processus).erreur_systeme != d_es)
                   1249:                                {
                   1250:                                    return(d_erreur);
                   1251:                                }
                   1252:                            }
                   1253:                        }
                   1254:                        else if ((strcmp(instruction_majuscule, "END") == 0) ||
                   1255:                                (strcmp(instruction_majuscule, "NEXT") == 0) ||
                   1256:                                (strcmp(instruction_majuscule, "STEP") == 0) ||
                   1257:                                (strcmp(instruction_majuscule, ">>") == 0))
                   1258:                        {
                   1259:                            if (strcmp(instruction_majuscule, ">>") == 0)
                   1260:                            {
                   1261:                                analyse(s_etat_processus, NULL);
                   1262: 
                   1263:                                if ((*(*s_etat_processus).l_base_pile_systeme)
                   1264:                                        .origine_routine_evaluation == 'Y')
                   1265:                                {
                   1266:                                    free(instruction_majuscule);
                   1267:                                    free((*s_etat_processus)
                   1268:                                            .instruction_courante);
                   1269: 
                   1270:                                    (*s_etat_processus).instruction_courante =
                   1271:                                            tampon;
                   1272: 
                   1273:                                    return(d_absence_erreur);
                   1274:                                }
                   1275:                            }
1.56      bertrand 1276:                            else if (((strcmp(instruction_majuscule, "NEXT")
                   1277:                                    == 0) || (strcmp(instruction_majuscule,
                   1278:                                    "STEP") == 0)) && ((*(*s_etat_processus)
                   1279:                                    .l_base_pile_systeme).type_cloture != 'L'))
                   1280:                            {
                   1281:                                /*
1.60      bertrand 1282:                                 * Libération des compteurs de boucle.
1.56      bertrand 1283:                                 */
                   1284: 
1.57      bertrand 1285:                                presence_compteur = (((*(*s_etat_processus)
                   1286:                                        .l_base_pile_systeme).type_cloture
                   1287:                                        == 'F') || ((*(*s_etat_processus)
1.56      bertrand 1288:                                        .l_base_pile_systeme).type_cloture
1.57      bertrand 1289:                                        == 'A')) ? d_vrai : d_faux;
1.56      bertrand 1290: 
                   1291:                                if (((*(*s_etat_processus).l_base_pile_systeme)
                   1292:                                        .type_cloture != 'S') &&
                   1293:                                        (presence_compteur == d_faux))
                   1294:                                {
                   1295:                                    return(d_erreur);
                   1296:                                }
                   1297: 
                   1298:                                if (presence_compteur == d_vrai)
                   1299:                                {
                   1300:                                    if (recherche_variable(s_etat_processus,
                   1301:                                            (*(*s_etat_processus)
                   1302:                                            .l_base_pile_systeme).nom_variable)
                   1303:                                            == d_faux)
                   1304:                                    {
                   1305:                                        return(d_erreur);
                   1306:                                    }
                   1307: 
                   1308:                                    if ((*(*s_etat_processus)
                   1309:                                            .pointeur_variable_courante).objet
                   1310:                                            == NULL)
                   1311:                                    {
                   1312:                                        return(d_erreur);
                   1313:                                    }
                   1314: 
                   1315:                                    (*s_etat_processus).niveau_courant--;
                   1316: 
1.59      bertrand 1317:                                    if (retrait_variables_par_niveau(
1.56      bertrand 1318:                                            s_etat_processus) == d_erreur)
                   1319:                                    {
                   1320:                                        return(d_erreur);
                   1321:                                    }
                   1322:                                }
                   1323: 
                   1324:                                depilement_pile_systeme(s_etat_processus);
                   1325: 
                   1326:                                if ((*s_etat_processus).erreur_systeme != d_es)
                   1327:                                {
                   1328:                                    return(d_erreur);
                   1329:                                }
                   1330:                            }
1.1       bertrand 1331:                            else
                   1332:                            {
1.60      bertrand 1333:                                // Traitement spécifique pour la fin
1.55      bertrand 1334:                                // d'une section critique
                   1335: 
                   1336:                                if ((*s_etat_processus).l_base_pile_systeme
                   1337:                                        == NULL)
                   1338:                                {
                   1339:                                    (*s_etat_processus).erreur_systeme =
                   1340:                                            d_es_processus;
                   1341:                                    return(d_erreur);
                   1342:                                }
                   1343: 
                   1344:                                if ((*(*s_etat_processus).l_base_pile_systeme)
                   1345:                                        .type_cloture == 'Q')
                   1346:                                {
                   1347:                                    if (pthread_mutex_unlock(
                   1348:                                            &mutex_sections_critiques) != 0)
                   1349:                                    {
                   1350:                                        (*s_etat_processus).erreur_systeme =
                   1351:                                                d_es_processus;
                   1352:                                        return(d_erreur);
                   1353:                                    }
                   1354: 
                   1355:                                    (*s_etat_processus).sections_critiques--;
                   1356:                                }
                   1357: 
1.1       bertrand 1358:                                depilement_pile_systeme(s_etat_processus);
                   1359: 
                   1360:                                if ((*s_etat_processus).erreur_systeme != d_es)
                   1361:                                {
                   1362:                                    return(d_erreur);
                   1363:                                }
                   1364:                            }
                   1365:                        }
                   1366: 
                   1367:                        free(instruction_majuscule);
                   1368:                    }
                   1369: 
                   1370:                    free((*s_etat_processus).instruction_courante);
                   1371:                }
                   1372: 
                   1373:                drapeau_then = d_faux;
                   1374:                niveau = 0;
                   1375: 
                   1376:                do
                   1377:                {
                   1378:                    erreur = recherche_instruction_suivante(s_etat_processus);
                   1379: 
                   1380:                    if (erreur == d_erreur)
                   1381:                    {
                   1382:                        return(d_erreur);
                   1383:                    }
                   1384:                    
                   1385:                    instruction_majuscule = conversion_majuscule(
                   1386:                            (*s_etat_processus).instruction_courante);
                   1387: 
                   1388:                    if (instruction_majuscule == NULL)
                   1389:                    {
                   1390:                        return(d_erreur);
                   1391:                    }
                   1392: 
                   1393:                    if ((strcmp(instruction_majuscule, "IF") == 0) ||
                   1394:                            (strcmp(instruction_majuscule, "IFERR") == 0) ||
                   1395:                            (strcmp(instruction_majuscule, "DO") == 0) ||
                   1396:                            (strcmp(instruction_majuscule, "WHILE") == 0) ||
                   1397:                            (strcmp(instruction_majuscule, "FOR") == 0) ||
1.56      bertrand 1398:                            (strcmp(instruction_majuscule, "FORALL") == 0) ||
1.1       bertrand 1399:                            (strcmp(instruction_majuscule, "START") == 0) ||
                   1400:                            (strcmp(instruction_majuscule, "SELECT") == 0)
1.55      bertrand 1401:                            || (strcmp(instruction_majuscule, "CRITICAL") == 0)
1.1       bertrand 1402:                            || (strcmp(instruction_majuscule, "CASE") == 0)
                   1403:                            || (strcmp(instruction_majuscule, "<<") == 0))
                   1404:                    {
                   1405:                        niveau++;
                   1406:                    }
                   1407:                    else if ((strcmp(instruction_majuscule, "END") == 0) ||
                   1408:                            (strcmp(instruction_majuscule, "NEXT") == 0) ||
                   1409:                            (strcmp(instruction_majuscule, "STEP") == 0) ||
                   1410:                            (strcmp(instruction_majuscule, ">>") == 0))
                   1411:                    {
                   1412:                        niveau--;
                   1413:                    }
                   1414: 
                   1415:                    drapeau_then = ((strcmp(instruction_majuscule, "THEN") == 0)
                   1416:                            && (niveau == 0)) ? d_vrai : d_faux;
                   1417: 
                   1418:                    free(instruction_majuscule);
                   1419:                    free((*s_etat_processus).instruction_courante);
                   1420:                } while(drapeau_then == d_faux);
                   1421: 
                   1422:                (*s_etat_processus).position_courante -= 5;
                   1423:                (*s_etat_processus).instruction_courante = tampon;
                   1424:                (*(*s_etat_processus).l_base_pile_systeme).clause = 'X';
                   1425: 
                   1426:                erreur = d_absence_erreur;
                   1427:                (*s_etat_processus).exception = d_ep;
                   1428:                (*s_etat_processus).erreur_execution = d_ex;
                   1429:            }
                   1430:        }
                   1431:        else
                   1432:        {
                   1433:            drapeau_fin = d_faux;
                   1434:        }
                   1435: 
                   1436:        if (erreur == d_absence_erreur)
                   1437:        {
                   1438:            free((*s_etat_processus).instruction_courante);
                   1439:        }
                   1440:    } while((erreur == d_absence_erreur) &&
                   1441:            ((*s_etat_processus).position_courante <
                   1442:            (*s_etat_processus).longueur_definitions_chainees) &&
                   1443:            (drapeau_fin == d_faux) &&
                   1444:            ((*s_etat_processus).retour_routine_evaluation == 'N'));
                   1445: 
                   1446: /*
                   1447: --------------------------------------------------------------------------------
1.60      bertrand 1448:   Messages d'erreur à afficher le cas échéant
1.1       bertrand 1449: --------------------------------------------------------------------------------
                   1450: */
                   1451: 
                   1452:    if ((erreur != d_absence_erreur) && ((*s_etat_processus)
                   1453:            .invalidation_message_erreur == d_faux))
                   1454:    {
                   1455:        if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1456:        {
                   1457:            l_element_courant = (*s_etat_processus).l_base_pile_last;
                   1458: 
                   1459:            while(l_element_courant != NULL)
                   1460:            {
                   1461:                if ((s_objet = copie_objet(s_etat_processus,
                   1462:                        (*l_element_courant).donnee, 'P')) == NULL)
                   1463:                {
                   1464:                    (*s_etat_processus).erreur_systeme =
                   1465:                            d_es_allocation_memoire;
                   1466:                    return(d_erreur);
                   1467:                }
                   1468: 
                   1469:                if (empilement(s_etat_processus, &((*s_etat_processus)
                   1470:                        .l_base_pile), s_objet) == d_erreur)
                   1471:                {
                   1472:                    return(d_erreur);
                   1473:                }
                   1474: 
                   1475:                l_element_courant = (*l_element_courant).suivant;
                   1476:            }
                   1477:        }
                   1478: 
                   1479:        if (test_cfsf(s_etat_processus, 51) == d_faux)
                   1480:        {
                   1481:            printf("%s", ds_beep);
                   1482:        }
                   1483: 
                   1484:        if ((message = messages(s_etat_processus)) == NULL)
                   1485:        {
                   1486:            return(d_erreur);
                   1487:        }
                   1488: 
                   1489:        printf("%s [%d]\n", message, (int) getpid());
                   1490: 
                   1491:        free(message);
                   1492:        free((*s_etat_processus).instruction_courante);
                   1493: 
                   1494:        if ((*s_etat_processus).var_volatile_processus_pere == 0)
                   1495:        {
1.43      bertrand 1496:            envoi_signal_processus((*s_etat_processus).pid_processus_pere,
                   1497:                    rpl_sigalrm);
1.1       bertrand 1498:        }
                   1499:        else
                   1500:        {
                   1501:            (*s_etat_processus).var_volatile_alarme = -1;
                   1502:        }
                   1503: 
                   1504:        return(d_erreur);
                   1505:    }
                   1506: 
                   1507:    return(d_absence_erreur);
                   1508: }
                   1509: 
                   1510: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>