--- psiconv/trunk/lib/psiconv/parse_word.c 2003/11/23 21:47:24 167 +++ psiconv/trunk/lib/psiconv/parse_word.c 2003/11/25 17:57:05 168 @@ -29,7 +29,8 @@ #include #endif -int psiconv_parse_word_status_section(const psiconv_buffer buf, int lev, +int psiconv_parse_word_status_section(const psiconv_config config, + const psiconv_buffer buf, int lev, psiconv_u32 off, int *length, psiconv_word_status_section *result) { @@ -38,129 +39,129 @@ psiconv_u32 temp; int leng; - psiconv_progress(lev+1,off,"Going to read the word status section"); + psiconv_progress(config,lev+1,off,"Going to read the word status section"); if (!(*result = malloc(sizeof(**result)))) goto ERROR1; - psiconv_progress(lev+2,off+len, + psiconv_progress(config,lev+2,off+len, "Going to read the initial byte (%02x expected)",0x02); - temp = psiconv_read_u8(buf,lev+2,off+len,&res); + temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); if (res) goto ERROR2; if (temp != 0x02) { - psiconv_warn(lev+2,off+len, + psiconv_warn(config,lev+2,off+len, "Word status section initial byte unknown value (ignored)"); - psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); + psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); } len ++; - psiconv_progress(lev+2,off+len, + psiconv_progress(config,lev+2,off+len, "Going to read the first byte of display flags"); - temp = psiconv_read_u8(buf,lev+2,off+len,&res); + temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); if (res) goto ERROR2; (*result)->show_tabs = temp&0x01 ? psiconv_bool_true : psiconv_bool_false; - psiconv_debug(lev+2,off+len,"Show tabs: %02x",(*result)->show_tabs); + psiconv_debug(config,lev+2,off+len,"Show tabs: %02x",(*result)->show_tabs); (*result)->show_spaces = temp&0x02 ? psiconv_bool_true : psiconv_bool_false; - psiconv_debug(lev+2,off+len,"Show spaces: %02x",(*result)->show_spaces); + psiconv_debug(config,lev+2,off+len,"Show spaces: %02x",(*result)->show_spaces); (*result)->show_paragraph_ends = temp &0x04 ? psiconv_bool_true : psiconv_bool_false; - psiconv_debug(lev+2,off+len,"Show paragraph ends: %02x", + psiconv_debug(config,lev+2,off+len,"Show paragraph ends: %02x", (*result)->show_paragraph_ends); (*result)->show_line_breaks = temp & 0x08 ? psiconv_bool_true : psiconv_bool_false; - psiconv_debug(lev+2,off+len,"Show line breaks: %02x", + psiconv_debug(config,lev+2,off+len,"Show line breaks: %02x", (*result)->show_line_breaks); (*result)->show_hard_minus = temp & 0x20 ? psiconv_bool_true : psiconv_bool_false; - psiconv_debug(lev+2,off+len,"Show hard minus: %02x", + psiconv_debug(config,lev+2,off+len,"Show hard minus: %02x", (*result)->show_hard_minus); (*result)->show_hard_space = temp & 0x40 ? psiconv_bool_true : psiconv_bool_false; - psiconv_debug(lev+2,off+len,"Show hard space: %02x", + psiconv_debug(config,lev+2,off+len,"Show hard space: %02x", (*result)->show_hard_space); if (temp & 0x90) { - psiconv_warn(lev+2,off+len,"Word status section first byte of display " + psiconv_warn(config,lev+2,off+len,"Word status section first byte of display " "flags contains unknown flags (ignored)"); - psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0x90); + psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp & 0x90); } len ++; - psiconv_progress(lev+2,off+len,"Going to read second byte of display flags"); - temp = psiconv_read_u8(buf,lev+2,off+len,&res); + psiconv_progress(config,lev+2,off+len,"Going to read second byte of display flags"); + temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); if (res) goto ERROR2; (*result)->show_full_pictures = temp & 0x01 ? psiconv_bool_true : psiconv_bool_false; - psiconv_debug(lev+2,off+len,"Show full pictures: %02x", + psiconv_debug(config,lev+2,off+len,"Show full pictures: %02x", (*result)->show_full_pictures); (*result)->show_full_graphs = temp & 0x02 ? psiconv_bool_true : psiconv_bool_false; - psiconv_debug(lev+2,off+len,"Show full graphs: %02x", + psiconv_debug(config,lev+2,off+len,"Show full graphs: %02x", (*result)->show_full_graphs); if (temp & 0xfc) { - psiconv_warn(lev+2,off+len,"Word status section second byte of display " + psiconv_warn(config,lev+2,off+len,"Word status section second byte of display " "flags contains unknown flags (ignored)"); - psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xfc); + psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp & 0xfc); } len ++; - psiconv_progress(lev+2,off+len,"Going to read top toolbar setting"); - if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, + psiconv_progress(config,lev+2,off+len,"Going to read top toolbar setting"); + if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng, &(*result)->show_top_toolbar))) goto ERROR2; len += leng; - psiconv_progress(lev+2,off+len,"Going to read side toolbar setting"); - if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, + psiconv_progress(config,lev+2,off+len,"Going to read side toolbar setting"); + if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng, &(*result)->show_side_toolbar))) goto ERROR2; len += leng; - psiconv_progress(lev+2,off+len,"Going to read operational flags"); - temp = psiconv_read_u8(buf,lev+2,off+len,&res); + psiconv_progress(config,lev+2,off+len,"Going to read operational flags"); + temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); if (res) goto ERROR2; (*result)->fit_lines_to_screen = temp & 0x08 ? psiconv_bool_true : psiconv_bool_false; - psiconv_debug(lev+2,off+len,"Fit lines to screen: %02x", + psiconv_debug(config,lev+2,off+len,"Fit lines to screen: %02x", (*result)->fit_lines_to_screen); if (temp & 0xf7) { - psiconv_warn(lev+2,off+len,"Word status section operational flags " + psiconv_warn(config,lev+2,off+len,"Word status section operational flags " "contains unknown flags (ignored)"); - psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xfc); + psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp & 0xfc); } len ++; - psiconv_progress(lev+2,off+len,"Going to read cursor position"); - (*result)->cursor_position = psiconv_read_u32(buf,lev+2,off + len,&res); + psiconv_progress(config,lev+2,off+len,"Going to read cursor position"); + (*result)->cursor_position = psiconv_read_u32(config,buf,lev+2,off + len,&res); if (res) goto ERROR2; - psiconv_debug(lev+2,off+len,"Cursor position: %08x", + psiconv_debug(config,lev+2,off+len,"Cursor position: %08x", (*result)->cursor_position); len += 0x04; - psiconv_progress(lev+2,off+len,"Going to read display size"); - (*result)->display_size = psiconv_read_u32(buf,lev+2,off + len,&res); + psiconv_progress(config,lev+2,off+len,"Going to read display size"); + (*result)->display_size = psiconv_read_u32(config,buf,lev+2,off + len,&res); if (res) goto ERROR2; - psiconv_debug(lev+2,off+len,"Display size: %08x", + psiconv_debug(config,lev+2,off+len,"Display size: %08x", (*result)->display_size); len += 0x04; if (length) *length = len; - psiconv_progress(lev,off+len-1, + psiconv_progress(config,lev,off+len-1, "End of word status section (total length: %08x)", len); return 0; ERROR2: free (*result); ERROR1: - psiconv_warn(lev+1,off,"Reading of Word Status Section failed"); + psiconv_warn(config,lev+1,off,"Reading of Word Status Section failed"); if (length) *length = 0; if (!res) @@ -169,7 +170,8 @@ return res; } -int psiconv_parse_word_styles_section(const psiconv_buffer buf, int lev, +int psiconv_parse_word_styles_section(const psiconv_config config, + const psiconv_buffer buf, int lev, psiconv_u32 off, int *length, psiconv_word_styles_section *result) { @@ -179,97 +181,97 @@ psiconv_word_style style; psiconv_u32 temp; - psiconv_progress(lev+1,off,"Going to read the word styles section"); + psiconv_progress(config,lev+1,off,"Going to read the word styles section"); if (!(*result = malloc(sizeof(**result)))) goto ERROR1; - psiconv_progress(lev+2,off+len,"Going to read style normal"); + psiconv_progress(config,lev+2,off+len,"Going to read style normal"); if (!(style = malloc(sizeof(*style)))) goto ERROR2; style->name = NULL; if (!(style->paragraph = psiconv_basic_paragraph_layout())) goto ERROR2_1; - psiconv_progress(lev+3,off+len,"Going to read the paragraph codes"); - if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, + psiconv_progress(config,lev+3,off+len,"Going to read the paragraph codes"); + if ((res = psiconv_parse_paragraph_layout_list(config,buf,lev+3,off+len,&leng, style->paragraph))) goto ERROR2_2; len += leng; - psiconv_progress(lev+3,off+len,"Going to read the character codes"); + psiconv_progress(config,lev+3,off+len,"Going to read the character codes"); if (!(style->character = psiconv_basic_character_layout())) goto ERROR2_2; - if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, + if ((res = psiconv_parse_character_layout_list(config,buf,lev+3,off+len,&leng, style->character))) goto ERROR2_3; len += leng; - psiconv_progress(lev+3,off+len,"Going to read the hotkey"); - temp = psiconv_read_u32(buf,lev+3,off+len,&res); + psiconv_progress(config,lev+3,off+len,"Going to read the hotkey"); + temp = psiconv_read_u32(config,buf,lev+3,off+len,&res); if (res) goto ERROR2_3; if (temp & 0xffffff00) { - psiconv_warn(lev+3,off+len, + psiconv_warn(config,lev+3,off+len, "Normal style hotkey has unknown value (ignored)"); - psiconv_debug(lev+3,off+len,"Hotkey value %08x",temp); + psiconv_debug(config,lev+3,off+len,"Hotkey value %08x",temp); temp = 0; } style->hotkey = temp & 0x000000ff; if ((style->hotkey >= 32) && (style->hotkey < 127)) - psiconv_debug(lev+3,off+len,"Hotkey: %c",style->hotkey); + psiconv_debug(config,lev+3,off+len,"Hotkey: %c",style->hotkey); else if (style->hotkey == 0x00) - psiconv_debug(lev+3,off+len,"Hotkey: "); + psiconv_debug(config,lev+3,off+len,"Hotkey: "); else - psiconv_debug(lev+3,off+len,"Hotkey: %02x",style->hotkey); + psiconv_debug(config,lev+3,off+len,"Hotkey: %02x",style->hotkey); (*result)->normal = style; len += 0x04; - psiconv_progress(lev+2,off+len,"Going to read hotkeys list"); + psiconv_progress(config,lev+2,off+len,"Going to read hotkeys list"); if (!((*result)->styles = psiconv_list_new(sizeof(*style)))) goto ERROR3; if (!(style = malloc(sizeof(*style)))) { goto ERROR3_1; } - psiconv_progress(lev+3,off+len,"Going to read the number of entries"); - nr = psiconv_read_u8(buf,lev+3,off+len,&res); + psiconv_progress(config,lev+3,off+len,"Going to read the number of entries"); + nr = psiconv_read_u8(config,buf,lev+3,off+len,&res); if (res) goto ERROR3_2; len ++; - psiconv_debug(lev+3,off+len,"Nummer of hotkeys: %02x",nr); + psiconv_debug(config,lev+3,off+len,"Nummer of hotkeys: %02x",nr); for (i = 0; i < nr; i ++) { - temp = psiconv_read_u32(buf,lev+2,off+len,&res); + temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); if (res) goto ERROR3_2; if (temp & 0xffffff00) { - psiconv_warn(lev+3,off+len,"Style hotkey has unknown value (ignored)"); - psiconv_debug(lev+3,off+len,"Hotkey %d value %08x",i,temp); + psiconv_warn(config,lev+3,off+len,"Style hotkey has unknown value (ignored)"); + psiconv_debug(config,lev+3,off+len,"Hotkey %d value %08x",i,temp); temp = 0; } style->hotkey = temp & 0x000000ff; if ((style->hotkey >= 32) && (style->hotkey < 127)) - psiconv_debug(lev+3,off+len,"Hotkey %d: %c",i,style->hotkey); + psiconv_debug(config,lev+3,off+len,"Hotkey %d: %c",i,style->hotkey); else if (style->hotkey == 0x00) - psiconv_debug(lev+3,off+len,"Hotkey %d: ",i); + psiconv_debug(config,lev+3,off+len,"Hotkey %d: ",i); else - psiconv_debug(lev+3,off+len,"Hotkey %d: %02x",i,style->hotkey); + psiconv_debug(config,lev+3,off+len,"Hotkey %d: %02x",i,style->hotkey); if ((res = psiconv_list_add((*result)->styles,style))) goto ERROR3_2; len += 0x04; } free(style); - psiconv_progress(lev+2,off+len,"Going to read all other styles"); - psiconv_progress(lev+2,off+len,"Going to read the number of styles"); - nr = psiconv_read_u8(buf,lev+3,off+len,&res); + psiconv_progress(config,lev+2,off+len,"Going to read all other styles"); + psiconv_progress(config,lev+2,off+len,"Going to read the number of styles"); + nr = psiconv_read_u8(config,buf,lev+3,off+len,&res); if (res) goto ERROR4; if (nr != psiconv_list_length((*result)->styles)) { - psiconv_warn(lev+3,off+len,"Number of styles and hotkeys do not match"); - psiconv_debug(lev+3,off+len,"%d hotkeys, %d styles", + psiconv_warn(config,lev+3,off+len,"Number of styles and hotkeys do not match"); + psiconv_debug(config,lev+3,off+len,"%d hotkeys, %d styles", psiconv_list_length((*result)->styles), nr); } len ++; for (i = 0; i < nr; i++) { - psiconv_progress(lev+2,off+len,"Next style: %d",i); + psiconv_progress(config,lev+2,off+len,"Next style: %d",i); if (i >= psiconv_list_length((*result)->styles)) { if (!(style = malloc(sizeof(*style)))) goto ERROR5; @@ -278,75 +280,75 @@ free(style); goto ERROR5; } - psiconv_debug(lev+3,off+len,"New entry added in list"); + psiconv_debug(config,lev+3,off+len,"New entry added in list"); free(style); } if (!(style = psiconv_list_get((*result)->styles,i))) goto ERROR5; - psiconv_progress(lev+3,off+len,"Going to read the style name"); - style->name = psiconv_read_string(buf,lev+3,off+len,&leng,&res); + psiconv_progress(config,lev+3,off+len,"Going to read the style name"); + style->name = psiconv_read_string(config,buf,lev+3,off+len,&leng,&res); if (res) goto ERROR5; len += leng; - psiconv_progress(lev+3,off+len, + psiconv_progress(config,lev+3,off+len, "Going to read whether this style is built-in"); - temp = psiconv_read_u32(buf,lev+2,off+len,&res); + temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); if (res) goto ERROR6; if (temp == PSICONV_ID_STYLE_BUILT_IN) { style->built_in = psiconv_bool_true; - psiconv_debug(lev+3,off+len,"Built-in style"); + psiconv_debug(config,lev+3,off+len,"Built-in style"); } else if (temp == PSICONV_ID_STYLE_REMOVABLE) { style->built_in = psiconv_bool_false; - psiconv_debug(lev+3,off+len,"Removable style"); + psiconv_debug(config,lev+3,off+len,"Removable style"); } else { - psiconv_warn(lev+3,off+len, + psiconv_warn(config,lev+3,off+len, "Word styles section unknown style id (treated as built-in)"); - psiconv_debug(lev+3,off+len,"Unknown id: %08x",temp); + psiconv_debug(config,lev+3,off+len,"Unknown id: %08x",temp); style->built_in = psiconv_bool_false; } len += 4; - psiconv_progress(lev+3,off+len,"Going to read outline level"); - style->outline_level = psiconv_read_u32(buf,lev+3,off+len,&res); + psiconv_progress(config,lev+3,off+len,"Going to read outline level"); + style->outline_level = psiconv_read_u32(config,buf,lev+3,off+len,&res); if (res) goto ERROR6; - psiconv_debug(lev+3,off+len,"Outline Level: %08x", style->outline_level); + psiconv_debug(config,lev+3,off+len,"Outline Level: %08x", style->outline_level); len += 4; - psiconv_progress(lev+3,off+len,"Going to read the character codes"); + psiconv_progress(config,lev+3,off+len,"Going to read the character codes"); if (!(style->character = psiconv_clone_character_layout((*result)->normal->character))) goto ERROR6; - if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, + if ((res = psiconv_parse_character_layout_list(config,buf,lev+3,off+len,&leng, style->character))) goto ERROR7; len += leng; - psiconv_progress(lev+3,off+len,"Going to read the paragraph codes"); + psiconv_progress(config,lev+3,off+len,"Going to read the paragraph codes"); if (!(style->paragraph = psiconv_clone_paragraph_layout((*result)->normal->paragraph))) goto ERROR7; - if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, + if ((res = psiconv_parse_paragraph_layout_list(config,buf,lev+3,off+len,&leng, style->paragraph))) goto ERROR8; len += leng; } - psiconv_progress(lev+2,off+len,"Reading trailing bytes"); + psiconv_progress(config,lev+2,off+len,"Reading trailing bytes"); for (i = 0; i < psiconv_list_length((*result)->styles); i++) { - temp = psiconv_read_u8(buf,lev+3,off+len,&res); + temp = psiconv_read_u8(config,buf,lev+3,off+len,&res); if (res) goto ERROR4; if (temp != 0xff) { - psiconv_warn(lev+3,off+len,"Unknown trailing style byte"); - psiconv_debug(lev+3,off+len,"Trailing byte: %02x expected, read %02x", + psiconv_warn(config,lev+3,off+len,"Unknown trailing style byte"); + psiconv_debug(config,lev+3,off+len,"Trailing byte: %02x expected, read %02x", 0xff,temp); } else - psiconv_debug(lev+3,off+len,"Read trailing byte 0xff"); + psiconv_debug(config,lev+3,off+len,"Read trailing byte 0xff"); len++; } if (length) *length = len; - psiconv_progress(lev,off+len-1, + psiconv_progress(config,lev,off+len-1, "End of word styles section (total length: %08x)", len); return res; @@ -375,7 +377,7 @@ ERROR5: for (j = 0; j < i ;j++) { if (!(style = psiconv_list_get((*result)->styles,j))) { - psiconv_warn(lev+1,off,"Massive memory corruption"); + psiconv_warn(config,lev+1,off,"Massive memory corruption"); goto ERROR4; } psiconv_free_character_layout(style->character); @@ -389,7 +391,7 @@ ERROR2: free (*result); ERROR1: - psiconv_warn(lev+1,off,"Reading of Word Status Section failed"); + psiconv_warn(config,lev+1,off,"Reading of Word Status Section failed"); if (length) *length = 0; if (!res)