Annotation of rpl/src/gestion_variables.c, revision 1.29

1.1       bertrand    1: /*
                      2: ================================================================================
1.21      bertrand    3:   RPL/2 (R) version 4.1.0.prerelease.0
1.19      bertrand    4:   Copyright (C) 1989-2011 Dr. BERTRAND Joël
1.1       bertrand    5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
                     22: 
1.14      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Routine de création d'une nouvelle variable
                     29:   Entrée : autorisation_creation_variable_statique vaut 'V' ou 'S'.
                     30:   Dans le cas 'V', la variable est volatile.
                     31:   Dans le cas 'S', elle est statique.
                     32:   Entrée : autorisation_creation_variable_partagee vaut 'P' ou 'S'.
                     33:   Dans le cas 'P', la variable est privée.
                     34:   Dans le cas 'S', elle est partagée.
                     35: --------------------------------------------------------------------------------
                     36:   Sortie :
                     37: --------------------------------------------------------------------------------
                     38:   Effets de bords : néant
                     39: ================================================================================
                     40: */
                     41: 
1.25      bertrand   42: static logical1
                     43: ajout_variable(struct_processus *s_etat_processus, struct_variable *s_variable)
1.1       bertrand   44: {
1.25      bertrand   45:    int                         i;
                     46: 
                     47:    struct_liste_variables      *l_nouvelle_variable;
                     48:    struct_liste_variables      *l_variable_candidate;
1.28      bertrand   49:    struct_arbre_variables      *l_variable_courante;
                     50:    struct_arbre_variables      *l_variable_precedente;
1.1       bertrand   51: 
1.25      bertrand   52:    struct_liste_chainee        *l_nouvel_element;
1.1       bertrand   53: 
1.25      bertrand   54:    unsigned char               *ptr;
1.1       bertrand   55: 
1.25      bertrand   56:    if ((*s_etat_processus).s_arbre_variables == NULL)
1.1       bertrand   57:    {
1.25      bertrand   58:        if (((*s_etat_processus).s_arbre_variables =
                     59:                malloc(sizeof(struct_arbre_variables))) == NULL)
                     60:        {
                     61:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                     62:            return(d_erreur);
                     63:        }
                     64: 
                     65:        (*(*s_etat_processus).s_arbre_variables).feuille = NULL;
                     66:        (*(*s_etat_processus).s_arbre_variables).noeuds_utilises = 0;
1.28      bertrand   67:        (*(*s_etat_processus).s_arbre_variables).noeud_pere = NULL;
1.1       bertrand   68: 
1.25      bertrand   69:        if (((*(*s_etat_processus).arbre_instructions).noeud =
                     70:                malloc((*s_etat_processus).nombre_caracteres_variables
                     71:                * sizeof(struct_arbre_variables))) == NULL)
1.1       bertrand   72:        {
1.25      bertrand   73:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                     74:            return(d_erreur);
                     75:        }
                     76: 
                     77:        for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)
                     78:        {
1.28      bertrand   79:            (*(*s_etat_processus).s_arbre_variables).noeuds[i] = NULL;
1.25      bertrand   80:        }
                     81:    }
                     82: 
1.28      bertrand   83:    l_variable_precedente = NULL;
1.25      bertrand   84:    l_variable_courante = (*s_etat_processus).s_arbre_variables;
                     85:    ptr = (*s_variable).nom;
                     86: 
                     87:    while((*ptr) != d_code_fin_chaine)
                     88:    {
                     89:        BUG((*s_etat_processus).pointeurs_caracteres_variables[*ptr] < 0,
                     90:                printf("Variable=\"%s\", (*ptr)='%c'\n", (*s_variable).nom,
                     91:                *ptr));
                     92: 
1.28      bertrand   93:        if ((*l_variable_courante).noeuds[(*s_etat_processus)
1.25      bertrand   94:                .pointeurs_caracteres_variables[*ptr]] == NULL)
                     95:        {
                     96:            // Le noeud n'existe pas encore, on le crée.
                     97: 
1.28      bertrand   98:            if (((*l_variable_courante).noeuds[(*s_etat_processus)
1.25      bertrand   99:                    .pointeurs_caracteres_variables[*ptr]] =
                    100:                    malloc(sizeof(struct_arbre_variables))) == NULL)
                    101:            {
                    102:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    103:                return(d_erreur);
                    104:            }
                    105: 
1.28      bertrand  106:            (*l_variable_courante).noeuds_utilises++;
                    107:            (*(*l_variable_courante).noeuds[(*s_etat_processus)
1.25      bertrand  108:                    .pointeurs_caracteres_variables[*ptr]]).feuille = NULL;
1.28      bertrand  109:            (*(*l_variable_courante).noeuds[(*s_etat_processus)
1.25      bertrand  110:                    .pointeurs_caracteres_variables[*ptr]]).noeuds_utilises = 0;
1.28      bertrand  111:            (*(*l_variable_courante).noeuds[(*s_etat_processus)
                    112:                    .pointeurs_caracteres_variables[*ptr]]).noeud_pere =
                    113:                    l_variable_precedente;
1.25      bertrand  114: 
1.28      bertrand  115:            if (((*(*l_variable_courante).noeuds[(*s_etat_processus)
                    116:                    .pointeurs_caracteres_variables[*ptr]]).noeuds =
1.25      bertrand  117:                    malloc((*s_etat_processus).nombre_caracteres_variables
                    118:                    * sizeof(struct_arbre_variables))) == NULL)
                    119:            {
                    120:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    121:                return(d_erreur);
                    122:            }
                    123: 
                    124:            for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)
                    125:            {
1.28      bertrand  126:                (*(*l_variable_courante).noeuds[(*s_etat_processus)
                    127:                        .pointeurs_caracteres_variables[*ptr]]).noeuds[i]
                    128:                        = NULL;
1.25      bertrand  129:            }
                    130:        }
                    131: 
1.28      bertrand  132:        l_variable_precedente = l_variable_courante;
                    133:        l_variable_courante = (*l_variable_courante).noeuds
