/* ================================================================================ RPL/2 (R) version 4.1.36 Copyright (C) 1989-2024 Dr. BERTRAND Joël This file is part of RPL/2. RPL/2 is free software; you can redistribute it and/or modify it under the terms of the CeCILL V2 License as published by the french CEA, CNRS and INRIA. RPL/2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License for more details. You should have received a copy of the CeCILL License along with RPL/2. If not, write to info@cecill.info. ================================================================================ */ #include "rpl-conv.h" /* ================================================================================ Fonction 'uncompress' ================================================================================ Entrées : -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void instruction_uncompress(struct_processus *s_etat_processus) { integer8 longueur_tampon; struct_liste_chainee *l_element_courant; struct_objet *s_objet_argument; struct_objet *s_objet_resultat; uLong taille; unsigned char *tampon; if ((*s_etat_processus).affichage_arguments == 'Y') { printf("\n UNCOMPRESS "); if ((*s_etat_processus).langue == 'F') { printf("(décompression de données)\n\n"); } else { printf("(data uncompression)\n\n"); } printf(" 1: %s\n", d_LST); printf("-> 1: %s\n", d_CHN); return; } else if ((*s_etat_processus).test_instruction == 'Y') { (*s_etat_processus).nombre_arguments = -1; return; } if (test_cfsf(s_etat_processus, 31) == d_vrai) { if (empilement_pile_last(s_etat_processus, 1) == d_erreur) { return; } } if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), &s_objet_argument) == d_erreur) { (*s_etat_processus).erreur_execution = d_ex_manque_argument; return; } if ((*s_objet_argument).type == LST) { l_element_courant = (*s_objet_argument).objet; if (l_element_courant == NULL) { liberation(s_etat_processus, s_objet_argument); (*s_etat_processus).erreur_execution = d_ex_argument_invalide; return; } if ((*(*l_element_courant).donnee).type != INT) { liberation(s_etat_processus, s_objet_argument); (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; return; } if ((*((integer8 *) (*(*l_element_courant).donnee).objet)) < 0) { liberation(s_etat_processus, s_objet_argument); (*s_etat_processus).erreur_execution = d_ex_argument_invalide; return; } taille = (uLong) (*((integer8 *) (*(*l_element_courant).donnee).objet)); l_element_courant = (*l_element_courant).suivant; if (l_element_courant == NULL) { liberation(s_etat_processus, s_objet_argument); (*s_etat_processus).erreur_execution = d_ex_argument_invalide; return; } if ((*(*l_element_courant).donnee).type != CHN) { liberation(s_etat_processus, s_objet_argument); (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; return; } if ((*l_element_courant).suivant != NULL) { liberation(s_etat_processus, s_objet_argument); (*s_etat_processus).erreur_execution = d_ex_argument_invalide; return; } if ((tampon = formateur_flux(s_etat_processus, (*(*l_element_courant).donnee).objet, &longueur_tampon)) == NULL) { return; } if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } if (((*s_objet_resultat).objet = malloc(((size_t) (taille + 1)) * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } switch(uncompress((*s_objet_resultat).objet, &taille, tampon, (uLong) longueur_tampon)) { case Z_MEM_ERROR: { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } case Z_BUF_ERROR: case Z_DATA_ERROR: { liberation(s_etat_processus, s_objet_argument); liberation(s_etat_processus, s_objet_resultat); free(tampon); (*s_etat_processus).erreur_execution = d_ex_argument_invalide; return; } default: case Z_OK: { break; } } ((unsigned char *) (*s_objet_resultat).objet)[taille] = d_code_fin_chaine; liberation(s_etat_processus, s_objet_argument); free(tampon); if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_resultat) == d_erreur) { return; } } else { liberation(s_etat_processus, s_objet_argument); (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; return; } return; } // vim: ts=4