--- psiconv/trunk/lib/psiconv/parse_common.c 2001/01/17 00:05:08 94 +++ psiconv/trunk/lib/psiconv/parse_common.c 2003/11/20 23:45:47 161 @@ -25,6 +25,11 @@ #include "parse_routines.h" #include "error.h" +#ifdef DMALLOC +#include +#endif + + static int psiconv_parse_layout_section(const psiconv_buffer buf, int lev,psiconv_u32 off, int *length, @@ -711,31 +716,73 @@ psiconv_debug(lev+3,off+len,"Can't read element!"); } else { total ++; + in_line.object = NULL; + in_line.layout = NULL; if (!(in_line.layout = psiconv_clone_character_layout (para->base_character))) goto ERROR4; psiconv_progress(lev+4,off+len,"Going to read the element type"); temp = psiconv_read_u8(buf,lev+4,len+off,&res); if (res) - goto ERROR4; + goto ERROR5; len += 1; psiconv_debug(lev+4,off+len,"Type: %02x",temp); psiconv_progress(lev+4,off+len, "Going to read the number of characters it applies to"); in_line.length = psiconv_read_u32(buf,lev+4,len+off,&res); if (res) - goto ERROR4; + goto ERROR5; psiconv_debug(lev+4,off+len,"Length: %02x",in_line.length); len += 4; psiconv_progress(lev+4,off+len,"Going to read the character layout"); if ((res = psiconv_parse_character_layout_list(buf,lev+4,off+len,&leng, in_line.layout))) - goto ERROR4; + goto ERROR5; len += leng; if (temp == 0x01) { - psiconv_debug(lev+4,off+len,"Skipping object data"); - len += 0x10; + psiconv_debug(lev+4,off+len,"Found an embedded object"); + psiconv_progress(lev+4,off+len,"Going to read the object marker " + "(0x%08x expected)",PSICONV_ID_OBJECT); + temp = psiconv_read_u32(buf,lev+4,off+len,&res); + if (res) + goto ERROR5; + if (temp != PSICONV_ID_OBJECT) { + psiconv_warn(lev+4,off+len,"Unknown id marks embedded object"); + psiconv_debug(lev+4,off+len,"Marker: read %08x, expected %08x", + temp,PSICONV_ID_OBJECT); + } + len += 4; + psiconv_progress(lev+4,off+len, + "Going to read the Embedded Object Section offset"); + temp = psiconv_read_u32(buf,lev+4,off+len,&res); + if (res) + goto ERROR5; + psiconv_debug(lev+4,off+len, "Offset: %08x",temp); + len += 4; + psiconv_progress(lev+4,off+len, + "Going to parse the Embedded Object"); + if ((res = psiconv_parse_embedded_object(buf,lev+4,temp, + NULL,&(in_line.object)))) + goto ERROR5; + psiconv_progress(lev+4,off+len, + "Going to read the object width"); + in_line.object_width = psiconv_read_length(buf,lev+4,off+len, + &leng,&res); + if (res) + goto ERROR5; + psiconv_debug(lev+4,off+len,"Object width: %f cm", + in_line.object_width); + len += leng; + psiconv_progress(lev+4,off+len, + "Going to read the object height"); + in_line.object_height = psiconv_read_length(buf,lev+4,off+len,&leng, + &res); + if (res) + goto ERROR5; + psiconv_debug(lev+4,off+len,"Object height: %f cm", + in_line.object_height); + len += leng; } else if (temp != 0x00) { psiconv_warn(lev+4,off+len,"Layout section unknown inline type"); } @@ -747,7 +794,7 @@ } line_length += in_line.length; if ((res = psiconv_list_add(para->in_lines,&in_line))) - goto ERROR4; + goto ERROR5; } } } @@ -793,6 +840,11 @@ psiconv_free_paragraph_layout(anon.paragraph); goto ERROR3; +ERROR5: + if (in_line.layout) + psiconv_free_character_layout(in_line.layout); + if (in_line.object) + psiconv_free_object(in_line.object); ERROR4: free(inline_count); ERROR3: @@ -879,3 +931,220 @@ return res; } +int psiconv_parse_embedded_object(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_object *result) +{ + int res=0; + int len=0; + int leng,i; + psiconv_section_table_section table; + psiconv_section_table_entry entry; + 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)))) + goto ERROR1; + + psiconv_progress(lev+2,off+len,"Going to read the Embedded Object Section"); + psiconv_parse_section_table_section(buf,lev+2,off+len,&leng,&table); + len += leng; + + for (i = 0; i < psiconv_list_length(table); i++) { + psiconv_progress(lev+2,off+len,"Going to read entry %d",i); + if (!(entry = psiconv_list_get(table,i))) + goto ERROR2; + if (entry->id == PSICONV_ID_OBJECT_DISPLAY_SECTION) { + display_sec = entry->offset; + psiconv_debug(lev+3,off+len,"Found the Object Display Section at %08x", + display_sec); + } else if (entry->id == PSICONV_ID_OBJECT_ICON_SECTION) { + icon_sec = entry->offset; + psiconv_debug(lev+3,off+len,"Found the Object Icon Section at %08x", + icon_sec); + } else if (entry->id == PSICONV_ID_OBJECT_SECTION_TABLE_SECTION) { + table_sec = entry->offset; + psiconv_debug(lev+3,off+len,"Found the Object Section Table Section at %08x", + table_sec); + } else { + psiconv_warn(lev+3,off+len, + "Found unknown section in the Object Display Section " + "(ignoring)"); + psiconv_debug(lev+3,off+len,"Section ID %08x, offset %08x", + entry->id, entry->offset); + } + } + + 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; + + +ERROR2: + 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; +}