/[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 196 Revision 217
325psiconv_string_t psiconv_read_string_aux(const psiconv_config config, 325psiconv_string_t psiconv_read_string_aux(const psiconv_config config,
326 const psiconv_buffer buf,int lev, 326 const psiconv_buffer buf,int lev,
327 psiconv_u32 off,int *length, int *status, 327 psiconv_u32 off,int *length, int *status,
328 int kind) 328 int kind)
329{ 329{
330 int stringlen,i,leng,len,localstatus; 330 int bytecount,i,leng,len,localstatus;
331 psiconv_string_t result; 331 psiconv_string_t result;
332 char *res_copy; 332 char *res_copy;
333 psiconv_u8 temp; 333 psiconv_list string;
334 psiconv_ucs2 nextchar;
335 psiconv_ucs2 *nextcharptr;
334 336
335 psiconv_progress(config,lev+1,off,"Going to read a string"); 337 psiconv_progress(config,lev+1,off,"Going to read a string");
336 338
337 if (kind == -1) 339 if (kind == -1)
338 stringlen = psiconv_read_S(config,buf,lev+2,off,&leng,&localstatus); 340 bytecount = psiconv_read_S(config,buf,lev+2,off,&leng,&localstatus);
339 else if (kind == -2) { 341 else if (kind == -2) {
340 stringlen = psiconv_read_u8(config,buf,lev+2,off,&localstatus); 342 bytecount = psiconv_read_u8(config,buf,lev+2,off,&localstatus);
341 leng = 1; 343 leng = 1;
342 } else { 344 } else {
343 stringlen = kind; 345 bytecount = kind;
344 leng = 0; 346 leng = 0;
345 localstatus = 0; 347 localstatus = 0;
346 } 348 }
347 if (localstatus) 349 if (localstatus)
348 goto ERROR1; 350 goto ERROR1;
349 psiconv_debug(config,lev+2,off,"Length: %i",stringlen); 351 psiconv_debug(config,lev+2,off,"Length: %i",bytecount);
350 len = leng; 352 len = leng;
351 353
352 result = malloc(sizeof(*result) * (stringlen + 1)); 354 if (!(string = psiconv_list_new(sizeof(*result))))
353 if (!result)
354 goto ERROR1; 355 goto ERROR1;
355 for (i = 0; i < stringlen; i++) { 356
356 temp = psiconv_read_u8(config,buf,lev,off+i+len,&localstatus); 357 /* Read the string into a temporary list */
358 i = 0;
359 while (i < bytecount) {
360 nextchar = psiconv_unicode_read_char(config,buf,lev,off+i+len,
361 &leng,&localstatus);
357 if (localstatus) 362 if (localstatus)
358 goto ERROR2; 363 goto ERROR2;
359 result[i] = psiconv_unicode_from_char(config,temp); 364 if ((localstatus = psiconv_list_add(string,&nextchar)))
365 goto ERROR2;
366 i += leng;
367 }
368 if (i > bytecount) {
369 psiconv_error(config,lev,off+i+len,"Malformed string");
370 localstatus = PSICONV_E_PARSE;
371 goto ERROR2;
372 }
373 len += bytecount;
374
375 /* Copy the list to the actual string */
376 if (!(result = malloc(sizeof(*result) * (psiconv_list_length(string) + 1))))
377 goto ERROR2;
378 for (i = 0; i < psiconv_list_length(string); i++) {
379 if (!(nextcharptr = psiconv_list_get(string,i))) {
380 psiconv_error(config,lev,off+i+len,"Internal data corruption");
381 goto ERROR3;
360 } 382 }
383 result[i] = *nextcharptr;
384 }
361 result[stringlen] = 0; 385 result[i] = 0;
362 len += stringlen;
363 386
364 res_copy = psiconv_make_printable(config,result); 387 res_copy = psiconv_make_printable(config,result);
365 if (!res_copy) 388 if (!res_copy)
366 goto ERROR2; 389 goto ERROR3;
367 psiconv_debug(config,lev+2,off,"Contents: `%s'",res_copy); 390 psiconv_debug(config,lev+2,off,"Contents: `%s'",res_copy);
368 free(res_copy); 391 free(res_copy);
369 392
393 psiconv_list_free(string);
394
370 if (length) 395 if (length)
371 *length = len; 396 *length = len;
372 397
373 if (status) 398 if (status)
374 *status = 0; 399 *status = 0;
375 400
376 psiconv_progress(config,lev+1,off+len-1,"End of string (total length: %08x)",len); 401 psiconv_progress(config,lev+1,off+len-1,"End of string (total length: %08x)",len);
377 402
378 return result; 403 return result;
379 404
405ERROR3:
406 free(result);
380ERROR2: 407ERROR2:
381 free(result); 408 psiconv_list_free(string);
382ERROR1: 409ERROR1:
383 psiconv_error(config,lev+1,off,"Reading of string failed"); 410 psiconv_error(config,lev+1,off,"Reading of string failed");
384 if (status) 411 if (status)
385 *status = localstatus; 412 *status = localstatus;
386 if (length) 413 if (length)

Legend:
Removed from v.196  
changed lines
  Added in v.217

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