Annotation of rpl/src/instructions_t3.c, revision 1.56

1.1       bertrand    1: /*
                      2: ================================================================================
1.56    ! bertrand    3:   RPL/2 (R) version 4.1.20
1.55      bertrand    4:   Copyright (C) 1989-2015 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: 
1.13      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   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: {
1.45      bertrand   41:    integer8                            parametre;
1.1       bertrand   42: 
1.45      bertrand   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))
1.1       bertrand  133:                    == NULL)
1.45      bertrand  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: 
1.54      bertrand  278:            (*s_etat_processus).type_en_cours = NON;
1.45      bertrand  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:    }
1.1       bertrand  305: 
                    306: /*
                    307: --------------------------------------------------------------------------------
                    308:   Fonction troncature impossible à réaliser
                    309: --------------------------------------------------------------------------------
                    310: */
                    311: 
1.45      bertrand  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:    }
1.1       bertrand  320: 
1.45      bertrand  321:    liberation(s_etat_processus, s_objet_argument_1);
                    322:    liberation(s_etat_processus, s_objet_argument_2);
1.1       bertrand  323: 
1.45      bertrand  324:    return;
1.1       bertrand  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: 
1.45      bertrand  346:    integer8                        i;
1.1       bertrand  347: 
                    348:    (*s_etat_processus).erreur_execution = d_ex;
                    349: 
                    350:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    351:    {
                    352:        printf("\n  TABLE-> ");
                    353: 
                    354:        if ((*s_etat_processus).langue == 'F')
                    355:        {
                    356:            printf("(expansion d'une table)\n\n");
                    357:        }
                    358:        else
                    359:        {
                    360:            printf("(expand table)\n\n");
                    361:        }
                    362: 
                    363:        printf("    1: %s\n", d_TAB);
                    364:        printf("->  n: %s, %s, %s, %s, %s, %s,\n"
1.45      bertrand  365:                "      %s, %s, %s, %s, %s,\n"
                    366:                "      %s, %s, %s, %s, %s,\n"
                    367:                "      %s, %s\n",
1.1       bertrand  368:                d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX,
                    369:                d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SLB);
                    370:        printf("    ...\n");
                    371:        printf("    2: %s, %s, %s, %s, %s, %s,\n"
1.45      bertrand  372:                "      %s, %s, %s, %s, %s,\n"
                    373:                "      %s, %s, %s, %s, %s,\n"
                    374:                "      %s, %s\n",
1.1       bertrand  375:                d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX,
                    376:                d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SLB);
                    377:        printf("    1: %s\n", d_INT);
                    378: 
                    379:        return;
                    380:    }
                    381:    else if ((*s_etat_processus).test_instruction == 'Y')
                    382:    {
                    383:        (*s_etat_processus).nombre_arguments = -1;
                    384:        return;
                    385:    }
                    386: 
                    387:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    388:    {
                    389:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    390:        {
                    391:            return;
                    392:        }
                    393:    }
                    394: 
                    395:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    396:            &s_objet) == d_erreur)
                    397:    {
                    398:        return;
                    399:    }
                    400: 
                    401:    if ((*s_objet).type != TBL)
                    402:    {
                    403:        liberation(s_etat_processus, s_objet);
                    404: 
                    405:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    406:        return;
                    407:    }
                    408: 
                    409:    for(i = 0; i < (*((struct_tableau *) (*s_objet).objet))
                    410:            .nombre_elements; i++)
                    411:    {
                    412:        if (((*((struct_tableau *) (*s_objet).objet)).elements[i] =
                    413:                copie_objet(s_etat_processus, (*((struct_tableau *)
                    414:                (*s_objet).objet)).elements[i], 'P')) == NULL)
                    415:        {
                    416:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    417:            return;
                    418:        }
                    419: 
                    420:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    421:                (*((struct_tableau *) (*s_objet).objet)).elements[i])
                    422:                == d_erreur)
                    423:        {
                    424:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    425:            return;
                    426:        }
                    427:    }
                    428: 
                    429:    if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
                    430:    {
                    431:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    432:        return;
                    433:    }
                    434: 
                    435:    (*((integer8 *) ((*s_objet_resultat).objet))) = (integer8)
                    436:            (*((struct_tableau *) (*s_objet).objet)).nombre_elements;
                    437: 
                    438:    liberation(s_etat_processus, s_objet);
                    439: 
                    440:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    441:            s_objet_resultat) == d_erreur)
                    442:    {
                    443:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    444:        return;
                    445:    }
                    446: 
                    447:    return;
                    448: }
                    449: 
                    450: 
                    451: /*
                    452: ================================================================================
                    453:   Fonction 'trim'
                    454: ================================================================================
                    455:   Entrées : pointeur sur une structure struct_processus
                    456: --------------------------------------------------------------------------------
                    457:   Sorties :
                    458: --------------------------------------------------------------------------------
                    459:   Effets de bord : néant
                    460: ================================================================================
                    461: */
                    462: 
                    463: void
                    464: instruction_trim(struct_processus *s_etat_processus)
                    465: {
1.45      bertrand  466:    struct_objet                        *s_objet_argument;
                    467:    struct_objet                        *s_objet_resultat;
1.1       bertrand  468: 
                    469:    unsigned char                       *debut;
                    470:    unsigned char                       *fin;
                    471: 
1.45      bertrand  472:    (*s_etat_processus).erreur_execution = d_ex;
                    473: 
                    474:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    475:    {
                    476:        printf("\n  TRIM ");
1.1       bertrand  477: 
1.45      bertrand  478:        if ((*s_etat_processus).langue == 'F')
                    479:        {
                    480:            printf("(suppression des espaces initiaux et finaux d'une "
1.1       bertrand  481:                    "chaîne)\n\n");
1.45      bertrand  482:        }
                    483:        else
                    484:        {
                    485:            printf("(delete initial and final spaces from string)\n\n");
                    486:        }
                    487: 
                    488:        printf("    1: %s\n", d_CHN);
                    489:        printf("->  1: %s\n", d_CHN);
1.1       bertrand  490: 
1.45      bertrand  491:        return;
                    492:    }
                    493:    else if ((*s_etat_processus).test_instruction == 'Y')
                    494:    {
                    495:        (*s_etat_processus).nombre_arguments = -1;
                    496:        return;
                    497:    }
                    498: 
                    499:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    500:    {
                    501:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    502:        {
                    503:            return;
                    504:        }
                    505:    }
                    506: 
                    507:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    508:            &s_objet_argument) == d_erreur)
                    509:    {
                    510:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    511:        return;
                    512:    }
                    513: 
                    514:    if ((*s_objet_argument).type == CHN)
                    515:    {
1.1       bertrand  516:        debut = (unsigned char *) (*s_objet_argument).objet;
                    517: 
1.10      bertrand  518:        while(((*debut) != d_code_fin_chaine) &&
                    519:                (((*debut) == d_code_espace)
                    520:                || ((*debut) == d_code_retour_chariot)
                    521:                || ((*debut) == d_code_tabulation)))
1.1       bertrand  522:        {
                    523:            debut++;
                    524:        }
                    525: 
                    526:        fin = &(((unsigned char *) (*s_objet_argument).objet)
                    527:                [strlen((unsigned char *) (*s_objet_argument).objet) - 1]);
                    528: 
1.10      bertrand  529:        while((fin > debut) &&
                    530:                (((*fin) == d_code_espace)
                    531:                || ((*fin) == d_code_retour_chariot)
                    532:                || ((*fin) == d_code_tabulation)))
1.1       bertrand  533:        {
                    534:            fin--;
                    535:        }
                    536: 
                    537:        (*(++fin)) = d_code_fin_chaine;
                    538: 
                    539:        if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
                    540:        {
                    541:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    542:            return;
                    543:        }
                    544: 
1.45      bertrand  545:        if (((*s_objet_resultat).objet = malloc(((size_t) (1 + fin - debut))
1.1       bertrand  546:                * sizeof(unsigned char))) == NULL)
                    547:        {
                    548:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    549:            return;
                    550:        }
                    551: 
                    552:        strcpy((unsigned char *) (*s_objet_resultat).objet, debut);
1.45      bertrand  553:    }
1.1       bertrand  554: 
                    555: /*
                    556: --------------------------------------------------------------------------------
                    557:   Fonction TRIM impossible à réaliser
                    558: --------------------------------------------------------------------------------
                    559: */
                    560: 
