/[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 168 Revision 182
27#include "error.h" 27#include "error.h"
28 28
29#ifdef DMALLOC 29#ifdef DMALLOC
30#include <dmalloc.h> 30#include <dmalloc.h>
31#endif 31#endif
32
33static psiconv_float_t pow2(int n);
34static psiconv_string_t psiconv_read_string_aux(const psiconv_config config,
35 const psiconv_buffer buf,int lev,
36 psiconv_u32 off,int *length, int *status,
37 int kind);
32 38
33/* Very inefficient, but good enough for now. By implementing it ourselves, 39/* Very inefficient, but good enough for now. By implementing it ourselves,
34 we do not have to link with -lm */ 40 we do not have to link with -lm */
35psiconv_float_t pow2(int n) 41psiconv_float_t pow2(int n)
36{ 42{
282 psiconv_debug(config,lev+1,off,"Boolean value: %02x",temp); 288 psiconv_debug(config,lev+1,off,"Boolean value: %02x",temp);
283 *result = psiconv_bool_true; 289 *result = psiconv_bool_true;
284 return 0; 290 return 0;
285} 291}
286 292
287psiconv_string_t psiconv_read_string(const psiconv_config config,const psiconv_buffer buf,int lev, 293psiconv_string_t psiconv_read_string(const psiconv_config config,
294 const psiconv_buffer buf,int lev,
288 psiconv_u32 off,int *length, int *status) 295 psiconv_u32 off,int *length, int *status)
296{
297 return psiconv_read_string_aux(config,buf,lev,off,length,status,0);
298}
299
300psiconv_string_t psiconv_read_short_string(const psiconv_config config,
301 const psiconv_buffer buf,int lev,
302 psiconv_u32 off,int *length, int *status)
303{
304 return psiconv_read_string_aux(config,buf,lev,off,length,status,1);
305}
306
307psiconv_string_t psiconv_read_string_aux(const psiconv_config config,
308 const psiconv_buffer buf,int lev,
309 psiconv_u32 off,int *length, int *status,
310 int kind)
289{ 311{
290 int stringlen,i,leng,len,localstatus; 312 int stringlen,i,leng,len,localstatus;
291 psiconv_string_t result; 313 psiconv_string_t result;
292 char *res_copy; 314 char *res_copy;
293 315
294 psiconv_progress(config,lev+1,off,"Going to read a string"); 316 psiconv_progress(config,lev+1,off,"Going to read a string");
295 317
318 if (kind == 0)
296 stringlen = psiconv_read_S(config,buf,lev+2,off,&leng,&localstatus); 319 stringlen = psiconv_read_S(config,buf,lev+2,off,&leng,&localstatus);
320 else {
321 stringlen = psiconv_read_u8(config,buf,lev+2,off,&localstatus);
322 leng = 1;
323 }
324
297 if (localstatus) 325 if (localstatus)
298 goto ERROR1; 326 goto ERROR1;
299 psiconv_debug(config,lev+2,off,"Length: %i",stringlen); 327 psiconv_debug(config,lev+2,off,"Length: %i",stringlen);
300 len = leng; 328 len = leng;
301 329
334 if (length) 362 if (length)
335 *length = 0; 363 *length = 0;
336 return NULL; 364 return NULL;
337} 365}
338 366
339psiconv_string_t psiconv_read_short_string(const psiconv_config config, const psiconv_buffer buf,
340 int lev,
341 psiconv_u32 off,int *length, int *status)
342{
343 int stringlen,i,len,localstatus;
344 psiconv_string_t result;
345 char *res_copy;
346
347 psiconv_progress(config,lev+1,off,"Going to read a short string");
348
349 stringlen = psiconv_read_u8(config,buf,lev+2,off,&localstatus);
350 if (localstatus)
351 goto ERROR1;
352 psiconv_debug(config,lev+2,off,"Length: %i",stringlen);
353 len = 1;
354
355 result = malloc(stringlen + 1);
356 if (!result)
357 goto ERROR1;
358 for (i = 0; (i < stringlen) && !localstatus; i++)
359 result[i] = psiconv_read_u8(config,buf,lev,off+i+len,&localstatus);
360 if (localstatus)
361 goto ERROR2;
362 result[stringlen] = 0;
363 len += stringlen;
364
365 res_copy = psiconv_make_printable(result);
366 if (!res_copy)
367 goto ERROR2;
368 psiconv_debug(config,lev+2,off,"Contents: `%s'",res_copy);
369 free(res_copy);
370
371 if (length)
372 *length = len;
373
374 if (status)
375 *status = 0;
376
377 psiconv_progress(config,lev+1,off+len-1,"End of short string (total length: %08x)",
378 len);
379
380 return result;
381
382
383ERROR2:
384 free(result);
385ERROR1:
386 psiconv_warn(config,lev+1,off,"Reading of short string failed");
387 if (status)
388 *status = localstatus;
389 if (length)
390 *length = 0;
391 return NULL;
392}
393
394psiconv_float_t psiconv_read_float(const psiconv_config config,const psiconv_buffer buf, int lev, 367psiconv_float_t psiconv_read_float(const psiconv_config config,const psiconv_buffer buf, int lev,
395 psiconv_u32 off, int *length, int *status) 368 psiconv_u32 off, int *length, int *status)
396{ 369{
397 psiconv_float_t result,bitvalue; 370 psiconv_float_t result,bitvalue;
398 int res,bit; 371 int res,bit;

Legend:
Removed from v.168  
changed lines
  Added in v.182

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