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

CVSweb interface <joel.bertrand@systella.fr>