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

1.1       bertrand    1: /*
                      2: ================================================================================
                      3:   RPL/2 (R) version 4.1.13
                      4:   Copyright (C) 1989-2013 Dr. BERTRAND Joël
                      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: 
                    111:        taille = (uLong) (*((integer8 *) (*(*l_element_courant).donnee).objet));
                    112:        l_element_courant = (*l_element_courant).suivant;
                    113: 
                    114:        if (l_element_courant == NULL)
                    115:        {
                    116:            liberation(s_etat_processus, s_objet_argument);
                    117: 
                    118:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    119:             return;
                    120:        }
                    121: 
                    122:        if ((*(*l_element_courant).donnee).type != CHN)
                    123:        {
                    124:            liberation(s_etat_processus, s_objet_argument);
                    125: 
                    126:            (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    127:            return;
                    128:        }
                    129: 
                    130:        if ((*l_element_courant).suivant != NULL)
                    131:        {
                    132:            liberation(s_etat_processus, s_objet_argument);
                    133: 
                    134:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    135:             return;
                    136:        }
                    137: 
                    138:        if ((tampon = formateur_flux(s_etat_processus,
                    139:                (*(*l_element_courant).donnee).objet, &longueur_tampon))
                    140:                == NULL)
                    141:        {
                    142:            return;
                    143:        }
                    144:                
                    145:        if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
                    146:        {
                    147:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    148:            return;
                    149:        }
                    150: 
                    151:        if (((*s_objet_resultat).objet = malloc(((size_t) (taille + 1)) *
                    152:                sizeof(unsigned char))) == NULL)
                    153:        {
                    154:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    155:            return;
                    156:        }
                    157: 
                    158:        switch(uncompress((*s_objet_resultat).objet, &taille,
                    159:                tampon, (uLong) longueur_tampon))
                    160:        {
                    161:            case Z_MEM_ERROR:
                    162:            {
                    163:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    164:                return;
                    165:            }
                    166: 
                    167:            case Z_BUF_ERROR:
                    168:            case Z_DATA_ERROR:
                    169:            {
                    170:                liberation(s_etat_processus, s_objet_argument);
                    171:                liberation(s_etat_processus, s_objet_resultat);
                    172:                free(tampon);
                    173: 
                    174:                (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    175:                return;
                    176:            }
                    177: 
                    178:            default:
                    179:            case Z_OK:
                    180:            {
                    181:                break;
                    182:            }
                    183:        }
                    184: 
                    185:        ((unsigned char *) (*s_objet_resultat).objet)[taille] =
                    186:                d_code_fin_chaine;
                    187:        liberation(s_etat_processus, s_objet_argument);
                    188:        free(tampon);
                    189: 
                    190:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    191:                s_objet_resultat) == d_erreur)
                    192:        {
                    193:            return;
                    194:        }
                    195:    }
                    196:    else
                    197:    {
                    198:        liberation(s_etat_processus, s_objet_argument);
                    199: 
                    200:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    201:        return;
                    202:    }
                    203: 
                    204:    return;
                    205: }
                    206: 
                    207: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>