/[public]/psiconv/trunk/lib/psiconv/parse_word.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/parse_word.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 142 Revision 217
1/* 1/*
2 parse_word.c - Part of psiconv, a PSION 5 file formats converter 2 parse_word.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
27 27
28#ifdef DMALLOC 28#ifdef DMALLOC
29#include <dmalloc.h> 29#include <dmalloc.h>
30#endif 30#endif
31 31
32int psiconv_parse_word_status_section(const psiconv_buffer buf, int lev, 32int psiconv_parse_word_status_section(const psiconv_config config,
33 const psiconv_buffer buf, int lev,
33 psiconv_u32 off, int *length, 34 psiconv_u32 off, int *length,
34 psiconv_word_status_section *result) 35 psiconv_word_status_section *result)
35{ 36{
36 int res=0; 37 int res=0;
37 int len=0; 38 int len=0;
38 psiconv_u32 temp; 39 psiconv_u32 temp;
39 int leng; 40 int leng;
40 41
41 psiconv_progress(lev+1,off,"Going to read the word status section"); 42 psiconv_progress(config,lev+1,off,"Going to read the word status section");
42 if (!(*result = malloc(sizeof(**result)))) 43 if (!(*result = malloc(sizeof(**result))))
43 goto ERROR1; 44 goto ERROR1;
44 45
45 psiconv_progress(lev+2,off+len, 46 psiconv_progress(config,lev+2,off+len,
46 "Going to read the initial byte (%02x expected)",0x02); 47 "Going to read the initial byte (%02x expected)",0x02);
47 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 48 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
48 if (res) 49 if (res)
49 goto ERROR2; 50 goto ERROR2;
50 if (temp != 0x02) { 51 if (temp != 0x02) {
51 psiconv_warn(lev+2,off+len, 52 psiconv_warn(config,lev+2,off+len,
52 "Word status section initial byte unknown value (ignored)"); 53 "Word status section initial byte unknown value (ignored)");
53 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); 54 psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp);
54 } 55 }
55 len ++; 56 len ++;
56 57
57 psiconv_progress(lev+2,off+len, 58 psiconv_progress(config,lev+2,off+len,
58 "Going to read the first byte of display flags"); 59 "Going to read the first byte of display flags");
59 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 60 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
60 if (res) 61 if (res)
61 goto ERROR2; 62 goto ERROR2;
62 63
63 (*result)->show_tabs = temp&0x01 ? psiconv_bool_true : psiconv_bool_false; 64 (*result)->show_tabs = temp&0x01 ? psiconv_bool_true : psiconv_bool_false;
64 psiconv_debug(lev+2,off+len,"Show tabs: %02x",(*result)->show_tabs); 65 psiconv_debug(config,lev+2,off+len,"Show tabs: %02x",(*result)->show_tabs);
65 (*result)->show_spaces = temp&0x02 ? psiconv_bool_true : psiconv_bool_false; 66 (*result)->show_spaces = temp&0x02 ? psiconv_bool_true : psiconv_bool_false;
66 psiconv_debug(lev+2,off+len,"Show spaces: %02x",(*result)->show_spaces); 67 psiconv_debug(config,lev+2,off+len,"Show spaces: %02x",(*result)->show_spaces);
67 (*result)->show_paragraph_ends = temp &0x04 ? psiconv_bool_true : 68 (*result)->show_paragraph_ends = temp &0x04 ? psiconv_bool_true :
68 psiconv_bool_false; 69 psiconv_bool_false;
69 psiconv_debug(lev+2,off+len,"Show paragraph ends: %02x", 70 psiconv_debug(config,lev+2,off+len,"Show paragraph ends: %02x",
70 (*result)->show_paragraph_ends); 71 (*result)->show_paragraph_ends);
71 (*result)->show_line_breaks = temp & 0x08 ? psiconv_bool_true : 72 (*result)->show_line_breaks = temp & 0x08 ? psiconv_bool_true :
72 psiconv_bool_false; 73 psiconv_bool_false;
73 psiconv_debug(lev+2,off+len,"Show line breaks: %02x", 74 psiconv_debug(config,lev+2,off+len,"Show line breaks: %02x",
74 (*result)->show_line_breaks); 75 (*result)->show_line_breaks);
75 (*result)->show_hard_minus = temp & 0x20 ? psiconv_bool_true : 76 (*result)->show_hard_minus = temp & 0x20 ? psiconv_bool_true :
76 psiconv_bool_false; 77 psiconv_bool_false;
77 psiconv_debug(lev+2,off+len,"Show hard minus: %02x", 78 psiconv_debug(config,lev+2,off+len,"Show hard minus: %02x",
78 (*result)->show_hard_minus); 79 (*result)->show_hard_minus);
79 (*result)->show_hard_space = temp & 0x40 ? psiconv_bool_true : 80 (*result)->show_hard_space = temp & 0x40 ? psiconv_bool_true :
80 psiconv_bool_false; 81 psiconv_bool_false;
81 psiconv_debug(lev+2,off+len,"Show hard space: %02x", 82 psiconv_debug(config,lev+2,off+len,"Show hard space: %02x",
82 (*result)->show_hard_space); 83 (*result)->show_hard_space);
83 if (temp & 0x90) { 84 if (temp & 0x90) {
84 psiconv_warn(lev+2,off+len,"Word status section first byte of display " 85 psiconv_warn(config,lev+2,off+len,"Word status section first byte of display "
85 "flags contains unknown flags (ignored)"); 86 "flags contains unknown flags (ignored)");
86 psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0x90); 87 psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp & 0x90);
87 } 88 }
88 len ++; 89 len ++;
89 90
90 psiconv_progress(lev+2,off+len,"Going to read second byte of display flags"); 91 psiconv_progress(config,lev+2,off+len,"Going to read second byte of display flags");
91 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 92 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
92 if (res) 93 if (res)
93 goto ERROR2; 94 goto ERROR2;
94 95
95 (*result)->show_full_pictures = temp & 0x01 ? psiconv_bool_true : 96 (*result)->show_full_pictures = temp & 0x01 ? psiconv_bool_true :
96 psiconv_bool_false; 97 psiconv_bool_false;
97 psiconv_debug(lev+2,off+len,"Show full pictures: %02x", 98 psiconv_debug(config,lev+2,off+len,"Show full pictures: %02x",
98 (*result)->show_full_pictures); 99 (*result)->show_full_pictures);
99 (*result)->show_full_graphs = temp & 0x02 ? psiconv_bool_true : 100 (*result)->show_full_graphs = temp & 0x02 ? psiconv_bool_true :
100 psiconv_bool_false; 101 psiconv_bool_false;
101 psiconv_debug(lev+2,off+len,"Show full graphs: %02x", 102 psiconv_debug(config,lev+2,off+len,"Show full graphs: %02x",
102 (*result)->show_full_graphs); 103 (*result)->show_full_graphs);
103 if (temp & 0xfc) { 104 if (temp & 0xfc) {
104 psiconv_warn(lev+2,off+len,"Word status section second byte of display " 105 psiconv_warn(config,lev+2,off+len,"Word status section second byte of display "
105 "flags contains unknown flags (ignored)"); 106 "flags contains unknown flags (ignored)");
106 psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xfc); 107 psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp & 0xfc);
107 } 108 }
108 len ++; 109 len ++;
109 110
110 psiconv_progress(lev+2,off+len,"Going to read top toolbar setting"); 111 psiconv_progress(config,lev+2,off+len,"Going to read top toolbar setting");
111 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, 112 if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng,
112 &(*result)->show_top_toolbar))) 113 &(*result)->show_top_toolbar)))
113 goto ERROR2; 114 goto ERROR2;
114 len += leng; 115 len += leng;
115 116
116 psiconv_progress(lev+2,off+len,"Going to read side toolbar setting"); 117 psiconv_progress(config,lev+2,off+len,"Going to read side toolbar setting");
117 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, 118 if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng,
118 &(*result)->show_side_toolbar))) 119 &(*result)->show_side_toolbar)))
119 goto ERROR2; 120 goto ERROR2;
120 len += leng; 121 len += leng;
121 122
122 psiconv_progress(lev+2,off+len,"Going to read operational flags"); 123 psiconv_progress(config,lev+2,off+len,"Going to read operational flags");
123 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 124 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
124 if (res) 125 if (res)
125 goto ERROR2; 126 goto ERROR2;
126 (*result)->fit_lines_to_screen = temp & 0x08 ? psiconv_bool_true : 127 (*result)->fit_lines_to_screen = temp & 0x08 ? psiconv_bool_true :
127 psiconv_bool_false; 128 psiconv_bool_false;
128 psiconv_debug(lev+2,off+len,"Fit lines to screen: %02x", 129 psiconv_debug(config,lev+2,off+len,"Fit lines to screen: %02x",
129 (*result)->fit_lines_to_screen); 130 (*result)->fit_lines_to_screen);
130 if (temp & 0xf7) { 131 if (temp & 0xf7) {
131 psiconv_warn(lev+2,off+len,"Word status section operational flags " 132 psiconv_warn(config,lev+2,off+len,"Word status section operational flags "
132 "contains unknown flags (ignored)"); 133 "contains unknown flags (ignored)");
133 psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xfc); 134 psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp & 0xfc);
134 } 135 }
135 len ++; 136 len ++;
136 137
137 psiconv_progress(lev+2,off+len,"Going to read cursor position"); 138 psiconv_progress(config,lev+2,off+len,"Going to read cursor position");
138 (*result)->cursor_position = psiconv_read_u32(buf,lev+2,off + len,&res); 139 (*result)->cursor_position = psiconv_read_u32(config,buf,lev+2,off + len,&res);
139 if (res) 140 if (res)
140 goto ERROR2; 141 goto ERROR2;
141 psiconv_debug(lev+2,off+len,"Cursor position: %08x", 142 psiconv_debug(config,lev+2,off+len,"Cursor position: %08x",
142 (*result)->cursor_position); 143 (*result)->cursor_position);
143 len += 0x04; 144 len += 0x04;
144 145
145 psiconv_progress(lev+2,off+len,"Going to read display size"); 146 psiconv_progress(config,lev+2,off+len,"Going to read display size");
146 (*result)->display_size = psiconv_read_u32(buf,lev+2,off + len,&res); 147 (*result)->display_size = psiconv_read_u32(config,buf,lev+2,off + len,&res);
147 if (res) 148 if (res)
148 goto ERROR2; 149 goto ERROR2;
149 psiconv_debug(lev+2,off+len,"Display size: %08x", 150 psiconv_debug(config,lev+2,off+len,"Display size: %08x",
150 (*result)->display_size); 151 (*result)->display_size);
151 len += 0x04; 152 len += 0x04;
152 153
153 if (length) 154 if (length)
154 *length = len; 155 *length = len;
155 156
156 psiconv_progress(lev,off+len-1, 157 psiconv_progress(config,lev,off+len-1,
157 "End of word status section (total length: %08x)", len); 158 "End of word status section (total length: %08x)", len);
158 return 0; 159 return 0;
159 160
160ERROR2: 161ERROR2:
161 free (*result); 162 free (*result);
162ERROR1: 163ERROR1:
163 psiconv_warn(lev+1,off,"Reading of Word Status Section failed"); 164 psiconv_error(config,lev+1,off,"Reading of Word Status Section failed");
164 if (length) 165 if (length)
165 *length = 0; 166 *length = 0;
166 if (!res) 167 if (!res)
167 return -PSICONV_E_NOMEM; 168 return -PSICONV_E_NOMEM;
168 else 169 else
169 return res; 170 return res;
170} 171}
171 172
172int psiconv_parse_word_styles_section(const psiconv_buffer buf, int lev, 173int psiconv_parse_word_styles_section(const psiconv_config config,
174 const psiconv_buffer buf, int lev,
173 psiconv_u32 off, int *length, 175 psiconv_u32 off, int *length,
174 psiconv_word_styles_section *result) 176 psiconv_word_styles_section *result)
175{ 177{
176 int res=0; 178 int res=0;
177 int len=0; 179 int len=0;
178 int leng,i,nr,j; 180 int leng,i,nr,j;
179 psiconv_word_style style; 181 psiconv_word_style style;
180 psiconv_u32 temp; 182 psiconv_u32 temp;
181 183
182 psiconv_progress(lev+1,off,"Going to read the word styles section"); 184 psiconv_progress(config,lev+1,off,"Going to read the word styles section");
183 if (!(*result = malloc(sizeof(**result)))) 185 if (!(*result = malloc(sizeof(**result))))
184 goto ERROR1; 186 goto ERROR1;
185 187
186 psiconv_progress(lev+2,off+len,"Going to read style normal"); 188 psiconv_progress(config,lev+2,off+len,"Going to read style normal");
187 if (!(style = malloc(sizeof(*style)))) 189 if (!(style = malloc(sizeof(*style))))
188 goto ERROR2; 190 goto ERROR2;
189 style->name = NULL; 191 style->name = NULL;
190 if (!(style->paragraph = psiconv_basic_paragraph_layout())) 192 if (!(style->paragraph = psiconv_basic_paragraph_layout()))
191 goto ERROR2_1; 193 goto ERROR2_1;
192 psiconv_progress(lev+3,off+len,"Going to read the paragraph codes"); 194 psiconv_progress(config,lev+3,off+len,"Going to read the paragraph codes");
193 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, 195 if ((res = psiconv_parse_paragraph_layout_list(config,buf,lev+3,off+len,&leng,
194 style->paragraph))) 196 style->paragraph)))
195 goto ERROR2_2; 197 goto ERROR2_2;
196 len += leng; 198 len += leng;
197 psiconv_progress(lev+3,off+len,"Going to read the character codes"); 199 psiconv_progress(config,lev+3,off+len,"Going to read the character codes");
198 if (!(style->character = psiconv_basic_character_layout())) 200 if (!(style->character = psiconv_basic_character_layout()))
199 goto ERROR2_2; 201 goto ERROR2_2;
200 if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, 202 if ((res = psiconv_parse_character_layout_list(config,buf,lev+3,off+len,&leng,
201 style->character))) 203 style->character)))
202 goto ERROR2_3; 204 goto ERROR2_3;
203 len += leng; 205 len += leng;
206 /* Ugly: I really don't know whether this is right for UTF8 */
204 psiconv_progress(lev+3,off+len,"Going to read the hotkey"); 207 psiconv_progress(config,lev+3,off+len,"Going to read the hotkey");
205 temp = psiconv_read_u32(buf,lev+3,off+len,&res); 208 style->hotkey = psiconv_unicode_read_char(config,buf,lev+3,off+len,NULL,&res);
209 psiconv_debug(config,lev+3,off+len,"Normal Hotkey value %08x",style->hotkey);
206 if (res) 210 if (res)
207 goto ERROR2_3; 211 goto ERROR2_3;
208 if (temp & 0xffffff00) { 212 len += 0x04;
209 psiconv_warn(lev+3,off+len,
210 "Normal style hotkey has unknown value (ignored)");
211 psiconv_debug(lev+3,off+len,"Hotkey value %08x",temp);
212 temp = 0;
213 }
214 style->hotkey = temp & 0x000000ff;
215 if ((style->hotkey >= 32) && (style->hotkey < 127))
216 psiconv_debug(lev+3,off+len,"Hotkey: %c",style->hotkey);
217 else if (style->hotkey == 0x00)
218 psiconv_debug(lev+3,off+len,"Hotkey: <none>");
219 else
220 psiconv_debug(lev+3,off+len,"Hotkey: %02x",style->hotkey);
221 (*result)->normal = style; 213 (*result)->normal = style;
222 len += 0x04;
223 214
224 psiconv_progress(lev+2,off+len,"Going to read hotkeys list"); 215 psiconv_progress(config,lev+2,off+len,"Going to read hotkeys list");
225 if (!((*result)->styles = psiconv_list_new(sizeof(*style)))) 216 if (!((*result)->styles = psiconv_list_new(sizeof(*style))))
226 goto ERROR3; 217 goto ERROR3;
227 if (!(style = malloc(sizeof(*style)))) { 218 if (!(style = malloc(sizeof(*style)))) {
228 goto ERROR3_1; 219 goto ERROR3_1;
229 } 220 }
230 221
231 psiconv_progress(lev+3,off+len,"Going to read the number of entries"); 222 psiconv_progress(config,lev+3,off+len,"Going to read the number of entries");
232 nr = psiconv_read_u8(buf,lev+3,off+len,&res); 223 nr = psiconv_read_u8(config,buf,lev+3,off+len,&res);
233 if (res) 224 if (res)
234 goto ERROR3_2; 225 goto ERROR3_2;
235 len ++; 226 len ++;
236 psiconv_debug(lev+3,off+len,"Nummer of hotkeys: %02x",nr); 227 psiconv_debug(config,lev+3,off+len,"Nummer of hotkeys: %02x",nr);
237 for (i = 0; i < nr; i ++) { 228 for (i = 0; i < nr; i ++) {
238 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 229 /* Ugly: I really don't know whether this is right for UTF8 */
239 if (res) 230 style->hotkey = psiconv_unicode_read_char(config,buf,lev+3,off+len,
240 goto ERROR3_2; 231 NULL,&res);
241 if (temp & 0xffffff00) {
242 psiconv_warn(lev+3,off+len,"Style hotkey has unknown value (ignored)");
243 psiconv_debug(lev+3,off+len,"Hotkey %d value %08x",i,temp);
244 temp = 0;
245 }
246 style->hotkey = temp & 0x000000ff;
247 if ((style->hotkey >= 32) && (style->hotkey < 127))
248 psiconv_debug(lev+3,off+len,"Hotkey %d: %c",i,style->hotkey);
249 else if (style->hotkey == 0x00)
250 psiconv_debug(lev+3,off+len,"Hotkey %d: <none>",i);
251 else
252 psiconv_debug(lev+3,off+len,"Hotkey %d: %02x",i,style->hotkey); 232 psiconv_debug(config,lev+3,off+len,"Hotkey %d value %08x",i,style->hotkey);
233 len += 0x04;
253 if ((res = psiconv_list_add((*result)->styles,style))) 234 if ((res = psiconv_list_add((*result)->styles,style)))
254 goto ERROR3_2; 235 goto ERROR3_2;
255 len += 0x04;
256 } 236 }
257 free(style); 237 free(style);
258 238
259 psiconv_progress(lev+2,off+len,"Going to read all other styles"); 239 psiconv_progress(config,lev+2,off+len,"Going to read all other styles");
260 psiconv_progress(lev+2,off+len,"Going to read the number of styles"); 240 psiconv_progress(config,lev+2,off+len,"Going to read the number of styles");
261 nr = psiconv_read_u8(buf,lev+3,off+len,&res); 241 nr = psiconv_read_u8(config,buf,lev+3,off+len,&res);
262 if (res) 242 if (res)
263 goto ERROR4; 243 goto ERROR4;
264 if (nr != psiconv_list_length((*result)->styles)) { 244 if (nr != psiconv_list_length((*result)->styles)) {
265 psiconv_warn(lev+3,off+len,"Number of styles and hotkeys do not match"); 245 psiconv_warn(config,lev+3,off+len,"Number of styles and hotkeys do not match");
266 psiconv_debug(lev+3,off+len,"%d hotkeys, %d styles", 246 psiconv_debug(config,lev+3,off+len,"%d hotkeys, %d styles",
267 psiconv_list_length((*result)->styles), nr); 247 psiconv_list_length((*result)->styles), nr);
268 } 248 }
269 len ++; 249 len ++;
270 250
271 for (i = 0; i < nr; i++) { 251 for (i = 0; i < nr; i++) {
272 psiconv_progress(lev+2,off+len,"Next style: %d",i); 252 psiconv_progress(config,lev+2,off+len,"Next style: %d",i);
273 if (i >= psiconv_list_length((*result)->styles)) { 253 if (i >= psiconv_list_length((*result)->styles)) {
274 if (!(style = malloc(sizeof(*style)))) 254 if (!(style = malloc(sizeof(*style))))
275 goto ERROR5; 255 goto ERROR5;
276 style->hotkey = 0; 256 style->hotkey = 0;
277 if (!(psiconv_list_add((*result)->styles,style))) { 257 if (psiconv_list_add((*result)->styles,style)) {
278 free(style); 258 free(style);
279 goto ERROR5; 259 goto ERROR5;
280 } 260 }
281 psiconv_debug(lev+3,off+len,"New entry added in list"); 261 psiconv_debug(config,lev+3,off+len,"New entry added in list");
282 free(style); 262 free(style);
283 } 263 }
284 if (!(style = psiconv_list_get((*result)->styles,i))) 264 if (!(style = psiconv_list_get((*result)->styles,i)))
285 goto ERROR5; 265 goto ERROR5;
286 psiconv_progress(lev+3,off+len,"Going to read the style name"); 266 psiconv_progress(config,lev+3,off+len,"Going to read the style name");
287 style->name = psiconv_read_string(buf,lev+3,off+len,&leng,&res); 267 style->name = psiconv_read_string(config,buf,lev+3,off+len,&leng,&res);
288 if (res) 268 if (res)
289 goto ERROR5; 269 goto ERROR5;
290 len += leng; 270 len += leng;
291 psiconv_progress(lev+3,off+len, 271 psiconv_progress(config,lev+3,off+len,
292 "Going to read whether this style is built-in"); 272 "Going to read whether this style is built-in");
293 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 273 temp = psiconv_read_u32(config,buf,lev+2,off+len,&res);
294 if (res) 274 if (res)
295 goto ERROR6; 275 goto ERROR6;
296 276
297 if (temp == PSICONV_ID_STYLE_BUILT_IN) { 277 if (temp == PSICONV_ID_STYLE_BUILT_IN) {
298 style->built_in = psiconv_bool_true; 278 style->built_in = psiconv_bool_true;
299 psiconv_debug(lev+3,off+len,"Built-in style"); 279 psiconv_debug(config,lev+3,off+len,"Built-in style");
300 } else if (temp == PSICONV_ID_STYLE_REMOVABLE) { 280 } else if (temp == PSICONV_ID_STYLE_REMOVABLE) {
301 style->built_in = psiconv_bool_false; 281 style->built_in = psiconv_bool_false;
302 psiconv_debug(lev+3,off+len,"Removable style"); 282 psiconv_debug(config,lev+3,off+len,"Removable style");
303 } else { 283 } else {
304 psiconv_warn(lev+3,off+len, 284 psiconv_warn(config,lev+3,off+len,
305 "Word styles section unknown style id (treated as built-in)"); 285 "Word styles section unknown style id (treated as built-in)");
306 psiconv_debug(lev+3,off+len,"Unknown id: %08x",temp); 286 psiconv_debug(config,lev+3,off+len,"Unknown id: %08x",temp);
307 style->built_in = psiconv_bool_false; 287 style->built_in = psiconv_bool_false;
308 } 288 }
309 len += 4; 289 len += 4;
310 psiconv_progress(lev+3,off+len,"Going to read outline level"); 290 psiconv_progress(config,lev+3,off+len,"Going to read outline level");
311 style->outline_level = psiconv_read_u32(buf,lev+3,off+len,&res); 291 style->outline_level = psiconv_read_u32(config,buf,lev+3,off+len,&res);
312 if (res) 292 if (res)
313 goto ERROR6; 293 goto ERROR6;
314 psiconv_debug(lev+3,off+len,"Outline Level: %08x", style->outline_level); 294 psiconv_debug(config,lev+3,off+len,"Outline Level: %08x", style->outline_level);
315 len += 4; 295 len += 4;
316 psiconv_progress(lev+3,off+len,"Going to read the character codes"); 296 psiconv_progress(config,lev+3,off+len,"Going to read the character codes");
317 if (!(style->character = psiconv_clone_character_layout((*result)->normal->character))) 297 if (!(style->character = psiconv_clone_character_layout((*result)->normal->character)))
318 goto ERROR6; 298 goto ERROR6;
319 if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, 299 if ((res = psiconv_parse_character_layout_list(config,buf,lev+3,off+len,&leng,
320 style->character))) 300 style->character)))
321 goto ERROR7; 301 goto ERROR7;
322 len += leng; 302 len += leng;
323 psiconv_progress(lev+3,off+len,"Going to read the paragraph codes"); 303 psiconv_progress(config,lev+3,off+len,"Going to read the paragraph codes");
324 if (!(style->paragraph = psiconv_clone_paragraph_layout((*result)->normal->paragraph))) 304 if (!(style->paragraph = psiconv_clone_paragraph_layout((*result)->normal->paragraph)))
325 goto ERROR7; 305 goto ERROR7;
326 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, 306 if ((res = psiconv_parse_paragraph_layout_list(config,buf,lev+3,off+len,&leng,
327 style->paragraph))) 307 style->paragraph)))
328 goto ERROR8; 308 goto ERROR8;
329 len += leng; 309 len += leng;
330 } 310 }
331 311
332 psiconv_progress(lev+2,off+len,"Reading trailing bytes"); 312 psiconv_progress(config,lev+2,off+len,"Reading trailing bytes");
333 for (i = 0; i < psiconv_list_length((*result)->styles); i++) { 313 for (i = 0; i < psiconv_list_length((*result)->styles); i++) {
334 temp = psiconv_read_u8(buf,lev+3,off+len,&res); 314 temp = psiconv_read_u8(config,buf,lev+3,off+len,&res);
335 if (res) 315 if (res)
336 goto ERROR4; 316 goto ERROR4;
337 if (temp != 0xff) { 317 if (temp != 0xff) {
338 psiconv_warn(lev+3,off+len,"Unknown trailing style byte"); 318 psiconv_warn(config,lev+3,off+len,"Unknown trailing style byte");
339 psiconv_debug(lev+3,off+len,"Trailing byte: %02x expected, read %02x", 319 psiconv_debug(config,lev+3,off+len,"Trailing byte: %02x expected, read %02x",
340 0xff,temp); 320 0xff,temp);
341 } else 321 } else
342 psiconv_debug(lev+3,off+len,"Read trailing byte 0xff"); 322 psiconv_debug(config,lev+3,off+len,"Read trailing byte 0xff");
343 len++; 323 len++;
344 } 324 }
345 325
346 if (length) 326 if (length)
347 *length = len; 327 *length = len;
348 328
349 psiconv_progress(lev,off+len-1, 329 psiconv_progress(config,lev,off+len-1,
350 "End of word styles section (total length: %08x)", len); 330 "End of word styles section (total length: %08x)", len);
351 331
352 return res; 332 return res;
353 333
354 334
373ERROR6: 353ERROR6:
374 free(style->name); 354 free(style->name);
375ERROR5: 355ERROR5:
376 for (j = 0; j < i ;j++) { 356 for (j = 0; j < i ;j++) {
377 if (!(style = psiconv_list_get((*result)->styles,j))) { 357 if (!(style = psiconv_list_get((*result)->styles,j))) {
378 psiconv_warn(lev+1,off,"Massive memory corruption"); 358 psiconv_error(config,lev+1,off,"Massive memory corruption");
379 goto ERROR4; 359 goto ERROR4;
380 } 360 }
381 psiconv_free_character_layout(style->character); 361 psiconv_free_character_layout(style->character);
382 psiconv_free_paragraph_layout(style->paragraph); 362 psiconv_free_paragraph_layout(style->paragraph);
383 free(style->name); 363 free(style->name);
387ERROR3: 367ERROR3:
388 psiconv_free_word_style((*result)->normal); 368 psiconv_free_word_style((*result)->normal);
389ERROR2: 369ERROR2:
390 free (*result); 370 free (*result);
391ERROR1: 371ERROR1:
392 psiconv_warn(lev+1,off,"Reading of Word Status Section failed"); 372 psiconv_error(config,lev+1,off,"Reading of Word Status Section failed");
393 if (length) 373 if (length)
394 *length = 0; 374 *length = 0;
395 if (!res) 375 if (!res)
396 return -PSICONV_E_NOMEM; 376 return -PSICONV_E_NOMEM;
397 else 377 else

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

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