1.45      bertrand  561:    else
                    562:    {
                    563:        liberation(s_etat_processus, s_objet_argument);
                    564: 
                    565:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    566:        return;
                    567:    }
1.1       bertrand  568: 
                    569:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    570:            s_objet_resultat) == d_erreur)
                    571:    {
                    572:        return;
                    573:    }
                    574: 
1.45      bertrand  575:    liberation(s_etat_processus, s_objet_argument);
1.1       bertrand  576: 
1.45      bertrand  577:    return;
1.1       bertrand  578: }
                    579: 
                    580: 
                    581: /*
                    582: ================================================================================
                    583:   Fonction 'tokenize'
                    584: ================================================================================
                    585:   Entrées : pointeur sur une structure struct_processus
                    586: --------------------------------------------------------------------------------
                    587:   Sorties :
                    588: --------------------------------------------------------------------------------
                    589:   Effets de bord : néant
                    590: ================================================================================
                    591: */
                    592: 
                    593: void
                    594: instruction_tokenize(struct_processus *s_etat_processus)
                    595: {
1.45      bertrand  596:    struct_objet                        *s_objet_argument;
                    597:    struct_objet                        *s_objet_resultat;
1.1       bertrand  598: 
                    599:    struct_liste_chainee                *l_element_courant;
                    600: 
1.10      bertrand  601:    unsigned char                       *ptr;
1.12      bertrand  602:    unsigned char                       *ptr2;
1.1       bertrand  603:    unsigned char                       *registre_instruction_courante;
                    604:    unsigned char                       *registre_definitions_chainees;
1.12      bertrand  605:    unsigned char                       *tampon;
1.46      bertrand  606:    unsigned char                       *tampon2;
1.1       bertrand  607: 
1.45      bertrand  608:    integer8                            nombre_caracteres_echappement;
                    609:    integer8                            registre_longueur_definitions_chainees;
                    610:    integer8                            registre_position_courante;
1.1       bertrand  611: 
1.45      bertrand  612:    (*s_etat_processus).erreur_execution = d_ex;
                    613: 
                    614:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    615:    {
                    616:        printf("\n  TOKENIZE ");
                    617: 
                    618:        if ((*s_etat_processus).langue == 'F')
                    619:        {
                    620:            printf("(extraction d'objets en sous-chaînes)\n\n");
                    621:        }
                    622:        else
                    623:        {
                    624:            printf("(extract objects in substrings)\n\n");
                    625:        }
                    626: 
                    627:        printf("    1: %s\n", d_CHN);
                    628:        printf("->  1: %s\n", d_LST);
                    629: 
                    630:        return;
                    631:    }
                    632:    else if ((*s_etat_processus).test_instruction == 'Y')
                    633:    {
                    634:        (*s_etat_processus).nombre_arguments = -1;
                    635:        return;
                    636:    }
                    637: 
                    638:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    639:    {
                    640:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    641:        {
                    642:            return;
                    643:        }
                    644:    }
                    645: 
                    646:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    647:            &s_objet_argument) == d_erreur)
                    648:    {
                    649:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    650:        return;
                    651:    }
                    652: 
                    653:    if ((*s_objet_argument).type == CHN)
                    654:    {
1.12      bertrand  655:        // Conversion des caractères d'échappement
                    656: 
1.46      bertrand  657:        if ((tampon2 = malloc((strlen((*s_objet_argument).objet) + 1) *
                    658:                sizeof(unsigned char))) == NULL)
                    659:        {
                    660:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    661:            return;
                    662:        }
                    663: 
                    664:        strcpy(tampon2, (*s_objet_argument).objet);
                    665:        ptr = tampon2;
1.12      bertrand  666:        ptr2 = ptr;
                    667: 
                    668:        while((*ptr) != d_code_fin_chaine)
                    669:        {
                    670:            (*ptr2) = (*ptr);
                    671: 
                    672:            // Début de la séquence d'échappement
                    673: 
                    674:            if ((*ptr) == '\\')
                    675:            {
                    676:                if ((*(ptr + 1)) == '"')
                    677:                {
                    678:                    ptr++;
                    679:                    (*ptr2) = '\"';
                    680:                }
                    681:                else if ((*(ptr + 1)) == 'n')
                    682:                {
                    683:                    ptr++;
                    684:                    (*ptr2) = '\n';
                    685:                }
                    686:                else if ((*(ptr + 1)) == 't')
                    687:                {
                    688:                    ptr++;
                    689:                    (*ptr2) = '\t';
                    690:                }
                    691:                else if ((*(ptr + 1)) == '\\')
                    692:                {
                    693:                        ptr++;
                    694:                }
                    695:                else
                    696:                {
                    697:                    if ((*s_etat_processus).langue == 'F')
                    698:                    {
                    699:                        printf("+++Information : Séquence d'échappement "
                    700:                                "inconnue [%d]\n", (int) getpid());
                    701:                    }
                    702:                    else
                    703:                    {
                    704:                        printf("+++Warning : Unknown escape code "
                    705:                                "[%d]\n", (int) getpid());
                    706:                    }
                    707:                }
                    708:            }
                    709: 
                    710:                ptr++;
                    711:                ptr2++;
                    712:        }
                    713: 
                    714:        (*ptr2) = d_code_fin_chaine;
                    715: 
1.10      bertrand  716:        // Remplacement des éventuels retours à la ligne et tabulations par
                    717:        // des espaces.
                    718: 
1.46      bertrand  719:        ptr = tampon2;
1.10      bertrand  720: 
                    721:        while((*ptr) != d_code_fin_chaine)
                    722:        {
                    723:            if (((*ptr) == d_code_retour_chariot) ||
                    724:                    ((*ptr) == d_code_tabulation))
                    725:            {
                    726:                (*ptr) = d_code_espace;
                    727:            }
                    728: 
                    729:            ptr++;
                    730:        }
                    731: 
1.1       bertrand  732:        if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL)
                    733:        {
                    734:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    735:            return;
                    736:        }
                    737: 
                    738:        registre_instruction_courante = (*s_etat_processus)
                    739:                .instruction_courante;
                    740:        registre_definitions_chainees = (*s_etat_processus)
                    741:                .definitions_chainees;
                    742:        registre_longueur_definitions_chainees = (*s_etat_processus)
                    743:                .longueur_definitions_chainees;
                    744:        registre_position_courante = (*s_etat_processus).position_courante;
                    745: 
