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

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

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