File:  [local] / rpl / src / instructions_c9.c
Revision 1.26: download - view: text, annotated - select for diffs - revision graph
Fri Jan 10 11:15:44 2020 UTC (4 years, 3 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_32, HEAD
Modification du copyright.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.32
    4:   Copyright (C) 1989-2020 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: 
   22: 
   23: #include "rpl-conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   Fonction 'compress'
   29: ================================================================================
   30:   Entrées :
   31: --------------------------------------------------------------------------------
   32:   Sorties :
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: void
   39: instruction_compress(struct_processus *s_etat_processus)
   40: {
   41:     struct_liste_chainee            *l_element_courant;
   42: 
   43:     struct_objet                    *s_objet_argument;
   44:     struct_objet                    *s_objet_resultat;
   45: 
   46:     uLong                           longueur_initiale;
   47:     uLong                           longueur_compression;
   48:     uLong                           longueur_max_compression;
   49: 
   50:     unsigned char                   *tampon;
   51: 
   52:     if ((*s_etat_processus).affichage_arguments == 'Y')
   53:     {
   54:         printf("\n  COMPRESS ");
   55: 
   56:         if ((*s_etat_processus).langue == 'F')
   57:         {
   58:             printf("(compression de données)\n\n");
   59:         }
   60:         else
   61:         {
   62:             printf("(data compression)\n\n");
   63:         }
   64: 
   65:         printf("    1: %s\n", d_CHN);
   66:         printf("->  1: %s\n", d_LST);
   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 == CHN)
   92:     {
   93:         longueur_initiale = (uLong) strlen((unsigned char*)
   94:                 (*s_objet_argument).objet);
   95:         longueur_max_compression = compressBound(longueur_initiale);
   96: 
   97:         if ((tampon = malloc(((size_t) longueur_max_compression) *
   98:                 sizeof(unsigned char))) == NULL)
   99:         {
  100:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  101:             return;
  102:         }
  103: 
  104:         longueur_compression = longueur_max_compression;
  105: 
  106:         if (compress2(tampon, &longueur_compression,
  107:                 (unsigned char *) (*s_objet_argument).objet,
  108:                 longueur_initiale, 9) != Z_OK)
  109:         {
  110:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  111:             return;
  112:         }
  113: 
  114:         liberation(s_etat_processus, s_objet_argument);
  115: 
  116:         if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL)
  117:         {
  118:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  119:             return;
  120:         }
  121: 
  122:         if (((*s_objet_resultat).objet = allocation_maillon(s_etat_processus))
  123:                 == NULL)
  124:         {
  125:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  126:             return;
  127:         }
  128: 
  129:         l_element_courant = (*s_objet_resultat).objet;
  130: 
  131:         if (((*l_element_courant).donnee = allocation(s_etat_processus, INT))
  132:                 == NULL)
  133:         {
  134:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  135:             return;
  136:         }
  137: 
  138:         (*((integer8 *) (*(*l_element_courant).donnee).objet)) =
  139:                 (integer8) longueur_initiale;
  140: 
  141:         if (((*l_element_courant).suivant = allocation_maillon(
  142:                 s_etat_processus)) == NULL)
  143:         {
  144:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  145:             return;
  146:         }
  147: 
  148:         l_element_courant = (*l_element_courant).suivant;
  149:         (*l_element_courant).suivant = NULL;
  150:         
  151:         if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
  152:                 == NULL)
  153:         {
  154:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  155:             return;
  156:         }
  157: 
  158:         if (((*(*l_element_courant).donnee).objet = analyse_flux(
  159:                 s_etat_processus, tampon, (integer8) longueur_compression))
  160:                 == NULL)
  161:         {
  162:             liberation(s_etat_processus, s_objet_resultat);
  163:             free(tampon);
  164:             return;
  165:         }
  166: 
  167:         free(tampon);
  168: 
  169:         if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  170:                 s_objet_resultat) == d_erreur)
  171:         {
  172:             return;
  173:         }
  174:     }
  175:     else
  176:     {
  177:         liberation(s_etat_processus, s_objet_argument);
  178: 
  179:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  180:         return;
  181:     }
  182: 
  183:     return;
  184: }
  185: 
  186: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>