1 | /* |
1 | /* |
2 | parse_common.c - Part of psiconv, a PSION 5 file formats converter |
2 | parse_common.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" |
21 | #include <stdlib.h> |
22 | #include <stdlib.h> |
22 | #include <string.h> |
23 | #include <string.h> |
23 | |
24 | |
24 | #include "data.h" |
25 | #include "data.h" |
25 | #include "parse_routines.h" |
26 | #include "parse_routines.h" |
… | |
… | |
43 | (*result) = malloc(sizeof(**result)); |
44 | (*result) = malloc(sizeof(**result)); |
44 | |
45 | |
45 | psiconv_progress(lev+2,off+len,"Going to read UID1 to UID3"); |
46 | psiconv_progress(lev+2,off+len,"Going to read UID1 to UID3"); |
46 | (*result)->uid1 = psiconv_read_u32(buf,lev+2,off+len); |
47 | (*result)->uid1 = psiconv_read_u32(buf,lev+2,off+len); |
47 | psiconv_debug(lev+2,off+len,"UID1: %08x",(*result)->uid1); |
48 | psiconv_debug(lev+2,off+len,"UID1: %08x",(*result)->uid1); |
|
|
49 | if ((*result)->uid1 == PSICONV_ID_CLIPART) { |
|
|
50 | /* That's all folks... */ |
|
|
51 | (*result)->file = psiconv_clipart_file; |
|
|
52 | (*result)->uid2 = 0; |
|
|
53 | (*result)->uid3 = 0; |
|
|
54 | (*result)->checksum = 0; |
|
|
55 | len += 4; |
|
|
56 | psiconv_debug(lev+2,off+len,"File is a Clipart file"); |
|
|
57 | goto DONE; |
|
|
58 | } |
48 | if ((*result)->uid1 != PSICONV_ID_PSION5) { |
59 | if ((*result)->uid1 != PSICONV_ID_PSION5) { |
49 | psiconv_warn(lev+2,off+len,"UID1 has unknown value. This is probably " |
60 | psiconv_warn(lev+2,off+len,"UID1 has unknown value. This is probably " |
50 | "not a (parsable) Psion 5 file"); |
61 | "not a (parsable) Psion 5 file"); |
51 | res = -1; |
62 | res = -1; |
52 | } |
63 | } |
… | |
… | |
65 | (*result)->file = psiconv_word_file; |
76 | (*result)->file = psiconv_word_file; |
66 | psiconv_debug(lev+2,off+len,"File is a Word file"); |
77 | psiconv_debug(lev+2,off+len,"File is a Word file"); |
67 | } else if ((*result)->uid3 == PSICONV_ID_TEXTED) { |
78 | } else if ((*result)->uid3 == PSICONV_ID_TEXTED) { |
68 | (*result)->file = psiconv_texted_file; |
79 | (*result)->file = psiconv_texted_file; |
69 | psiconv_debug(lev+2,off+len,"File is a TextEd file"); |
80 | psiconv_debug(lev+2,off+len,"File is a TextEd file"); |
|
|
81 | } else if ((*result)->uid3 == PSICONV_ID_SKETCH) { |
|
|
82 | (*result)->file = psiconv_sketch_file; |
|
|
83 | psiconv_debug(lev+2,off+len,"File is a Sketch file"); |
70 | } |
84 | } |
71 | } else if ((*result)->uid2 == PSICONV_ID_MBM_FILE) { |
85 | } else if ((*result)->uid2 == PSICONV_ID_MBM_FILE) { |
72 | (*result)->file = psiconv_mbm_file; |
86 | (*result)->file = psiconv_mbm_file; |
73 | if ((*result)->uid3 != 0x00) |
87 | if ((*result)->uid3 != 0x00) |
74 | psiconv_warn(lev+2,off+len,"UID3 set in MBM file?!?"); |
88 | psiconv_warn(lev+2,off+len,"UID3 set in MBM file?!?"); |
75 | psiconv_debug(lev+2,off+len,"File is a MBM file"); |
89 | psiconv_debug(lev+2,off+len,"File is a MBM file"); |
… | |
… | |
91 | psiconv_checkuid((*result)->uid1,(*result)->uid2, |
105 | psiconv_checkuid((*result)->uid1,(*result)->uid2, |
92 | (*result)->uid3),temp); |
106 | (*result)->uid3),temp); |
93 | res = -1; |
107 | res = -1; |
94 | } |
108 | } |
95 | len += 4; |
109 | len += 4; |
96 | |
|
|
97 | psiconv_progress(lev+2,off+len,"Going to read Section Table Section offset"); |
|
|
98 | (*result)->section_table_offset = psiconv_read_u32(buf,lev+2,off+len); |
|
|
99 | psiconv_debug(lev+2,off+len,"Section Table Section starts at offset %08x", |
|
|
100 | (*result)->section_table_offset) ; |
|
|
101 | len += 4; |
|
|
102 | |
110 | |
|
|
111 | DONE: |
103 | if (length) |
112 | if (length) |
104 | *length = len; |
113 | *length = len; |
105 | |
114 | |
106 | psiconv_progress(lev+1,off+len-1, |
115 | psiconv_progress(lev+1,off+len-1, |
107 | "End of Header Section (total length: %08x)",len); |
116 | "End of Header Section (total length: %08x)",len); |
… | |
… | |
149 | |
158 | |
150 | if (length) |
159 | if (length) |
151 | *length = len; |
160 | *length = len; |
152 | |
161 | |
153 | psiconv_progress(lev+1,off+len-1,"End of section table section " |
162 | psiconv_progress(lev+1,off+len-1,"End of section table section " |
154 | "(total length: %08x", len); |
163 | "(total length: %08x)", len); |
155 | |
164 | |
156 | return res; |
165 | return res; |
157 | } |
166 | } |
158 | |
167 | |
159 | int psiconv_parse_application_id_section(const psiconv_buffer buf, int lev, |
168 | int psiconv_parse_application_id_section(const psiconv_buffer buf, int lev, |
… | |
… | |
249 | free(para); |
258 | free(para); |
250 | |
259 | |
251 | /* Initialize the remaining parts of each paragraph */ |
260 | /* Initialize the remaining parts of each paragraph */ |
252 | for (i = 0; i < psiconv_list_length(*result); i ++) { |
261 | for (i = 0; i < psiconv_list_length(*result); i ++) { |
253 | para = psiconv_list_get(*result,i); |
262 | para = psiconv_list_get(*result,i); |
254 | para->in_lines = psiconv_list_new(sizeof(struct psiconv_in_line_layout)); |
263 | para->in_lines = psiconv_list_new(sizeof(struct psiconv_in_line_layout_s)); |
255 | para->replacements = psiconv_list_new(sizeof(struct psiconv_replacement)); |
264 | para->replacements = psiconv_list_new(sizeof(struct psiconv_replacement_s)); |
256 | para->base_style = 0; |
265 | para->base_style = 0; |
257 | para->base_character = psiconv_basic_character_layout(); |
266 | para->base_character = psiconv_basic_character_layout(); |
258 | para->base_paragraph = psiconv_basic_paragraph_layout(); |
267 | para->base_paragraph = psiconv_basic_paragraph_layout(); |
259 | } |
268 | } |
260 | |
269 | |
… | |
… | |
281 | int res = 0; |
290 | int res = 0; |
282 | int len = 0; |
291 | int len = 0; |
283 | psiconv_u32 temp; |
292 | psiconv_u32 temp; |
284 | int parse_styles,nr,i,j,total,leng,line_length; |
293 | int parse_styles,nr,i,j,total,leng,line_length; |
285 | |
294 | |
286 | typedef struct anon_style |
295 | typedef struct anon_style_s |
287 | { |
296 | { |
288 | int nr; |
297 | int nr; |
289 | psiconv_s16 base_style; |
298 | psiconv_s16 base_style; |
290 | psiconv_character_layout character; |
299 | psiconv_character_layout character; |
291 | psiconv_paragraph_layout paragraph; |
300 | psiconv_paragraph_layout paragraph; |
292 | } *anon_style; |
301 | } *anon_style; |
293 | |
302 | |
294 | typedef psiconv_list anon_style_list; /* of struct anon_style */ |
303 | typedef psiconv_list anon_style_list; /* of struct anon_style */ |
295 | |
304 | |
296 | anon_style_list anon_styles; |
305 | anon_style_list anon_styles; |
297 | struct anon_style anon; |
306 | struct anon_style_s anon; |
298 | anon_style anon_ptr=NULL; |
307 | anon_style anon_ptr=NULL; |
299 | |
308 | |
300 | psiconv_paragraph para; |
309 | psiconv_paragraph para; |
301 | struct psiconv_in_line_layout in_line; |
310 | struct psiconv_in_line_layout_s in_line; |
302 | |
311 | |
303 | int *inline_count; |
312 | int *inline_count; |
304 | |
313 | |
305 | |
314 | |
306 | psiconv_progress(lev+1,off,"Going to read the layout section"); |
315 | psiconv_progress(lev+1,off,"Going to read the layout section"); |
… | |
… | |
387 | for (i = 0; i < nr; i ++) { |
396 | for (i = 0; i < nr; i ++) { |
388 | psiconv_progress(lev+3,off+len,"Element %d",i); |
397 | psiconv_progress(lev+3,off+len,"Element %d",i); |
389 | if (i >= psiconv_list_length(result)) { |
398 | if (i >= psiconv_list_length(result)) { |
390 | psiconv_debug(lev+4,off+len,"Going to allocate a new element"); |
399 | psiconv_debug(lev+4,off+len,"Going to allocate a new element"); |
391 | para = malloc(sizeof(*para)); |
400 | para = malloc(sizeof(*para)); |
392 | para->in_lines = psiconv_list_new(sizeof(struct psiconv_in_line_layout)); |
401 | para->in_lines = psiconv_list_new(sizeof(struct psiconv_in_line_layout_s)); |
393 | para->base_style = 0; |
402 | para->base_style = 0; |
394 | para->base_character = psiconv_basic_character_layout(); |
403 | para->base_character = psiconv_basic_character_layout(); |
395 | para->base_paragraph = psiconv_basic_paragraph_layout(); |
404 | para->base_paragraph = psiconv_basic_paragraph_layout(); |
396 | free(para); |
405 | free(para); |
397 | } |
406 | } |
… | |
… | |
443 | } else { |
452 | } else { |
444 | psiconv_debug(lev+4,off+len,"Type: %02x (not based on a paragraph type)" |
453 | psiconv_debug(lev+4,off+len,"Type: %02x (not based on a paragraph type)" |
445 | ,temp); |
454 | ,temp); |
446 | len += 0x01; |
455 | len += 0x01; |
447 | if (parse_styles) { |
456 | if (parse_styles) { |
448 | psiconv_progress(lev+4,off+len+psiconv_read_u32(buf,lev+4,off+len), |
457 | psiconv_progress(lev+4,off+len+psiconv_read_u32(buf,lev+4,off+len)+4, |
449 | "Going to read the paragraph element base style"); |
458 | "Going to read the paragraph element base style"); |
450 | temp = psiconv_read_u8(buf,lev+4, |
459 | temp = psiconv_read_u8(buf,lev+4, |
451 | off+len+psiconv_read_u32(buf,lev+4,off+len)); |
460 | off+len+psiconv_read_u32(buf,lev+4,off+len)+4); |
452 | psiconv_debug(lev+4,off+len+psiconv_read_u32(buf,lev+4,off+len), |
461 | psiconv_debug(lev+4,off+len+psiconv_read_u32(buf,lev+4,off+len)+4, |
453 | "Style: %02x",temp); |
462 | "Style: %02x",temp); |
454 | } else |
463 | } else |
455 | temp = 0x00; |
464 | temp = 0x00; |
456 | psiconv_free_paragraph_layout(para->base_paragraph); |
465 | psiconv_free_paragraph_layout(para->base_paragraph); |
457 | psiconv_free_character_layout(para->base_character); |
466 | psiconv_free_character_layout(para->base_character); |
… | |
… | |
577 | styles_section->normal = malloc(sizeof(*styles_section->normal)); |
586 | styles_section->normal = malloc(sizeof(*styles_section->normal)); |
578 | styles_section->normal->character = psiconv_clone_character_layout(base_char); |
587 | styles_section->normal->character = psiconv_clone_character_layout(base_char); |
579 | styles_section->normal->paragraph = psiconv_clone_paragraph_layout(base_para); |
588 | styles_section->normal->paragraph = psiconv_clone_paragraph_layout(base_para); |
580 | styles_section->normal->hotkey = 0; |
589 | styles_section->normal->hotkey = 0; |
581 | styles_section->normal->name = strdup(""); |
590 | styles_section->normal->name = strdup(""); |
582 | styles_section->styles = psiconv_list_new(sizeof(struct psiconv_word_style)); |
591 | styles_section->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s)); |
583 | |
592 | |
584 | res = psiconv_parse_layout_section(buf,lev,off,length,result, |
593 | res = psiconv_parse_layout_section(buf,lev,off,length,result, |
585 | styles_section,0); |
594 | styles_section,0); |
586 | |
595 | |
587 | psiconv_free_word_styles_section(styles_section); |
596 | psiconv_free_word_styles_section(styles_section); |