File:  [local] / rpl / src / instructions_x1.c
Revision 1.66: download - view: text, annotated - select for diffs - revision graph
Fri Jan 10 11:15:49 2020 UTC (4 years, 2 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_32, HEAD
Modification du copyright.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.32
    4:   Copyright (C) 1989-2020 Dr. BERTRAND Joël
    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: 
   23: #include "rpl-conv.h"
   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:     integer8                    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((real8) (*((integer8 *)
  794:                 (*s_objet_argument).objet))));
  795:     }
  796: 
  797: /*
  798: --------------------------------------------------------------------------------
  799:   Exposant d'un réel
  800: --------------------------------------------------------------------------------
  801: */
  802: 
  803:     else if ((*s_objet_argument).type == REL)
  804:     {
  805:         if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
  806:         {
  807:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  808:             return;
  809:         }
  810: 
  811:         (*((integer8 *) (*s_objet_resultat).objet)) = (integer8)
  812:                 floor(log10((*((real8 *) (*s_objet_argument).objet))));
  813:     }
  814: 
  815: /*
  816: --------------------------------------------------------------------------------
  817:   Exposant d'un nom
  818: --------------------------------------------------------------------------------
  819: */
  820: 
  821:     else if ((*s_objet_argument).type == NOM)
  822:     {
  823:         if ((s_objet_resultat = allocation(s_etat_processus, ALG)) == NULL)
  824:         {
  825:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  826:             return;
  827:         }
  828: 
  829:         if (((*s_objet_resultat).objet =
  830:                 allocation_maillon(s_etat_processus)) == NULL)
  831:         {
  832:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  833:             return;
  834:         }
  835: 
  836:         l_element_courant = (*s_objet_resultat).objet;
  837: 
  838:         if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
  839:                 == NULL)
  840:         {
  841:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  842:             return;
  843:         }
  844: 
  845:         (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  846:                 .nombre_arguments = 0;
  847:         (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  848:                 .fonction = instruction_vers_niveau_superieur;
  849: 
  850:         if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  851:                 .nom_fonction = malloc(3 * sizeof(unsigned char))) == NULL)
  852:         {
  853:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  854:             return;
  855:         }
  856: 
  857:         strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  858:                 .nom_fonction, "<<");
  859: 
  860:         if (((*l_element_courant).suivant =
  861:                 allocation_maillon(s_etat_processus)) == NULL)
  862:         {
  863:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  864:             return;
  865:         }
  866: 
  867:         l_element_courant = (*l_element_courant).suivant;
  868:         (*l_element_courant).donnee = s_objet_argument;
  869: 
  870:         if (((*l_element_courant).suivant =
  871:                 allocation_maillon(s_etat_processus)) == NULL)
  872:         {
  873:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  874:             return;
  875:         }
  876: 
  877:         l_element_courant = (*l_element_courant).suivant;
  878: 
  879:         if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
  880:                 == NULL)
  881:         {
  882:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  883:             return;
  884:         }
  885: 
  886:         (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  887:                 .nombre_arguments = 1;
  888:         (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  889:                 .fonction = instruction_xpon;
  890: 
  891:         if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  892:                 .nom_fonction = malloc(5 * sizeof(unsigned char))) == NULL)
  893:         {
  894:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  895:             return;
  896:         }
  897: 
  898:         strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  899:                 .nom_fonction, "XPON");
  900: 
  901:         if (((*l_element_courant).suivant =
  902:                 allocation_maillon(s_etat_processus)) == NULL)
  903:         {
  904:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  905:             return;
  906:         }
  907: 
  908:         l_element_courant = (*l_element_courant).suivant;
  909: 
  910:         if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
  911:                 == NULL)
  912:         {
  913:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  914:             return;
  915:         }
  916: 
  917:         (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  918:                 .nombre_arguments = 0;
  919:         (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  920:                 .fonction = instruction_vers_niveau_inferieur;
  921: 
  922:         if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  923:                 .nom_fonction = malloc(3 *
  924:                 sizeof(unsigned char))) == NULL)
  925:         {
  926:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  927:             return;
  928:         }
  929: 
  930:         strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
  931:                 .nom_fonction, ">>");
  932: 
  933:         (*l_element_courant).suivant = NULL;
  934:         s_objet_argument = NULL;
  935:     }
  936: 
  937: /*
  938: --------------------------------------------------------------------------------
  939:   Exposant d'une expression
  940: --------------------------------------------------------------------------------
  941: */
  942: 
  943:     else if (((*s_objet_argument).type == ALG) ||
  944:             ((*s_objet_argument).type == RPN))
  945:     {
  946:         if ((s_copie_argument = copie_objet(s_etat_processus, s_objet_argument,
  947:                 'N')) == NULL)
  948:         {
  949:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  950:             return;
  951:         }
  952: 
  953:         l_element_courant = (struct_liste_chainee *)
  954:                 (*s_copie_argument).objet;
  955:         l_element_precedent = l_element_courant;
  956: 
  957:         while((*l_element_courant).suivant != NULL)
  958:         {
  959:             l_element_precedent = l_element_courant;
  960:             l_element_courant = (*l_element_courant).suivant;
  961:         }
  962: 
  963:         if (((*l_element_precedent).suivant =
  964:                 allocation_maillon(s_etat_processus)) == NULL)
  965:         {
  966:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  967:             return;
  968:         }
  969: 
  970:         if (((*(*l_element_precedent).suivant).donnee =
  971:                 allocation(s_etat_processus, FCT)) == NULL)
  972:         {
  973:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  974:             return;
  975:         }
  976: 
  977:         (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
  978:                 .donnee).objet)).nombre_arguments = 1;
  979:         (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
  980:                 .donnee).objet)).fonction = instruction_xpon;
  981: 
  982:         if (((*((struct_fonction *) (*(*(*l_element_precedent)
  983:                 .suivant).donnee).objet)).nom_fonction =
  984:                 malloc(5 * sizeof(unsigned char))) == NULL)
  985:         {
  986:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  987:             return;
  988:         }
  989: 
  990:         strcpy((*((struct_fonction *) (*(*(*l_element_precedent)
  991:                 .suivant).donnee).objet)).nom_fonction, "XPON");
  992: 
  993:         (*(*l_element_precedent).suivant).suivant = l_element_courant;
  994: 
  995:         s_objet_resultat = s_copie_argument;
  996:     }
  997: 
  998: /*
  999: --------------------------------------------------------------------------------
 1000:   Fonction exposant impossible à réaliser
 1001: --------------------------------------------------------------------------------
 1002: */
 1003: 
 1004:     else
 1005:     {
 1006:         liberation(s_etat_processus, s_objet_argument);
 1007: 
 1008:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1009:         return;
 1010:     }
 1011: 
 1012:     if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1013:             s_objet_resultat) == d_erreur)
 1014:     {
 1015:         return;
 1016:     }
 1017: 
 1018:     liberation(s_etat_processus, s_objet_argument);
 1019: 
 1020:     return;
 1021: }
 1022: 
 1023: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>