--- psiconv/trunk/lib/psiconv/parse_simple.c 2004/01/04 22:20:43 183 +++ psiconv/trunk/lib/psiconv/parse_simple.c 2004/01/06 20:15:01 184 @@ -25,6 +25,7 @@ #include "parse_routines.h" #include "error.h" +#include "unicode.h" #ifdef DMALLOC #include @@ -54,7 +55,7 @@ psiconv_u8 *ptr; ptr = psiconv_buffer_get(buf,off); if (!ptr) { - psiconv_warn(config,lev,off,"Trying byte read past the end of the file"); + psiconv_error(config,lev,off,"Trying byte read past the end of the file"); if (status) *status = -PSICONV_E_PARSE; return 0; @@ -71,7 +72,7 @@ ptr0 = psiconv_buffer_get(buf,off); ptr1 = psiconv_buffer_get(buf,off+1); if (!ptr0 || !ptr1) { - psiconv_warn(config,lev,off,"Trying word read past the end of the file"); + psiconv_error(config,lev,off,"Trying word read past the end of the file"); if (status) *status = -PSICONV_E_PARSE; return 0; @@ -90,7 +91,7 @@ ptr2 = psiconv_buffer_get(buf,off+2); ptr3 = psiconv_buffer_get(buf,off+3); if (!ptr0 || !ptr1 || !ptr2 || !ptr3) { - psiconv_warn(config,lev,off,"Trying long read past the end of the file"); + psiconv_error(config,lev,off,"Trying long read past the end of the file"); if (status) *status = -PSICONV_E_PARSE; return 0; @@ -139,7 +140,7 @@ len = 2; psiconv_debug(config,lev+2,off,"Indicator (2 bytes): %04x",res); } else { - psiconv_warn(config,lev+2,off,"S indicator: unknown encoding!"); + psiconv_error(config,lev+2,off,"S indicator: unknown encoding!"); psiconv_debug(config,lev+2,off,"Raw data first byte: %02x",temp); goto ERROR; } @@ -155,7 +156,7 @@ return res; ERROR: - psiconv_warn(config,lev+1,off,"Reading of S indicator failed"); + psiconv_error(config,lev+1,off,"Reading of S indicator failed"); if (status) *status = localstatus; if (length) @@ -193,7 +194,7 @@ len = 4; psiconv_debug(config,lev+2,off,"Indicator (4 bytes): %08x",res); } else { - psiconv_warn(config,lev+2,off,"X indicator: unknown encoding!"); + psiconv_error(config,lev+2,off,"X indicator: unknown encoding!"); psiconv_debug(config,lev+2,off,"Raw data first byte: %02x",temp); goto ERROR; } @@ -209,7 +210,7 @@ return res; ERROR: - psiconv_warn(config,lev+1,off,"Reading of X indicator failed"); + psiconv_error(config,lev+1,off,"Reading of X indicator failed"); if (status) *status = localstatus; if (length) @@ -226,7 +227,7 @@ res = (2.54/1440.0) * ((psiconv_s32) psiconv_read_u32(config,buf,lev,off, &localstatus)); if (localstatus) { - psiconv_warn(config,lev+1,off,"Reading of length failed"); + psiconv_error(config,lev+1,off,"Reading of length failed"); if (length) *length = 0; if (status) @@ -248,7 +249,7 @@ int localstatus; res = ((psiconv_s32) psiconv_read_u32(config,buf,lev,off,&localstatus)) / 20.0; if (localstatus) { - psiconv_warn(config,lev+1,off,"Reading of size failed"); + psiconv_error(config,lev+1,off,"Reading of size failed"); if (length) *length = 0; if (status) @@ -270,7 +271,7 @@ int localstatus; temp = psiconv_read_u8(config,buf,lev,off,&localstatus); if (localstatus) { - psiconv_warn(config,lev+1,off,"Reading of bool failed"); + psiconv_error(config,lev+1,off,"Reading of bool failed"); if (length) *length = 0; return localstatus; @@ -294,16 +295,33 @@ const psiconv_buffer buf,int lev, psiconv_u32 off,int *length, int *status) { - return psiconv_read_string_aux(config,buf,lev,off,length,status,0); + return psiconv_read_string_aux(config,buf,lev,off,length,status,-1); } psiconv_string_t psiconv_read_short_string(const psiconv_config config, const psiconv_buffer buf,int lev, psiconv_u32 off,int *length, int *status) { - return psiconv_read_string_aux(config,buf,lev,off,length,status,1); + return psiconv_read_string_aux(config,buf,lev,off,length,status,-2); } +psiconv_string_t psiconv_read_charlist(const psiconv_config config, + const psiconv_buffer buf, int lev, + psiconv_u32 off, int nrofchars, + int *status) +{ + int length; + if (nrofchars <= 0) { + psiconv_error(config,lev,off, + "psiconv_read_charlist called with non-positive nrofchars"); + if (status) + *status = -PSICONV_E_OTHER; + return NULL; + } + return psiconv_read_string_aux(config,buf,lev,off,&length,status,nrofchars); +} + + psiconv_string_t psiconv_read_string_aux(const psiconv_config config, const psiconv_buffer buf,int lev, psiconv_u32 off,int *length, int *status, @@ -312,32 +330,38 @@ int stringlen,i,leng,len,localstatus; psiconv_string_t result; char *res_copy; + psiconv_u8 temp; psiconv_progress(config,lev+1,off,"Going to read a string"); - if (kind == 0) + if (kind == -1) stringlen = psiconv_read_S(config,buf,lev+2,off,&leng,&localstatus); - else { + else if (kind == -2) { stringlen = psiconv_read_u8(config,buf,lev+2,off,&localstatus); leng = 1; + } else { + stringlen = kind; + leng = 0; + localstatus = 0; } - if (localstatus) goto ERROR1; psiconv_debug(config,lev+2,off,"Length: %i",stringlen); len = leng; - result = malloc(stringlen + 1); + result = malloc(sizeof(*result) * (stringlen + 1)); if (!result) goto ERROR1; - for (i = 0; (i < stringlen) && !localstatus; i++) - result[i] = psiconv_read_u8(config,buf,lev,off+i+len,&localstatus); - if (localstatus) - goto ERROR2; + for (i = 0; i < stringlen; i++) { + temp = psiconv_read_u8(config,buf,lev,off+i+len,&localstatus); + if (localstatus) + goto ERROR2; + result[i] = psiconv_unicode_from_char(config,temp); + } result[stringlen] = 0; len += stringlen; - res_copy = psiconv_make_printable(result); + res_copy = psiconv_make_printable(config,result); if (!res_copy) goto ERROR2; psiconv_debug(config,lev+2,off,"Contents: `%s'",res_copy); @@ -356,7 +380,7 @@ ERROR2: free(result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of string failed"); + psiconv_error(config,lev+1,off,"Reading of string failed"); if (status) *status = localstatus; if (length) @@ -398,7 +422,7 @@ *status = res; return result; ERROR: - psiconv_warn(config,lev+1,off,"Reading of float failed"); + psiconv_error(config,lev+1,off,"Reading of float failed"); if (length) *length = 0; if (*status)