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

Legend:
Removed from v.104  
changed lines
  Added in v.270

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