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

Legend:
Removed from v.27  
changed lines
  Added in v.168

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