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

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

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