/[public]/psiconv/trunk/lib/psiconv/parse_simple.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/parse_simple.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 142 Revision 171
28 28
29#ifdef DMALLOC 29#ifdef DMALLOC
30#include <dmalloc.h> 30#include <dmalloc.h>
31#endif 31#endif
32 32
33static psiconv_float_t pow2(int n);
34
33/* Very inefficient, but good enough for now. By implementing it ourselves, 35/* Very inefficient, but good enough for now. By implementing it ourselves,
34 we do not have to link with -lm */ 36 we do not have to link with -lm */
35psiconv_float_t pow2(int n) 37psiconv_float_t pow2(int n)
36{ 38{
37 psiconv_float_t res=1.0; 39 psiconv_float_t res=1.0;
40 for (i = 0; i < (n<0?-n:n); i++) 42 for (i = 0; i < (n<0?-n:n); i++)
41 res *= 2.0; 43 res *= 2.0;
42 44
43 return n<0?1/res:res; 45 return n<0?1/res:res;
44} 46}
45psiconv_u8 psiconv_read_u8(const psiconv_buffer buf,int lev,psiconv_u32 off, 47psiconv_u8 psiconv_read_u8(const psiconv_config config,const psiconv_buffer buf,int lev,psiconv_u32 off,
46 int *status) 48 int *status)
47{ 49{
48 psiconv_u8 *ptr; 50 psiconv_u8 *ptr;
49 ptr = psiconv_buffer_get(buf,off); 51 ptr = psiconv_buffer_get(buf,off);
50 if (!ptr) { 52 if (!ptr) {
51 psiconv_warn(lev,off,"Trying byte read past the end of the file"); 53 psiconv_warn(config,lev,off,"Trying byte read past the end of the file");
52 if (status) 54 if (status)
53 *status = -PSICONV_E_PARSE; 55 *status = -PSICONV_E_PARSE;
54 return 0; 56 return 0;
55 } 57 }
56 if (status) 58 if (status)
57 *status = 0; 59 *status = 0;
58 return *ptr; 60 return *ptr;
59} 61}
60 62
61psiconv_u16 psiconv_read_u16(const psiconv_buffer buf,int lev,psiconv_u32 off, 63psiconv_u16 psiconv_read_u16(const psiconv_config config,const psiconv_buffer buf,int lev,psiconv_u32 off,
62 int *status) 64 int *status)
63{ 65{
64 psiconv_u8 *ptr0,*ptr1; 66 psiconv_u8 *ptr0,*ptr1;
65 ptr0 = psiconv_buffer_get(buf,off); 67 ptr0 = psiconv_buffer_get(buf,off);
66 ptr1 = psiconv_buffer_get(buf,off+1); 68 ptr1 = psiconv_buffer_get(buf,off+1);
67 if (!ptr0 || !ptr1) { 69 if (!ptr0 || !ptr1) {
68 psiconv_warn(lev,off,"Trying word read past the end of the file"); 70 psiconv_warn(config,lev,off,"Trying word read past the end of the file");
69 if (status) 71 if (status)
70 *status = -PSICONV_E_PARSE; 72 *status = -PSICONV_E_PARSE;
71 return 0; 73 return 0;
72 } 74 }
73 if (status) 75 if (status)
74 *status = 0; 76 *status = 0;
75 return *ptr0 + (*ptr1 << 8); 77 return *ptr0 + (*ptr1 << 8);
76} 78}
77 79
78psiconv_u32 psiconv_read_u32(const psiconv_buffer buf,int lev,psiconv_u32 off, 80psiconv_u32 psiconv_read_u32(const psiconv_config config,const psiconv_buffer buf,int lev,psiconv_u32 off,
79 int *status) 81 int *status)
80{ 82{
81 psiconv_u8 *ptr0,*ptr1,*ptr2,*ptr3; 83 psiconv_u8 *ptr0,*ptr1,*ptr2,*ptr3;
82 ptr0 = psiconv_buffer_get(buf,off); 84 ptr0 = psiconv_buffer_get(buf,off);
83 ptr1 = psiconv_buffer_get(buf,off+1); 85 ptr1 = psiconv_buffer_get(buf,off+1);
84 ptr2 = psiconv_buffer_get(buf,off+2); 86 ptr2 = psiconv_buffer_get(buf,off+2);
85 ptr3 = psiconv_buffer_get(buf,off+3); 87 ptr3 = psiconv_buffer_get(buf,off+3);
86 if (!ptr0 || !ptr1 || !ptr2 || !ptr3) { 88 if (!ptr0 || !ptr1 || !ptr2 || !ptr3) {
87 psiconv_warn(lev,off,"Trying long read past the end of the file"); 89 psiconv_warn(config,lev,off,"Trying long read past the end of the file");
88 if (status) 90 if (status)
89 *status = -PSICONV_E_PARSE; 91 *status = -PSICONV_E_PARSE;
90 return 0; 92 return 0;
91 } 93 }
92 if (status) 94 if (status)
93 *status = 0; 95 *status = 0;
94 return *ptr0 + (*ptr1 << 8) + (*ptr2 << 16) + (*ptr3 << 24); 96 return *ptr0 + (*ptr1 << 8) + (*ptr2 << 16) + (*ptr3 << 24);
95} 97}
96 98
97psiconv_s32 psiconv_read_sint(const psiconv_buffer buf,int lev,psiconv_u32 off, 99psiconv_s32 psiconv_read_sint(const psiconv_config config,const psiconv_buffer buf,int lev,psiconv_u32 off,
98 int *length,int *status) 100 int *length,int *status)
99{ 101{
100 int localstatus; 102 int localstatus;
101 psiconv_u32 temp; 103 psiconv_u32 temp;
102 104
103 temp=psiconv_read_u32(buf,lev,off,&localstatus); 105 temp=psiconv_read_u32(config,buf,lev,off,&localstatus);
104 if (status) 106 if (status)
105 *status = localstatus; 107 *status = localstatus;
106 if (length) 108 if (length)
107 *length = localstatus?0:4; 109 *length = localstatus?0:4;
108 110
109 return localstatus?0:(temp & 0x7fffffff)*(temp&0x80000000?-1:1); 111 return localstatus?0:(temp & 0x7fffffff)*(temp&0x80000000?-1:1);
110} 112}
111 113
112psiconv_S_t psiconv_read_S(const psiconv_buffer buf, int lev, psiconv_u32 off, 114psiconv_S_t psiconv_read_S(const psiconv_config config,const psiconv_buffer buf, int lev, psiconv_u32 off,
113 int *length,int *status) 115 int *length,int *status)
114{ 116{
115 psiconv_u8 temp; 117 psiconv_u8 temp;
116 psiconv_S_t res; 118 psiconv_S_t res;
117 int len,localstatus; 119 int len,localstatus;
118 120
119 psiconv_progress(lev+1,off,"Going to read a S length indicator"); 121 psiconv_progress(config,lev+1,off,"Going to read a S length indicator");
120 temp = psiconv_read_u8(buf,lev+2,off,&localstatus); 122 temp = psiconv_read_u8(config,buf,lev+2,off,&localstatus);
121 if (localstatus) 123 if (localstatus)
122 goto ERROR; 124 goto ERROR;
123 if ((temp & 0x03) == 0x02) { 125 if ((temp & 0x03) == 0x02) {
124 res = psiconv_read_u8(buf,lev+2,off,&localstatus) >> 2; 126 res = psiconv_read_u8(config,buf,lev+2,off,&localstatus) >> 2;
125 if (localstatus) 127 if (localstatus)
126 goto ERROR; 128 goto ERROR;
127 len = 1; 129 len = 1;
128 psiconv_debug(lev+2,off,"Indicator (1 byte): %02x",res); 130 psiconv_debug(config,lev+2,off,"Indicator (1 byte): %02x",res);
129 } else if ((temp & 0x07) == 0x05) { 131 } else if ((temp & 0x07) == 0x05) {
130 res = psiconv_read_u16(buf,lev+2,off,&localstatus) >> 3; 132 res = psiconv_read_u16(config,buf,lev+2,off,&localstatus) >> 3;
131 if (localstatus) 133 if (localstatus)
132 goto ERROR; 134 goto ERROR;
133 len = 2; 135 len = 2;
134 psiconv_debug(lev+2,off,"Indicator (2 bytes): %04x",res); 136 psiconv_debug(config,lev+2,off,"Indicator (2 bytes): %04x",res);
135 } else { 137 } else {
136 psiconv_warn(lev+2,off,"S indicator: unknown encoding!"); 138 psiconv_warn(config,lev+2,off,"S indicator: unknown encoding!");
137 psiconv_debug(lev+2,off,"Raw data first byte: %02x",temp); 139 psiconv_debug(config,lev+2,off,"Raw data first byte: %02x",temp);
138 goto ERROR; 140 goto ERROR;
139 } 141 }
140 142
141 if (length) 143 if (length)
142 *length = len; 144 *length = len;
143 if (status) 145 if (status)
144 *status = 0; 146 *status = 0;
145 147
146 psiconv_progress(lev+1,off+len-1, 148 psiconv_progress(config,lev+1,off+len-1,
147 "End of S length indicator (total length: %08x)", len); 149 "End of S length indicator (total length: %08x)", len);
148 150
149 return res; 151 return res;
150 152
151ERROR: 153ERROR:
152 psiconv_warn(lev+1,off,"Reading of S indicator failed"); 154 psiconv_warn(config,lev+1,off,"Reading of S indicator failed");
153 if (status) 155 if (status)
154 *status = localstatus; 156 *status = localstatus;
155 if (length) 157 if (length)
156 *length = 0; 158 *length = 0;
157 return 0; 159 return 0;
158} 160}
159 161
160psiconv_X_t psiconv_read_X(const psiconv_buffer buf, int lev, psiconv_u32 off, 162psiconv_X_t psiconv_read_X(const psiconv_config config,const psiconv_buffer buf, int lev, psiconv_u32 off,
161 int *length, int *status) 163 int *length, int *status)
162{ 164{
163 psiconv_u8 temp; 165 psiconv_u8 temp;
164 psiconv_X_t res; 166 psiconv_X_t res;
165 int len,localstatus; 167 int len,localstatus;
166 168
167 psiconv_progress(lev+1,off,"Going to read a X length indicator"); 169 psiconv_progress(config,lev+1,off,"Going to read a X length indicator");
168 temp = psiconv_read_u8(buf,lev+2,off,&localstatus); 170 temp = psiconv_read_u8(config,buf,lev+2,off,&localstatus);
169 if (localstatus) 171 if (localstatus)
170 goto ERROR; 172 goto ERROR;
171 if ((temp & 0x01) == 0x00) { 173 if ((temp & 0x01) == 0x00) {
172 res = psiconv_read_u8(buf,lev+2,off,&localstatus) >> 1; 174 res = psiconv_read_u8(config,buf,lev+2,off,&localstatus) >> 1;
173 if (localstatus) 175 if (localstatus)
174 goto ERROR; 176 goto ERROR;
175 len = 1; 177 len = 1;
176 psiconv_debug(lev+2,off,"Indicator (1 byte): %02x",res); 178 psiconv_debug(config,lev+2,off,"Indicator (1 byte): %02x",res);
177 } else if ((temp & 0x03) == 0x01) { 179 } else if ((temp & 0x03) == 0x01) {
178 res = psiconv_read_u16(buf,lev+2,off,&localstatus) >> 2; 180 res = psiconv_read_u16(config,buf,lev+2,off,&localstatus) >> 2;
179 if (localstatus) 181 if (localstatus)
180 goto ERROR; 182 goto ERROR;
181 len = 2; 183 len = 2;
182 psiconv_debug(lev+2,off,"Indicator (2 bytes): %04x",res); 184 psiconv_debug(config,lev+2,off,"Indicator (2 bytes): %04x",res);
183 } else if ((temp & 0x07) == 0x03) { 185 } else if ((temp & 0x07) == 0x03) {
184 res = psiconv_read_u32(buf,lev+2,off,&localstatus) >> 3; 186 res = psiconv_read_u32(config,buf,lev+2,off,&localstatus) >> 3;
185 if (localstatus) 187 if (localstatus)
186 goto ERROR; 188 goto ERROR;
187 len = 4; 189 len = 4;
188 psiconv_debug(lev+2,off,"Indicator (4 bytes): %08x",res); 190 psiconv_debug(config,lev+2,off,"Indicator (4 bytes): %08x",res);
189 } else { 191 } else {
190 psiconv_warn(lev+2,off,"X indicator: unknown encoding!"); 192 psiconv_warn(config,lev+2,off,"X indicator: unknown encoding!");
191 psiconv_debug(lev+2,off,"Raw data first byte: %02x",temp); 193 psiconv_debug(config,lev+2,off,"Raw data first byte: %02x",temp);
192 goto ERROR; 194 goto ERROR;
193 } 195 }
194 196
195 if (length) 197 if (length)
196 *length = len; 198 *length = len;
197 if (status) 199 if (status)
198 *status = 0; 200 *status = 0;
199 201
200 psiconv_progress(lev+1,off+len-1, 202 psiconv_progress(config,lev+1,off+len-1,
201 "End of X length indicator (total length: %08x)", len); 203 "End of X length indicator (total length: %08x)", len);
202 204
203 return res; 205 return res;
204 206
205ERROR: 207ERROR:
206 psiconv_warn(lev+1,off,"Reading of X indicator failed"); 208 psiconv_warn(config,lev+1,off,"Reading of X indicator failed");
207 if (status) 209 if (status)
208 *status = localstatus; 210 *status = localstatus;
209 if (length) 211 if (length)
210 *length = 0; 212 *length = 0;
211 return 0; 213 return 0;
212} 214}
213 215
214psiconv_length_t psiconv_read_length(const psiconv_buffer buf, int lev, 216psiconv_length_t psiconv_read_length(const psiconv_config config,const psiconv_buffer buf, int lev,
215 psiconv_u32 off, int *length, int *status) 217 psiconv_u32 off, int *length, int *status)
216{ 218{
217 psiconv_length_t res; 219 psiconv_length_t res;
218 int localstatus; 220 int localstatus;
219 221
220 res = (2.54/1440.0) * ((psiconv_s32) psiconv_read_u32(buf,lev,off, 222 res = (2.54/1440.0) * ((psiconv_s32) psiconv_read_u32(config,buf,lev,off,
221 &localstatus)); 223 &localstatus));
222 if (localstatus) { 224 if (localstatus) {
223 psiconv_warn(lev+1,off,"Reading of length failed"); 225 psiconv_warn(config,lev+1,off,"Reading of length failed");
224 if (length) 226 if (length)
225 *length = 0; 227 *length = 0;
226 if (status) 228 if (status)
227 *status = localstatus; 229 *status = localstatus;
228 return 0; 230 return 0;
229 } 231 }
230 psiconv_debug(lev+1,off,"Length: %f",res); 232 psiconv_debug(config,lev+1,off,"Length: %f",res);
231 if (length) 233 if (length)
232 *length = 4; 234 *length = 4;
233 if (status) 235 if (status)
234 *status = 0; 236 *status = 0;
235 return res; 237 return res;
236} 238}
237 239
238psiconv_size_t psiconv_read_size(const psiconv_buffer buf, int lev, 240psiconv_size_t psiconv_read_size(const psiconv_config config,const psiconv_buffer buf, int lev,
239 psiconv_u32 off, int *length, int *status) 241 psiconv_u32 off, int *length, int *status)
240{ 242{
241 psiconv_size_t res; 243 psiconv_size_t res;
242 int localstatus; 244 int localstatus;
243 res = ((psiconv_s32) psiconv_read_u32(buf,lev,off,&localstatus)) / 20.0; 245 res = ((psiconv_s32) psiconv_read_u32(config,buf,lev,off,&localstatus)) / 20.0;
244 if (localstatus) { 246 if (localstatus) {
245 psiconv_warn(lev+1,off,"Reading of size failed"); 247 psiconv_warn(config,lev+1,off,"Reading of size failed");
246 if (length) 248 if (length)
247 *length = 0; 249 *length = 0;
248 if (status) 250 if (status)
249 *status = localstatus; 251 *status = localstatus;
250 return 0; 252 return 0;
251 } 253 }
252 psiconv_debug(lev+1,off,"Size: %f",res); 254 psiconv_debug(config,lev+1,off,"Size: %f",res);
253 if (status) 255 if (status)
254 *status = 0; 256 *status = 0;
255 if (length) 257 if (length)
256 *length = 4; 258 *length = 4;
257 return res; 259 return res;
258} 260}
259 261
260int psiconv_parse_bool(const psiconv_buffer buf, int lev, psiconv_u32 off, 262int psiconv_parse_bool(const psiconv_config config,const psiconv_buffer buf, int lev, psiconv_u32 off,
261 int *length, psiconv_bool_t *result) 263 int *length, psiconv_bool_t *result)
262{ 264{
263 psiconv_u8 temp; 265 psiconv_u8 temp;
264 int localstatus; 266 int localstatus;
265 temp = psiconv_read_u8(buf,lev,off,&localstatus); 267 temp = psiconv_read_u8(config,buf,lev,off,&localstatus);
266 if (localstatus) { 268 if (localstatus) {
267 psiconv_warn(lev+1,off,"Reading of bool failed"); 269 psiconv_warn(config,lev+1,off,"Reading of bool failed");
268 if (length) 270 if (length)
269 *length = 0; 271 *length = 0;
270 return localstatus; 272 return localstatus;
271 } 273 }
272 if (length) 274 if (length)
276 return 0; 278 return 0;
277 } else if (temp == 1) { 279 } else if (temp == 1) {
278 *result = psiconv_bool_true; 280 *result = psiconv_bool_true;
279 return 0; 281 return 0;
280 } 282 }
281 psiconv_warn(lev+1,off,"Unknown value for boolean"); 283 psiconv_warn(config,lev+1,off,"Unknown value for boolean");
282 psiconv_debug(lev+1,off,"Boolean value: %02x",temp); 284 psiconv_debug(config,lev+1,off,"Boolean value: %02x",temp);
283 *result = psiconv_bool_true; 285 *result = psiconv_bool_true;
284 return 0; 286 return 0;
285} 287}
286 288
287psiconv_string_t psiconv_read_string(const psiconv_buffer buf,int lev, 289psiconv_string_t psiconv_read_string(const psiconv_config config,const psiconv_buffer buf,int lev,
288 psiconv_u32 off,int *length, int *status) 290 psiconv_u32 off,int *length, int *status)
289{ 291{
290 int stringlen,i,leng,len,localstatus; 292 int stringlen,i,leng,len,localstatus;
291 psiconv_string_t result; 293 psiconv_string_t result;
292 char *res_copy; 294 char *res_copy;
293 295
294 psiconv_progress(lev+1,off,"Going to read a string"); 296 psiconv_progress(config,lev+1,off,"Going to read a string");
295 297
296 stringlen = psiconv_read_S(buf,lev+2,off,&leng,&localstatus); 298 stringlen = psiconv_read_S(config,buf,lev+2,off,&leng,&localstatus);
297 if (localstatus) 299 if (localstatus)
298 goto ERROR1; 300 goto ERROR1;
299 psiconv_debug(lev+2,off,"Length: %i",stringlen); 301 psiconv_debug(config,lev+2,off,"Length: %i",stringlen);
300 len = leng; 302 len = leng;
301 303
302 result = malloc(stringlen + 1); 304 result = malloc(stringlen + 1);
303 if (!result) 305 if (!result)
304 goto ERROR1; 306 goto ERROR1;
305 for (i = 0; (i < stringlen) && !localstatus; i++) 307 for (i = 0; (i < stringlen) && !localstatus; i++)
306 result[i] = psiconv_read_u8(buf,lev,off+i+len,&localstatus); 308 result[i] = psiconv_read_u8(config,buf,lev,off+i+len,&localstatus);
307 if (localstatus) 309 if (localstatus)
308 goto ERROR2; 310 goto ERROR2;
309 result[stringlen] = 0; 311 result[stringlen] = 0;
310 len += stringlen; 312 len += stringlen;
311 313
312 res_copy = psiconv_make_printable(result); 314 res_copy = psiconv_make_printable(result);
313 if (!res_copy) 315 if (!res_copy)
314 goto ERROR2; 316 goto ERROR2;
315 psiconv_debug(lev+2,off,"Contents: `%s'",res_copy); 317 psiconv_debug(config,lev+2,off,"Contents: `%s'",res_copy);
316 free(res_copy); 318 free(res_copy);
317 319
318 if (length) 320 if (length)
319 *length = len; 321 *length = len;
320 322
321 if (status) 323 if (status)
322 *status = 0; 324 *status = 0;
323 325
324 psiconv_progress(lev+1,off+len-1,"End of string (total length: %08x)",len); 326 psiconv_progress(config,lev+1,off+len-1,"End of string (total length: %08x)",len);
325 327
326 return result; 328 return result;
327 329
328ERROR2: 330ERROR2:
329 free(result); 331 free(result);
330ERROR1: 332ERROR1:
331 psiconv_warn(lev+1,off,"Reading of string failed"); 333 psiconv_warn(config,lev+1,off,"Reading of string failed");
332 if (status) 334 if (status)
333 *status = localstatus; 335 *status = localstatus;
334 if (length) 336 if (length)
335 *length = 0; 337 *length = 0;
336 return NULL; 338 return NULL;
337} 339}
338 340
339psiconv_string_t psiconv_read_short_string(const psiconv_buffer buf, 341psiconv_string_t psiconv_read_short_string(const psiconv_config config, const psiconv_buffer buf,
340 int lev, 342 int lev,
341 psiconv_u32 off,int *length, int *status) 343 psiconv_u32 off,int *length, int *status)
342{ 344{
343 int stringlen,i,len,localstatus; 345 int stringlen,i,len,localstatus;
344 psiconv_string_t result; 346 psiconv_string_t result;
345 char *res_copy; 347 char *res_copy;
346 348
347 psiconv_progress(lev+1,off,"Going to read a short string"); 349 psiconv_progress(config,lev+1,off,"Going to read a short string");
348 350
349 stringlen = psiconv_read_u8(buf,lev+2,off,&localstatus); 351 stringlen = psiconv_read_u8(config,buf,lev+2,off,&localstatus);
350 if (localstatus) 352 if (localstatus)
351 goto ERROR1; 353 goto ERROR1;
352 psiconv_debug(lev+2,off,"Length: %i",stringlen); 354 psiconv_debug(config,lev+2,off,"Length: %i",stringlen);
353 len = 1; 355 len = 1;
354 356
355 result = malloc(stringlen + 1); 357 result = malloc(stringlen + 1);
356 if (!result) 358 if (!result)
357 goto ERROR1; 359 goto ERROR1;
358 for (i = 0; (i < stringlen) && !localstatus; i++) 360 for (i = 0; (i < stringlen) && !localstatus; i++)
359 result[i] = psiconv_read_u8(buf,lev,off+i+len,&localstatus); 361 result[i] = psiconv_read_u8(config,buf,lev,off+i+len,&localstatus);
360 if (localstatus) 362 if (localstatus)
361 goto ERROR2; 363 goto ERROR2;
362 result[stringlen] = 0; 364 result[stringlen] = 0;
363 len += stringlen; 365 len += stringlen;
364 366
365 res_copy = psiconv_make_printable(result); 367 res_copy = psiconv_make_printable(result);
366 if (!res_copy) 368 if (!res_copy)
367 goto ERROR2; 369 goto ERROR2;
368 psiconv_debug(lev+2,off,"Contents: `%s'",res_copy); 370 psiconv_debug(config,lev+2,off,"Contents: `%s'",res_copy);
369 free(res_copy); 371 free(res_copy);
370 372
371 if (length) 373 if (length)
372 *length = len; 374 *length = len;
373 375
374 if (status) 376 if (status)
375 *status = 0; 377 *status = 0;
376 378
377 psiconv_progress(lev+1,off+len-1,"End of short string (total length: %08x)", 379 psiconv_progress(config,lev+1,off+len-1,"End of short string (total length: %08x)",
378 len); 380 len);
379 381
380 return result; 382 return result;
381 383
382 384
383ERROR2: 385ERROR2:
384 free(result); 386 free(result);
385ERROR1: 387ERROR1:
386 psiconv_warn(lev+1,off,"Reading of short string failed"); 388 psiconv_warn(config,lev+1,off,"Reading of short string failed");
387 if (status) 389 if (status)
388 *status = localstatus; 390 *status = localstatus;
389 if (length) 391 if (length)
390 *length = 0; 392 *length = 0;
391 return NULL; 393 return NULL;
392} 394}
393 395
394psiconv_float_t psiconv_read_float(const psiconv_buffer buf, int lev, 396psiconv_float_t psiconv_read_float(const psiconv_config config,const psiconv_buffer buf, int lev,
395 psiconv_u32 off, int *length, int *status) 397 psiconv_u32 off, int *length, int *status)
396{ 398{
397 psiconv_float_t result,bitvalue; 399 psiconv_float_t result,bitvalue;
398 int res,bit; 400 int res,bit;
399 psiconv_u32 temp=0; 401 psiconv_u32 temp=0;
400 402
401 psiconv_progress(lev+1,off,"Going to read a float"); 403 psiconv_progress(config,lev+1,off,"Going to read a float");
402 404
403 bitvalue = 0.5; 405 bitvalue = 0.5;
404 result = 1.0; 406 result = 1.0;
405 for (bit = 0x33; bit > 0; bit--) { 407 for (bit = 0x33; bit > 0; bit--) {
406 if ((bit == 0x33) || ((bit & 0x07) == 0x07)) 408 if ((bit == 0x33) || ((bit & 0x07) == 0x07))
407 temp = psiconv_read_u8(buf,lev+2,off+ (bit >> 3),&res); 409 temp = psiconv_read_u8(config,buf,lev+2,off+ (bit >> 3),&res);
408 if (res) 410 if (res)
409 goto ERROR; 411 goto ERROR;
410 if (temp & (0x01 << (bit & 0x07))) 412 if (temp & (0x01 << (bit & 0x07)))
411 result += bitvalue; 413 result += bitvalue;
412 bitvalue /= 2.0; 414 bitvalue /= 2.0;
413 } 415 }
414 temp = psiconv_read_u16(buf,lev+2,off+6,&res); 416 temp = psiconv_read_u16(config,buf,lev+2,off+6,&res);
415 if (res) 417 if (res)
416 goto ERROR; 418 goto ERROR;
417 if (temp & 0x8000) 419 if (temp & 0x8000)
418 result = -result; 420 result = -result;
419 temp = (temp & 0x7ff0) >> 4; 421 temp = (temp & 0x7ff0) >> 4;
420 result *= pow2(((int) temp)-0x3ff); 422 result *= pow2(((int) temp)-0x3ff);
421 psiconv_debug(lev+1,off,"Float value: %f",result); 423 psiconv_debug(config,lev+1,off,"Float value: %f",result);
422 if (length) 424 if (length)
423 *length = 8; 425 *length = 8;
424 if (*status) 426 if (*status)
425 *status = res; 427 *status = res;
426 return result; 428 return result;
427ERROR: 429ERROR:
428 psiconv_warn(lev+1,off,"Reading of float failed"); 430 psiconv_warn(config,lev+1,off,"Reading of float failed");
429 if (length) 431 if (length)
430 *length = 0; 432 *length = 0;
431 if (*status) 433 if (*status)
432 *status = res; 434 *status = res;
433 return 0.0; 435 return 0.0;

Legend:
Removed from v.142  
changed lines
  Added in v.171

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26