1.46      bertrand  746:        (*s_etat_processus).definitions_chainees = tampon2;
1.1       bertrand  747:        (*s_etat_processus).longueur_definitions_chainees =
1.45      bertrand  748:                (integer8) strlen((*s_etat_processus).definitions_chainees);
1.1       bertrand  749:        (*s_etat_processus).position_courante = 0;
                    750: 
                    751:        l_element_courant = NULL;
                    752: 
                    753:        while((*s_etat_processus).position_courante
                    754:                < (*s_etat_processus).longueur_definitions_chainees)
                    755:        {
                    756:            if (recherche_instruction_suivante(s_etat_processus) == d_erreur)
                    757:            {
                    758:                free((*s_etat_processus).instruction_courante);
                    759: 
                    760:                (*s_etat_processus).instruction_courante =
                    761:                        registre_instruction_courante;
                    762:                (*s_etat_processus).definitions_chainees =
                    763:                        registre_definitions_chainees;
                    764:                (*s_etat_processus).longueur_definitions_chainees =
                    765:                        registre_longueur_definitions_chainees;
                    766:                (*s_etat_processus).position_courante =
                    767:                        registre_position_courante;
                    768: 
1.46      bertrand  769:                free(tampon2);
                    770: 
1.1       bertrand  771:                liberation(s_etat_processus, s_objet_argument);
                    772:                liberation(s_etat_processus, s_objet_resultat);
                    773: 
                    774:                return;
                    775:            }
                    776: 
                    777:            if ((*s_etat_processus).instruction_courante[0] !=
                    778:                    d_code_fin_chaine)
                    779:            {
                    780:                if (l_element_courant == NULL)
                    781:                {
                    782:                    if (((*s_objet_resultat).objet =
                    783:                            allocation_maillon(s_etat_processus)) == NULL)
                    784:                    {
                    785:                        (*s_etat_processus).erreur_systeme =
                    786:                                d_es_allocation_memoire;
                    787:                        return;
                    788:                    }
                    789: 
                    790:                    l_element_courant = (*s_objet_resultat).objet;
                    791:                }
                    792:                else
                    793:                {
                    794:                    if (((*l_element_courant).suivant =
                    795:                            allocation_maillon(s_etat_processus)) == NULL)
                    796:                    {
                    797:                        (*s_etat_processus).erreur_systeme =
                    798:                                d_es_allocation_memoire;
                    799:                        return;
                    800:                    }
                    801: 
                    802:                    l_element_courant = (*l_element_courant).suivant;
                    803:                }
                    804: 
                    805:                if (((*l_element_courant).donnee = allocation(s_etat_processus,
                    806:                        CHN)) == NULL)
                    807:                {
                    808:                    (*s_etat_processus).erreur_systeme =
                    809:                            d_es_allocation_memoire;
                    810:                    return;
                    811:                }
                    812: 
                    813:                (*(*l_element_courant).donnee).objet = (*s_etat_processus)
                    814:                        .instruction_courante;
                    815:                (*l_element_courant).suivant = NULL;
1.12      bertrand  816: 
                    817:                /*
                    818:                 * Rajout du caractère d'échappement devant un guillemet
                    819:                 */
                    820: 
                    821:                nombre_caracteres_echappement = 0;
                    822:                ptr = (unsigned char *) (*(*l_element_courant).donnee).objet;
                    823: 
                    824:                while((*ptr) != d_code_fin_chaine)
                    825:                {
                    826:                    if ((*ptr) == '\"')
                    827:                    {
                    828:                        nombre_caracteres_echappement++;
                    829:                    }
                    830: 
                    831:                    ptr++;
                    832:                }
                    833: 
                    834:                if (nombre_caracteres_echappement != 0)
                    835:                {
                    836:                    tampon = (unsigned char *) (*(*l_element_courant)
                    837:                            .donnee).objet;
                    838: 
                    839:                    if (((*(*l_element_courant).donnee).objet = malloc(
1.45      bertrand  840:                            (strlen(tampon) + 1 +
                    841:                            ((size_t) nombre_caracteres_echappement))
1.12      bertrand  842:                            * sizeof(unsigned char))) == NULL)
                    843:                    {
                    844:                        (*s_etat_processus).erreur_systeme =
                    845:                                d_es_allocation_memoire;
                    846:                        return;
                    847:                    }
                    848: 
                    849:                    ptr = tampon;
                    850:                    ptr2 = (*(*l_element_courant).donnee).objet;
                    851: 
                    852:                    while((*ptr) != d_code_fin_chaine)
                    853:                    {
                    854:                        if ((*ptr) == '\"')
                    855:                        {
                    856:                            (*(ptr2++)) = '\\';
                    857: 
                    858:                        }
                    859:                        else if ((*ptr) == '\\')
                    860:                        {
                    861:                            (*(ptr2++)) = '\\';
                    862:                        }
                    863: 
                    864:                        (*(ptr2++)) = (*(ptr++));
                    865:                    }
                    866: 
                    867:                    (*ptr2) = d_code_fin_chaine;
                    868:                    free(tampon);
                    869:                }
1.1       bertrand  870:            }
                    871:            else
                    872:            {
                    873:                free((*s_etat_processus).instruction_courante);
                    874:            }
                    875:        }
                    876: 
                    877:        (*s_etat_processus).instruction_courante =
                    878:                registre_instruction_courante;
                    879:        (*s_etat_processus).definitions_chainees =
                    880:                registre_definitions_chainees;
                    881:        (*s_etat_processus).longueur_definitions_chainees =
                    882:                registre_longueur_definitions_chainees;
                    883:        (*s_etat_processus).position_courante = registre_position_courante;
