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:
22: #define DEBUG_ERREURS
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:
95: if ((*(*l_element_courant).donnee).type != INT)
96: {
97: liberation(s_etat_processus, s_objet_argument);
98:
99: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
100: return;
101: }
102:
103: taille = (uLong) (*((integer8 *) (*(*l_element_courant).donnee).objet));
104: l_element_courant = (*l_element_courant).suivant;
105:
106: if (l_element_courant == NULL)
107: {
108: liberation(s_etat_processus, s_objet_argument);
109:
110: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
111: return;
112: }
113:
114: if ((*(*l_element_courant).donnee).type != CHN)
115: {
116: liberation(s_etat_processus, s_objet_argument);
117:
118: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
119: return;
120: }
121:
122: if ((*l_element_courant).suivant != 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 ((tampon = formateur_flux(s_etat_processus,
131: (*(*l_element_courant).donnee).objet, &longueur_tampon))
132: == NULL)
133: {
134: return;
135: }
136:
137: if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
138: {
139: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
140: return;
141: }
142:
143: if (((*s_objet_resultat).objet = malloc(((size_t) (taille + 1)) *
144: sizeof(unsigned char))) == NULL)
145: {
146: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
147: return;
148: }
149:
150: switch(uncompress((*s_objet_resultat).objet, &taille,
151: tampon, (uLong) longueur_tampon))
152: {
153: case Z_MEM_ERROR:
154: {
155: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
156: return;
157: }
158:
159: case Z_BUF_ERROR:
160: case Z_DATA_ERROR:
161: {
162: liberation(s_etat_processus, s_objet_argument);
163: liberation(s_etat_processus, s_objet_resultat);
164: free(tampon);
165:
166: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
167: return;
168: }
169:
170: default:
171: case Z_OK:
172: {
173: break;
174: }
175: }
176:
177: ((unsigned char *) (*s_objet_resultat).objet)[taille] =
178: d_code_fin_chaine;
179: liberation(s_etat_processus, s_objet_argument);
180: free(tampon);
181:
182: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
183: s_objet_resultat) == d_erreur)
184: {
185: return;
186: }
187: }
188: else
189: {
190: liberation(s_etat_processus, s_objet_argument);
191:
192: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
193: return;
194: }
195:
196: return;
197: }
198:
199: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>