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

1.1       bertrand    1: /*
                      2: ================================================================================
1.18      bertrand    3:   RPL/2 (R) version 4.1.15
1.14      bertrand    4:   Copyright (C) 1989-2013 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: 
1.19    ! bertrand  139:        printf("    2: %s\n", d_LST);
1.16      bertrand  140:        printf("    1: %s\n", d_CHN);
1.2       bertrand  141:        printf("->  1: %s\n\n", d_LST);
                    142: 
1.16      bertrand  143:        printf("    2: %s\n", d_CHN);
1.2       bertrand  144:        printf("    1: %s\n", d_CHN);
                    145:        printf("->  1: %s (0 or -1)\n", d_INT);
                    146: 
                    147:        return;
                    148:    }
                    149:    else if ((*s_etat_processus).test_instruction == 'Y')
                    150:    {
1.19    ! bertrand  151:        (*s_etat_processus).nombre_arguments = -1;
1.2       bertrand  152:        return;
                    153:    }
                    154: 
                    155:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    156:    {
                    157:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    158:        {
                    159:            return;
                    160:        }
                    161:    }
                    162: 
                    163:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    164:            &s_objet_argument_1) == d_erreur)
                    165:    {
                    166:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    167:        return;
                    168:    }
                    169: 
                    170:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    171:            &s_objet_argument_2) == d_erreur)
                    172:    {
                    173:        liberation(s_etat_processus, s_objet_argument_1);
                    174: 
                    175:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    176:        return;
                    177:    }
                    178: 
                    179:    if (((*s_objet_argument_1).type == CHN) &&
                    180:            ((*s_objet_argument_2).type == CHN))
                    181:    {
                    182:        // Renvoie 0 ou -1
                    183: 
                    184:        if (regcomp(&expression, (const char *) (*s_objet_argument_1).objet,
                    185:                REG_EXTENDED | REG_NOSUB) != 0)
                    186:        {
                    187:            liberation(s_etat_processus, s_objet_argument_1);
                    188:            liberation(s_etat_processus, s_objet_argument_2);
                    189: 
                    190:            (*s_etat_processus).erreur_execution = d_ex_expression_reguliere;
                    191:            return;
                    192:        }
                    193: 
                    194:        if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
                    195:        {
                    196:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    197:            return;
                    198:        }
                    199: 
1.4       bertrand  200:        if (regexec(&expression, (const char *) (*s_objet_argument_2).objet,
1.2       bertrand  201:                0, NULL, 0) == 0)
                    202:        {
                    203:            (*((integer8 *) (*s_objet_resultat).objet)) = -1;
                    204:        }
                    205:        else // REG_NOMATCH
                    206:        {
                    207:            (*((integer8 *) (*s_objet_resultat).objet)) = 0;
                    208:        }
                    209: 
                    210:        regfree(&expression);
                    211:    }
                    212:    else if (((*s_objet_argument_1).type == CHN) &&
                    213:            ((*s_objet_argument_2).type == LST))
                    214:    {
                    215:        // Renvoie une liste de chaînes qui correspondent
                    216: 
                    217:        if (regcomp(&expression, (const char *) (*s_objet_argument_1).objet,
                    218:                REG_EXTENDED | REG_NOSUB) != 0)
                    219:        {
                    220:            liberation(s_etat_processus, s_objet_argument_1);
                    221:            liberation(s_etat_processus, s_objet_argument_2);
                    222: 
                    223:            (*s_etat_processus).erreur_execution = d_ex_expression_reguliere;
                    224:            return;
                    225:        }
                    226: 
                    227:        if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL)
                    228:        {
                    229:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    230:            return;
                    231:        }
                    232: 
                    233:        l_element_courant_lecture = (*s_objet_argument_2).objet;
                    234:        l_element_courant_ecriture = NULL;
                    235: 
                    236:        while(l_element_courant_lecture != NULL)
                    237:        {
                    238:            if ((*(*l_element_courant_lecture).donnee).type != CHN)
                    239:            {
1.3       bertrand  240:                regfree(&expression);
1.2       bertrand  241:                liberation(s_etat_processus, s_objet_argument_1);
                    242:                liberation(s_etat_processus, s_objet_argument_2);
                    243:                liberation(s_etat_processus, s_objet_resultat);
                    244: 
                    245:                (*s_etat_processus).erreur_execution =
                    246:                        d_ex_erreur_type_argument;
                    247:                return;
                    248:            }
                    249: 
                    250:            if (regexec(&expression, (const char *)
                    251:                    (*(*l_element_courant_lecture).donnee).objet,
                    252:                    0, NULL, 0) == 0)
                    253:            {
                    254:                if (l_element_courant_ecriture == NULL)
                    255:                {
                    256:                    if (((*s_objet_resultat).objet =
                    257:                            allocation_maillon(s_etat_processus)) == NULL)
                    258:                    {
                    259:                        (*s_etat_processus).erreur_systeme =
                    260:                                d_es_allocation_memoire;
                    261:                        return;
                    262:                    }
                    263: 
                    264:                    l_element_courant_ecriture = (*s_objet_resultat).objet;
                    265: 
                    266:                    if (((*l_element_courant_ecriture).donnee =
                    267:                            copie_objet(s_etat_processus,
                    268:                            (*l_element_courant_lecture).donnee, 'P'))
                    269:                            == NULL)
                    270:                    {
                    271:                        (*s_etat_processus).erreur_systeme =
                    272:                                d_es_allocation_memoire;
                    273:                        return;
                    274:                    }
                    275: 
                    276:                    (*l_element_courant_ecriture).suivant = NULL;
                    277:                }
                    278:                else
                    279:                {
                    280:                    if (((*l_element_courant_ecriture).suivant =
                    281:                            allocation_maillon(s_etat_processus)) == NULL)
                    282:                    {
                    283:                        (*s_etat_processus).erreur_systeme =
                    284:                                d_es_allocation_memoire;
                    285:                        return;
                    286:                    }
                    287: 
                    288:                    l_element_courant_ecriture =
                    289:                            (*l_element_courant_ecriture).suivant;
                    290: 
                    291:                    if (((*l_element_courant_ecriture).donnee =
                    292:                            copie_objet(s_etat_processus,
                    293:                            (*l_element_courant_lecture).donnee, 'P'))
                    294:                            == NULL)
                    295:                    {
                    296:                        (*s_etat_processus).erreur_systeme =
                    297:                                d_es_allocation_memoire;
                    298:                        return;
                    299:                    }
                    300: 
                    301:                    (*l_element_courant_ecriture).suivant = NULL;
                    302:                }
                    303:            }
                    304: 
                    305:            l_element_courant_lecture = (*l_element_courant_lecture).suivant;
                    306:        }
                    307: 
                    308:        regfree(&expression);
                    309:    }
                    310:    else
                    311:    {
                    312:        liberation(s_etat_processus, s_objet_argument_1);
                    313:        liberation(s_etat_processus, s_objet_argument_2);
                    314: 
                    315:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    316:        return;
                    317:    }
                    318: 
                    319:    liberation(s_etat_processus, s_objet_argument_1);
                    320:    liberation(s_etat_processus, s_objet_argument_2);
                    321: 
                    322:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    323:            s_objet_resultat) == d_erreur)
                    324:    {
                    325:        return;
                    326:    }
                    327: 
                    328:    return;
                    329: }
                    330: 
1.19    ! bertrand  331: 
        !           332: /*
        !           333: ================================================================================
        !           334:   Fonction 'rgdl'
        !           335: ================================================================================
        !           336:   Entrées : pointeur sur une structure struct_processus
        !           337: --------------------------------------------------------------------------------
        !           338:   Sorties :
        !           339: --------------------------------------------------------------------------------
        !           340:   Effets de bord : néant
        !           341: ================================================================================
        !           342: */
        !           343: 
        !           344: void
        !           345: instruction_rgdl(struct_processus *s_etat_processus)
        !           346: {
        !           347:    integer8                        i;
        !           348:    integer8                        l;
        !           349: 
        !           350:    struct_objet                    *s_objet_argument_1;
        !           351:    struct_objet                    *s_objet_argument_2;
        !           352:    struct_objet                    *s_objet_argument_3;
        !           353:    struct_objet                    *s_objet_resultat;
        !           354: 
        !           355:    unsigned char                   *ptr_e;
        !           356:    unsigned char                   *ptr_l;
        !           357: 
        !           358:    (*s_etat_processus).erreur_execution = d_ex;
        !           359: 
        !           360:    if ((*s_etat_processus).affichage_arguments == 'Y')
        !           361:    {
        !           362:        printf("\n  RGDL ");
        !           363: 
        !           364:        if ((*s_etat_processus).langue == 'F')
        !           365:        {
        !           366:            printf("(fer à droite)\n\n");
        !           367:        }
        !           368:        else
        !           369:        {
        !           370:            printf("(ragged left)\n\n");
        !           371:        }
        !           372: 
        !           373:        printf("    3: %s\n", d_CHN);
        !           374:        printf("    2: %s\n", d_INT);
        !           375:        printf("    1: %s\n", d_CHN);
        !           376:        printf("->  1: %s\n", d_CHN);
        !           377: 
        !           378:        return;
        !           379:    }
        !           380:    else if ((*s_etat_processus).test_instruction == 'Y')
        !           381:    {
        !           382:        (*s_etat_processus).nombre_arguments = -1;
        !           383:        return;
        !           384:    }
        !           385: 
        !           386:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
        !           387:    {
        !           388:        if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
        !           389:        {
        !           390:            return;
        !           391:        }
        !           392:    }
        !           393: 
        !           394:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
        !           395:            &s_objet_argument_1) == d_erreur)
        !           396:    {
        !           397:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
        !           398:        return;
        !           399:    }
        !           400: 
        !           401:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
        !           402:            &s_objet_argument_2) == d_erreur)
        !           403:    {
        !           404:        liberation(s_etat_processus, s_objet_argument_1);
        !           405: 
        !           406:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
        !           407:        return;
        !           408:    }
        !           409: 
        !           410:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
        !           411:            &s_objet_argument_3) == d_erreur)
        !           412:    {
        !           413:        liberation(s_etat_processus, s_objet_argument_1);
        !           414:        liberation(s_etat_processus, s_objet_argument_2);
        !           415: 
        !           416:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
        !           417:        return;
        !           418:    }
        !           419: 
        !           420:    if (((*s_objet_argument_1).type == CHN) &&
        !           421:            ((*s_objet_argument_2).type == INT) &&
        !           422:            ((*s_objet_argument_3).type == CHN))
        !           423:    {
        !           424:        if ((strlen((unsigned char *) (*s_objet_argument_1).objet) != 1) ||
        !           425:                ((*((integer8 *) (*s_objet_argument_2).objet)) < 0))
        !           426:        {
        !           427:            liberation(s_etat_processus, s_objet_argument_1);
        !           428:            liberation(s_etat_processus, s_objet_argument_2);
        !           429:            liberation(s_etat_processus, s_objet_argument_3);
        !           430: 
        !           431:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
        !           432:            return;
        !           433:        }
        !           434: 
        !           435:        if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
        !           436:        {
        !           437:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
        !           438:            return;
        !           439:        }
        !           440: 
        !           441:        if (((*s_objet_resultat).objet = malloc(((size_t) ((*((integer8 *)
        !           442:                (*s_objet_argument_2).objet)) + 1)) * sizeof(unsigned char)))
        !           443:                == NULL)
        !           444:        {
        !           445:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
        !           446:            return;
        !           447:        }
        !           448: 
        !           449:        if (((l = (integer8) strlen((unsigned char *) (*s_objet_argument_3)
        !           450:                .objet))) >= (*((integer8 *) (*s_objet_argument_2).objet)))
        !           451:        {
        !           452:            // Recadrage simple
        !           453: 
        !           454:            ptr_e = (unsigned char *) (*s_objet_resultat).objet;
        !           455:            ptr_l = ((unsigned char *) (*s_objet_argument_3).objet)
        !           456:                    + (l - (*((integer8 *) (*s_objet_argument_2).objet)));
        !           457: 
        !           458:            while((*ptr_l) != d_code_fin_chaine)
        !           459:            {
        !           460:                *ptr_e++ = *ptr_l++;
        !           461:            }
        !           462: 
        !           463:            (*ptr_e) = d_code_fin_chaine;
        !           464:        }
        !           465:        else
        !           466:        {
        !           467:            // Ajout des caractères
        !           468: 
        !           469:            ptr_e = (unsigned char *) (*s_objet_resultat).objet;
        !           470:            ptr_l = (unsigned char *) (*s_objet_argument_3).objet;
        !           471: 
        !           472:            for(i = 0; i < (*((integer8 *) (*s_objet_argument_2).objet)) - l;
        !           473:                    i++)
        !           474:            {
        !           475:                *ptr_e++ = ((unsigned char *) (*s_objet_argument_1).objet)[0];
        !           476:            }
        !           477: 
        !           478:            while((*ptr_l) != d_code_fin_chaine)
        !           479:            {
        !           480:                *ptr_e++ = *ptr_l++;
        !           481:            }
        !           482: 
        !           483:            (*ptr_e) = d_code_fin_chaine;
        !           484:        }
        !           485:    }
        !           486:    else
        !           487:    {
        !           488:        liberation(s_etat_processus, s_objet_argument_1);
        !           489:        liberation(s_etat_processus, s_objet_argument_2);
        !           490:        liberation(s_etat_processus, s_objet_argument_3);
        !           491: 
        !           492:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
        !           493:        return;
        !           494:    }
        !           495: 
        !           496:    liberation(s_etat_processus, s_objet_argument_1);
        !           497:    liberation(s_etat_processus, s_objet_argument_2);
        !           498:    liberation(s_etat_processus, s_objet_argument_3);
        !           499: 
        !           500:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
        !           501:            s_objet_resultat) == d_erreur)
        !           502:    {
        !           503:        return;
        !           504:    }
        !           505: 
        !           506:    return;
        !           507: }
        !           508: 
        !           509: void
        !           510: instruction_rgdr(struct_processus *s_etat_processus)
        !           511: {
        !           512: }
        !           513: 
1.1       bertrand  514: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>