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

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

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

Revision 63 Revision 142
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>
22#include <math.h> 24#include <math.h>
23 25
24#include "data.h"
25#include "parse_routines.h" 26#include "parse_routines.h"
27#include "error.h"
28
29#ifdef DMALLOC
30#include <dmalloc.h>
31#endif
32
26 33
27int psiconv_parse_color(const psiconv_buffer buf, int lev, psiconv_u32 off, 34int psiconv_parse_color(const psiconv_buffer buf, int lev, psiconv_u32 off,
28 int *length, psiconv_color *result) 35 int *length, psiconv_color *result)
29{ 36{
30 int res = 0; 37 int res = 0;
31 int len = 0; 38 int len = 0;
32 39
33 psiconv_progress(lev+1,off,"Going to parse color"); 40 psiconv_progress(lev+1,off,"Going to parse color");
34 *result = malloc(sizeof(**result)); 41 if (!(*result = malloc(sizeof(**result))))
42 goto ERROR1;
35 43
36 (*result)->red = psiconv_read_u8(buf,lev+2,off+len); 44 (*result)->red = psiconv_read_u8(buf,lev+2,off+len,&res);
45 if (res)
46 goto ERROR2;
37 (*result)->green = psiconv_read_u8(buf,lev+2,off+len+1); 47 (*result)->green = psiconv_read_u8(buf,lev+2,off+len+1,&res);
48 if (res)
49 goto ERROR2;
38 (*result)->blue = psiconv_read_u8(buf,lev+2,off+len+2); 50 (*result)->blue = psiconv_read_u8(buf,lev+2,off+len+2,&res);
51 if (res)
52 goto ERROR2;
39 len += 3; 53 len += 3;
40 54
41 psiconv_debug(lev+2,off,"Color: red %02x, green %02x, blue %02x", 55 psiconv_debug(lev+2,off,"Color: red %02x, green %02x, blue %02x",
42 (*result)->red, (*result)->green, (*result)->blue); 56 (*result)->red, (*result)->green, (*result)->blue);
43 if (length) 57 if (length)
44 *length = len; 58 *length = len;
45 59
46 psiconv_progress(lev+1,off+len-1,"End of color (total length: %08x)",len); 60 psiconv_progress(lev+1,off+len-1,"End of color (total length: %08x)",len);
61 return 0;
62
63ERROR2:
64 free(*result);
65ERROR1:
66 psiconv_warn(lev+1,off,"Reading of Color failed");
67 if (length)
68 *length = 0;
69 if (res == 0)
70 return -PSICONV_E_NOMEM;
71 else
47 return res; 72 return res;
48} 73}
49 74
50 75
51 76
52int psiconv_parse_font(const psiconv_buffer buf, int lev, psiconv_u32 off, 77int psiconv_parse_font(const psiconv_buffer buf, int lev, psiconv_u32 off,
56 int strlength,i; 81 int strlength,i;
57 char *str_copy; 82 char *str_copy;
58 int len; 83 int len;
59 84
60 psiconv_progress(lev+1,off,"Going to parse font"); 85 psiconv_progress(lev+1,off,"Going to parse font");
61 *result = malloc(sizeof(**result)); 86 if (!(*result = malloc(sizeof(**result))))
87 goto ERROR1;
62 88
63 strlength = psiconv_read_u8(buf,lev+2,off); 89 strlength = psiconv_read_u8(buf,lev+2,off,&res);
90 if (res)
91 goto ERROR2;
64 (*result)->name = malloc(strlength); 92 if (!((*result)->name = malloc(strlength))) {
93 goto ERROR2;
94 }
65 for (i = 0; i < strlength-1; i++) 95 for (i = 0; (i < strlength-1) && !res; i++)
66 (*result)->name[i] = psiconv_read_u8(buf,lev+2,off + 1 + i); 96 (*result)->name[i] = psiconv_read_u8(buf,lev+2,off + 1 + i,&res);
97 if (res)
98 goto ERROR3;
67 (*result)->name[strlength-1] = 0; 99 (*result)->name[strlength-1] = 0;
68 (*result)->screenfont = psiconv_read_u8(buf,lev+2,off + strlength); 100 (*result)->screenfont = psiconv_read_u8(buf,lev+2,off + strlength,&res);
101 if (res)
102 goto ERROR3;
69 103
70 str_copy = psiconv_make_printable((*result)->name); 104 if (!(str_copy = psiconv_make_printable((*result)->name)))
105 goto ERROR3;
106
71 psiconv_debug(lev+2,off+1,"Found font `%s', displayed with screen font %02x", 107 psiconv_debug(lev+2,off+1,"Found font `%s', displayed with screen font %02x",
72 str_copy,(*result)->screenfont); 108 str_copy,(*result)->screenfont);
73 free(str_copy); 109 free(str_copy);
74 len = strlength + 1; 110 len = strlength + 1;
75 if (length) 111 if (length)
76 *length = len; 112 *length = len;
77 113
78 psiconv_progress(lev+1,off + len - 1,"End of font (total length: %08x)",len); 114 psiconv_progress(lev+1,off + len - 1,"End of font (total length: %08x)",len);
115 return 0;
116
117ERROR3:
118 free ((*result)->name);
119ERROR2:
120 free (*result);
121ERROR1:
122 psiconv_warn(lev+1,off,"Reading of Font failed");
123 if (length)
124 *length = 0;
125 if (!res)
126 return -PSICONV_E_NOMEM;
127 else
79 return res; 128 return res;
80} 129}
81 130
82int psiconv_parse_border(const psiconv_buffer buf,int lev,psiconv_u32 off, 131int psiconv_parse_border(const psiconv_buffer buf,int lev,psiconv_u32 off,
83 int *length, psiconv_border *result) 132 int *length, psiconv_border *result)
84{ 133{
86 int len = 0; 135 int len = 0;
87 psiconv_u32 temp; 136 psiconv_u32 temp;
88 int leng; 137 int leng;
89 138
90 psiconv_progress(lev+1,off,"Going to parse border data"); 139 psiconv_progress(lev+1,off,"Going to parse border data");
91 *result = malloc(sizeof(**result)); 140 if (!(*result = malloc(sizeof(**result)))) {
141 goto ERROR1;
142 }
92 143
93 psiconv_progress(lev+2,off+len,"Going to read border kind"); 144 psiconv_progress(lev+2,off+len,"Going to read border kind");
94 temp = psiconv_read_u8(buf,lev+2,off+len); 145 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
146 if (res)
147 goto ERROR2;
95 if (temp == 0x00) 148 if (temp == 0x00)
96 (*result)->kind = psiconv_border_none; 149 (*result)->kind = psiconv_border_none;
97 else if (temp == 0x01) 150 else if (temp == 0x01)
98 (*result)->kind = psiconv_border_solid; 151 (*result)->kind = psiconv_border_solid;
99 else if (temp == 0x02) 152 else if (temp == 0x02)
100 (*result)->kind = psiconv_border_double; 153 (*result)->kind = psiconv_border_double;
101 else if (temp == 0x03) 154 else if (temp == 0x03)
102 (*result)->kind = psiconv_border_dotted; 155 (*result)->kind = psiconv_border_dotted;
103 else if (temp == 0x04) 156 else if (temp == 0x04)
104 (*result)->kind = psiconv_border_striped; 157 (*result)->kind = psiconv_border_dashed;
105 else if (temp == 0x05) 158 else if (temp == 0x05)
106 (*result)->kind = psiconv_border_dotstripe; 159 (*result)->kind = psiconv_border_dotdashed;
107 else if (temp == 0x06) 160 else if (temp == 0x06)
108 (*result)->kind = psiconv_border_dotdotstripe; 161 (*result)->kind = psiconv_border_dotdotdashed;
109 else { 162 else {
110 psiconv_warn(lev+2,off,"Unknown border kind (defaults to `none')"); 163 psiconv_warn(lev+2,off,"Unknown border kind (defaults to `none')");
111 (*result)->kind = psiconv_border_none; 164 (*result)->kind = psiconv_border_none;
112 res = -1;
113 } 165 }
114 psiconv_debug(lev+2,off+len,"Kind: %02x",temp); 166 psiconv_debug(lev+2,off+len,"Kind: %02x",temp);
115 len ++; 167 len ++;
116 168
117 psiconv_progress(lev+2,off+len,"Going to read border thickness"); 169 psiconv_progress(lev+2,off+len,"Going to read border thickness");
118 (*result)->thickness = psiconv_read_size(buf,lev+2,off+len,&leng); 170 (*result)->thickness = psiconv_read_size(buf,lev+2,off+len,&leng,&res);
171 if (res)
172 goto ERROR2;
173#if 0
174 /* This seems no longer necessary to test? */
119 if (((*result)->kind != psiconv_border_solid) && 175 if (((*result)->kind != psiconv_border_solid) &&
120 ((*result)->kind != psiconv_border_double) && 176 ((*result)->kind != psiconv_border_double) &&
121 ((*result)->thickness != 0.0) && 177 ((*result)->thickness != 0.0) &&
122 (fabs((*result)->thickness - 1/20) >= 1/1000)) { 178 (fabs((*result)->thickness - 1/20) >= 1/1000)) {
123 psiconv_warn(lev+2,off, 179 psiconv_warn(lev+2,off,
124 "Border thickness specified for unlikely border type"); 180 "Border thickness specified for unlikely border type");
125 res = -1;
126 } 181 }
182#endif
127 psiconv_debug(lev+2,off+len,"Thickness: %f",(*result)->thickness); 183 psiconv_debug(lev+2,off+len,"Thickness: %f",(*result)->thickness);
128 len += leng; 184 len += leng;
129 185
130 psiconv_progress(lev+2,off+len,"Going to read the border color"); 186 psiconv_progress(lev+2,off+len,"Going to read the border color");
131 res |= psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color); 187 if ((psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color)))
188 goto ERROR2;
132 len += leng; 189 len += leng;
133 190
134 psiconv_progress(lev+2,off+len,"Going to read the final unknown byte " 191 psiconv_progress(lev+2,off+len,"Going to read the final unknown byte "
135 "(0x01 expected)"); 192 "(0x00 or 0x01 expected)");
136 temp = psiconv_read_u8(buf,lev+2,off + len); 193 temp = psiconv_read_u8(buf,lev+2,off + len,&res);
137 if (temp != 0x01) { 194 if (res)
195 goto ERROR3;
196 if ((temp != 0x01) && (temp != 0x00)) {
138 psiconv_warn(lev+2,off,"Unknown last byte in border specification"); 197 psiconv_warn(lev+2,off,"Unknown last byte in border specification");
139 psiconv_debug(lev+2,off+len, "Last byte: read %02x, expected %02x", 198 psiconv_debug(lev+2,off+len, "Last byte: read %02x, expected %02x or %02x",
140 temp,0x01); 199 temp,0x00,0x01);
141 res = -1;
142 } 200 }
143 len ++; 201 len ++;
144 202
145 if (length) 203 if (length)
146 *length = len; 204 *length = len;
147 205
148 psiconv_progress(lev+1,off + len - 1, 206 psiconv_progress(lev+1,off + len - 1,
149 "End of border (total length: %08x)",len); 207 "End of border (total length: %08x)",len);
150 208
209 return 0;
210
211ERROR3:
212 psiconv_free_color((*result)->color);
213ERROR2:
214 free (result);
215ERROR1:
216 psiconv_warn(lev+1,off,"Reading of Border failed");
217 if (length)
218 *length = 0;
219 if (!res)
220 return -PSICONV_E_NOMEM;
221 else
151 return res; 222 return res;
152} 223}
153 224
154int psiconv_parse_bullet(const psiconv_buffer buf,int lev,psiconv_u32 off, 225int psiconv_parse_bullet(const psiconv_buffer buf,int lev,psiconv_u32 off,
155 int *length, psiconv_bullet *result) 226 int *length, psiconv_bullet *result)
156{ 227{
157 int res = 0; 228 int res = 0;
158 int len = 0; 229 int len = 0;
159 int leng; 230 int leng;
160 int bullet_length; 231 int bullet_length;
161 232
162 *result = malloc(sizeof(**result)); 233 if (!(*result = malloc(sizeof(**result))))
234 goto ERROR1;
163 (*result)->on = psiconv_bool_true; 235 (*result)->on = psiconv_bool_true;
164 236
165 psiconv_progress(lev+1,off,"Going to parse bullet data"); 237 psiconv_progress(lev+1,off,"Going to parse bullet data");
166 psiconv_progress(lev+2,off+len,"Going to read bullet length"); 238 psiconv_progress(lev+2,off+len,"Going to read bullet length");
167 bullet_length = psiconv_read_u8(buf,lev+2,off+len); 239 bullet_length = psiconv_read_u8(buf,lev+2,off+len,&res);
240 if (res)
241 goto ERROR2;
168 psiconv_debug(lev+2,off+len,"Length: %02x",bullet_length); 242 psiconv_debug(lev+2,off+len,"Length: %02x",bullet_length);
169 len ++; 243 len ++;
170 244
171 psiconv_progress(lev+2,off+len,"Going to read bullet font size"); 245 psiconv_progress(lev+2,off+len,"Going to read bullet font size");
172 (*result)->font_size = psiconv_read_size(buf,lev+2,off+len, &leng); 246 (*result)->font_size = psiconv_read_size(buf,lev+2,off+len, &leng,&res);
247 if (res)
248 goto ERROR2;
173 len +=leng; 249 len +=leng;
174 250
175 psiconv_progress(lev+2,off+len,"Going to read bullet character"); 251 psiconv_progress(lev+2,off+len,"Going to read bullet character");
176 (*result)->character = psiconv_read_u8(buf,lev+2,off+len); 252 (*result)->character = psiconv_read_u8(buf,lev+2,off+len,&res);
253 if (res)
254 goto ERROR2;
177 psiconv_debug(lev+2,off+len,"Character: %02x",(*result)->character); 255 psiconv_debug(lev+2,off+len,"Character: %02x",(*result)->character);
178 len ++; 256 len ++;
179 257
180 psiconv_progress(lev+2,off+len,"Going to read indent on/off"); 258 psiconv_progress(lev+2,off+len,"Going to read indent on/off");
181 res |= psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->indent); 259 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->indent)))
260 goto ERROR2;
182 psiconv_debug(lev+2,off+len,"Indent on: %02x",(*result)->indent); 261 psiconv_debug(lev+2,off+len,"Indent on: %02x",(*result)->indent);
183 len += leng; 262 len += leng;
184 263
185 psiconv_progress(lev+2,off+len,"Going to read bullet color"); 264 psiconv_progress(lev+2,off+len,"Going to read bullet color");
186 res |= psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color); 265 if ((res = psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color)))
266 goto ERROR2;
187 len += leng; 267 len += leng;
188 268
189 psiconv_progress(lev+2,off+len,"Going to read bullet font"); 269 psiconv_progress(lev+2,off+len,"Going to read bullet font");
190 res |= psiconv_parse_font(buf,lev+2,off+len,&leng,&(*result)->font); 270 if ((res = psiconv_parse_font(buf,lev+2,off+len,&leng,&(*result)->font)))
271 goto ERROR3;
191 len += leng; 272 len += leng;
192 273
193 if (len != bullet_length + 1) { 274 if (len != bullet_length + 1) {
194 psiconv_warn(lev+2,off,"Bullet data structure length mismatch"); 275 psiconv_warn(lev+2,off,"Bullet data structure length mismatch");
195 psiconv_debug(lev+2,off,"Length: specified %02x, found %02x", 276 psiconv_debug(lev+2,off,"Length: specified %02x, found %02x",
196 bullet_length,len-1); 277 bullet_length,len-1);
197 res = -1;
198 } 278 }
199 279
200 psiconv_progress(lev+1,off + len - 1, 280 psiconv_progress(lev+1,off + len - 1,
201 "End of bullet data (total length: %08x)",len); 281 "End of bullet data (total length: %08x)",len);
202 282
203 if (length) 283 if (length)
204 *length = len; 284 *length = len;
285 return 0;
286
287ERROR3:
288 psiconv_free_color((*result)->color);
289ERROR2:
290 free (result);
291ERROR1:
292 psiconv_warn(lev+1,off,"Reading of Bullet failed");
293 if (length)
294 *length = 0;
295 if (!res)
296 return -PSICONV_E_NOMEM;
297 else
205 return res; 298 return res;
206} 299}
207 300
208int psiconv_parse_tab(const psiconv_buffer buf, int lev, psiconv_u32 off, 301int psiconv_parse_tab(const psiconv_buffer buf, int lev, psiconv_u32 off,
209 int *length, psiconv_tab *result) 302 int *length, psiconv_tab *result)
210{ 303{
212 int len = 0; 305 int len = 0;
213 int leng; 306 int leng;
214 psiconv_u8 temp; 307 psiconv_u8 temp;
215 308
216 psiconv_progress(lev+1,off,"Going to parse tab"); 309 psiconv_progress(lev+1,off,"Going to parse tab");
217 *result = malloc(sizeof(**result)); 310 if (!(*result = malloc(sizeof(**result))))
311 goto ERROR1;
218 312
219 psiconv_progress(lev+2,off,"Going to read tab location"); 313 psiconv_progress(lev+2,off,"Going to read tab location");
220 (*result)->location = psiconv_read_length(buf,lev+2,off+len,&leng); 314 (*result)->location = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
315 if (res)
316 goto ERROR2;
221 len += leng; 317 len += leng;
222 318
223 psiconv_progress(lev+2,off+len,"Going to read the tab kind"); 319 psiconv_progress(lev+2,off+len,"Going to read the tab kind");
224 temp = psiconv_read_u8(buf,lev+2,off+len); 320 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
321 if (res)
322 goto ERROR2;
225 if (temp == 1) 323 if (temp == 1)
226 (*result)->kind = psiconv_tab_left; 324 (*result)->kind = psiconv_tab_left;
227 else if (temp == 2) 325 else if (temp == 2)
228 (*result)->kind = psiconv_tab_centre; 326 (*result)->kind = psiconv_tab_centre;
229 else if (temp == 3) 327 else if (temp == 3)
230 (*result)->kind = psiconv_tab_right; 328 (*result)->kind = psiconv_tab_right;
231 else { 329 else {
232 res = -1;
233 psiconv_warn(lev+2,off+len,"Unknown tab kind argument"); 330 psiconv_warn(lev+2,off+len,"Unknown tab kind argument");
234 psiconv_debug(lev+2,off+len,"Kind found: %02x (defaulted to left tab)", 331 psiconv_debug(lev+2,off+len,"Kind found: %02x (defaulted to left tab)",
235 temp); 332 temp);
236 (*result)->kind = psiconv_tab_left; 333 (*result)->kind = psiconv_tab_left;
237 } 334 }
240 337
241 if (length) 338 if (length)
242 *length = len; 339 *length = len;
243 340
244 psiconv_progress(lev+1,off+len-1,"End of tab (total length: %08x)",len); 341 psiconv_progress(lev+1,off+len-1,"End of tab (total length: %08x)",len);
245 return res; 342 return 0;
246 343
344ERROR2:
345 free (result);
346ERROR1:
347 psiconv_warn(lev+1,off,"Reading of Tab failed");
348 if (length)
349 *length = 0;
350 if (!res)
351 return -PSICONV_E_NOMEM;
352 else
353 return res;
247} 354}
248 355
249int psiconv_parse_paragraph_layout_list(const psiconv_buffer buf, int lev, 356int psiconv_parse_paragraph_layout_list(const psiconv_buffer buf, int lev,
250 psiconv_u32 off, int *length, 357 psiconv_u32 off, int *length,
251 psiconv_paragraph_layout result) 358 psiconv_paragraph_layout result)
253 int res=0; 360 int res=0;
254 int len=0; 361 int len=0;
255 int list_length,leng,nr; 362 int list_length,leng,nr;
256 psiconv_u8 id; 363 psiconv_u8 id;
257 psiconv_u32 temp; 364 psiconv_u32 temp;
258 psiconv_tab tab; 365 psiconv_tab temp_tab;
366 psiconv_color temp_color;
367 psiconv_border temp_border;
368 psiconv_bullet temp_bullet;
259 369
260 psiconv_progress(lev+1,off,"Going to read paragraph layout list"); 370 psiconv_progress(lev+1,off,"Going to read paragraph layout list");
261 371
262 psiconv_progress(lev+2,off,"Going to read the list length"); 372 psiconv_progress(lev+2,off,"Going to read the list length");
263 list_length = psiconv_read_u32(buf,lev+2,off + len); 373 list_length = psiconv_read_u32(buf,lev+2,off + len,&res);
374 if (res)
375 goto ERROR1;
264 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length); 376 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length);
265 len += 4; 377 len += 4;
266 378
267 nr = 0; 379 nr = 0;
268 while(len - 4 < list_length) { 380 while(len - 4 < list_length) {
269 psiconv_progress(lev+2,off+len,"Going to read element %d",nr); 381 psiconv_progress(lev+2,off+len,"Going to read element %d",nr);
270 psiconv_progress(lev+3,off+len,"Going to read the element id"); 382 psiconv_progress(lev+3,off+len,"Going to read the element id");
271 id = psiconv_read_u8(buf,lev+2,off+len); 383 id = psiconv_read_u8(buf,lev+2,off+len,&res);
384 if (res)
385 goto ERROR1;
272 psiconv_debug(lev+3,off+len,"Id: %02x",id); 386 psiconv_debug(lev+3,off+len,"Id: %02x",id);
273 len ++; 387 len ++;
274 switch(id) { 388 switch(id) {
275 case 0x01: 389 case 0x01:
276 psiconv_progress(lev+3,off+len,"Going to read background color"); 390 psiconv_progress(lev+3,off+len,"Going to read background color");
391 if ((res = psiconv_parse_color(buf,lev+3,off+len,&leng,&temp_color)))
392 goto ERROR1;
277 psiconv_free_color(result->back_color); 393 psiconv_free_color(result->back_color);
278 res |= psiconv_parse_color(buf,lev+3,off+len,&leng, 394 result->back_color = temp_color;
279 &result->back_color);
280 len += leng; 395 len += leng;
281 break; 396 break;
282 case 0x02: 397 case 0x02:
283 psiconv_progress(lev+3,off+len ,"Going to read indent left"); 398 psiconv_progress(lev+3,off+len ,"Going to read indent left");
284 result->indent_left = psiconv_read_length(buf,lev+3,off+len,&leng); 399 result->indent_left = psiconv_read_length(buf,lev+3,off+len,&leng,&res);
400 if (res)
401 goto ERROR1;
285 len += leng; 402 len += leng;
286 break; 403 break;
287 case 0x03: 404 case 0x03:
288 psiconv_progress(lev+3,off+len,"Going to read indent right"); 405 psiconv_progress(lev+3,off+len,"Going to read indent right");
289 result->indent_right = psiconv_read_length(buf,lev+2,off+len,&leng); 406 result->indent_right = psiconv_read_length(buf,lev+2,off+len,&leng,
407 &res);
408 if (res)
409 goto ERROR1;
290 len += leng; 410 len += leng;
291 break; 411 break;
292 case 0x04: 412 case 0x04:
293 psiconv_progress(lev+3,off+len,"Going to read indent left first line"); 413 psiconv_progress(lev+3,off+len,"Going to read indent left first line");
294 result->indent_first = psiconv_read_length(buf,lev+2,off+len, &leng); 414 result->indent_first = psiconv_read_length(buf,lev+2,off+len, &leng,
415 &res);
416 if (res)
417 goto ERROR1;
295 len += leng; 418 len += leng;
296 break; 419 break;
297 case 0x05: 420 case 0x05:
298 psiconv_progress(lev+3,off+len,"Going to read horizontal justify"); 421 psiconv_progress(lev+3,off+len,"Going to read horizontal justify");
299 temp = psiconv_read_u8(buf,lev+3,off+len); 422 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
423 if (res)
424 goto ERROR1;
300 if (temp == 0x00) 425 if (temp == 0x00)
301 result->justify_hor = psiconv_justify_left; 426 result->justify_hor = psiconv_justify_left;
302 else if (temp == 0x01) 427 else if (temp == 0x01)
303 result->justify_hor = psiconv_justify_centre; 428 result->justify_hor = psiconv_justify_centre;
304 else if (temp == 0x02) 429 else if (temp == 0x02)
305 result->justify_hor = psiconv_justify_right; 430 result->justify_hor = psiconv_justify_right;
306 else if (temp == 0x03) 431 else if (temp == 0x03)
307 result->justify_hor = psiconv_justify_full; 432 result->justify_hor = psiconv_justify_full;
308 else { 433 else {
309 res = -1;
310 psiconv_warn(lev+3,off+len, "Unknown horizontal justify argument " 434 psiconv_warn(lev+3,off+len, "Unknown horizontal justify argument "
311 "in paragraph layout codes list"); 435 "in paragraph layout codes list");
436 result->justify_hor = psiconv_justify_left;
312 } 437 }
313 psiconv_debug(lev+3,off+len,"Justify: %02x",temp); 438 psiconv_debug(lev+3,off+len,"Justify: %02x",temp);
314 len ++; 439 len ++;
315 break; 440 break;
316 case 0x06: 441 case 0x06:
317 psiconv_progress(lev+3,off+len,"Going to read vertical justify"); 442 psiconv_progress(lev+3,off+len,"Going to read vertical justify");
318 temp = psiconv_read_u8(buf,lev+3,off+len); 443 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
444 if (res)
445 goto ERROR1;
319 if (temp == 0x00) 446 if (temp == 0x00)
320 result->justify_ver = psiconv_justify_top; 447 result->justify_ver = psiconv_justify_top;
321 else if (temp == 0x01) 448 else if (temp == 0x01)
322 result->justify_ver = psiconv_justify_middle; 449 result->justify_ver = psiconv_justify_middle;
323 else if (temp == 0x02) 450 else if (temp == 0x02)
324 result->justify_ver = psiconv_justify_bottom; 451 result->justify_ver = psiconv_justify_bottom;
325 else { 452 else {
326 res = -1;
327 psiconv_warn(lev+3,off+len, "Unknown vertical justify argument " 453 psiconv_warn(lev+3,off+len, "Unknown vertical justify argument "
328 "in paragraph layout codes list"); 454 "in paragraph layout codes list");
455 result->justify_ver = psiconv_justify_bottom;
329 } 456 }
330 psiconv_debug(lev+3,off+len,"Justify: %02x",temp); 457 psiconv_debug(lev+3,off+len,"Justify: %02x",temp);
331 len ++; 458 len ++;
459 break;
332 case 0x07: 460 case 0x07:
333 psiconv_progress(lev+3,off+len,"Going to read interline distance"); 461 psiconv_progress(lev+3,off+len,"Going to read linespacing distance");
334 result->interline = psiconv_read_size(buf,lev+3,off+len,&leng); 462 result->linespacing = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
463 if (res)
464 goto ERROR1;
335 len += leng; 465 len += leng;
336 break; 466 break;
337 case 0x08: 467 case 0x08:
338 psiconv_progress(lev+3,off+len,"Going to read interline exact"); 468 psiconv_progress(lev+3,off+len,"Going to read linespacing exact");
339 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 469 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
340 &result->interline_exact); 470 &result->linespacing_exact)))
471 goto ERROR1;
341 len += leng; 472 len += leng;
342 break; 473 break;
343 case 0x09: 474 case 0x09:
344 psiconv_progress(lev+3,off+len,"Going to read top space"); 475 psiconv_progress(lev+3,off+len,"Going to read top space");
345 result->top_space = psiconv_read_size(buf,lev+3,off+len,&leng); 476 result->space_above = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
477 if (res)
478 goto ERROR1;
346 len += leng; 479 len += leng;
347 break; 480 break;
348 case 0x0a: 481 case 0x0a:
349 psiconv_progress(lev+3,off+len,"Going to read bottom space"); 482 psiconv_progress(lev+3,off+len,"Going to read bottom space");
350 result->bottom_space = psiconv_read_size(buf,lev+3,off+len,&leng); 483 result->space_below = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
484 if (res)
485 goto ERROR1;
351 len += leng; 486 len += leng;
352 break; 487 break;
353 case 0x0b: 488 case 0x0b:
354 psiconv_progress(lev+3,off+len,"Going to read on one page"); 489 psiconv_progress(lev+3,off+len,"Going to read on one page");
355 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 490 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
356 &result->on_one_page); 491 &result->keep_together)))
492 goto ERROR1;
357 len += leng; 493 len += leng;
358 break; 494 break;
359 case 0x0c: 495 case 0x0c:
360 psiconv_progress(lev+3,off+len,"Going to read together with"); 496 psiconv_progress(lev+3,off+len,"Going to read together with");
361 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 497 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
362 &result->together_with); 498 &result->keep_with_next)))
499 goto ERROR1;
363 len += leng; 500 len += leng;
364 break; 501 break;
365 case 0x0d: 502 case 0x0d:
366 psiconv_progress(lev+3,off+len,"Going to read on next page"); 503 psiconv_progress(lev+3,off+len,"Going to read on next page");
367 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 504 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
368 &result->on_next_page); 505 &result->on_next_page)))
506 goto ERROR1;
369 len += leng; 507 len += leng;
370 break; 508 break;
371 case 0x0e: 509 case 0x0e:
372 psiconv_progress(lev+3,off+len,"Going to read no widow protection"); 510 psiconv_progress(lev+3,off+len,"Going to read no widow protection");
373 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 511 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
374 &result->no_widow_protection); 512 &result->no_widow_protection)))
513 goto ERROR1;
514 len += leng;
515 break;
516 case 0x0f:
517 psiconv_progress(lev+3,off+len,"Going to read wrap to fit cell limits");
518 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
519 &result->wrap_to_fit_cell)))
520 goto ERROR1;
375 len += leng; 521 len += leng;
376 break; 522 break;
377 case 0x10: 523 case 0x10:
378 psiconv_progress(lev+3,off+len,"Going to read border distance to text"); 524 psiconv_progress(lev+3,off+len,"Going to read border distance to text");
379 result->border_distance = psiconv_read_length(buf,lev+3, 525 result->border_distance = psiconv_read_length(buf,lev+3,
380 off+len,&leng); 526 off+len,&leng,&res);
527 if (res)
528 goto ERROR1;
381 len += leng; 529 len += leng;
382 break; 530 break;
383 case 0x11: 531 case 0x11:
384 psiconv_progress(lev+3,off+len,"Going to read top border"); 532 psiconv_progress(lev+3,off+len,"Going to read top border");
533 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
534 goto ERROR1;
385 psiconv_free_border(result->top_border); 535 psiconv_free_border(result->top_border);
386 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 536 result->top_border = temp_border;
387 &result->top_border);
388 len += leng; 537 len += leng;
389 break; 538 break;
390 case 0x12: 539 case 0x12:
391 psiconv_progress(lev+3,off+len,"Going to read bottom border"); 540 psiconv_progress(lev+3,off+len,"Going to read bottom border");
541 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
542 goto ERROR1;
392 psiconv_free_border(result->bottom_border); 543 psiconv_free_border(result->bottom_border);
393 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 544 result->bottom_border = temp_border;
394 &result->bottom_border);
395 len += leng; 545 len += leng;
396 break; 546 break;
397 case 0x13: 547 case 0x13:
398 psiconv_progress(lev+3,off+len,"Going to read left border"); 548 psiconv_progress(lev+3,off+len,"Going to read left border");
549 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
550 goto ERROR1;
399 psiconv_free_border(result->left_border); 551 psiconv_free_border(result->left_border);
400 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 552 result->left_border = temp_border;
401 &result->left_border);
402 len += leng; 553 len += leng;
403 break; 554 break;
404 case 0x14: 555 case 0x14:
405 psiconv_progress(lev+3,off+len,"Going to read right border"); 556 psiconv_progress(lev+3,off+len,"Going to read right border");
557 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
558 goto ERROR1;
406 psiconv_free_border(result->right_border); 559 psiconv_free_border(result->right_border);
407 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 560 result->right_border = temp_border;
408 &result->right_border);
409 len += leng; 561 len += leng;
410 break; 562 break;
411 case 0x15: 563 case 0x15:
412 psiconv_progress(lev+3,off+len,"Going to read bullet"); 564 psiconv_progress(lev+3,off+len,"Going to read bullet");
565 if ((res = psiconv_parse_bullet(buf,lev+3,off+len,&leng,&temp_bullet)))
566 goto ERROR1;
413 psiconv_free_bullet(result->bullet); 567 psiconv_free_bullet(result->bullet);
414 res |= psiconv_parse_bullet(buf,lev+3,off+len,&leng, 568 result->bullet = temp_bullet;
415 &result->bullet);
416 len += leng; 569 len += leng;
417 break; 570 break;
418 case 0x16: 571 case 0x16:
419 psiconv_progress(lev+3,off+len,"Going to read standard tabs"); 572 psiconv_progress(lev+3,off+len,"Going to read standard tabs");
420 result->tabs->normal = psiconv_read_length(buf,lev+3,off+len,&leng); 573 result->tabs->normal = psiconv_read_length(buf,lev+3,off+len,&leng,
574 &res);
575 if (res)
576 goto ERROR1;
421 len += leng; 577 len += leng;
422 break; 578 break;
423 case 0x17: 579 case 0x17:
424 psiconv_progress(lev+3,off+len,"Going to read extra tab"); 580 psiconv_progress(lev+3,off+len,"Going to read extra tab");
425 res |= psiconv_parse_tab(buf,lev+3,off+len,&leng,&tab); 581 if ((res = psiconv_parse_tab(buf,lev+3,off+len,&leng,&temp_tab)))
582 goto ERROR1;
426 psiconv_list_add(result->tabs->extras,tab); 583 if ((res = psiconv_list_add(result->tabs->extras,temp_tab))) {
584 psiconv_free_tab(temp_tab);
585 goto ERROR1;
586 }
427 len += leng; 587 len += leng;
428 break; 588 break;
429 default: 589 default:
430 psiconv_warn(lev+3,off+len, 590 psiconv_warn(lev+3,off+len,
431 "Unknown code in paragraph layout codes list"); 591 "Unknown code in paragraph layout codes list");
432 psiconv_debug(lev+3,off+len,"Code: %02x",id); 592 psiconv_debug(lev+3,off+len,"Code: %02x",id);
433 len ++; 593 len ++;
434 res = -1;
435 break; 594 break;
436 } 595 }
437 nr ++; 596 nr ++;
438 } 597 }
439 598
441 psiconv_warn(lev+2,off+len, 600 psiconv_warn(lev+2,off+len,
442 "Read past end of paragraph layout codes list. I probably lost track" 601 "Read past end of paragraph layout codes list. I probably lost track"
443 "somewhere!"); 602 "somewhere!");
444 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d", 603 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d",
445 len-4,list_length); 604 len-4,list_length);
605 res = PSICONV_E_PARSE;
606 goto ERROR1;
446 } 607 }
447 608
448 len = list_length + 4; 609 len = list_length + 4;
449 610
450 psiconv_progress(lev+1,off+len, 611 psiconv_progress(lev+1,off+len,
451 "End of paragraph layout list (total length: %08x)",len); 612 "End of paragraph layout list (total length: %08x)",len);
452 613
453 if (length) 614 if (length)
454 *length = len; 615 *length = len;
616 return 0;
617
618ERROR1:
619 psiconv_warn(lev+1,off,"Reading of paragraph_layout_list failed");
620 if (length)
621 *length = 0;
622 if (!res)
623 return -PSICONV_E_NOMEM;
624 else
455 return res; 625 return res;
456} 626}
457 627
458int psiconv_parse_character_layout_list(const psiconv_buffer buf, int lev, 628int psiconv_parse_character_layout_list(const psiconv_buffer buf, int lev,
459 psiconv_u32 off, int *length, 629 psiconv_u32 off, int *length,
460 psiconv_character_layout result) 630 psiconv_character_layout result)
462 int res=0; 632 int res=0;
463 int len=0; 633 int len=0;
464 int list_length,leng,nr; 634 int list_length,leng,nr;
465 psiconv_u8 id; 635 psiconv_u8 id;
466 psiconv_u32 temp; 636 psiconv_u32 temp;
637 psiconv_color temp_color;
638 psiconv_font temp_font;
467 639
468 psiconv_progress(lev+1,off,"Going to read character layout codes"); 640 psiconv_progress(lev+1,off,"Going to read character layout codes");
469 641
470 psiconv_progress(lev+2,off,"Going to read the list length"); 642 psiconv_progress(lev+2,off,"Going to read the list length");
471 list_length = psiconv_read_u32(buf,lev+2,off + len); 643 list_length = psiconv_read_u32(buf,lev+2,off + len,&res);
644 if (res)
645 goto ERROR1;
472 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length); 646 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length);
473 len += 4; 647 len += 4;
474 648
475 nr = 0; 649 nr = 0;
476 while(len-4 < list_length) { 650 while(len-4 < list_length) {
477 psiconv_progress(lev+2,off+len,"Going to read element %d",nr); 651 psiconv_progress(lev+2,off+len,"Going to read element %d",nr);
478 psiconv_progress(lev+3,off+len,"Going to read the element id"); 652 psiconv_progress(lev+3,off+len,"Going to read the element id");
479 id = psiconv_read_u8(buf,lev+2,off+len); 653 id = psiconv_read_u8(buf,lev+2,off+len,&res);
654 if (res)
655 goto ERROR1;
480 psiconv_debug(lev+3,off+len,"Id: %02x",id); 656 psiconv_debug(lev+3,off+len,"Id: %02x",id);
481 len ++; 657 len ++;
482 switch(id) { 658 switch(id) {
659 case 0x18:
660 psiconv_progress(lev+3,off+len,"Going to skip an unknown setting");
661 len ++;
662 break;
483 case 0x19: 663 case 0x19:
484 psiconv_progress(lev+3,off+len,"Going to read text color"); 664 psiconv_progress(lev+3,off+len,"Going to read text color");
665 if ((res = psiconv_parse_color(buf,lev+3,off+len, &leng,&temp_color)))
666 goto ERROR1;
485 psiconv_free_color(result->color); 667 psiconv_free_color(result->color);
486 res |= psiconv_parse_color(buf,lev+3,off+len, &leng,&result->color); 668 result->color = temp_color;
487 len += leng; 669 len += leng;
488 break; 670 break;
489 case 0x1a: 671 case 0x1a:
490 psiconv_progress(lev+3,off+len,"Going to read background color (?)"); 672 psiconv_progress(lev+3,off+len,"Going to read background color (?)");
673 if ((res = psiconv_parse_color(buf,lev+2,off+len, &leng,&temp_color)))
674 goto ERROR1;
491 psiconv_free_color(result->back_color); 675 psiconv_free_color(result->back_color);
492 res |= psiconv_parse_color(buf,lev+2,off+len, &leng, 676 result->back_color = temp_color;
493 &result->back_color); 677 len += leng;
678 break;
679 case 0x1b:
680 psiconv_progress(lev+3,off+len,"Going to skip an unknown setting");
494 len += leng; 681 len ++;
495 break; 682 break;
496 case 0x1c: 683 case 0x1c:
497 psiconv_progress(lev+3,off+len,"Going to read font size"); 684 psiconv_progress(lev+3,off+len,"Going to read font size");
498 result->font_size = psiconv_read_size(buf,lev+3,off+len,&leng); 685 result->font_size = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
686 if (res)
687 goto ERROR1;
499 len += leng; 688 len += leng;
500 break; 689 break;
501 case 0x1d: 690 case 0x1d:
502 psiconv_progress(lev+3,off+len,"Going to read italic"); 691 psiconv_progress(lev+3,off+len,"Going to read italic");
503 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->italic); 692 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->italic)))
693 goto ERROR1;
504 len += leng; 694 len += leng;
505 break; 695 break;
506 case 0x1e: 696 case 0x1e:
507 psiconv_progress(lev+3,off+len,"Going to read bold"); 697 psiconv_progress(lev+3,off+len,"Going to read bold");
508 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->bold); 698 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->bold)))
699 goto ERROR1;
509 len += leng; 700 len += leng;
510 break; 701 break;
511 case 0x1f: 702 case 0x1f:
512 psiconv_progress(lev+3,off+len,"Going to read super_sub"); 703 psiconv_progress(lev+3,off+len,"Going to read super_sub");
513 temp = psiconv_read_u8(buf,lev+3,off+len); 704 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
705 if (res)
706 goto ERROR1;
514 if (temp == 0x00) 707 if (temp == 0x00)
515 result->super_sub = psiconv_normalscript; 708 result->super_sub = psiconv_normalscript;
516 else if (temp == 0x01) 709 else if (temp == 0x01)
517 result->super_sub = psiconv_superscript; 710 result->super_sub = psiconv_superscript;
518 else if (temp == 0x02) 711 else if (temp == 0x02)
519 result->super_sub = psiconv_subscript; 712 result->super_sub = psiconv_subscript;
520 else { 713 else {
521 psiconv_warn(lev+3,off+len, 714 psiconv_warn(lev+3,off+len,
522 "Unknown super_sub argument in character layout codes list"); 715 "Unknown super_sub argument in character layout codes list");
523 res = -1;
524 } 716 }
525 psiconv_debug(lev+3,off+len,"Super_sub: %02x",temp); 717 psiconv_debug(lev+3,off+len,"Super_sub: %02x",temp);
526 len ++; 718 len ++;
527 break; 719 break;
528 case 0x20: 720 case 0x20:
529 psiconv_progress(lev+3,off+len,"Going to read underline"); 721 psiconv_progress(lev+3,off+len,"Going to read underline");
530 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->underline); 722 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
723 &result->underline)))
724 goto ERROR1;
531 len += leng; 725 len += leng;
532 break; 726 break;
533 case 0x21: 727 case 0x21:
534 psiconv_progress(lev+3,off+len,"Going to read strike_out"); 728 psiconv_progress(lev+3,off+len,"Going to read strikethrough");
535 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->strike_out); 729 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
730 &result->strikethrough)))
731 goto ERROR1;
536 len += leng; 732 len += leng;
537 break; 733 break;
538 case 0x22: 734 case 0x22:
539 psiconv_progress(lev+3,off+len,"Going to read font"); 735 psiconv_progress(lev+3,off+len,"Going to read font");
736 if ((res = psiconv_parse_font(buf,lev+3,off+len, &leng, &temp_font)))
737 goto ERROR1;
540 psiconv_free_font(result->font); 738 psiconv_free_font(result->font);
541 res |= psiconv_parse_font(buf,lev+3,off+len, &leng, &result->font); 739 result->font = temp_font;
740 len += leng;
741 break;
742 case 0x23:
743 psiconv_progress(lev+3,off+len,"Going to skip an unknown setting");
542 len += leng; 744 len ++;
543 break; 745 break;
544 case 0x24: 746 case 0x24:
545 psiconv_progress(lev+3,off+len, 747 psiconv_progress(lev+3,off+len,
546 "Going to read unknown code 0x24 (%02x expected)", 0); 748 "Going to read unknown code 0x24 (%02x expected)", 0);
547 temp = psiconv_read_u8(buf,lev+3,off+len); 749 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
750 if (res)
751 goto ERROR1;
548 if (temp != 0) { 752 if (temp != 0) {
549 psiconv_warn(lev+3,off+len, 753 psiconv_warn(lev+3,off+len,
550 "Unknown code 0x24 value != 0x0 (0x%02x)", temp); 754 "Unknown code 0x24 value != 0x0 (0x%02x)", temp);
551 } 755 }
552 len ++; 756 len ++;
553 break; 757 break;
554 default: 758 default:
555 psiconv_warn(lev+3,off+len,"Unknown code in character layout list"); 759 psiconv_warn(lev+3,off+len,"Unknown code in character layout list");
556 psiconv_debug(lev+3,off+len,"Code: %02x",id); 760 psiconv_debug(lev+3,off+len,"Code: %02x",id);
557 len ++; 761 len ++;
558 res = -1;
559 break; 762 break;
560 } 763 }
561 nr ++; 764 nr ++;
562 } 765 }
563 766
565 psiconv_warn(lev+2,off+len, 768 psiconv_warn(lev+2,off+len,
566 "Read past end of character layout codes list. I probably lost track" 769 "Read past end of character layout codes list. I probably lost track"
567 "somewhere!"); 770 "somewhere!");
568 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d", 771 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d",
569 len-4,list_length); 772 len-4,list_length);
773 res = PSICONV_E_PARSE;
774 goto ERROR1;
570 } 775 }
571 776
572 len = list_length + 4; 777 len = list_length + 4;
573 778
574 psiconv_progress(lev+1,off+len, 779 psiconv_progress(lev+1,off+len,
575 "End of character layout list (total length: %08x)",len); 780 "End of character layout list (total length: %08x)",len);
576 781
577 if (length) 782 if (length)
578 *length = len; 783 *length = len;
579 return res; 784 return res;
785
786ERROR1:
787 psiconv_warn(lev+1,off,"Reading of character_layout_list failed");
788 if (length)
789 *length = 0;
790 if (!res)
791 return -PSICONV_E_NOMEM;
792 else
793 return res;
580} 794}

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

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