/[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 64 Revision 101
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 18*/
19 19
20#include "config.h" 20#include "config.h"
21#include "compat.h"
22
21#include <stdlib.h> 23#include <stdlib.h>
24#include <math.h>
22 25
23#include "parse_routines.h" 26#include "parse_routines.h"
27#include "error.h"
24 28
25psiconv_u8 psiconv_read_u8(const psiconv_buffer buf,int lev,psiconv_u32 off, 29psiconv_u8 psiconv_read_u8(const psiconv_buffer buf,int lev,psiconv_u32 off,
26 int *status) 30 int *status)
27{ 31{
28 psiconv_u8 *ptr; 32 psiconv_u8 *ptr;
29 ptr = psiconv_list_get(buf,off); 33 ptr = psiconv_buffer_get(buf,off);
30 if (!ptr) { 34 if (!ptr) {
31 psiconv_warn(lev,off,"Trying byte read past the end of the file"); 35 psiconv_warn(lev,off,"Trying byte read past the end of the file");
32 if (status) 36 if (status)
33 *status = -PSICONV_E_PARSE; 37 *status = -PSICONV_E_PARSE;
34 return 0; 38 return 0;
40 44
41psiconv_u16 psiconv_read_u16(const psiconv_buffer buf,int lev,psiconv_u32 off, 45psiconv_u16 psiconv_read_u16(const psiconv_buffer buf,int lev,psiconv_u32 off,
42 int *status) 46 int *status)
43{ 47{
44 psiconv_u8 *ptr0,*ptr1; 48 psiconv_u8 *ptr0,*ptr1;
45 ptr0 = psiconv_list_get(buf,off); 49 ptr0 = psiconv_buffer_get(buf,off);
46 ptr1 = psiconv_list_get(buf,off+1); 50 ptr1 = psiconv_buffer_get(buf,off+1);
47 if (!ptr0 || !ptr1) { 51 if (!ptr0 || !ptr1) {
48 psiconv_warn(lev,off,"Trying word read past the end of the file"); 52 psiconv_warn(lev,off,"Trying word read past the end of the file");
49 if (status) 53 if (status)
50 *status = -PSICONV_E_PARSE; 54 *status = -PSICONV_E_PARSE;
51 return 0; 55 return 0;
57 61
58psiconv_u32 psiconv_read_u32(const psiconv_buffer buf,int lev,psiconv_u32 off, 62psiconv_u32 psiconv_read_u32(const psiconv_buffer buf,int lev,psiconv_u32 off,
59 int *status) 63 int *status)
60{ 64{
61 psiconv_u8 *ptr0,*ptr1,*ptr2,*ptr3; 65 psiconv_u8 *ptr0,*ptr1,*ptr2,*ptr3;
62 ptr0 = psiconv_list_get(buf,off); 66 ptr0 = psiconv_buffer_get(buf,off);
63 ptr1 = psiconv_list_get(buf,off+1); 67 ptr1 = psiconv_buffer_get(buf,off+1);
64 ptr2 = psiconv_list_get(buf,off+2); 68 ptr2 = psiconv_buffer_get(buf,off+2);
65 ptr3 = psiconv_list_get(buf,off+3); 69 ptr3 = psiconv_buffer_get(buf,off+3);
66 if (!ptr0 || !ptr1 || !ptr2 || !ptr3) { 70 if (!ptr0 || !ptr1 || !ptr2 || !ptr3) {
67 psiconv_warn(lev,off,"Trying long read past the end of the file"); 71 psiconv_warn(lev,off,"Trying long read past the end of the file");
68 if (status) 72 if (status)
69 *status = -PSICONV_E_PARSE; 73 *status = -PSICONV_E_PARSE;
70 return 0; 74 return 0;
298 *status = localstatus; 302 *status = localstatus;
299 if (length) 303 if (length)
300 *length = 0; 304 *length = 0;
301 return NULL; 305 return NULL;
302} 306}
307
308psiconv_float_t psiconv_read_float(const psiconv_buffer buf, int lev,
309 psiconv_u32 off, int *length, int *status)
310{
311 psiconv_float_t result,bitvalue;
312 int res,bit;
313 psiconv_u32 temp=0;
314
315 psiconv_progress(lev+1,off,"Going to read a float");
316
317 bitvalue = 0.5;
318 result = 1.0;
319 for (bit = 0x33; bit > 0; bit--) {
320 if ((bit == 0x33) || ((bit & 0x07) == 0x07))
321 temp = psiconv_read_u8(buf,lev+2,off+ (bit >> 3),&res);
322 if (res)
323 goto ERROR;
324 if (temp & (0x01 << (bit & 0x07)))
325 result += bitvalue;
326 bitvalue /= 2.0;
327 }
328 temp = psiconv_read_u16(buf,lev+2,off+6,&res);
329 if (res)
330 goto ERROR;
331 if (temp & 0x8000)
332 result = -result;
333 temp = (temp & 0x7ff0) >> 4;
334 result *= pow(2.0,((int) temp)-0x3ff);
335 psiconv_debug(lev+1,off,"Float value: %f",result);
336 if (length)
337 *length = 8;
338 if (*status)
339 *status = res;
340 return result;
341ERROR:
342 psiconv_warn(lev+1,off,"Reading of float failed");
343 if (length)
344 *length = 0;
345 if (*status)
346 *status = res;
347 return 0.0;
348}

Legend:
Removed from v.64  
changed lines
  Added in v.101

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