1.25      bertrand  134:                [(*s_etat_processus).pointeurs_caracteres_variables[*ptr]];
                    135:        ptr++;
                    136:    }
                    137: 
                    138:    if ((*l_variable_courante).feuille == NULL)
                    139:    {
                    140:        // Aucune variable de même nom préexiste. On alloue le premier
                    141:        // élément de la liste doublement chaînée contenant toutes les
                    142:        // variables de même nom. Cette liste boucle en premier lieu sur
                    143:        // elle-même.
                    144: 
                    145:        if (((*l_variable_courante).feuille = malloc(
                    146:                sizeof(struct_liste_variables))) == NULL)
                    147:        {
                    148:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    149:            return(d_erreur);
                    150:        }
                    151: 
                    152:        (*(*l_variable_courante).feuille).suivant =
                    153:                (*l_variable_courante).feuille;
                    154:        (*(*l_variable_courante).feuille).precedent =
                    155:                (*l_variable_courante).feuille;
1.28      bertrand  156:        (*(*l_variable_courante).feuille).noeud_pere = l_variable_precedente;
1.25      bertrand  157: 
                    158:        // Allocation de la variable sur l'élément de la liste.
                    159: 
                    160:        if (((*(*l_variable_courante).feuille).variable =
                    161:                malloc(sizeof(struct_variable))) == NULL)
                    162:        { 
                    163:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    164:            return(d_erreur);
                    165:        }
                    166: 
                    167:        (*((struct_variable *) (*(*l_variable_courante).feuille).variable)) =
                    168:                (*s_variable);
                    169: 
                    170:        if (((*((struct_variable *) (*(*l_variable_courante).feuille).variable))
                    171:                .nom = strdup((*s_variable).nom)) == NULL)
                    172:        {
                    173:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    174:            return(d_erreur);
                    175:        }
                    176:    }
                    177:    else
                    178:    {
1.28      bertrand  179:        if ((l_nouvelle_variable = malloc(sizeof(struct_liste_variables)))
                    180:                == NULL)
                    181:        {
                    182:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    183:            return(d_erreur);
                    184:        }
                    185: 
1.25      bertrand  186:        if ((*s_variable).niveau > 1)
                    187:        {
                    188:            // Cas d'une variable locale
                    189: 
                    190:            // Si le niveau de la dernière variable de même nom est
                    191:            // supérieur au niveau de la variable locale que l'on veut
                    192:            // enregistrer dans la liste, cette liste est incohérente.
                    193: 
                    194:            BUG((*(*(*l_variable_courante).feuille).variable).niveau >=
                    195:                    (*s_variable).niveau,
                    196:                    printf("Variable=\"%s\"\n", (*s_variable).nom));
                    197: 
                    198:            // On ajoute la variable à la liste existante.
                    199: 
                    200:            (*l_nouvelle_variable).suivant = (*l_variable_courante).feuille;
                    201:            (*l_nouvelle_variable).precedent = (*(*l_variable_courante).feuille)
                    202:                    .precedent;
1.28      bertrand  203:            (*l_nouvelle_variable).noeud_pere = l_variable_precedente;
1.25      bertrand  204:            (*(*(*l_variable_courante).feuille).precedent).suivant =
                    205:                    l_nouvelle_variable;
                    206:            (*(*l_variable_courante).feuille).precedent =
                    207:                    l_nouvelle_variable;
                    208:            (*l_variable_courante).feuille = l_nouvelle_variable;
                    209: 
                    210:            if (((*(*l_variable_courante).feuille).variable =
                    211:                    malloc(sizeof(struct_variable))) == NULL)
                    212:            { 
                    213:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    214:                return(d_erreur);
                    215:            }
                    216: 
                    217:            (*((struct_variable *) (*(*l_variable_courante).feuille).variable))
                    218:                    = (*s_variable);
                    219: 
                    220:            if (((*((struct_variable *) (*(*l_variable_courante).feuille)
                    221:                    .variable)).nom = strdup((*s_variable).nom)) == NULL)
                    222:            {
                    223:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    224:                return(d_erreur);
                    225:            }
1.1       bertrand  226:        }
                    227:        else
                    228:        {
1.25      bertrand  229:            // Cas d'une variable globale (niveau 0 [définitions] ou 1
                    230:            // [variables globales])
                    231: 
                    232:            l_variable_candidate = (*l_variable_courante).feuille;
                    233: 
                    234:            do
                    235:            {
                    236:                // S'il y a déjà une variable de même niveau, la pile
                    237:                // est incohérente.
                    238: 
                    239:                BUG((*(*l_variable_candidate).variable).niveau ==
                    240:                        (*s_variable).niveau,
                    241:                        printf("Variable=\"%s\"\n", (*s_variable).nom));
                    242: 
                    243:                l_variable_candidate = (*l_variable_candidate).precedent;
                    244:            } while((l_variable_candidate != (*l_variable_courante).feuille) &&
                    245:                    ((*(*l_variable_candidate).variable).niveau <= 1));
                    246: 
                    247:            if ((*(*(*(*l_variable_courante).feuille).precedent).variable)
                    248:                    .niveau > 1)
                    249:            {
                    250:                // Ajout inconditionnel des variables de niveaux 0 et 1
                    251:            }
                    252:            else
1.1       bertrand  253:            {
1.25      bertrand  254:                l_variable_candidate = (*(*l_variable_courante).feuille)
                    255:                        .precedent;
                    256:            }
                    257: 
                    258:            (*l_nouvelle_variable).suivant = l_variable_candidate;
                    259:            (*l_nouvelle_variable).precedent = (*l_variable_candidate)
                    260:                    .precedent;
1.28      bertrand  261:            (*l_nouvelle_variable).noeud_pere = l_variable_precedente;
1.25      bertrand  262:            (*(*l_variable_candidate).precedent).suivant = l_nouvelle_variable;
                    263:            (*l_variable_candidate).precedent = l_nouvelle_variable;
                    264: 
                    265:            if (((*l_nouvelle_variable).variable =
                    266:                    malloc(sizeof(struct_variable))) == NULL)
                    267:            { 
                    268:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    269:                return(d_erreur);
                    270:            }
                    271: 
                    272:            (*(*l_nouvelle_variable).variable) = (*s_variable);
                    273: 
                    274:            if (((*(*l_nouvelle_variable).variable).nom =
                    275:                    strdup((*s_variable).nom)) == NULL)
                    276:            {
                    277:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    278:                return(d_erreur);
1.1       bertrand  279:            }
                    280:        }
1.25      bertrand  281:    }
                    282: 
                    283:    // Ajout de la variable nouvellement créée à la liste par niveaux.
                    284:    // Le pointeur contenu dans la structure de description du processus indique
                    285:    // toujours le plus haut niveau utilisé.
                    286: 
                    287:    if ((*s_etat_processus).l_liste_variables_par_niveau == NULL)
                    288:    {
                    289:        // Le niveau courant n'existe pas. Il est créé.
                    290: 
                    291:        if ((l_nouvelle_variable = malloc(sizeof(struct_liste_variables)))
                    292:                == NULL)
                    293:        {
                    294:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    295:            return(d_erreur);
                    296:        }
                    297: 
                    298:        (*l_nouvelle_variable).suivant = l_nouvelle_variable;
                    299:        (*l_nouvelle_variable).precedent = l_nouvelle_variable;
1.28      bertrand  300:        (*l_nouvelle_variable).noeud_pere = NULL;
1.25      bertrand  301: 
                    302:        (*s_etat_processus).l_liste_variables_par_niveau = l_nouvelle_variable;
                    303:    }
                    304:    else if ((*s_variable).niveau > (*((struct_variable *)
                    305:            (*(*(*s_etat_processus).l_liste_variables_par_niveau).liste)
                    306:            .donnee)).niveau)
                    307:    {
                    308:        // Le niveau courant n'existe pas. Il est créé.
1.1       bertrand  309: 
1.25      bertrand  310:        if ((l_nouvelle_variable = malloc(sizeof(struct_liste_variables)))
                    311:                == NULL)
1.1       bertrand  312:        {
                    313:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    314:            return(d_erreur);
                    315:        }
                    316: 
1.25      bertrand  317:        (*l_nouvelle_variable).suivant = (*s_etat_processus)
                    318:                .l_liste_variables_par_niveau;
                    319:        (*l_nouvelle_variable).precedent = (*(*s_etat_processus)
                    320:                .l_liste_variables_par_niveau).precedent;
1.28      bertrand  321:        (*l_nouvelle_variable).noeud_pere = NULL;
1.25      bertrand  322:        (*(*(*s_etat_processus).l_liste_variables_par_niveau).precedent)
                    323:                .suivant = l_nouvelle_variable;
                    324:        (*(*s_etat_processus).l_liste_variables_par_niveau).precedent =
                    325:                l_nouvelle_variable;
                    326: 
                    327:        (*s_etat_processus).l_liste_variables_par_niveau = l_nouvelle_variable;
                    328:    }
                    329:    else
                    330:    {
                    331:        // Création d'une variable de niveau 0 ou 1
                    332: 
1.28      bertrand  333:        if ((l_nouvelle_variable = malloc(sizeof(struct_liste_variables)))
                    334:                == NULL)
                    335:        {
                    336:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    337:            return(d_erreur);
                    338:        }
                    339: 
1.25      bertrand  340:        l_variable_candidate = (*s_etat_processus).l_liste_variables_par_niveau;
                    341: 
                    342:        if ((*((struct_variable *) (*(*(*(*s_etat_processus)
                    343:                .l_liste_variables_par_niveau).precedent).liste).donnee))
                    344:                .niveau > 1)
                    345:        {
                    346:            // Ajout inconditionnel des variables de niveaux 0 et 1
                    347:        }
                    348:        else
                    349:        {
                    350:            l_variable_candidate = (*(*s_etat_processus)
                    351:                    .l_liste_variables_par_niveau).precedent;
                    352:        }
                    353: 
                    354:        (*l_nouvelle_variable).suivant = l_variable_candidate;
                    355:        (*l_nouvelle_variable).precedent = (*l_variable_candidate)
                    356:                .precedent;
1.28      bertrand  357:        (*l_nouvelle_variable).noeud_pere = NULL;
1.25      bertrand  358:        (*(*l_variable_candidate).precedent).suivant = l_nouvelle_variable;
                    359:        (*l_variable_candidate).precedent = l_nouvelle_variable;
                    360:    }
                    361: 
                    362:    // Ajout de la variable en tête de la liste
                    363: 
                    364:    if ((l_nouvel_element = malloc(sizeof(struct_liste_chainee))) == NULL)
                    365:    {
                    366:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    367:        return(d_erreur);
1.1       bertrand  368:    }
                    369: 
