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

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

CVSweb interface <joel.bertrand@systella.fr>