File:  [local] / rpl / src / instructions_r7.c
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Thu Dec 1 15:23:49 2011 UTC (12 years, 5 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Ajout de la fonction REGEX.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.5
    4:   Copyright (C) 1989-2011 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 'restart'
   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_restart(struct_processus *s_etat_processus)
   40: {
   41:     struct timespec                     attente;
   42: 
   43:     (*s_etat_processus).erreur_execution = d_ex;
   44: 
   45:     if ((*s_etat_processus).affichage_arguments == 'Y')
   46:     {
   47:         printf("\n  RESTART ");
   48: 
   49:         if ((*s_etat_processus).langue == 'F')
   50:         {
   51:             printf("(réinitialisation du programme)\n\n");
   52:             printf("  Aucun argument\n");
   53:         }
   54:         else
   55:         {
   56:             printf("(program reinitialization)\n\n");
   57:             printf("  No argument\n");
   58:         }
   59: 
   60:         return;
   61:     }
   62:     else if ((*s_etat_processus).test_instruction == 'Y')
   63:     {
   64:         (*s_etat_processus).nombre_arguments = -1;
   65:         return;
   66:     }
   67:     
   68:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
   69:     {
   70:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
   71:         {
   72:             return;
   73:         }
   74:     }
   75: 
   76:     envoi_signal_processus((*s_etat_processus).pid_processus_pere,
   77:             rpl_sigabort);
   78:     (*s_etat_processus).requete_arret = 'Y';
   79: 
   80:     attente.tv_sec = 0;
   81:     attente.tv_nsec = GRANULARITE_us * 1000;
   82: 
   83:     while((*s_etat_processus).var_volatile_requete_arret == 0)
   84:     {
   85:         scrutation_interruptions(s_etat_processus);
   86:         nanosleep(&attente, NULL);
   87:         INCR_GRANULARITE(attente.tv_nsec);
   88:     }
   89: 
   90:     if ((*s_etat_processus).traitement_instruction_halt == d_vrai)
   91:     {
   92:         (*s_etat_processus).execution_pas_suivant = d_vrai;
   93:     }
   94: 
   95:     (*s_etat_processus).requete_redemarrage = d_vrai;
   96:     return;
   97: }
   98: 
   99: 
  100: /*
  101: ================================================================================
  102:   Fonction 'regex'
  103: ================================================================================
  104:   Entrées : pointeur sur une structure struct_processus
  105: --------------------------------------------------------------------------------
  106:   Sorties :
  107: --------------------------------------------------------------------------------
  108:   Effets de bord : néant
  109: ================================================================================
  110: */
  111: 
  112: void
  113: instruction_regex(struct_processus *s_etat_processus)
  114: {
  115:     regex_t                         expression;
  116: 
  117:     struct_liste_chainee            *l_element_courant_ecriture;
  118:     struct_liste_chainee            *l_element_courant_lecture;
  119: 
  120:     struct_objet                    *s_objet_argument_1;
  121:     struct_objet                    *s_objet_argument_2;
  122:     struct_objet                    *s_objet_resultat;
  123: 
  124:     (*s_etat_processus).erreur_execution = d_ex;
  125: 
  126:     if ((*s_etat_processus).affichage_arguments == 'Y')
  127:     {
  128:         printf("\n  REGEX ");
  129: 
  130:         if ((*s_etat_processus).langue == 'F')
  131:         {
  132:             printf("(expression régulière)\n\n");
  133:         }
  134:         else
  135:         {
  136:             printf("(regular expression)\n\n");
  137:         }
  138: 
  139:         printf("    1: %s, %s\n", d_LST);
  140:         printf("->  1: %s\n\n", d_LST);
  141: 
  142:         printf("    1: %s\n", d_CHN);
  143:         printf("->  1: %s (0 or -1)\n", d_INT);
  144: 
  145:         return;
  146:     }
  147:     else if ((*s_etat_processus).test_instruction == 'Y')
  148:     {
  149:         (*s_etat_processus).nombre_arguments = 2;
  150:         return;
  151:     }
  152: 
  153:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  154:     {
  155:         if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
  156:         {
  157:             return;
  158:         }
  159:     }
  160: 
  161:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  162:             &s_objet_argument_1) == d_erreur)
  163:     {
  164:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  165:         return;
  166:     }
  167: 
  168:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  169:             &s_objet_argument_2) == d_erreur)
  170:     {
  171:         liberation(s_etat_processus, s_objet_argument_1);
  172: 
  173:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  174:         return;
  175:     }
  176: 
  177:     if (((*s_objet_argument_1).type == CHN) &&
  178:             ((*s_objet_argument_2).type == CHN))
  179:     {
  180:         // Renvoie 0 ou -1
  181: 
  182:         if (regcomp(&expression, (const char *) (*s_objet_argument_1).objet,
  183:                 REG_EXTENDED | REG_NOSUB) != 0)
  184:         {
  185:             liberation(s_etat_processus, s_objet_argument_1);
  186:             liberation(s_etat_processus, s_objet_argument_2);
  187: 
  188:             (*s_etat_processus).erreur_execution = d_ex_expression_reguliere;
  189:             return;
  190:         }
  191: 
  192:         if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
  193:         {
  194:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  195:             return;
  196:         }
  197: 
  198:         if (regexec(&expression, (const char *) (*s_objet_argument_1).objet,
  199:                 0, NULL, 0) == 0)
  200:         {
  201:             (*((integer8 *) (*s_objet_resultat).objet)) = -1;
  202:         }
  203:         else // REG_NOMATCH
  204:         {
  205:             (*((integer8 *) (*s_objet_resultat).objet)) = 0;
  206:         }
  207: 
  208:         regfree(&expression);
  209:     }
  210:     else if (((*s_objet_argument_1).type == CHN) &&
  211:             ((*s_objet_argument_2).type == LST))
  212:     {
  213:         // Renvoie une liste de chaînes qui correspondent
  214: 
  215:         if (regcomp(&expression, (const char *) (*s_objet_argument_1).objet,
  216:                 REG_EXTENDED | REG_NOSUB) != 0)
  217:         {
  218:             liberation(s_etat_processus, s_objet_argument_1);
  219:             liberation(s_etat_processus, s_objet_argument_2);
  220: 
  221:             (*s_etat_processus).erreur_execution = d_ex_expression_reguliere;
  222:             return;
  223:         }
  224: 
  225:         if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL)
  226:         {
  227:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  228:             return;
  229:         }
  230: 
  231:         l_element_courant_lecture = (*s_objet_argument_2).objet;
  232:         l_element_courant_ecriture = NULL;
  233: 
  234:         while(l_element_courant_lecture != NULL)
  235:         {
  236:             if ((*(*l_element_courant_lecture).donnee).type != CHN)
  237:             {
  238:                 liberation(s_etat_processus, s_objet_argument_1);
  239:                 liberation(s_etat_processus, s_objet_argument_2);
  240:                 liberation(s_etat_processus, s_objet_resultat);
  241: 
  242:                 (*s_etat_processus).erreur_execution =
  243:                         d_ex_erreur_type_argument;
  244:                 return;
  245:             }
  246: 
  247:             if (regexec(&expression, (const char *)
  248:                     (*(*l_element_courant_lecture).donnee).objet,
  249:                     0, NULL, 0) == 0)
  250:             {
  251:                 if (l_element_courant_ecriture == NULL)
  252:                 {
  253:                     if (((*s_objet_resultat).objet =
  254:                             allocation_maillon(s_etat_processus)) == NULL)
  255:                     {
  256:                         (*s_etat_processus).erreur_systeme =
  257:                                 d_es_allocation_memoire;
  258:                         return;
  259:                     }
  260: 
  261:                     l_element_courant_ecriture = (*s_objet_resultat).objet;
  262: 
  263:                     if (((*l_element_courant_ecriture).donnee =
  264:                             copie_objet(s_etat_processus,
  265:                             (*l_element_courant_lecture).donnee, 'P'))
  266:                             == NULL)
  267:                     {
  268:                         (*s_etat_processus).erreur_systeme =
  269:                                 d_es_allocation_memoire;
  270:                         return;
  271:                     }
  272: 
  273:                     (*l_element_courant_ecriture).suivant = NULL;
  274:                 }
  275:                 else
  276:                 {
  277:                     if (((*l_element_courant_ecriture).suivant =
  278:                             allocation_maillon(s_etat_processus)) == NULL)
  279:                     {
  280:                         (*s_etat_processus).erreur_systeme =
  281:                                 d_es_allocation_memoire;
  282:                         return;
  283:                     }
  284: 
  285:                     l_element_courant_ecriture =
  286:                             (*l_element_courant_ecriture).suivant;
  287: 
  288:                     if (((*l_element_courant_ecriture).donnee =
  289:                             copie_objet(s_etat_processus,
  290:                             (*l_element_courant_lecture).donnee, 'P'))
  291:                             == NULL)
  292:                     {
  293:                         (*s_etat_processus).erreur_systeme =
  294:                                 d_es_allocation_memoire;
  295:                         return;
  296:                     }
  297: 
  298:                     (*l_element_courant_ecriture).suivant = NULL;
  299:                 }
  300:             }
  301: 
  302:             l_element_courant_lecture = (*l_element_courant_lecture).suivant;
  303:         }
  304: 
  305:         regfree(&expression);
  306:     }
  307:     else
  308:     {
  309:         liberation(s_etat_processus, s_objet_argument_1);
  310:         liberation(s_etat_processus, s_objet_argument_2);
  311: 
  312:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  313:         return;
  314:     }
  315: 
  316:     liberation(s_etat_processus, s_objet_argument_1);
  317:     liberation(s_etat_processus, s_objet_argument_2);
  318: 
  319:     if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  320:             s_objet_resultat) == d_erreur)
  321:     {
  322:         return;
  323:     }
  324: 
  325:     return;
  326: }
  327: 
  328: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>