1.46      bertrand  884: 
                    885:        free(tampon2);
1.45      bertrand  886:    }
1.1       bertrand  887: 
                    888: /*
                    889: --------------------------------------------------------------------------------
                    890:   Fonction TOKENIZE impossible à réaliser
                    891: --------------------------------------------------------------------------------
                    892: */
                    893: 
1.45      bertrand  894:    else
                    895:    {
                    896:        liberation(s_etat_processus, s_objet_argument);
                    897: 
                    898:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    899:        return;
                    900:    }
1.1       bertrand  901: 
                    902:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    903:            s_objet_resultat) == d_erreur)
                    904:    {
                    905:        return;
                    906:    }
                    907: 
1.45      bertrand  908:    liberation(s_etat_processus, s_objet_argument);
                    909:    return;
1.1       bertrand  910: }
                    911: 
1.19      bertrand  912: 
                    913: /*
                    914: ================================================================================
                    915:   Fonction 't->l'
                    916: ================================================================================
                    917:   Entrées : pointeur sur une structure struct_processus
                    918: --------------------------------------------------------------------------------
                    919:   Sorties :
                    920: --------------------------------------------------------------------------------
                    921:   Effets de bord : néant
                    922: ================================================================================
                    923: */
                    924: 
                    925: void
                    926: instruction_t_vers_l(struct_processus *s_etat_processus)
                    927: {
1.20      bertrand  928:    logical1                    last;
1.19      bertrand  929: 
                    930:    (*s_etat_processus).erreur_execution = d_ex;
                    931: 
                    932:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    933:    {
                    934:        printf("\n  T->L ");
                    935:        
                    936:        if ((*s_etat_processus).langue == 'F')
                    937:        {
                    938:            printf("(converison d'une table en liste)\n\n");
                    939:        }
                    940:        else
                    941:        {
                    942:            printf("(convert table to list)\n\n");
                    943:        }
                    944: 
                    945:        printf("    1: %s\n", d_TAB);
                    946:        printf("->  1: %s\n", d_LST);
                    947:        return;
                    948:    }
                    949:    else if ((*s_etat_processus).test_instruction == 'Y')
                    950:    {
                    951:        (*s_etat_processus).nombre_arguments = -1;
                    952:        return;
                    953:    }
                    954: 
1.20      bertrand  955:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    956:    {
                    957:        last = d_vrai;
                    958:        cf(s_etat_processus, 31);
                    959: 
                    960:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    961:        {
                    962:            return;
                    963:        }
                    964:    }
                    965:    else
                    966:    {
                    967:        last = d_faux;
                    968:    }
                    969: 
                    970:    instruction_table_fleche(s_etat_processus);
                    971: 
                    972:    if (((*s_etat_processus).erreur_systeme == d_es) &&
                    973:            ((*s_etat_processus).erreur_execution == d_ex))
                    974:    {
                    975:        instruction_fleche_list(s_etat_processus);
                    976:    }
                    977: 
                    978:    if (last == d_vrai)
                    979:    {
                    980:        sf(s_etat_processus, 31);
                    981:    }
                    982: 
1.19      bertrand  983:    return;
                    984: }
1.1       bertrand  985: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>