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

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

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