/* ================================================================================ RPL/2 (R) version 4.1.32 Copyright (C) 1989-2020 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 'compress' ================================================================================ Entrées : -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void instruction_compress(struct_processus *s_etat_processus) { struct_liste_chainee *l_element_courant; struct_objet *s_objet_argument; struct_objet *s_objet_resultat; uLong longueur_initiale; uLong longueur_compression; uLong longueur_max_compression; unsigned char *tampon; if ((*s_etat_processus).affichage_arguments == 'Y') { printf("\n COMPRESS "); if ((*s_etat_processus).langue == 'F') { printf("(compression de données)\n\n"); } else { printf("(data compression)\n\n"); } printf(" 1: %s\n", d_CHN); printf("-> 1: %s\n", d_LST); 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 == CHN) { longueur_initiale = (uLong) strlen((unsigned char*) (*s_objet_argument).objet); longueur_max_compression = compressBound(longueur_initiale); if ((tampon = malloc(((size_t) longueur_max_compression) * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } longueur_compression = longueur_max_compression; if (compress2(tampon, &longueur_compression, (unsigned char *) (*s_objet_argument).objet, longueur_initiale, 9) != Z_OK) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } liberation(s_etat_processus, s_objet_argument); if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } if (((*s_objet_resultat).objet = allocation_maillon(s_etat_processus)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } l_element_courant = (*s_objet_resultat).objet; if (((*l_element_courant).donnee = allocation(s_etat_processus, INT)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } (*((integer8 *) (*(*l_element_courant).donnee).objet)) = (integer8) longueur_initiale; if (((*l_element_courant).suivant = allocation_maillon( s_etat_processus)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } l_element_courant = (*l_element_courant).suivant; (*l_element_courant).suivant = NULL; if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } if (((*(*l_element_courant).donnee).objet = analyse_flux( s_etat_processus, tampon, (integer8) longueur_compression)) == NULL) { liberation(s_etat_processus, s_objet_resultat); free(tampon); return; } 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