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