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