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

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

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