1.25      bertrand  370:    (*l_nouvel_element).suivant = (*(*s_etat_processus)
                    371:            .l_liste_variables_par_niveau).liste;
                    372:    (*l_nouvel_element).donnee = (struct_objet *) s_variable;
                    373:    (*l_nouvelle_variable).liste = l_nouvel_element;
                    374: 
                    375:    return(d_absence_erreur);
                    376: }
                    377: 
                    378: logical1
                    379: creation_variable(struct_processus *s_etat_processus,
                    380:        struct_variable *s_variable,
                    381:        unsigned char autorisation_creation_variable_statique,
                    382:        unsigned char autorisation_creation_variable_partagee)
                    383: {
1.1       bertrand  384:    if ((*s_etat_processus).mode_execution_programme == 'Y')
                    385:    {
                    386:        (*s_variable).origine = 'P';
                    387:    }
                    388:    else
                    389:    {
                    390:        (*s_variable).origine = 'E';
                    391:    }
                    392: 
                    393:    if ((*s_variable).niveau == 0)
                    394:    {
                    395:        // Un point d'entrée de définition est verrouillé.
                    396: 
                    397:        if ((*s_variable).origine == 'P')
                    398:        {
                    399:            (*s_variable).variable_statique.adresse = 0;
                    400:            (*s_variable).variable_partagee.adresse = 0;
                    401:        }
                    402:        else
                    403:        {
                    404:            (*s_variable).variable_statique.pointeur = NULL;
                    405:            (*s_variable).variable_partagee.pointeur = NULL;
                    406:        }
                    407: 
                    408:        (*s_variable).variable_verrouillee = d_vrai;
                    409:    }
                    410:    else if ((*s_variable).niveau == 1)
                    411:    {
                    412:        // Une variable globale ne peut être statique.
                    413: 
                    414:        if ((*s_variable).origine == 'P')
                    415:        {
                    416:            (*s_variable).variable_statique.adresse = 0;
                    417:            (*s_variable).variable_partagee.adresse = 0;
                    418:        }
                    419:        else
                    420:        {
                    421:            (*s_variable).variable_statique.pointeur = NULL;
                    422:            (*s_variable).variable_partagee.pointeur = NULL;
                    423:        }
                    424: 
                    425:        (*s_variable).variable_verrouillee = d_faux;
                    426:    }
                    427:    else
                    428:    {
                    429:        // 0 -> variable volatile
                    430:        // adresse de création -> variable statique
                    431: 
                    432:        if (autorisation_creation_variable_statique == 'V')
                    433:        {
                    434:            if (autorisation_creation_variable_partagee == 'S')
                    435:            {
                    436:                // On force la création d'une variable partagée
                    437: 
                    438:                if ((*s_variable).origine == 'P')
                    439:                {
                    440:                    (*s_variable).variable_statique.adresse = 0;
                    441:                    (*s_variable).variable_partagee.adresse =
                    442:                            (*s_etat_processus).position_courante;
                    443:                }
                    444:                else
                    445:                {
                    446:                    (*s_variable).variable_statique.pointeur = NULL;
                    447:                    (*s_variable).variable_partagee.pointeur =
                    448:                            (*s_etat_processus).objet_courant;
                    449:                }
                    450:            }
                    451:            else
                    452:            {
                    453:                // On force la création d'une variable volatile
                    454: 
                    455:                if ((*s_variable).origine == 'P')
                    456:                {
                    457:                    (*s_variable).variable_statique.adresse = 0;
                    458:                    (*s_variable).variable_partagee.adresse = 0;
                    459:                }
                    460:                else
                    461:                {
                    462:                    (*s_variable).variable_statique.pointeur = NULL;
                    463:                    (*s_variable).variable_partagee.pointeur = NULL;
                    464:                }
                    465:            }
                    466:        }
                    467:        else
                    468:        {
                    469:            // On force la création d'une variable statique.
                    470: 
                    471:            if ((*s_variable).origine == 'P')
                    472:            {
                    473:                (*s_variable).variable_statique.adresse =
                    474:                        (*s_etat_processus).position_courante;
                    475:                (*s_variable).variable_partagee.adresse = 0;
                    476:            }
                    477:            else
                    478:            {
                    479:                (*s_variable).variable_statique.pointeur =
                    480:                        (*s_etat_processus).objet_courant;
                    481:                (*s_variable).variable_partagee.pointeur = 0;
                    482:            }
                    483:        }
                    484: 
                    485:        (*s_variable).variable_verrouillee = d_faux;
                    486:    }
                    487: 
                    488:    /*
1.25      bertrand  489:     * Recherche de la feuille correspondante dans l'arbre des variables.
                    490:     * Si cette feuille n'existe pas, elle est créée.
1.1       bertrand  491:     */
                    492: 
1.25      bertrand  493:    if (ajout_variable(s_etat_processus, s_variable) == d_erreur)
                    494:    {
                    495:        return(d_erreur);
                    496:    }
                    497: 
                    498:    return(d_absence_erreur);
                    499: }
                    500: 
                    501: 
                    502: /*
                    503: ================================================================================
                    504:   Procédure de recherche d'une variable par son nom dans la base
                    505: ================================================================================
                    506:   Entrée :
                    507: --------------------------------------------------------------------------------
                    508:   Sortie :
                    509: --------------------------------------------------------------------------------
                    510:   Effets de bord : néant
                    511: ================================================================================
                    512: */
                    513: 
                    514: logical1
                    515: recherche_variable(struct_processus *s_etat_processus,
                    516:        unsigned char *nom_variable)
                    517: {
                    518:    int                         pointeur;
                    519: 
                    520:    struct_arbre_variables      *l_variable_courante;
                    521:    struct_liste_pile_systeme   *l_element_courant;
                    522: 
                    523:    unsigned char               *ptr;
                    524: 
                    525:    unsigned long               niveau_appel;
1.1       bertrand  526: 
1.25      bertrand  527:    if ((*s_etat_processus).s_arbre_variables == NULL)
1.1       bertrand  528:    {
1.25      bertrand  529:        (*s_etat_processus).erreur_systeme = d_es_variable_introuvable;
                    530:        return d_faux;
1.1       bertrand  531:    }
1.25      bertrand  532: 
1.28      bertrand  533:    l_variable_courante = (*s_etat_processus).s_arbre_variables;
1.25      bertrand  534:    ptr = nom_variable;
                    535: 
                    536:    while((*ptr) != d_code_fin_chaine)
1.1       bertrand  537:    {
1.25      bertrand  538:        pointeur = (*s_etat_processus).pointeurs_caracteres_variables[*ptr];
                    539: 
                    540:        if (pointeur < 0)
                    541:        {
                    542:            // Caractère hors de l'alphabet des variables
                    543:            return(d_erreur);
                    544:        }
                    545: 
1.28      bertrand  546:        if ((*l_variable_courante).noeuds[pointeur] == NULL)
1.1       bertrand  547:        {
1.25      bertrand  548:            // Le chemin de la variable candidate n'existe pas.
                    549:            return(d_erreur);
1.1       bertrand  550:        }
                    551: 
1.28      bertrand  552:        l_variable_courante = (*l_variable_courante).noeuds[pointeur];
1.25      bertrand  553:        ptr++;
                    554:    }
                    555: 
                    556:    if ((*l_variable_courante).feuille != NULL)
                    557:    {
                    558:        // Il existe une pile de variables de même nom. Le sommet de la
                    559:        // pile est la variable de niveau le plus haut.
                    560: 
                    561:        l_element_courant = (*s_etat_processus).l_base_pile_systeme;
                    562: 
                    563:        if (l_element_courant == NULL)
1.12      bertrand  564:        {
1.25      bertrand  565:            // Problème : la pile système est vide !
                    566:            (*s_etat_processus).erreur_systeme = d_es_pile_vide;
                    567:            return(d_erreur);
1.12      bertrand  568:        }
1.25      bertrand  569: 
                    570:        while((*l_element_courant).retour_definition != 'Y')
1.12      bertrand  571:        {
1.25      bertrand  572:            l_element_courant = (*l_element_courant).suivant;
1.12      bertrand  573: 
1.25      bertrand  574:            if (l_element_courant == NULL)
1.12      bertrand  575:            {
1.25      bertrand  576:                (*s_etat_processus).erreur_systeme = d_es_pile_vide;
                    577:                return(d_erreur);
1.12      bertrand  578:            }
1.25      bertrand  579:        }
                    580: 
                    581:        niveau_appel = (*l_element_courant).niveau_courant;
1.12      bertrand  582: 
1.25      bertrand  583:        if (niveau_appel < (*(*(*l_variable_courante).feuille).variable).niveau)
                    584:        {
                    585:            // Une variable locale est accessible puisque créée dans la
                    586:            // fonction courante.
                    587: 
                    588:            (*s_etat_processus).pointeur_variable_courante =
                    589:                    (*(*l_variable_courante).feuille).variable;
                    590:            (*s_etat_processus).pointeur_feuille_courante =
                    591:                    (*l_variable_courante).feuille;
                    592:            return(d_absence_erreur);
                    593:        }
                    594:        else
                    595:        {
                    596:            // Aucune variable locale n'est accessible depuis la fonction.
                    597:            // Dans ce cas, on prend la variable de niveau le plus bas
                    598:            // si ce niveau est inférieur ou égal à 1 (variable globale
                    599:            // ou fonction définie par l'utilisateur). Si le niveau de la
1.27      bertrand  600:            // plus ancienne variable est strictement supérieur à 1, il
1.25      bertrand  601:            // s'agit d'une variable locale inaccessible.
                    602: 
                    603:            if ((*(*(*(*l_variable_courante).feuille).precedent).variable)
                    604:                    .niveau <= 1)
                    605:            {
                    606:                (*s_etat_processus).pointeur_variable_courante =
                    607:                        (*(*(*l_variable_courante).feuille).precedent).variable;
                    608:                (*s_etat_processus).pointeur_feuille_courante =
                    609:                        (*l_variable_courante).feuille;
1.27      bertrand  610: 
                    611:                // S'il existe une variable de niveau 0 et une seconde de
                    612:                // niveau 1, la variable de niveau 0 (fonction) est masquée
                    613:                // par celle de niveau 1.
                    614: 
                    615:                if (((*(*(*l_variable_courante).feuille).variable).niveau == 0)
                    616:                        && ((*(*(*(*l_variable_courante).feuille).precedent)
                    617:                        .variable).niveau == 1))
                    618:                {
                    619:                    (*s_etat_processus).pointeur_variable_courante =
                    620:                            (*(*(*l_variable_courante).feuille).precedent)
                    621:                            .variable;
                    622:                    (*s_etat_processus).pointeur_feuille_courante =
                    623:                            (*l_variable_courante).feuille;
                    624:                }
                    625: 
1.25      bertrand  626:                return(d_absence_erreur);
1.12      bertrand  627:            }
                    628:        }
1.1       bertrand  629:    }
                    630: 
1.25      bertrand  631:    return(d_erreur);
1.1       bertrand  632: }
                    633: 
                    634: 
