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