File:  [local] / rpl / src / instructions_l6.c
Revision 1.15: download - view: text, annotated - select for diffs - revision graph
Wed Feb 27 17:11:42 2013 UTC (11 years, 2 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
En route pour la 4.1.13.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.13
    4:   Copyright (C) 1989-2013 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: #define DEBUG_ERREURS
   24: #include "rpl-conv.h"
   25: 
   26: 
   27: /*
   28: ================================================================================
   29:   Fonction 'limit'
   30: ================================================================================
   31:   Entrées : pointeur sur une struct_processus
   32: --------------------------------------------------------------------------------
   33:   Sorties :
   34: --------------------------------------------------------------------------------
   35:   Effets de bord : néant
   36: ================================================================================
   37: */
   38: 
   39: void
   40: instruction_limit(struct_processus *s_etat_processus)
   41: {
   42:     struct_liste_chainee        *l_element_courant;
   43: 
   44:     struct_objet                *s_objet_argument_1;
   45:     struct_objet                *s_objet_argument_2;
   46: 
   47:     (*s_etat_processus).erreur_execution = d_ex;
   48: 
   49:     if ((*s_etat_processus).affichage_arguments == 'Y')
   50:     {
   51:         printf("\n  LIMIT ");
   52: 
   53:         if ((*s_etat_processus).langue == 'F')
   54:         {
   55:             printf("(limite d'une fonction)\n\n");
   56:         }
   57:         else
   58:         {
   59:             printf("(function limit)\n\n");
   60:         }
   61: 
   62:         printf("    2: %s, %s, %s, %s\n", d_INT, d_REL, d_NOM, d_ALG);
   63:         printf("    1: %s\n", d_LST);
   64:         printf("->  1: %s, %s, %s, %s\n\n", d_INT, d_REL, d_NOM, d_ALG);
   65: 
   66:         if ((*s_etat_processus).langue == 'F')
   67:         {
   68:             printf("  Utilisation :\n\n");
   69:         }
   70:         else
   71:         {
   72:             printf("  Usage:\n\n");
   73:         }
   74: 
   75:         printf("    'SIN(X)/X' { 'X' 0 } LIMIT\n");
   76:         printf("    '1/X' { 'X' 0 + } LIMIT\n");
   77:         printf("    'SQRT(X+SQRT(X+SQRT(X)))-SQRT(X)' { 'X' '+infinity' } "
   78:                 "LIMIT\n");
   79:         return;
   80:     }
   81:     else if ((*s_etat_processus).test_instruction == 'Y')
   82:     {
   83:         (*s_etat_processus).nombre_arguments = -1;
   84:         return;
   85:     }
   86: 
   87:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
   88:     {
   89:         if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
   90:         {
   91:             return;
   92:         }
   93:     }
   94: 
   95:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
   96:             &s_objet_argument_1) == d_erreur)
   97:     {
   98:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
   99:         return;
  100:     }
  101: 
  102:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  103:             &s_objet_argument_2) == d_erreur)
  104:     {
  105:         liberation(s_etat_processus, s_objet_argument_1);
  106: 
  107:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  108:         return;
  109:     }
  110: 
  111:     if (((*s_objet_argument_1).type == LST) &&
  112:             (((*s_objet_argument_2).type == NOM) ||
  113:             ((*s_objet_argument_2).type == ALG) ||
  114:             ((*s_objet_argument_2).type == REL) ||
  115:             ((*s_objet_argument_2).type == INT)))
  116:     {
  117:         l_element_courant = (*s_objet_argument_1).objet;
  118: 
  119:         if (l_element_courant == NULL)
  120:         {
  121:             liberation(s_etat_processus, s_objet_argument_1);
  122:             liberation(s_etat_processus, s_objet_argument_2);
  123: 
  124:             (*s_etat_processus).erreur_execution =
  125:                     d_ex_erreur_type_argument;
  126:             return;
  127:         }
  128: 
  129:         if ((*(*l_element_courant).donnee).type != NOM)
  130:         {
  131:             liberation(s_etat_processus, s_objet_argument_1);
  132:             liberation(s_etat_processus, s_objet_argument_2);
  133: 
  134:             (*s_etat_processus).erreur_execution =
  135:                     d_ex_erreur_type_argument;
  136:             return;
  137:         }
  138: 
  139:         l_element_courant = (*l_element_courant).suivant;
  140: 
  141:         if (l_element_courant == NULL)
  142:         {
  143:             liberation(s_etat_processus, s_objet_argument_1);
  144:             liberation(s_etat_processus, s_objet_argument_2);
  145: 
  146:             (*s_etat_processus).erreur_execution =
  147:                     d_ex_erreur_type_argument;
  148:             return;
  149:         }
  150: 
  151:         if (((*(*l_element_courant).donnee).type != INT) &&
  152:                 ((*(*l_element_courant).donnee).type != REL) &&
  153:                 ((*(*l_element_courant).donnee).type != NOM) &&
  154:                 ((*(*l_element_courant).donnee).type != ALG))
  155:         {
  156:             liberation(s_etat_processus, s_objet_argument_1);
  157:             liberation(s_etat_processus, s_objet_argument_2);
  158: 
  159:             (*s_etat_processus).erreur_execution =
  160:                     d_ex_erreur_type_argument;
  161:             return;
  162:         }
  163: 
  164:         l_element_courant = (*l_element_courant).suivant;
  165: 
  166:         if (l_element_courant != NULL)
  167:         {
  168:             // S'il y a un troisième argument, il ne peut être
  169:             // que + ou -.
  170: 
  171:             if ((*(*l_element_courant).donnee).type != FCT)
  172:             {
  173:                 liberation(s_etat_processus, s_objet_argument_1);
  174:                 liberation(s_etat_processus, s_objet_argument_2);
  175: 
  176:                 (*s_etat_processus).erreur_execution =
  177:                         d_ex_erreur_type_argument;
  178:                 return;
  179:             }
  180: 
  181:             if ((strcmp((*((struct_fonction *) (*(*l_element_courant).donnee)
  182:                     .objet)).nom_fonction, "-") != 0) &&
  183:                     (strcmp((*((struct_fonction *) (*(*l_element_courant)
  184:                     .donnee).objet)).nom_fonction, "+") != 0))
  185:             {
  186:                 liberation(s_etat_processus, s_objet_argument_1);
  187:                 liberation(s_etat_processus, s_objet_argument_2);
  188: 
  189:                 (*s_etat_processus).erreur_execution =
  190:                         d_ex_argument_invalide;
  191:                 return;
  192:             }
  193: 
  194:             if ((*l_element_courant).suivant != NULL)
  195:             {
  196:                 liberation(s_etat_processus, s_objet_argument_1);
  197:                 liberation(s_etat_processus, s_objet_argument_2);
  198: 
  199:                 (*s_etat_processus).erreur_execution =
  200:                         d_ex_erreur_type_argument;
  201:                 return;
  202:             }
  203:         }
  204: 
  205:         if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  206:                 s_objet_argument_2) == d_erreur)
  207:         {
  208:             return;
  209:         }
  210: 
  211:         if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  212:                 s_objet_argument_1) == d_erreur)
  213:         {
  214:             return;
  215:         }
  216: 
  217:         interface_cas(s_etat_processus, RPLCAS_LIMITE);
  218:     }
  219:     else
  220:     {
  221:         liberation(s_etat_processus, s_objet_argument_1);
  222:         liberation(s_etat_processus, s_objet_argument_2);
  223: 
  224:         (*s_etat_processus).erreur_execution =
  225:                 d_ex_erreur_type_argument;
  226:         return;
  227:     }
  228: 
  229:         return;
  230: }

CVSweb interface <joel.bertrand@systella.fr>