1.29    ! bertrand  635: logical1
        !           636: recherche_variable_globale(struct_processus *s_etat_processus,
        !           637:        unsigned char *nom)
        !           638: {
        !           639:    logical1            presence_variable;
        !           640: 
        !           641:    presence_variable = recherche_variable(s_etat_processus, nom);
        !           642: 
        !           643:    if (presence_variable == d_vrai)
        !           644:    {
        !           645:        switch((*(*s_etat_processus).pointeur_variable_courante).niveau)
        !           646:        {
        !           647:            case 0:
        !           648:            {
        !           649:                // Nous sommes en présence d'une définition et non d'une
        !           650:                // variable.
        !           651: 
        !           652:                presence_variable = d_faux;
        !           653:                break;
        !           654:            }
        !           655: 
        !           656:            case 1:
        !           657:            {
        !           658:                break;
        !           659:            }
        !           660: 
        !           661:            default:
        !           662:            {
        !           663:                if ((*(*(*(*s_etat_processus).pointeur_feuille_courante)
        !           664:                        .precedent).variable).niveau == 1)
        !           665:                {
        !           666:                    (*s_etat_processus).pointeur_feuille_courante =
        !           667:                            (*(*s_etat_processus).pointeur_feuille_courante)
        !           668:                            .precedent;
        !           669:                    (*s_etat_processus).pointeur_variable_courante =
        !           670:                            (*(*s_etat_processus).pointeur_feuille_courante)
        !           671:                            .variable;
        !           672:                }
        !           673:                else if ((*(*(*(*(*s_etat_processus).pointeur_feuille_courante)
        !           674:                        .precedent).precedent).variable).niveau == 1)
        !           675:                {
        !           676:                    (*s_etat_processus).pointeur_feuille_courante =
        !           677:                            (*(*(*s_etat_processus).pointeur_feuille_courante)
        !           678:                            .precedent).precedent;
        !           679:                    (*s_etat_processus).pointeur_variable_courante =
        !           680:                            (*(*s_etat_processus).pointeur_feuille_courante)
        !           681:                            .variable;
        !           682:                }
        !           683:                else
        !           684:                {
        !           685:                    presence_variable = d_faux;
        !           686:                }
        !           687: 
        !           688:                break;
        !           689:            }
        !           690:        }
        !           691:    }
        !           692: 
        !           693:    if (presence_variable == d_vrai)
        !           694:    {
        !           695:        if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL)
        !           696:        {
        !           697:            // La variable n'est pas globale, elle est partagée.
        !           698:            presence_variable = d_faux;
        !           699:            (*s_etat_processus).erreur_execution = d_ex_variable_partagee;
        !           700:        }
        !           701:    }
        !           702: 
        !           703:    return(presence_variable);
        !           704: }
        !           705: 
        !           706: 
