--- psiconv/trunk/lib/psiconv/parse_common.c 2003/11/20 22:14:43 160 +++ psiconv/trunk/lib/psiconv/parse_common.c 2003/11/20 23:45:47 161 @@ -940,7 +940,7 @@ int leng,i; psiconv_section_table_section table; psiconv_section_table_entry entry; - psiconv_u32 icon_sec,display_sec,table_sec; + psiconv_u32 icon_sec=0,display_sec=0,table_sec=0; psiconv_progress(lev+1,off+len,"Going to read an Embedded Object"); if (!(*result = malloc(sizeof(**result)))) @@ -975,8 +975,35 @@ } } + psiconv_progress(lev+2,off+len,"Looking for the Object Display Section"); + if (!icon_sec) { + psiconv_warn(lev+2,off+len,"Object Display Section not found"); + (*result)->display = NULL; + } else { + psiconv_debug(lev+2,off+len,"Object Display Section at offset %08x", + display_sec); + if ((res = psiconv_parse_object_display_section(buf,lev+2,display_sec,NULL, + &(*result)->display))) + goto ERROR2; + } + + psiconv_progress(lev+2,off+len,"Looking for the Object Icon Section"); + if (!icon_sec) { + psiconv_warn(lev+2,off+len,"Object Icon Section not found"); + (*result)->icon = NULL; + } else { + psiconv_debug(lev+2,off+len,"Object Icon Section at offset %08x",icon_sec); + if ((res = psiconv_parse_object_icon_section(buf,lev+2,icon_sec,NULL, + &(*result)->icon))) + goto ERROR2; + } + + if (length) + *length = len; + psiconv_progress(lev+1,off+len-1,"End of Embedded Object Section " "(total length: %08x)",len); + return res; @@ -984,10 +1011,140 @@ psiconv_free_section_table_section(table); ERROR1: psiconv_warn(lev+1,off,"Reading Embedded Object failed"); + if (length) *length = 0; + if (res == 0) return -PSICONV_E_NOMEM; else return res; +} + +int psiconv_parse_object_display_section(const psiconv_buffer buf,int lev, + psiconv_u32 off, int *length, + psiconv_object_display_section *result) +{ + int res = 0; + int len = 0; + int leng; + psiconv_u32 temp; + + psiconv_progress(lev+1,off,"Going to read the Object Display Section"); + if (!(*result = malloc(sizeof(**result)))) + goto ERROR1; + + psiconv_progress(lev+2,off+len,"Going to read the display as icon flag " + "(expecting 0x00 or 0x01)"); + temp = psiconv_read_u8(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + if (temp == 0x00) { + (*result)->show_icon = psiconv_bool_true; + psiconv_debug(lev+2,off+len,"Displayed as full document"); + } else if (temp == 0x01) { + (*result)->show_icon = psiconv_bool_false; + psiconv_debug(lev+2,off+len,"Displayed as icon"); + } else { + psiconv_warn(lev+2,off+len,"Unknown Object Display Section Icon Flag"); + psiconv_debug(lev+2,off+len,"Icon flag found: %02x",temp); + /* Improvise */ + (*result)->show_icon = (temp & 0x01?psiconv_bool_false:psiconv_bool_true); + } + len ++; + + psiconv_progress(lev+2,off+len,"Going to read the icon width"); + (*result)->width = psiconv_read_length(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Icon width: %f cm",(*result)->width); + len += leng; + + psiconv_progress(lev+2,off+len,"Going to read the icon height"); + (*result)->height = psiconv_read_length(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Icon length: %f cm",(*result)->height); + len += leng; + + psiconv_progress(lev+2,off+len,"Going to read unknown long (%08x expected)", + 0); + temp = psiconv_read_u32(buf,lev+2,off+len,&res); + if (temp != 0) { + psiconv_warn(lev+2,off+len,"Unknown Object Display Section final long"); + psiconv_debug(lev+2,off+len,"Long read: %08x",temp); + } + len += 4; + + if (length) + *length = len; + + psiconv_progress(lev+1,off+len-1,"End of Object Display Section" + "(total length: %08x",len); + return res; + +ERROR2: + free(*result); +ERROR1: + psiconv_warn(lev+1,off+len,"Reading of Object Display Section failed"); + if (length) + *length=0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +} + +int psiconv_parse_object_icon_section(const psiconv_buffer buf,int lev, + psiconv_u32 off, int *length, + psiconv_object_icon_section *result) +{ + int res = 0; + int len = 0; + int leng; + + psiconv_progress(lev+1,off,"Going to read the Object Icon Section"); + if (!(*result = malloc(sizeof(**result)))) + goto ERROR1; + + psiconv_progress(lev+2,off+len,"Going to read the icon name"); + (*result)->icon_name = psiconv_read_string(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Icon name: %s",(*result)->icon_name); + len += leng; + + psiconv_progress(lev+2,off+len,"Going to read the icon width"); + (*result)->icon_width = psiconv_read_length(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR3; + psiconv_debug(lev+2,off+len,"Icon width: %f cm",(*result)->icon_width); + len += leng; + + psiconv_progress(lev+2,off+len,"Going to read the icon height"); + (*result)->icon_height = psiconv_read_length(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR3; + psiconv_debug(lev+2,off+len,"Icon length: %f cm",(*result)->icon_height); + len += leng; + + if (length) + *length = len; + + psiconv_progress(lev+1,off+len-1,"End of Object Icon Section" + "(total length: %08x",len); + return res; + +ERROR3: + free((*result)->icon_name); +ERROR2: + free(*result); +ERROR1: + psiconv_warn(lev+1,off+len,"Reading of Object Icon Section failed"); + if (length) + *length=0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; }