… | |
… | |
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 | |
24 | |
23 | #include "data.h" |
|
|
24 | #include "parse_routines.h" |
25 | #include "parse_routines.h" |
|
|
26 | #include "error.h" |
25 | |
27 | |
|
|
28 | #ifdef DMALLOC |
|
|
29 | #include <dmalloc.h> |
|
|
30 | #endif |
|
|
31 | |
26 | int psiconv_parse_texted_section(const psiconv_buffer buf,int lev, |
32 | int psiconv_parse_texted_section(const psiconv_config config, |
|
|
33 | const psiconv_buffer buf,int lev, |
27 | psiconv_u32 off, int *length, |
34 | psiconv_u32 off, int *length, |
28 | psiconv_texted_section *result, |
35 | psiconv_texted_section *result, |
29 | psiconv_character_layout base_char, |
36 | psiconv_character_layout base_char, |
30 | psiconv_paragraph_layout base_para) |
37 | psiconv_paragraph_layout base_para) |
31 | { |
38 | { |
… | |
… | |
35 | psiconv_u32 unknown_sec = 0; |
42 | psiconv_u32 unknown_sec = 0; |
36 | psiconv_u32 replacement_sec = 0; |
43 | psiconv_u32 replacement_sec = 0; |
37 | psiconv_u32 temp; |
44 | psiconv_u32 temp; |
38 | int leng; |
45 | int leng; |
39 | |
46 | |
40 | psiconv_progress(lev+1,off,"Going to read a texted section"); |
47 | psiconv_progress(config,lev+1,off,"Going to read a texted section"); |
41 | if (!((*result) = malloc(sizeof(**result)))) |
48 | if (!((*result) = malloc(sizeof(**result)))) |
42 | goto ERROR1; |
49 | goto ERROR1; |
43 | |
50 | |
44 | psiconv_progress(lev+2,off+len,"Going to read section id"); |
51 | psiconv_progress(config,lev+2,off+len,"Going to read section id"); |
45 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
52 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
46 | if (res) |
53 | if (res) |
47 | goto ERROR2; |
54 | goto ERROR2; |
48 | if (temp != PSICONV_ID_TEXTED_BODY) { |
55 | if (temp != PSICONV_ID_TEXTED_BODY) { |
49 | psiconv_warn(lev+2,off+len, |
56 | psiconv_error(config,lev+2,off+len, |
50 | "Page header section body id not found"); |
57 | "Page header section body id not found"); |
51 | psiconv_debug(lev+2,off+len, |
58 | psiconv_debug(config,lev+2,off+len, |
52 | "Page body id: read %08x, expected %08x",temp, |
59 | "Page body id: read %08x, expected %08x",temp, |
53 | PSICONV_ID_TEXTED); |
60 | PSICONV_ID_TEXTED); |
54 | res = -PSICONV_E_PARSE; |
61 | res = -PSICONV_E_PARSE; |
55 | goto ERROR2; |
62 | goto ERROR2; |
56 | } |
63 | } |
57 | len += 4; |
64 | len += 4; |
58 | |
65 | |
59 | psiconv_progress(lev+2,off+len,"Going to read the section jumptable"); |
66 | psiconv_progress(config,lev+2,off+len,"Going to read the section jumptable"); |
60 | while (temp = psiconv_read_u32(buf,lev+3,off+len,&res), |
67 | while (temp = psiconv_read_u32(config,buf,lev+3,off+len,&res), |
61 | !res && temp != PSICONV_ID_TEXTED_TEXT) { |
68 | !res && temp != PSICONV_ID_TEXTED_TEXT) { |
62 | len += 4; |
69 | len += 4; |
63 | if (temp == PSICONV_ID_TEXTED_LAYOUT) { |
70 | if (temp == PSICONV_ID_TEXTED_LAYOUT) { |
64 | layout_sec = psiconv_read_u32(buf,lev+3,off+len,&res); |
71 | layout_sec = psiconv_read_u32(config,buf,lev+3,off+len,&res); |
65 | if (res) |
72 | if (res) |
66 | goto ERROR2; |
73 | goto ERROR2; |
67 | psiconv_debug(lev+3,off+len,"Found Layout section at %08x",layout_sec); |
74 | psiconv_debug(config,lev+3,off+len,"Found Layout section at %08x",layout_sec); |
68 | } else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) { |
75 | } else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) { |
69 | replacement_sec = psiconv_read_u32(buf,lev+3,off+len,&res); |
76 | replacement_sec = psiconv_read_u32(config,buf,lev+3,off+len,&res); |
70 | if (res) |
77 | if (res) |
71 | goto ERROR2; |
78 | goto ERROR2; |
72 | psiconv_debug(lev+3,off+len,"Found Replacement section at %08x", |
79 | psiconv_debug(config,lev+3,off+len,"Found Replacement section at %08x", |
73 | replacement_sec); |
80 | replacement_sec); |
74 | } else if (temp == PSICONV_ID_TEXTED_UNKNOWN) { |
81 | } else if (temp == PSICONV_ID_TEXTED_UNKNOWN) { |
75 | unknown_sec= psiconv_read_u32(buf,lev+3,off+len,&res); |
82 | unknown_sec= psiconv_read_u32(config,buf,lev+3,off+len,&res); |
76 | if (res) |
83 | if (res) |
77 | goto ERROR2; |
84 | goto ERROR2; |
78 | if (unknown_sec) { |
85 | if (unknown_sec) { |
79 | psiconv_warn(lev+3,off+len, |
86 | psiconv_warn(config,lev+3,off+len, |
80 | "Unknown section in TextEd jumptable has real offset (ignoring)"); |
87 | "Unknown section in TextEd jumptable has real offset (ignoring)"); |
81 | } |
88 | } |
82 | psiconv_debug(lev+3,off+len,"Found Unknown section at %08x", |
89 | psiconv_debug(config,lev+3,off+len,"Found Unknown section at %08x", |
83 | unknown_sec); |
90 | unknown_sec); |
84 | } else { |
91 | } else { |
85 | psiconv_warn(lev+3,off+len, |
92 | psiconv_warn(config,lev+3,off+len, |
86 | "Unknown section in TextEd jumptable (ignoring)"); |
93 | "Unknown section in TextEd jumptable (ignoring)"); |
87 | psiconv_debug(lev+3,off+len,"Section ID %08x at offset %08x",temp, |
94 | psiconv_debug(config,lev+3,off+len,"Section ID %08x at offset %08x",temp, |
88 | psiconv_read_u32(buf,lev+3,off+len,NULL)); |
95 | psiconv_read_u32(config,buf,lev+3,off+len,NULL)); |
89 | } |
96 | } |
90 | len += 4; |
97 | len += 4; |
91 | } |
98 | } |
92 | if (res) |
99 | if (res) |
93 | goto ERROR2; |
100 | goto ERROR2; |
94 | |
101 | |
95 | len += 4; |
102 | len += 4; |
96 | psiconv_progress(lev+2,off+len,"Going to read the text"); |
103 | psiconv_progress(config,lev+2,off+len,"Going to read the text"); |
97 | if ((res = psiconv_parse_text_section(buf,lev+2,off+len,&leng, |
104 | if ((res = psiconv_parse_text_section(config,buf,lev+2,off+len,&leng, |
98 | &(*result)->paragraphs))) |
105 | &(*result)->paragraphs))) |
99 | goto ERROR2; |
106 | goto ERROR2; |
100 | len += leng; |
107 | len += leng; |
101 | |
108 | |
102 | if (layout_sec) { |
109 | if (layout_sec) { |
103 | psiconv_progress(lev+2,off+len,"Going to read the layout"); |
110 | psiconv_progress(config,lev+2,off+len,"Going to read the layout"); |
104 | if ((res = psiconv_parse_styleless_layout_section(buf,lev+2,layout_sec,NULL, |
111 | if ((res = psiconv_parse_styleless_layout_section(config,buf,lev+2,layout_sec,NULL, |
105 | (*result)->paragraphs, |
112 | (*result)->paragraphs, |
106 | base_char,base_para))) |
113 | base_char,base_para))) |
107 | goto ERROR3; |
114 | goto ERROR3; |
108 | } |
115 | } |
109 | |
116 | |
110 | #if 0 |
117 | #if 0 |
111 | if (replacement_sec) { |
118 | if (replacement_sec) { |
112 | psiconv_progress(lev+2,off+len,"Going to read the replacements"); |
119 | psiconv_progress(config,lev+2,off+len,"Going to read the replacements"); |
113 | /* WHATEVER */ |
120 | /* WHATEVER */ |
114 | } |
121 | } |
115 | #endif |
122 | #endif |
116 | |
123 | |
117 | if (length) |
124 | if (length) |
118 | *length = len; |
125 | *length = len; |
119 | |
126 | |
120 | psiconv_progress(lev+1,off+len-1,"End of TextEd section " |
127 | psiconv_progress(config,lev+1,off+len-1,"End of TextEd section " |
121 | "(total length: %08x", len); |
128 | "(total length: %08x", len); |
122 | |
129 | |
123 | return 0; |
130 | return 0; |
124 | |
131 | |
125 | ERROR3: |
132 | ERROR3: |
126 | psiconv_free_text_and_layout((*result)->paragraphs); |
133 | psiconv_free_text_and_layout((*result)->paragraphs); |
127 | ERROR2: |
134 | ERROR2: |
128 | free (*result); |
135 | free (*result); |
129 | ERROR1: |
136 | ERROR1: |
130 | psiconv_warn(lev+1,off,"Reading of TextEd Section failed"); |
137 | psiconv_error(config,lev+1,off,"Reading of TextEd Section failed"); |
131 | if (length) |
138 | if (length) |
132 | *length = 0; |
139 | *length = 0; |
133 | if (!res) |
140 | if (!res) |
134 | return -PSICONV_E_NOMEM; |
141 | return -PSICONV_E_NOMEM; |
135 | else |
142 | else |