1.1       bertrand  707: /*
                    708: ================================================================================
                    709:   Procédure de retrait d'une variable de la base
                    710: ================================================================================
                    711:   Entrée : type 'G' ou 'L' selon que l'on retire une variable locale (incluant
                    712:            les globales) ou strictement globale.
                    713: --------------------------------------------------------------------------------
                    714:   Sortie :
                    715: --------------------------------------------------------------------------------
                    716:   Effets de bord : néant
                    717: ================================================================================
                    718: */
                    719: 
                    720: logical1
                    721: retrait_variable(struct_processus *s_etat_processus,
                    722:        unsigned char *nom_variable, unsigned char type)
                    723: {
1.28      bertrand  724:    logical1                    erreur;
                    725: 
                    726:    struct_arbre_variables      *s_arbre_a_supprimer;
                    727:    struct_arbre_variables      *s_arbre_courant;
                    728: 
                    729:    struct_liste_chainee        *l_element_courant;
                    730:    struct_liste_chainee        *l_element_precedent;
                    731: 
                    732:    struct_liste_variables      *variable_a_supprimer;
                    733:    struct_liste_variables      *variables_par_niveau;
                    734: 
                    735:    unsigned long               niveau;
1.1       bertrand  736: 
                    737:    if (recherche_variable(s_etat_processus, nom_variable) == d_vrai)
                    738:    {
1.25      bertrand  739:        // Une variable correspondant au nom recherché est accessible.
                    740: 
1.1       bertrand  741:        if (type == 'G')
                    742:        {
1.25      bertrand  743:            if ((*(*s_etat_processus).pointeur_variable_courante).niveau > 1)
                    744:            {
                    745:                // La variable obtenue est une variable locale. il faut
                    746:                // s'assurer qu'il existe une variable de niveau 1 de même
                    747:                // nom sur la feuille.
                    748: 
1.27      bertrand  749:                if ((*(*(*(*s_etat_processus).pointeur_feuille_courante)
                    750:                        .precedent).variable).niveau <= 1)
1.1       bertrand  751:                {
1.27      bertrand  752:                    (*s_etat_processus).pointeur_feuille_courante =
                    753:                            (*(*s_etat_processus).pointeur_feuille_courante)
                    754:                            .precedent;
                    755:                    (*s_etat_processus).pointeur_variable_courante =
                    756:                            (*(*s_etat_processus).pointeur_feuille_courante)
                    757:                            .variable;
                    758: 
                    759:                    // Si la variable retournée est de niveau 0, on regarde
                    760:                    // un peu plus loin si une variable de niveau 1 existe.
                    761: 
                    762:                    if (((*(*(*s_etat_processus).pointeur_feuille_courante)
                    763:                            .variable).niveau == 0) &&
                    764:                            ((*(*(*(*s_etat_processus)
                    765:                            .pointeur_feuille_courante).precedent).variable)
                    766:                            .niveau == 1))
1.1       bertrand  767:                    {
1.27      bertrand  768:                        (*s_etat_processus).pointeur_feuille_courante =
                    769:                                (*(*s_etat_processus).pointeur_feuille_courante)
                    770:                                .precedent;
                    771:                        (*s_etat_processus).pointeur_variable_courante =
                    772:                                (*(*s_etat_processus).pointeur_feuille_courante)
                    773:                                .variable;
1.1       bertrand  774:                    }
                    775:                }
1.27      bertrand  776:                else
                    777:                {
                    778:                    // Aucune variable globale (niveau 1) n'existe.
1.1       bertrand  779: 
1.27      bertrand  780:                    erreur = d_erreur;
                    781:                    (*s_etat_processus).erreur_execution =
                    782:                            d_ex_variable_non_definie;
                    783:                    return(erreur);
                    784:                }
1.1       bertrand  785:            }
                    786: 
1.27      bertrand  787:            if ((*(*s_etat_processus).pointeur_variable_courante)
1.1       bertrand  788:                    .variable_verrouillee == d_vrai)
                    789:            {
                    790:                erreur = d_erreur;
                    791:                (*s_etat_processus).erreur_execution =
                    792:                        d_ex_variable_verrouillee;
1.28      bertrand  793:                return(erreur);
1.1       bertrand  794:            }
                    795:        }
                    796: 
1.27      bertrand  797:        // Suppression de la variable de la liste.
                    798:        // Deux cas peuvent survenir :
                    799:        // 1/ les pointeurs sur la variable et la variable suivante
                    800:        // sont identiques et on supprime la variable ainsi que la feuille
                    801:        // associée ;
                    802:        // 2/ ces deux pointeurs sont différents et se contente de retirer
                    803:        // la structure décrivant la variable.
1.1       bertrand  804: 
1.28      bertrand  805:        if ((*s_etat_processus).pointeur_feuille_courante ==
                    806:                (*(*s_etat_processus).pointeur_feuille_courante).suivant)
                    807:        {
                    808:            // Cas 1 :
                    809:            // On retire la variable du noeud en décrémentant le nombre
                    810:            // de feuilles de ce noeud. Si le nombre de feuilles du noeud
                    811:            // est nul, on retire les noeuds récursivement jusqu'à obtenir
                    812:            // un nombre non nul de feuilles utilisées (ou la racine des
                    813:            // variables).
                    814: 
                    815:            variable_a_supprimer = (*s_etat_processus)
                    816:                    .pointeur_feuille_courante;
                    817:            s_arbre_courant = (*variable_a_supprimer).noeud_pere;
                    818: 
                    819:            BUG((*s_arbre_courant).noeuds_utilises == 0,
                    820:                    uprintf("Freed node !\n"));
                    821:            (*s_arbre_courant).noeuds_utilises--;
1.1       bertrand  822: 
1.28      bertrand  823:            while((*s_arbre_courant).noeuds_utilises == 0)
                    824:            {
                    825:                s_arbre_a_supprimer = s_arbre_courant;
                    826:                s_arbre_courant = (*s_arbre_courant).noeud_pere;
1.1       bertrand  827: 
1.28      bertrand  828:                free((*s_arbre_a_supprimer).noeuds);
                    829:                free(s_arbre_a_supprimer);
1.1       bertrand  830: 
1.28      bertrand  831:                if (s_arbre_courant == NULL)
                    832:                {
                    833:                    break;
                    834:                }
                    835: 
                    836:                BUG((*s_arbre_courant).noeuds_utilises == 0,
                    837:                        uprintf("Freed node !\n"));
                    838:                (*s_arbre_courant).noeuds_utilises--;
                    839:            }
                    840:        }
                    841:        else
1.1       bertrand  842:        {
1.28      bertrand  843:            // Cas 2 :
                    844:            // On retire la variable de la liste.
                    845: 
                    846:            variable_a_supprimer = (*s_etat_processus)
                    847:                    .pointeur_feuille_courante;
                    848: 
                    849:            (*(*(*s_etat_processus).pointeur_feuille_courante).precedent)
                    850:                    .suivant = (*(*s_etat_processus).pointeur_feuille_courante)
                    851:                    .suivant;
                    852:            (*(*(*s_etat_processus).pointeur_feuille_courante).suivant)
                    853:                    .precedent = (*(*s_etat_processus)
                    854:                    .pointeur_feuille_courante).precedent;
1.1       bertrand  855:        }
                    856: 
1.28      bertrand  857:        // Dans tous les cas, on retire la variable de la liste des variables
                    858:        // par niveau.
                    859: 
                    860:        niveau = (*(*variable_a_supprimer).variable).niveau;
                    861:        variables_par_niveau = (*s_etat_processus).l_liste_variables_par_niveau;
                    862: 
                    863:        while(variables_par_niveau != NULL)
                    864:        {
                    865:            l_element_courant = (*variables_par_niveau).liste;
                    866: 
                    867:            if (l_element_courant != NULL)
                    868:            {
                    869:                if ((*((struct_variable *) (*l_element_courant).donnee)).niveau
                    870:                        == niveau)
                    871:                {
                    872:                    // On parcourt le bon niveau.
                    873: 
                    874:                    l_element_precedent = NULL;
                    875: 
                    876:                    while(l_element_courant != NULL)
                    877:                    {
                    878:                        // Tant que l_element_courant est non nul, il reste des
                    879:                        // variables à explorer dans le niveau courant.
                    880: 
                    881:                        if ((*l_element_courant).donnee ==
                    882:                                (void *) (*variable_a_supprimer).variable)
                    883:                        {
                    884:                            // On a trouvé la variable à supprimer.
                    885: 
                    886:                            if (l_element_precedent == NULL)
                    887:                            {
                    888:                                (*variables_par_niveau).liste =
                    889:                                        (*l_element_courant).suivant;
                    890:                            }
                    891:                            else
                    892:                            {
                    893:                                (*l_element_precedent).suivant =
                    894:                                        (*l_element_courant).suivant;
                    895:                            }
                    896:                        }
                    897: 
                    898:                        l_element_precedent = l_element_courant;
                    899:                        l_element_courant = (*l_element_courant).suivant;
                    900:                    }
                    901:                }
                    902:            }
                    903: 
                    904:            variables_par_niveau = (*variables_par_niveau).suivant;
                    905:        }
                    906: 
                    907:        // Puis on libère le contenu de la variable.
                    908: 
                    909:        free((*(*variable_a_supprimer).variable).nom);
                    910:        liberation(s_etat_processus, (*(*variable_a_supprimer).variable).objet);
                    911: 
1.1       bertrand  912:        erreur = d_absence_erreur;
                    913:    }
                    914:    else
                    915:    {
1.25      bertrand  916:        // Aucune variable n'est accessible depuis le point courant du
                    917:        // programme.
                    918: 
1.1       bertrand  919:        erreur = d_erreur;
                    920:        (*s_etat_processus).erreur_systeme = d_es_variable_introuvable;
                    921:    }
                    922: 
1.25      bertrand  923:    return(erreur);
1.1       bertrand  924: }
                    925: 
                    926: 
                    927: /*
                    928: ================================================================================
                    929:   Procédure de retrait des variables de niveau strictement supérieur au
                    930:   niveau courant
                    931: ================================================================================
                    932:   Entrée :
                    933: --------------------------------------------------------------------------------
                    934:   Sortie :
                    935: --------------------------------------------------------------------------------
                    936:   Effets de bord : néant
                    937: ================================================================================
                    938: */
                    939: 
                    940: logical1
                    941: retrait_variable_par_niveau(struct_processus *s_etat_processus)
                    942: {
1.28      bertrand  943:    // Utilisation du champ (*s_etat_processus).liste_variables_par_niveau.
                    944:    // La tête de la pile contient toujours les variables de plus haut niveau
                    945:    // créées.
1.1       bertrand  946: 
1.28      bertrand  947:    struct_liste_variables          *l_niveau_suivant;
1.1       bertrand  948: 
1.28      bertrand  949:    while((*s_etat_processus).l_liste_variables_par_niveau != NULL)
1.1       bertrand  950:    {
1.28      bertrand  951:        l_niveau_suivant = (*(*s_etat_processus).l_liste_variables_par_niveau)
                    952:                .suivant;
                    953: 
                    954:        if ((*(*s_etat_processus).l_liste_variables_par_niveau).liste == NULL)
1.1       bertrand  955:        {
1.28      bertrand  956:            // Si le niveau ne contient aucune variable, on le détruit.
                    957:            // Le pointeur sur la chaîne est déjà nul et il ne reste rien à
                    958:            // faire.
1.1       bertrand  959:        }
                    960:        else
                    961:        {
1.28      bertrand  962:            // Le niveau contient des variables.
                    963: 
                    964:            if ((*((struct_variable *) (*(*(*s_etat_processus)
                    965:                    .l_liste_variables_par_niveau).liste).donnee)).niveau
                    966:                    <= (*s_etat_processus).niveau_courant)
1.1       bertrand  967:            {
1.28      bertrand  968:                // On a retiré de l'arbre des variables toutes les
                    969:                // variables de niveau strictement supérieur au niveau
                    970:                // courant.
1.1       bertrand  971: 
1.28      bertrand  972:                break;
1.1       bertrand  973:            }
1.28      bertrand  974: 
                    975:            while((*(*s_etat_processus).l_liste_variables_par_niveau).liste
                    976:                    != NULL)
1.1       bertrand  977:            {
1.28      bertrand  978:                // Sauvegarde des variables statiques.
                    979: 
                    980:                if ((*((struct_variable *) (*(*(*s_etat_processus)
                    981:                        .l_liste_variables_par_niveau).liste).donnee)).origine
                    982:                        == 'P')
1.1       bertrand  983:                {
1.28      bertrand  984:                    if ((*((struct_variable *) (*(*(*s_etat_processus)
                    985:                            .l_liste_variables_par_niveau).liste).donnee))
                    986:                            .variable_statique.adresse != 0)
1.1       bertrand  987:                    {
1.28      bertrand  988:                        if (recherche_variable_statique(s_etat_processus,
                    989:                                (*((struct_variable *) (*(*(*s_etat_processus)
                    990:                                .l_liste_variables_par_niveau).liste).donnee))
                    991:                                .nom, (*((struct_variable *)
                    992:                                (*(*(*s_etat_processus)
                    993:                                .l_liste_variables_par_niveau).liste).donnee))
                    994:                                .variable_statique, ((*s_etat_processus)
                    995:                                .mode_execution_programme
                    996:                                 == 'Y') ? 'P' : 'E') == d_vrai)
                    997:                        {
                    998:                            (*s_etat_processus).s_liste_variables_statiques
                    999:                                    [(*s_etat_processus)
                   1000:                                    .position_variable_statique_courante]
                   1001:                                    .objet = (*((struct_variable *)
                   1002:                                    (*(*(*s_etat_processus)
                   1003:                                    .l_liste_variables_par_niveau).liste)
                   1004:                                    .donnee)).objet;
                   1005:                        }
                   1006:                        else
                   1007:                        {
                   1008:                            (*s_etat_processus).erreur_systeme =
                   1009:                                    d_es_variable_introuvable;
                   1010:                        }
                   1011: 
                   1012:                        (*((struct_variable *) (*(*(*s_etat_processus)
                   1013:                                .l_liste_variables_par_niveau).liste).donnee))
                   1014:                                .objet = NULL;
1.1       bertrand 1015:                    }
1.28      bertrand 1016:                }
                   1017:                else
                   1018:                {
                   1019:                    if ((*((struct_variable *) (*(*(*s_etat_processus)
                   1020:                            .l_liste_variables_par_niveau).liste).donnee))
                   1021:                            .variable_statique.pointeur != NULL)
1.1       bertrand 1022:                    {
1.28      bertrand 1023:                        /*
                   1024:                         * Gestion des variables statiques
                   1025:                         */
                   1026: 
                   1027:                        if (recherche_variable_statique(s_etat_processus,
                   1028:                                (*((struct_variable *) (*(*(*s_etat_processus)
                   1029:                                .l_liste_variables_par_niveau).liste).donnee))
                   1030:                                .nom, (*((struct_variable *)
                   1031:                                (*(*(*s_etat_processus)
                   1032:                                .l_liste_variables_par_niveau).liste).donnee))
                   1033:                                .variable_statique, ((*s_etat_processus)
                   1034:                                .mode_execution_programme
                   1035:                                 == 'Y') ? 'P' : 'E') == d_vrai)
                   1036:                        {
                   1037:                            (*s_etat_processus).s_liste_variables_statiques
                   1038:                                    [(*s_etat_processus)
                   1039:                                    .position_variable_statique_courante]
                   1040:                                    .objet = (*((struct_variable *)
                   1041:                                    (*(*(*s_etat_processus)
                   1042:                                    .l_liste_variables_par_niveau).liste)
                   1043:                                    .donnee)).objet;
                   1044:                        }
                   1045:                        else
                   1046:                        {
                   1047:                            (*s_etat_processus).erreur_systeme =
                   1048:                                    d_es_variable_introuvable;
                   1049:                            return(d_erreur);
                   1050:                        }
                   1051: 
                   1052:                        (*((struct_variable *) (*(*(*s_etat_processus)
                   1053:                                .l_liste_variables_par_niveau).liste).donnee))
                   1054:                                .objet = NULL;
1.1       bertrand 1055:                    }
1.28      bertrand 1056:                }
1.1       bertrand 1057: 
1.28      bertrand 1058:                if (retrait_variable(s_etat_processus,
                   1059:                        (*((struct_variable *) (*(*(*s_etat_processus)
                   1060:                        .l_liste_variables_par_niveau).liste).donnee)).nom,
                   1061:                        'L') == d_erreur)
                   1062:                {
                   1063:                    return(d_erreur);
1.1       bertrand 1064:                }
                   1065:            }
                   1066:        }
                   1067: 
1.28      bertrand 1068:        free((*s_etat_processus).l_liste_variables_par_niveau);
                   1069:        (*s_etat_processus).l_liste_variables_par_niveau = l_niveau_suivant;
1.1       bertrand 1070:    }
                   1071: 
                   1072:    return(d_absence_erreur);
                   1073: }
                   1074: 
