Annotation of rpl/src/instructions_x1.c, revision 1.15

1.1       bertrand    1: /*
                      2: ================================================================================
1.14      bertrand    3:   RPL/2 (R) version 4.0.20
1.15    ! 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.11      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Fonction 'xor'
                     29: ================================================================================
                     30:   Entrées : pointeur sur une structure struct_processus
                     31: --------------------------------------------------------------------------------
                     32:   Sorties :
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: void
                     39: instruction_xor(struct_processus *s_etat_processus)
                     40: {
                     41:    struct_liste_chainee        *l_element_courant;
                     42:    struct_liste_chainee        *l_element_precedent;
                     43: 
                     44:    struct_objet                *s_copie_argument_1;
                     45:    struct_objet                *s_copie_argument_2;
                     46:    struct_objet                *s_objet_argument_1;
                     47:    struct_objet                *s_objet_argument_2;
                     48:    struct_objet                *s_objet_resultat;
                     49: 
                     50:    unsigned long               nombre_elements;
                     51: 
                     52:    (*s_etat_processus).erreur_execution = d_ex;
                     53: 
                     54:    if ((*s_etat_processus).affichage_arguments == 'Y')
                     55:    {
                     56:        printf("\n  XOR ");
                     57: 
                     58:        if ((*s_etat_processus).langue == 'F')
                     59:        {
                     60:            printf("(opérateur ou exclusif)\n\n");
                     61:        }
                     62:        else
                     63:        {
                     64:            printf("(exclusive or operator)\n\n");
                     65:        }
                     66: 
                     67:        printf("    2: %s, %s\n", d_INT, d_REL);
                     68:        printf("    1: %s, %s\n", d_INT, d_REL);
                     69:        printf("->  1: %s\n\n", d_INT);
                     70: 
                     71:        printf("    2: %s\n", d_BIN);
                     72:        printf("    1: %s\n", d_BIN);
                     73:        printf("->  1: %s\n\n", d_BIN);
                     74: 
                     75:        printf("    2: %s\n", d_NOM);
                     76:        printf("    1: %s, %s, %s, %s\n", d_NOM, d_ALG, d_INT, d_REL);
                     77:        printf("->  1: %s\n\n", d_ALG);
                     78: 
                     79:        printf("    2: %s, %s, %s, %s\n", d_NOM, d_ALG, d_INT, d_REL);
                     80:        printf("    1: %s\n", d_NOM);
                     81:        printf("->  1: %s\n\n", d_ALG);
                     82: 
                     83:        printf("    2: %s\n", d_ALG);
                     84:        printf("    1: %s\n", d_ALG);
                     85:        printf("->  1: %s\n\n", d_ALG);
                     86: 
                     87:        printf("    2: %s\n", d_RPN);
                     88:        printf("    1: %s\n", d_RPN);
                     89:        printf("->  1: %s\n", d_RPN);
                     90: 
                     91:        return;
                     92:    }
                     93:    else if ((*s_etat_processus).test_instruction == 'Y')
                     94:    {
                     95:        (*s_etat_processus).nombre_arguments = 0;
                     96:        return;
                     97:    }
                     98:    
                     99:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    100:    {
                    101:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    102:        {
                    103:            return;
                    104:        }
                    105:    }
                    106: 
                    107:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    108:            &s_objet_argument_1) == d_erreur)
                    109:    {
                    110:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    111:        return;
                    112:    }
                    113: 
                    114:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    115:            &s_objet_argument_2) == d_erreur)
                    116:    {
                    117:        liberation(s_etat_processus, s_objet_argument_1);
                    118: 
                    119:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    120:        return;
                    121:    }
                    122: 
                    123: /*
                    124: --------------------------------------------------------------------------------
                    125:   XOR logique
                    126: --------------------------------------------------------------------------------
                    127: */
                    128: 
                    129:    if ((((*s_objet_argument_1).type == INT) ||
                    130:            ((*s_objet_argument_1).type == REL)) &&
                    131:            (((*s_objet_argument_2).type == INT) ||
                    132:            ((*s_objet_argument_2).type == REL)))
                    133:    {
                    134:        if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
                    135:        {
                    136:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    137:            return;
                    138:        }
                    139: 
                    140:        if ((*s_objet_argument_1).type == INT)
                    141:        {
                    142:            if ((*s_objet_argument_2).type == INT)
                    143:            {
                    144:                if ((((*((integer8 *) (*s_objet_argument_1).objet)) == 0) &&
                    145:                        ((*((integer8 *) (*s_objet_argument_2).objet)) != 0))
                    146:                        || (((*((integer8 *) (*s_objet_argument_1).objet))
                    147:                        != 0) && ((*((integer8 *) (*s_objet_argument_2).objet))
                    148:                        != 0)))
                    149:                {
                    150:                    (*((integer8 *) (*s_objet_resultat).objet)) = -1;
                    151:                }
                    152:                else
                    153:                {
                    154:                    (*((integer8 *) (*s_objet_resultat).objet)) = 0;
                    155:                }
                    156:            }
                    157:            else
                    158:            {
                    159:                if ((((*((integer8 *) (*s_objet_argument_1).objet)) == 0) &&
                    160:                        ((*((real8 *) (*s_objet_argument_2).objet)) != 0))
                    161:                        || (((*((integer8 *) (*s_objet_argument_1).objet))
                    162:                        != 0) && ((*((real8 *) (*s_objet_argument_2).objet))
                    163:                        != 0)))
                    164:                {
                    165:                    (*((integer8 *) (*s_objet_resultat).objet)) = -1;
                    166:                }
                    167:                else
                    168:                {
                    169:                    (*((integer8 *) (*s_objet_resultat).objet)) = 0;
                    170:                }
                    171:            }
                    172:        }
                    173:        else
                    174:        {
                    175:            if ((*s_objet_argument_2).type == INT)
                    176:            {
                    177:                if ((((*((real8 *) (*s_objet_argument_1).objet)) == 0) &&
                    178:                        ((*((integer8 *) (*s_objet_argument_2).objet)) != 0))
                    179:                        || (((*((real8 *) (*s_objet_argument_1).objet))
                    180:                        != 0) && ((*((integer8 *) (*s_objet_argument_2).objet))
                    181:                        != 0)))
                    182:                {
                    183:                    (*((integer8 *) (*s_objet_resultat).objet)) = -1;
                    184:                }
                    185:                else
                    186:                {
                    187:                    (*((integer8 *) (*s_objet_resultat).objet)) = 0;
                    188:                }
                    189:            }
                    190:            else
                    191:            {
                    192:                if ((((*((real8 *) (*s_objet_argument_1).objet)) == 0) &&
                    193:                        ((*((real8 *) (*s_objet_argument_2).objet)) != 0))
                    194:                        || (((*((real8 *) (*s_objet_argument_1).objet))
                    195:                        != 0) && ((*((real8 *) (*s_objet_argument_2).objet))
                    196:                        != 0)))
                    197:                {
                    198:                    (*((integer8 *) (*s_objet_resultat).objet)) = -1;
                    199:                }
                    200:                else
                    201:                {
                    202:                    (*((integer8 *) (*s_objet_resultat).objet)) = 0;
                    203:                }
                    204:            }
                    205:        }
                    206:    }
                    207: 
                    208: /*
                    209: --------------------------------------------------------------------------------
                    210:   XOR binaire
                    211: --------------------------------------------------------------------------------
                    212: */
                    213: 
                    214:    else if (((*s_objet_argument_1).type == BIN) &&
                    215:            ((*s_objet_argument_2).type == BIN))
                    216:    {
                    217:        if ((s_objet_resultat = allocation(s_etat_processus, BIN)) == NULL)
                    218:        {
                    219:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    220:            return;
                    221:        }
                    222: 
                    223:        (*((logical8 *) (*s_objet_resultat).objet)) = 
                    224:                (*((logical8 *) (*s_objet_argument_1).objet)) ^
                    225:                (*((logical8 *) (*s_objet_argument_2).objet));
                    226:    }
                    227: 
                    228: /*
                    229: --------------------------------------------------------------------------------
                    230:    XOR entre des arguments complexes
                    231: --------------------------------------------------------------------------------
                    232: */
                    233: 
                    234:    /*
                    235:     * Nom ou valeur numérique / Nom ou valeur numérique
                    236:     */
                    237: 
                    238:    else if ((((*s_objet_argument_1).type == NOM) &&
                    239:            (((*s_objet_argument_2).type == NOM) ||
                    240:            ((*s_objet_argument_2).type == INT) ||
                    241:            ((*s_objet_argument_2).type == REL))) ||
                    242:            (((*s_objet_argument_2).type == NOM) &&
                    243:            (((*s_objet_argument_1).type == INT) ||
                    244:            ((*s_objet_argument_1).type == REL))))
                    245:    {
                    246:        if ((s_objet_resultat = allocation(s_etat_processus, ALG)) == NULL)
                    247:        {
                    248:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    249:            return;
                    250:        }
                    251: 
                    252:        if (((*s_objet_resultat).objet =
                    253:                allocation_maillon(s_etat_processus)) == NULL)
                    254:        {
                    255:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    256:            return;
                    257:        }
                    258: 
                    259:        l_element_courant = (*s_objet_resultat).objet;
                    260: 
                    261:        if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
                    262:                == NULL)
                    263:        {
                    264:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    265:            return;
                    266:        }
                    267: 
                    268:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    269:                .nombre_arguments = 0;
                    270:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    271:                .fonction = instruction_vers_niveau_superieur;
                    272: 
                    273:        if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    274:                .nom_fonction = malloc(3 * sizeof(unsigned char))) == NULL)
                    275:        {
                    276:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    277:            return;
                    278:        }
                    279: 
                    280:        strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    281:                .nom_fonction, "<<");
                    282: 
                    283:        if (((*l_element_courant).suivant =
                    284:                allocation_maillon(s_etat_processus)) == NULL)
                    285:        {
                    286:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    287:            return;
                    288:        }
                    289: 
                    290:        l_element_courant = (*l_element_courant).suivant;
                    291:        (*l_element_courant).donnee = s_objet_argument_2;
                    292: 
                    293:        if (((*l_element_courant).suivant =
                    294:                allocation_maillon(s_etat_processus)) == NULL)
                    295:        {
                    296:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    297:            return;
                    298:        }
                    299: 
                    300:        l_element_courant = (*l_element_courant).suivant;
                    301:        (*l_element_courant).donnee = s_objet_argument_1;
                    302: 
                    303:        if (((*l_element_courant).suivant =
                    304:                allocation_maillon(s_etat_processus)) == NULL)
                    305:        {
                    306:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    307:            return;
                    308:        }
                    309: 
                    310:        l_element_courant = (*l_element_courant).suivant;
                    311: 
                    312:        if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
                    313:                == NULL)
                    314:        {
                    315:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    316:            return;
                    317:        }
                    318: 
                    319:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    320:                .nombre_arguments = 0;
                    321:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    322:                .fonction = instruction_xor;
                    323: 
                    324:        if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    325:                .nom_fonction = malloc(4 * sizeof(unsigned char))) == NULL)
                    326:        {
                    327:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    328:            return;
                    329:        }
                    330: 
                    331:        strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    332:                .nom_fonction, "XOR");
                    333: 
                    334:        if (((*l_element_courant).suivant =
                    335:                allocation_maillon(s_etat_processus)) == NULL)
                    336:        {
                    337:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    338:            return;
                    339:        }
                    340: 
                    341:        l_element_courant = (*l_element_courant).suivant;
                    342: 
                    343:        if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
                    344:                == NULL)
                    345:        {
                    346:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    347:            return;
                    348:        }
                    349: 
                    350:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    351:                .nombre_arguments = 0;
                    352:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    353:                .fonction = instruction_vers_niveau_inferieur;
                    354: 
                    355:        if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    356:                .nom_fonction = malloc(3 * sizeof(unsigned char))) == NULL)
                    357:        {
                    358:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    359:            return;
                    360:        }
                    361: 
                    362:        strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    363:                .nom_fonction, ">>");
                    364: 
                    365:        (*l_element_courant).suivant = NULL;
                    366: 
                    367:        s_objet_argument_1 = NULL;
                    368:        s_objet_argument_2 = NULL;
                    369:    }
                    370: 
                    371:    /*
                    372:     * Nom ou valeur numérique / Expression
                    373:     */
                    374: 
                    375:    else if ((((*s_objet_argument_1).type == ALG) ||
                    376:            ((*s_objet_argument_1).type == RPN)) &&
                    377:            (((*s_objet_argument_2).type == NOM) ||
                    378:            ((*s_objet_argument_2).type == INT) ||
                    379:            ((*s_objet_argument_2).type == REL)))
                    380:    {
                    381:        nombre_elements = 0;
                    382:        l_element_courant = (struct_liste_chainee *)
                    383:                (*s_objet_argument_1).objet;
                    384: 
                    385:        while(l_element_courant != NULL)
                    386:        {
                    387:            nombre_elements++;
                    388:            l_element_courant = (*l_element_courant).suivant;
                    389:        }
                    390: 
                    391:        if (nombre_elements == 2)
                    392:        {
                    393:            liberation(s_etat_processus, s_objet_argument_1);
                    394:            liberation(s_etat_processus, s_objet_argument_2);
                    395: 
                    396:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    397:            return;
                    398:        }
                    399: 
                    400:        if ((s_objet_resultat = copie_objet(s_etat_processus,
                    401:                s_objet_argument_1, 'N')) == NULL)
                    402:        {
                    403:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    404:            return;
                    405:        }
                    406: 
                    407:        l_element_courant = (struct_liste_chainee *)
                    408:                (*s_objet_resultat).objet;
                    409:        l_element_precedent = l_element_courant;
                    410:        l_element_courant = (*l_element_courant).suivant;
                    411: 
                    412:        if (((*l_element_precedent).suivant = (struct_liste_chainee *)
                    413:                allocation_maillon(s_etat_processus)) == NULL)
                    414:        {
                    415:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    416:            return;
                    417:        }
                    418: 
                    419:        (*(*l_element_precedent).suivant).donnee = s_objet_argument_2;
                    420:        (*(*l_element_precedent).suivant).suivant = l_element_courant;
                    421: 
                    422:        while((*l_element_courant).suivant != NULL)
                    423:        {
                    424:            l_element_precedent = l_element_courant;
                    425:            l_element_courant = (*l_element_courant).suivant;
                    426:        }
                    427: 
                    428:        if (((*l_element_precedent).suivant =
                    429:                allocation_maillon(s_etat_processus)) == NULL)
                    430:        {
                    431:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    432:            return;
                    433:        }
                    434: 
                    435:        if (((*(*l_element_precedent).suivant).donnee =
                    436:                allocation(s_etat_processus, FCT)) == NULL)
                    437:        {
                    438:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    439:            return;
                    440:        }
                    441: 
                    442:        (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
                    443:                .donnee).objet)).nombre_arguments = 0;
                    444:        (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
                    445:                .donnee).objet)).fonction = instruction_xor;
                    446: 
                    447:        if (((*((struct_fonction *) (*(*(*l_element_precedent)
                    448:                .suivant).donnee).objet)).nom_fonction =
                    449:                malloc(4 * sizeof(unsigned char))) == NULL)
                    450:        {
                    451:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    452:            return;
                    453:        }
                    454: 
                    455:        strcpy((*((struct_fonction *) (*(*(*l_element_precedent)
                    456:                .suivant).donnee).objet)).nom_fonction, "XOR");
                    457: 
                    458:        (*(*l_element_precedent).suivant).suivant = l_element_courant;
                    459: 
                    460:        s_objet_argument_2 = NULL;
                    461:    }
                    462: 
                    463:    /*
                    464:     * Expression / Nom ou valeur numérique
                    465:     */
                    466: 
                    467:    else if ((((*s_objet_argument_1).type == NOM) ||
                    468:            ((*s_objet_argument_1).type == INT) ||
                    469:            ((*s_objet_argument_1).type == REL)) &&
                    470:            (((*s_objet_argument_2).type == ALG) ||
                    471:            ((*s_objet_argument_2).type == RPN)))
                    472:    {
                    473:        nombre_elements = 0;
                    474:        l_element_courant = (struct_liste_chainee *)
                    475:                (*s_objet_argument_2).objet;
                    476: 
                    477:        while(l_element_courant != NULL)
                    478:        {
                    479:            nombre_elements++;
                    480:            l_element_courant = (*l_element_courant).suivant;
                    481:        }
                    482: 
                    483:        if (nombre_elements == 2)
                    484:        {
                    485:            liberation(s_etat_processus, s_objet_argument_1);
                    486:            liberation(s_etat_processus, s_objet_argument_2);
                    487: 
                    488:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    489:            return;
                    490:        }
                    491: 
                    492:        if ((s_objet_resultat = copie_objet(s_etat_processus,
                    493:                s_objet_argument_2, 'N')) == NULL)
                    494:        {
                    495:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    496:            return;
                    497:        }
                    498: 
                    499:        l_element_courant = (struct_liste_chainee *)
                    500:                (*s_objet_resultat).objet;
                    501:        l_element_precedent = l_element_courant;
                    502: 
                    503:        while((*l_element_courant).suivant != NULL)
                    504:        {
                    505:            l_element_precedent = l_element_courant;
                    506:            l_element_courant = (*l_element_courant).suivant;
                    507:        }
                    508: 
                    509:        if (((*l_element_precedent).suivant =
                    510:                allocation_maillon(s_etat_processus)) == NULL)
                    511:        {
                    512:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    513:            return;
                    514:        }
                    515: 
                    516:        (*(*l_element_precedent).suivant).donnee = s_objet_argument_1;
                    517:        l_element_precedent = (*l_element_precedent).suivant;
                    518: 
                    519:        if (((*l_element_precedent).suivant =
                    520:                allocation_maillon(s_etat_processus)) == NULL)
                    521:        {
                    522:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    523:            return;
                    524:        }
                    525: 
                    526:        if (((*(*l_element_precedent).suivant).donnee =
                    527:                allocation(s_etat_processus, FCT)) == NULL)
                    528:        {
                    529:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    530:            return;
                    531:        }
                    532: 
                    533:        (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
                    534:                .donnee).objet)).nombre_arguments = 0;
                    535:        (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
                    536:                .donnee).objet)).fonction = instruction_xor;
                    537: 
                    538:        if (((*((struct_fonction *) (*(*(*l_element_precedent)
                    539:                .suivant).donnee).objet)).nom_fonction =
                    540:                malloc(4 * sizeof(unsigned char))) == NULL)
                    541:        {
                    542:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    543:            return;
                    544:        }
                    545: 
                    546:        strcpy((*((struct_fonction *) (*(*(*l_element_precedent)
                    547:                .suivant).donnee).objet)).nom_fonction, "XOR");
                    548: 
                    549:        (*(*l_element_precedent).suivant).suivant = l_element_courant;
                    550: 
                    551:        s_objet_argument_1 = NULL;
                    552:    }
                    553: 
                    554:    /*
                    555:     * Expression / Expression
                    556:     */
                    557: 
                    558:    else if ((((*s_objet_argument_1).type == ALG) &&
                    559:            ((*s_objet_argument_2).type == ALG)) ||
                    560:            (((*s_objet_argument_1).type == RPN) &&
                    561:            ((*s_objet_argument_2).type == RPN)))
                    562:    {
                    563:        nombre_elements = 0;
                    564:        l_element_courant = (struct_liste_chainee *)
                    565:                (*s_objet_argument_1).objet;
                    566: 
                    567:        while(l_element_courant != NULL)
                    568:        {
                    569:            nombre_elements++;
                    570:            l_element_courant = (*l_element_courant).suivant;
                    571:        }
                    572: 
                    573:        if (nombre_elements == 2)
                    574:        {
                    575:            liberation(s_etat_processus, s_objet_argument_1);
                    576:            liberation(s_etat_processus, s_objet_argument_2);
                    577: 
                    578:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    579:            return;
                    580:        }
                    581: 
                    582:        nombre_elements = 0;
                    583:        l_element_courant = (struct_liste_chainee *)
                    584:                (*s_objet_argument_2).objet;
                    585: 
                    586:        while(l_element_courant != NULL)
                    587:        {
                    588:            nombre_elements++;
                    589:            l_element_courant = (*l_element_courant).suivant;
                    590:        }
                    591: 
                    592:        if (nombre_elements == 2)
                    593:        {
                    594:            liberation(s_etat_processus, s_objet_argument_1);
                    595:            liberation(s_etat_processus, s_objet_argument_2);
                    596: 
                    597:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    598:            return;
                    599:        }
                    600: 
                    601:        if ((s_copie_argument_1 = copie_objet(s_etat_processus,
                    602:                s_objet_argument_1, 'N')) == NULL)
                    603:        {
                    604:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    605:            return;
                    606:        }
                    607: 
                    608:        if ((s_copie_argument_2 = copie_objet(s_etat_processus,
                    609:                s_objet_argument_2, 'N')) == NULL)
                    610:        {
                    611:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    612:            return;
                    613:        }
                    614: 
                    615:        l_element_courant = (struct_liste_chainee *)
                    616:                (*s_copie_argument_1).objet;
                    617:        (*s_copie_argument_1).objet = (void *) (*((struct_liste_chainee *)
                    618:                (*s_copie_argument_1).objet)).suivant;
                    619: 
                    620:        liberation(s_etat_processus, (*l_element_courant).donnee);
                    621:        free(l_element_courant);
                    622: 
                    623:        l_element_courant = (struct_liste_chainee *)
                    624:                (*s_copie_argument_2).objet;
                    625:        l_element_precedent = l_element_courant;
                    626:        s_objet_resultat = s_copie_argument_2;
                    627: 
                    628:        while((*l_element_courant).suivant != NULL)
                    629:        {
                    630:            l_element_precedent = l_element_courant;
                    631:            l_element_courant = (*l_element_courant).suivant;
                    632:        }
                    633: 
                    634:        liberation(s_etat_processus, (*l_element_courant).donnee);
                    635:        free(l_element_courant);
                    636: 
                    637:        (*l_element_precedent).suivant = (struct_liste_chainee *)
                    638:                (*s_copie_argument_1).objet;
                    639:        free(s_copie_argument_1);
                    640: 
                    641:        l_element_courant = (*l_element_precedent).suivant;
                    642:        while((*l_element_courant).suivant != NULL)
                    643:        {
                    644:            l_element_precedent = l_element_courant;
                    645:            l_element_courant = (*l_element_courant).suivant;
                    646:        }
                    647: 
                    648:        if (((*l_element_precedent).suivant =
                    649:                allocation_maillon(s_etat_processus)) == NULL)
                    650:        {
                    651:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    652:            return;
                    653:        }
                    654: 
                    655:        (*(*l_element_precedent).suivant).suivant = l_element_courant;
                    656:        l_element_courant = (*l_element_precedent).suivant;
                    657: 
                    658:        if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
                    659:                == NULL)
                    660:        {
                    661:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    662:            return;
                    663:        }
                    664: 
                    665:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    666:                .nombre_arguments = 0;
                    667:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    668:                .fonction = instruction_xor;
                    669: 
                    670:        if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    671:                .nom_fonction = malloc(4 * sizeof(unsigned char))) == NULL)
                    672:        {
                    673:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    674:            return;
                    675:        }
                    676: 
                    677:        strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    678:                .nom_fonction, "XOR");
                    679:    }
                    680: 
                    681: /*
                    682: --------------------------------------------------------------------------------
                    683:   XOR impossible
                    684: --------------------------------------------------------------------------------
                    685: */
                    686: 
                    687:    else
                    688:    {
                    689:        liberation(s_etat_processus, s_objet_argument_1);
                    690:        liberation(s_etat_processus, s_objet_argument_2);
                    691: 
                    692:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    693:        return;
                    694:    }
                    695: 
                    696:    liberation(s_etat_processus, s_objet_argument_1);
                    697:    liberation(s_etat_processus, s_objet_argument_2);
                    698: 
                    699:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    700:            s_objet_resultat) == d_erreur)
                    701:    {
                    702:        return;
                    703:    }
                    704: 
                    705:    return;
                    706: }
                    707: 
                    708: 
                    709: /*
                    710: ================================================================================
                    711:   Fonction 'xpon'
                    712: ================================================================================
                    713:   Entrées :
                    714: --------------------------------------------------------------------------------
                    715:   Sorties :
                    716: --------------------------------------------------------------------------------
                    717:   Effets de bord : néant
                    718: ================================================================================
                    719: */
                    720: 
                    721: void
                    722: instruction_xpon(struct_processus *s_etat_processus)
                    723: {
                    724:    struct_liste_chainee                *l_element_courant;
                    725:    struct_liste_chainee                *l_element_precedent;
                    726: 
                    727:    struct_objet                        *s_copie_argument;
                    728:    struct_objet                        *s_objet_argument;
                    729:    struct_objet                        *s_objet_resultat;
                    730: 
                    731:    (*s_etat_processus).erreur_execution = d_ex;
                    732: 
                    733:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    734:    {
                    735:        printf("\n  XPON ");
                    736: 
                    737:        if ((*s_etat_processus).langue == 'F')
                    738:        {
                    739:            printf("(exposant)\n\n");
                    740:        }
                    741:        else
                    742:        {
                    743:            printf("(exponant)\n\n");
                    744:        }
                    745: 
                    746:        printf("    1: %s, %s\n", d_INT, d_REL);
                    747:        printf("->  1: %s\n\n", d_INT);
                    748: 
                    749:        printf("    1: %s, %s\n", d_NOM, d_ALG);
                    750:        printf("->  1: %s\n\n", d_ALG);
                    751: 
                    752:        printf("    1: %s\n", d_RPN);
                    753:        printf("->  1: %s\n", d_RPN);
                    754: 
                    755:        return;
                    756:    }
                    757:    else if ((*s_etat_processus).test_instruction == 'Y')
                    758:    {
                    759:        (*s_etat_processus).nombre_arguments = 1;
                    760:        return;
                    761:    }
                    762:    
                    763:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    764:    {
                    765:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    766:        {
                    767:            return;
                    768:        }
                    769:    }
                    770: 
                    771:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    772:            &s_objet_argument) == d_erreur)
                    773:    {
                    774:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    775:        return;
                    776:    }
                    777: 
                    778: /*
                    779: --------------------------------------------------------------------------------
                    780:   Exposant d'un entier
                    781: --------------------------------------------------------------------------------
                    782: */
                    783: 
                    784:    if ((*s_objet_argument).type == INT)
                    785:    {
                    786:        if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
                    787:        {
                    788:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    789:            return;
                    790:        }
                    791: 
                    792:        (*((integer8 *) (*s_objet_resultat).objet)) = (integer8)
                    793:                floor(log10((*((integer8 *) (*s_objet_argument).objet))));
                    794:    }
                    795: 
                    796: /*
                    797: --------------------------------------------------------------------------------
                    798:   Exposant d'un réel
                    799: --------------------------------------------------------------------------------
                    800: */
                    801: 
                    802:    else if ((*s_objet_argument).type == REL)
                    803:    {
                    804:        if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
                    805:        {
                    806:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    807:            return;
                    808:        }
                    809: 
                    810:        (*((integer8 *) (*s_objet_resultat).objet)) = (integer8)
                    811:                floor(log10((*((real8 *) (*s_objet_argument).objet))));
                    812:    }
                    813: 
                    814: /*
                    815: --------------------------------------------------------------------------------
                    816:   Exposant d'un nom
                    817: --------------------------------------------------------------------------------
                    818: */
                    819: 
                    820:    else if ((*s_objet_argument).type == NOM)
                    821:    {
                    822:        if ((s_objet_resultat = allocation(s_etat_processus, ALG)) == NULL)
                    823:        {
                    824:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    825:            return;
                    826:        }
                    827: 
                    828:        if (((*s_objet_resultat).objet =
                    829:                allocation_maillon(s_etat_processus)) == NULL)
                    830:        {
                    831:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    832:            return;
                    833:        }
                    834: 
                    835:        l_element_courant = (*s_objet_resultat).objet;
                    836: 
                    837:        if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
                    838:                == NULL)
                    839:        {
                    840:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    841:            return;
                    842:        }
                    843: 
                    844:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    845:                .nombre_arguments = 0;
                    846:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    847:                .fonction = instruction_vers_niveau_superieur;
                    848: 
                    849:        if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    850:                .nom_fonction = malloc(3 * sizeof(unsigned char))) == NULL)
                    851:        {
                    852:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    853:            return;
                    854:        }
                    855: 
                    856:        strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    857:                .nom_fonction, "<<");
                    858: 
                    859:        if (((*l_element_courant).suivant =
                    860:                allocation_maillon(s_etat_processus)) == NULL)
                    861:        {
                    862:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    863:            return;
                    864:        }
                    865: 
                    866:        l_element_courant = (*l_element_courant).suivant;
                    867:        (*l_element_courant).donnee = s_objet_argument;
                    868: 
                    869:        if (((*l_element_courant).suivant =
                    870:                allocation_maillon(s_etat_processus)) == NULL)
                    871:        {
                    872:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    873:            return;
                    874:        }
                    875: 
                    876:        l_element_courant = (*l_element_courant).suivant;
                    877: 
                    878:        if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
                    879:                == NULL)
                    880:        {
                    881:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    882:            return;
                    883:        }
                    884: 
                    885:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    886:                .nombre_arguments = 1;
                    887:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    888:                .fonction = instruction_xpon;
                    889: 
                    890:        if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    891:                .nom_fonction = malloc(5 * sizeof(unsigned char))) == NULL)
                    892:        {
                    893:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    894:            return;
                    895:        }
                    896: 
                    897:        strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    898:                .nom_fonction, "XPON");
                    899: 
                    900:        if (((*l_element_courant).suivant =
                    901:                allocation_maillon(s_etat_processus)) == NULL)
                    902:        {
                    903:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    904:            return;
                    905:        }
                    906: 
                    907:        l_element_courant = (*l_element_courant).suivant;
                    908: 
                    909:        if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
                    910:                == NULL)
                    911:        {
                    912:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    913:            return;
                    914:        }
                    915: 
                    916:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    917:                .nombre_arguments = 0;
                    918:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    919:                .fonction = instruction_vers_niveau_inferieur;
                    920: 
                    921:        if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    922:                .nom_fonction = malloc(3 *
                    923:                sizeof(unsigned char))) == NULL)
                    924:        {
                    925:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    926:            return;
                    927:        }
                    928: 
                    929:        strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    930:                .nom_fonction, ">>");
                    931: 
                    932:        (*l_element_courant).suivant = NULL;
                    933:        s_objet_argument = NULL;
                    934:    }
                    935: 
                    936: /*
                    937: --------------------------------------------------------------------------------
                    938:   Exposant d'une expression
                    939: --------------------------------------------------------------------------------
                    940: */
                    941: 
                    942:    else if (((*s_objet_argument).type == ALG) ||
                    943:            ((*s_objet_argument).type == RPN))
                    944:    {
                    945:        if ((s_copie_argument = copie_objet(s_etat_processus, s_objet_argument,
                    946:                'N')) == NULL)
                    947:        {
                    948:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    949:            return;
                    950:        }
                    951: 
                    952:        l_element_courant = (struct_liste_chainee *)
                    953:                (*s_copie_argument).objet;
                    954:        l_element_precedent = l_element_courant;
                    955: 
                    956:        while((*l_element_courant).suivant != NULL)
                    957:        {
                    958:            l_element_precedent = l_element_courant;
                    959:            l_element_courant = (*l_element_courant).suivant;
                    960:        }
                    961: 
                    962:        if (((*l_element_precedent).suivant =
                    963:                allocation_maillon(s_etat_processus)) == NULL)
                    964:        {
                    965:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    966:            return;
                    967:        }
                    968: 
                    969:        if (((*(*l_element_precedent).suivant).donnee =
                    970:                allocation(s_etat_processus, FCT)) == NULL)
                    971:        {
                    972:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    973:            return;
                    974:        }
                    975: 
                    976:        (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
                    977:                .donnee).objet)).nombre_arguments = 1;
                    978:        (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
                    979:                .donnee).objet)).fonction = instruction_xpon;
                    980: 
                    981:        if (((*((struct_fonction *) (*(*(*l_element_precedent)
                    982:                .suivant).donnee).objet)).nom_fonction =
                    983:                malloc(5 * sizeof(unsigned char))) == NULL)
                    984:        {
                    985:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    986:            return;
                    987:        }
                    988: 
                    989:        strcpy((*((struct_fonction *) (*(*(*l_element_precedent)
                    990:                .suivant).donnee).objet)).nom_fonction, "XPON");
                    991: 
                    992:        (*(*l_element_precedent).suivant).suivant = l_element_courant;
                    993: 
                    994:        s_objet_resultat = s_copie_argument;
                    995:    }
                    996: 
                    997: /*
                    998: --------------------------------------------------------------------------------
                    999:   Fonction exposant impossible à réaliser
                   1000: --------------------------------------------------------------------------------
                   1001: */
                   1002: 
                   1003:    else
                   1004:    {
                   1005:        liberation(s_etat_processus, s_objet_argument);
                   1006: 
                   1007:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1008:        return;
                   1009:    }
                   1010: 
                   1011:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1012:            s_objet_resultat) == d_erreur)
                   1013:    {
                   1014:        return;
                   1015:    }
                   1016: 
                   1017:    liberation(s_etat_processus, s_objet_argument);
                   1018: 
                   1019:    return;
                   1020: }
                   1021: 
                   1022: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>