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

1.1       bertrand    1: /*
                      2: ================================================================================
1.19    ! bertrand    3:   RPL/2 (R) version 4.1.26
1.18      bertrand    4:   Copyright (C) 1989-2016 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: 
1.2       bertrand   22: 
1.1       bertrand   23: #include "rpl-conv.h"
                     24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Fonction 'uncompress'
                     29: ================================================================================
                     30:   Entrées :
                     31: --------------------------------------------------------------------------------
                     32:   Sorties :
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: void
                     39: instruction_uncompress(struct_processus *s_etat_processus)
                     40: {
                     41:    integer8                        longueur_tampon;
                     42: 
                     43:    struct_liste_chainee            *l_element_courant;
                     44: 
                     45:    struct_objet                    *s_objet_argument;
                     46:    struct_objet                    *s_objet_resultat;
                     47: 
                     48:    uLong                           taille;
                     49: 
                     50:    unsigned char                   *tampon;
                     51: 
                     52:    if ((*s_etat_processus).affichage_arguments == 'Y')
                     53:    {
                     54:        printf("\n  UNCOMPRESS ");
                     55: 
                     56:        if ((*s_etat_processus).langue == 'F')
                     57:        {
                     58:            printf("(décompression de données)\n\n");
                     59:        }
                     60:        else
                     61:        {
                     62:            printf("(data uncompression)\n\n");
                     63:        }
                     64: 
                     65:        printf("    1: %s\n", d_LST);
                     66:        printf("->  1: %s\n", d_CHN);
                     67: 
                     68:        return;
                     69:    }
                     70:    else if ((*s_etat_processus).test_instruction == 'Y')
                     71:    {
                     72:        (*s_etat_processus).nombre_arguments = -1;
                     73:        return;
                     74:    }
                     75: 
                     76:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                     77:    {
                     78:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                     79:        {
                     80:            return;
                     81:        }
                     82:    }
                     83: 
                     84:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                     85:            &s_objet_argument) == d_erreur)
                     86:    {
                     87:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                     88:        return;
                     89:    }
                     90: 
                     91:    if ((*s_objet_argument).type == LST)
                     92:    {
                     93:        l_element_courant = (*s_objet_argument).objet;
                     94: 
1.3       bertrand   95:        if (l_element_courant == NULL)
                     96:        {
                     97:            liberation(s_etat_processus, s_objet_argument);
                     98: 
                     99:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    100:             return;
                    101:        }
                    102: 
1.1       bertrand  103:        if ((*(*l_element_courant).donnee).type != INT)
                    104:        {
                    105:            liberation(s_etat_processus, s_objet_argument);
                    106: 
                    107:            (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    108:            return;
                    109:        }
                    110: 
1.4       bertrand  111:        if ((*((integer8 *) (*(*l_element_courant).donnee).objet)) < 0)
                    112:        {
                    113:            liberation(s_etat_processus, s_objet_argument);
                    114: 
                    115:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    116:             return;
                    117:        }
                    118: 
1.1       bertrand  119:        taille = (uLong) (*((integer8 *) (*(*l_element_courant).donnee).objet));
                    120:        l_element_courant = (*l_element_courant).suivant;
                    121: 
                    122:        if (l_element_courant == NULL)
                    123:        {
                    124:            liberation(s_etat_processus, s_objet_argument);
                    125: 
                    126:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    127:             return;
                    128:        }
                    129: 
                    130:        if ((*(*l_element_courant).donnee).type != CHN)
                    131:        {
                    132:            liberation(s_etat_processus, s_objet_argument);
                    133: 
                    134:            (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    135:            return;
                    136:        }
                    137: 
                    138:        if ((*l_element_courant).suivant != NULL)
                    139:        {
                    140:            liberation(s_etat_processus, s_objet_argument);
                    141: 
                    142:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    143:             return;
                    144:        }
                    145: 
                    146:        if ((tampon = formateur_flux(s_etat_processus,
                    147:                (*(*l_element_courant).donnee).objet, &longueur_tampon))
                    148:                == NULL)
                    149:        {
                    150:            return;
                    151:        }
                    152:                
                    153:        if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
                    154:        {
                    155:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    156:            return;
                    157:        }
                    158: 
                    159:        if (((*s_objet_resultat).objet = malloc(((size_t) (taille + 1)) *
                    160:                sizeof(unsigned char))) == NULL)
                    161:        {
                    162:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    163:            return;
                    164:        }
                    165: 
                    166:        switch(uncompress((*s_objet_resultat).objet, &taille,
                    167:                tampon, (uLong) longueur_tampon))
                    168:        {
                    169:            case Z_MEM_ERROR:
                    170:            {
                    171:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    172:                return;
                    173:            }
                    174: 
                    175:            case Z_BUF_ERROR:
                    176:            case Z_DATA_ERROR:
                    177:            {
                    178:                liberation(s_etat_processus, s_objet_argument);
                    179:                liberation(s_etat_processus, s_objet_resultat);
                    180:                free(tampon);
                    181: 
                    182:                (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    183:                return;
                    184:            }
                    185: 
                    186:            default:
                    187:            case Z_OK:
                    188:            {
                    189:                break;
                    190:            }
                    191:        }
                    192: 
                    193:        ((unsigned char *) (*s_objet_resultat).objet)[taille] =
                    194:                d_code_fin_chaine;
                    195:        liberation(s_etat_processus, s_objet_argument);
                    196:        free(tampon);
                    197: 
                    198:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    199:                s_objet_resultat) == d_erreur)
                    200:        {
                    201:            return;
                    202:        }
                    203:    }
                    204:    else
                    205:    {
                    206:        liberation(s_etat_processus, s_objet_argument);
                    207: 
                    208:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    209:        return;
                    210:    }
                    211: 
                    212:    return;
                    213: }
                    214: 
                    215: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>