1.23      bertrand 1075: 
                   1076: /*
                   1077: ================================================================================
1.24      bertrand 1078:   Procédure de retrait des toutes les variables locales et globales
                   1079: ================================================================================
                   1080:   Entrée : drapeau indiquant s'il faut retirer les définitions (variables
                   1081:            de niveau 0)
                   1082: --------------------------------------------------------------------------------
                   1083:   Sortie :
                   1084: --------------------------------------------------------------------------------
                   1085:   Effets de bord : néant
                   1086: ================================================================================
                   1087: */
                   1088: 
                   1089: void
                   1090: liberation_arbre_variables(struct_processus *s_etat_processus,
                   1091:        struct_arbre_variables *arbre, logical1 retrait_definitions)
                   1092: {
                   1093:    int                     i;
                   1094: 
1.28      bertrand 1095:    struct_liste_chainee    *l_element_courant_liste;
                   1096:    struct_liste_chainee    *l_element_suivant_liste;
                   1097: 
                   1098:    struct_liste_variables  *l_element_courant;
                   1099:    struct_liste_variables  *l_element_suivant;
                   1100: 
                   1101:    // Libération de l'arbre des variables. Le contenu des variables n'est
                   1102:    // pas détruit par cette opération, il sera détruit lors de la libération
                   1103:    // de la liste des variables par niveau.
1.24      bertrand 1104: 
                   1105:    for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)
                   1106:    {
1.28      bertrand 1107:        if ((*arbre).noeuds[i] != NULL)
1.24      bertrand 1108:        {
1.28      bertrand 1109:            l_element_courant = (*arbre).feuille;
1.24      bertrand 1110: 
                   1111:            while(l_element_courant != NULL)
                   1112:            {
                   1113:                l_element_suivant = (*l_element_courant).suivant;
1.28      bertrand 1114:                free(l_element_courant);
                   1115:                l_element_courant = l_element_suivant;
                   1116:            }
                   1117: 
                   1118:            liberation_arbre_variables(s_etat_processus, (*arbre).noeuds[i],
                   1119:                    retrait_definitions);
                   1120:        }
                   1121:    }
                   1122: 
                   1123:    // Suppression de la liste des variables par niveau.
                   1124: 
                   1125:    if (arbre == (*s_etat_processus).s_arbre_variables)
                   1126:    {
                   1127:        l_element_courant = (*s_etat_processus).l_liste_variables_par_niveau;
                   1128: 
                   1129:        while(l_element_courant != NULL)
                   1130:        {
                   1131:            l_element_courant_liste = (*l_element_courant).liste;
1.24      bertrand 1132: 
1.28      bertrand 1133:            while(l_element_courant_liste != NULL)
                   1134:            {
                   1135:                if ((retrait_definitions == d_vrai) ||
                   1136:                        ((*((struct_variable *) (*l_element_courant_liste)
                   1137:                        .donnee)).niveau >= 1))
1.24      bertrand 1138:                {
                   1139:                    liberation(s_etat_processus, (*((struct_variable *)
1.28      bertrand 1140:                            (*l_element_courant_liste).donnee)).objet);
                   1141:                    free((*((struct_variable *) (*l_element_courant_liste)
1.24      bertrand 1142:                            .donnee)).nom);
1.28      bertrand 1143:                    free((*l_element_courant_liste).donnee);
1.24      bertrand 1144:                }
                   1145: 
1.28      bertrand 1146:                l_element_suivant_liste = (*l_element_courant_liste).suivant;
                   1147:                free(l_element_courant_liste);
                   1148:                l_element_courant_liste = l_element_suivant_liste;
1.24      bertrand 1149:            }
                   1150: 
1.28      bertrand 1151:            l_element_suivant = (*l_element_courant).suivant;
                   1152:            free(l_element_courant);
                   1153:            l_element_courant = l_element_suivant;
1.24      bertrand 1154:        }
                   1155:    }
                   1156: 
