Annotation of rpl/src/instructions_r7.c, revision 1.8

1.1       bertrand    1: /*
                      2: ================================================================================
1.8     ! bertrand    3:   RPL/2 (R) version 4.1.8
1.5       bertrand    4:   Copyright (C) 1989-2012 Dr. BERTRAND Joël
1.1       bertrand    5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
                     22: 
                     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: 
1.2       bertrand   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: 
1.4       bertrand  198:        if (regexec(&expression, (const char *) (*s_objet_argument_2).objet,
1.2       bertrand  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:            {
1.3       bertrand  238:                regfree(&expression);
1.2       bertrand  239:                liberation(s_etat_processus, s_objet_argument_1);
                    240:                liberation(s_etat_processus, s_objet_argument_2);
                    241:                liberation(s_etat_processus, s_objet_resultat);
                    242: 
                    243:                (*s_etat_processus).erreur_execution =
                    244:                        d_ex_erreur_type_argument;
                    245:                return;
                    246:            }
                    247: 
                    248:            if (regexec(&expression, (const char *)
                    249:                    (*(*l_element_courant_lecture).donnee).objet,
                    250:                    0, NULL, 0) == 0)
                    251:            {
                    252:                if (l_element_courant_ecriture == NULL)
                    253:                {
                    254:                    if (((*s_objet_resultat).objet =
                    255:                            allocation_maillon(s_etat_processus)) == NULL)
                    256:                    {
                    257:                        (*s_etat_processus).erreur_systeme =
                    258:                                d_es_allocation_memoire;
                    259:                        return;
                    260:                    }
                    261: 
                    262:                    l_element_courant_ecriture = (*s_objet_resultat).objet;
                    263: 
                    264:                    if (((*l_element_courant_ecriture).donnee =
                    265:                            copie_objet(s_etat_processus,
                    266:                            (*l_element_courant_lecture).donnee, 'P'))
                    267:                            == NULL)
                    268:                    {
                    269:                        (*s_etat_processus).erreur_systeme =
                    270:                                d_es_allocation_memoire;
                    271:                        return;
                    272:                    }
                    273: 
                    274:                    (*l_element_courant_ecriture).suivant = NULL;
                    275:                }
                    276:                else
                    277:                {
                    278:                    if (((*l_element_courant_ecriture).suivant =
                    279:                            allocation_maillon(s_etat_processus)) == NULL)
                    280:                    {
                    281:                        (*s_etat_processus).erreur_systeme =
                    282:                                d_es_allocation_memoire;
                    283:                        return;
                    284:                    }
                    285: 
                    286:                    l_element_courant_ecriture =
                    287:                            (*l_element_courant_ecriture).suivant;
                    288: 
                    289:                    if (((*l_element_courant_ecriture).donnee =
                    290:                            copie_objet(s_etat_processus,
                    291:                            (*l_element_courant_lecture).donnee, 'P'))
                    292:                            == NULL)
                    293:                    {
                    294:                        (*s_etat_processus).erreur_systeme =
                    295:                                d_es_allocation_memoire;
                    296:                        return;
                    297:                    }
                    298: 
                    299:                    (*l_element_courant_ecriture).suivant = NULL;
                    300:                }
                    301:            }
                    302: 
                    303:            l_element_courant_lecture = (*l_element_courant_lecture).suivant;
                    304:        }
                    305: 
                    306:        regfree(&expression);
                    307:    }
                    308:    else
                    309:    {
                    310:        liberation(s_etat_processus, s_objet_argument_1);
                    311:        liberation(s_etat_processus, s_objet_argument_2);
                    312: 
                    313:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    314:        return;
                    315:    }
                    316: 
                    317:    liberation(s_etat_processus, s_objet_argument_1);
                    318:    liberation(s_etat_processus, s_objet_argument_2);
                    319: 
                    320:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    321:            s_objet_resultat) == d_erreur)
                    322:    {
                    323:        return;
                    324:    }
                    325: 
                    326:    return;
                    327: }
                    328: 
1.1       bertrand  329: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>