1.28      bertrand 1157:    free((*arbre).noeuds);
1.24      bertrand 1158:    free(arbre);
                   1159: 
                   1160:    return;
                   1161: }
                   1162: 
1.28      bertrand 1163: 
1.24      bertrand 1164: /*
                   1165: ================================================================================
1.23      bertrand 1166:   Procédure de copie de l'arbre des variables
                   1167: ================================================================================
                   1168:   Entrée :
                   1169: --------------------------------------------------------------------------------
                   1170:   Sortie :
                   1171: --------------------------------------------------------------------------------
                   1172:   Effets de bord : néant
                   1173: ================================================================================
                   1174: */
                   1175: 
                   1176: struct_arbre_variables *
                   1177: copie_arbre_variables(struct_processus *s_etat_processus)
                   1178: {
                   1179:    // Les définitions sont partagées entre tous les threads et ne sont pas
                   1180:    // copiées.
1.28      bertrand 1181:    //
                   1182:    // NB : on ne copie que les variables de niveaux 0 et 1, les autres
                   1183:    // variables locales étant masquées par le processus de création de thread
                   1184:    // ou de processus, elles sont inaccessibles.
                   1185: 
                   1186:    BUG(1, uprintf("Oops !\n"));
1.23      bertrand 1187: 
                   1188:    return(d_absence_erreur);
                   1189: }
                   1190: 
                   1191: 
                   1192: /*
                   1193: ================================================================================
                   1194:   Procédure d'initialisation de la table de correspondance des variables
                   1195: ================================================================================
                   1196:   Entrée :
                   1197: --------------------------------------------------------------------------------
                   1198:   Sortie :
                   1199: --------------------------------------------------------------------------------
                   1200:   Effets de bord : néant
                   1201: ================================================================================
                   1202: */
                   1203: 
                   1204: /*
                   1205:  * Caractères autorisés dans les instructions
                   1206:  *
                   1207:  * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
                   1208:  * a b c d e f g h i j k l m n o p q r s t u v w x y z
                   1209:  * _
                   1210:  * 1 2 3 4 5 6 7 8 9 0
                   1211:  */
                   1212: 
                   1213: void
                   1214: initialisation_variables(struct_processus *s_etat_processus)
                   1215: {
                   1216:    int             decalage;
                   1217:    int             i;
                   1218:    int             longueur_tableau;
                   1219: 
                   1220:    unsigned char   caractere;
                   1221: 
                   1222:    // Récupération de la longueur d'un unsigned char
                   1223: 
                   1224:    longueur_tableau = 1;
                   1225:    decalage = 0;
                   1226:    caractere = 1;
                   1227: 
                   1228:    while((1L << decalage) == (long) ((unsigned char) (caractere << decalage)))
                   1229:    {
                   1230:        decalage++;
                   1231:        longueur_tableau *= 2;
                   1232:    }
                   1233: 
                   1234:    if (((*s_etat_processus).pointeurs_caracteres_variables =
                   1235:            malloc(longueur_tableau * sizeof(int))) == NULL)
                   1236:    {
                   1237:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1238:        return;
                   1239:    }
                   1240: 
                   1241:    for(i = 0; i < longueur_tableau; i++)
                   1242:    {
                   1243:        (*s_etat_processus).pointeurs_caracteres_variables[i] = -1;
                   1244:    }
                   1245: 
                   1246:    (*s_etat_processus).nombre_caracteres_variables = 0;
                   1247: 
                   1248: #define DECLARATION_CARACTERE(c) \
                   1249:        do { (*s_etat_processus).pointeurs_caracteres_variables[c] = \
                   1250:        (*s_etat_processus).nombre_caracteres_variables++; } while(0)
                   1251: 
                   1252:    DECLARATION_CARACTERE('A');
                   1253:    DECLARATION_CARACTERE('B');
                   1254:    DECLARATION_CARACTERE('C');
                   1255:    DECLARATION_CARACTERE('D');
                   1256:    DECLARATION_CARACTERE('E');
                   1257:    DECLARATION_CARACTERE('F');
                   1258:    DECLARATION_CARACTERE('G');
                   1259:    DECLARATION_CARACTERE('H');
                   1260:    DECLARATION_CARACTERE('I');
                   1261:    DECLARATION_CARACTERE('J');
                   1262:    DECLARATION_CARACTERE('K');
                   1263:    DECLARATION_CARACTERE('L');
                   1264:    DECLARATION_CARACTERE('M');
                   1265:    DECLARATION_CARACTERE('N');
                   1266:    DECLARATION_CARACTERE('O');
                   1267:    DECLARATION_CARACTERE('P');
                   1268:    DECLARATION_CARACTERE('Q');
                   1269:    DECLARATION_CARACTERE('R');
                   1270:    DECLARATION_CARACTERE('S');
                   1271:    DECLARATION_CARACTERE('T');
                   1272:    DECLARATION_CARACTERE('U');
                   1273:    DECLARATION_CARACTERE('V');
                   1274:    DECLARATION_CARACTERE('W');
                   1275:    DECLARATION_CARACTERE('X');
                   1276:    DECLARATION_CARACTERE('Y');
                   1277:    DECLARATION_CARACTERE('Z');
                   1278: 
                   1279:    DECLARATION_CARACTERE('a');
                   1280:    DECLARATION_CARACTERE('b');
                   1281:    DECLARATION_CARACTERE('c');
                   1282:    DECLARATION_CARACTERE('d');
                   1283:    DECLARATION_CARACTERE('e');
                   1284:    DECLARATION_CARACTERE('f');
                   1285:    DECLARATION_CARACTERE('g');
                   1286:    DECLARATION_CARACTERE('h');
                   1287:    DECLARATION_CARACTERE('i');
                   1288:    DECLARATION_CARACTERE('j');
                   1289:    DECLARATION_CARACTERE('k');
                   1290:    DECLARATION_CARACTERE('l');
                   1291:    DECLARATION_CARACTERE('m');
                   1292:    DECLARATION_CARACTERE('n');
                   1293:    DECLARATION_CARACTERE('o');
                   1294:    DECLARATION_CARACTERE('p');
                   1295:    DECLARATION_CARACTERE('q');
                   1296:    DECLARATION_CARACTERE('r');
                   1297:    DECLARATION_CARACTERE('s');
                   1298:    DECLARATION_CARACTERE('t');
                   1299:    DECLARATION_CARACTERE('u');
                   1300:    DECLARATION_CARACTERE('v');
                   1301:    DECLARATION_CARACTERE('w');
                   1302:    DECLARATION_CARACTERE('x');
                   1303:    DECLARATION_CARACTERE('y');
                   1304:    DECLARATION_CARACTERE('z');
                   1305: 
                   1306:    DECLARATION_CARACTERE('_');
                   1307: 
                   1308:    DECLARATION_CARACTERE('1');
                   1309:    DECLARATION_CARACTERE('2');
                   1310:    DECLARATION_CARACTERE('3');
                   1311:    DECLARATION_CARACTERE('4');
                   1312:    DECLARATION_CARACTERE('5');
                   1313:    DECLARATION_CARACTERE('6');
                   1314:    DECLARATION_CARACTERE('7');
                   1315:    DECLARATION_CARACTERE('8');
                   1316:    DECLARATION_CARACTERE('9');
                   1317:    DECLARATION_CARACTERE('0');
                   1318: #undef DECLARATION_CARACTERE
                   1319: 
                   1320:    return;
                   1321: }
1.25      bertrand 1322: 
1.1       bertrand 1323: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>