… | |
… | |
62 | psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); |
62 | psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); |
63 | return -PSICONV_E_NOMEM; |
63 | return -PSICONV_E_NOMEM; |
64 | } |
64 | } |
65 | if ((res = psiconv_write_u32(buf,entry->id))) |
65 | if ((res = psiconv_write_u32(buf,entry->id))) |
66 | return res; |
66 | return res; |
67 | if ((res = psiconv_write_u32(buf,entry->offset))) |
67 | if ((res = psiconv_write_offset(buf,entry->offset))) |
68 | return res; |
68 | return res; |
69 | } |
69 | } |
70 | return -PSICONV_E_OK; |
70 | return -PSICONV_E_OK; |
71 | } |
71 | } |
72 | |
72 | |
… | |
… | |
90 | if (!value) { |
90 | if (!value) { |
91 | psiconv_warn(0,psiconv_buffer_length(buf),"Null text section"); |
91 | psiconv_warn(0,psiconv_buffer_length(buf),"Null text section"); |
92 | return -PSICONV_E_GENERATE; |
92 | return -PSICONV_E_GENERATE; |
93 | } |
93 | } |
94 | |
94 | |
|
|
95 | if (psiconv_list_length(value)) { |
95 | if (!(extra_buf = psiconv_buffer_new(0))) |
96 | if (!(extra_buf = psiconv_buffer_new())) |
96 | return -PSICONV_E_NOMEM; |
97 | return -PSICONV_E_NOMEM; |
97 | for (i = 0; i < psiconv_list_length(value); i++) { |
98 | for (i = 0; i < psiconv_list_length(value); i++) { |
98 | if (!(paragraph = psiconv_list_get(value,i))) { |
99 | if (!(paragraph = psiconv_list_get(value,i))) { |
99 | psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); |
100 | psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); |
100 | res = -PSICONV_E_OTHER; |
101 | res = -PSICONV_E_OTHER; |
|
|
102 | goto ERROR; |
|
|
103 | } |
|
|
104 | for (j = 0; j < strlen(paragraph->text); j++) |
|
|
105 | if ((res = psiconv_write_u8(extra_buf,paragraph->text[j]))) |
|
|
106 | goto ERROR; |
|
|
107 | psiconv_write_u8(extra_buf,0x06); |
|
|
108 | } |
|
|
109 | if ((res = psiconv_write_X(buf,psiconv_buffer_length(extra_buf)))) |
101 | goto ERROR; |
110 | goto ERROR; |
102 | } |
|
|
103 | for (j = 0; j < strlen(paragraph->text); j++) |
|
|
104 | if ((res = psiconv_write_u8(extra_buf,paragraph->text[j]))) |
|
|
105 | goto ERROR; |
|
|
106 | psiconv_write_u8(extra_buf,0x06); |
|
|
107 | } |
|
|
108 | if ((res = psiconv_write_X(buf,psiconv_buffer_length(extra_buf)))) |
|
|
109 | goto ERROR; |
|
|
110 | res = psiconv_buffer_concat(buf,extra_buf); |
111 | res = psiconv_buffer_concat(buf,extra_buf); |
|
|
112 | } else |
|
|
113 | /* Hack: empty text sections are just not allowed */ |
|
|
114 | return psiconv_write_u16(buf,0x0602); |
111 | |
115 | |
112 | ERROR: |
116 | ERROR: |
113 | psiconv_buffer_free(extra_buf); |
117 | psiconv_buffer_free(extra_buf); |
114 | return res; |
118 | return res; |
115 | } |
119 | } |
… | |
… | |
131 | struct psiconv_paragraph_type_list_s new_type; |
135 | struct psiconv_paragraph_type_list_s new_type; |
132 | psiconv_buffer buf_types,buf_elements,buf_inlines; |
136 | psiconv_buffer buf_types,buf_elements,buf_inlines; |
133 | psiconv_paragraph paragraph; |
137 | psiconv_paragraph paragraph; |
134 | psiconv_in_line_layout in_line; |
138 | psiconv_in_line_layout in_line; |
135 | psiconv_word_style style; |
139 | psiconv_word_style style; |
136 | int i,j,para_type,nr_of_inlines=0,res; |
140 | int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length; |
137 | |
141 | |
138 | if (!value) { |
142 | if (!value) { |
139 | psiconv_warn(0,psiconv_buffer_length(buf),"Null text section"); |
143 | psiconv_warn(0,psiconv_buffer_length(buf),"Null text section"); |
140 | return -PSICONV_E_GENERATE; |
144 | return -PSICONV_E_GENERATE; |
141 | } |
145 | } |
… | |
… | |
143 | if (!(paragraph_type_list = psiconv_list_new(sizeof(new_type)))) { |
147 | if (!(paragraph_type_list = psiconv_list_new(sizeof(new_type)))) { |
144 | res = -PSICONV_E_NOMEM; |
148 | res = -PSICONV_E_NOMEM; |
145 | goto ERROR1; |
149 | goto ERROR1; |
146 | } |
150 | } |
147 | |
151 | |
148 | if (!(buf_types = psiconv_buffer_new(0))) { |
152 | if (!(buf_types = psiconv_buffer_new())) { |
149 | res = -PSICONV_E_NOMEM; |
153 | res = -PSICONV_E_NOMEM; |
150 | goto ERROR2; |
154 | goto ERROR2; |
151 | } |
155 | } |
152 | |
156 | |
153 | if (!(buf_elements = psiconv_buffer_new(0))) { |
157 | if (!(buf_elements = psiconv_buffer_new())) { |
154 | res = -PSICONV_E_NOMEM; |
158 | res = -PSICONV_E_NOMEM; |
155 | goto ERROR3; |
159 | goto ERROR3; |
156 | } |
160 | } |
157 | |
161 | |
158 | if (!(buf_inlines = psiconv_buffer_new(0))) { |
162 | if (!(buf_inlines = psiconv_buffer_new())) { |
159 | res = -PSICONV_E_NOMEM; |
163 | res = -PSICONV_E_NOMEM; |
160 | goto ERROR4; |
164 | goto ERROR4; |
161 | } |
165 | } |
162 | |
166 | |
163 | for (i = 0; i < psiconv_list_length(value); i++) { |
167 | for (i = 0; i < psiconv_list_length(value); i++) { |
… | |
… | |
170 | goto ERROR5; |
174 | goto ERROR5; |
171 | |
175 | |
172 | if (psiconv_list_length(paragraph->in_lines)) { |
176 | if (psiconv_list_length(paragraph->in_lines)) { |
173 | /* Inline layouts, so we generate a paragraph element and inline |
177 | /* Inline layouts, so we generate a paragraph element and inline |
174 | elements */ |
178 | elements */ |
175 | if ((res = psiconv_write_u32(buf_elements,0x00))) |
179 | if ((res = psiconv_write_u8(buf_elements,0x00))) |
176 | goto ERROR5; |
180 | goto ERROR5; |
177 | if (!(style = psiconv_get_style(styles,paragraph->base_style))) { |
181 | if (!(style = psiconv_get_style(styles,paragraph->base_style))) { |
178 | psiconv_warn(0,psiconv_buffer_length(buf),"Unknown style"); |
182 | psiconv_warn(0,psiconv_buffer_length(buf),"Unknown style"); |
179 | res = -PSICONV_E_GENERATE; |
183 | res = -PSICONV_E_GENERATE; |
180 | goto ERROR5; |
184 | goto ERROR5; |
… | |
… | |
200 | } |
204 | } |
201 | if ((res = psiconv_write_u8(buf_inlines,0x00))) |
205 | if ((res = psiconv_write_u8(buf_inlines,0x00))) |
202 | goto ERROR5; |
206 | goto ERROR5; |
203 | if ((res = psiconv_write_u32(buf_inlines,in_line->length))) |
207 | if ((res = psiconv_write_u32(buf_inlines,in_line->length))) |
204 | goto ERROR5; |
208 | goto ERROR5; |
205 | if ((res = psiconv_write_character_layout_list(buf_elements, |
209 | if ((res = psiconv_write_character_layout_list(buf_inlines, |
206 | in_line->layout, |
210 | in_line->layout, |
207 | style->character))) |
211 | style->character))) |
208 | goto ERROR5; |
212 | goto ERROR5; |
209 | } |
213 | } |
210 | } else { |
214 | } else { |
… | |
… | |
255 | if ((res = psiconv_write_u8(buf_elements,para_type))) |
259 | if ((res = psiconv_write_u8(buf_elements,para_type))) |
256 | goto ERROR5; |
260 | goto ERROR5; |
257 | } |
261 | } |
258 | } |
262 | } |
259 | |
263 | |
|
|
264 | /* HACK: special case: no paragraphs at all. We need to improvize. */ |
|
|
265 | if (!psiconv_list_length(value)) { |
|
|
266 | if ((res = psiconv_write_u32(buf_types,1))) |
|
|
267 | goto ERROR5; |
|
|
268 | if ((res = psiconv_write_u32(buf_types,0))) |
|
|
269 | goto ERROR5; |
|
|
270 | if (with_styles) |
|
|
271 | if ((res = psiconv_write_u8(buf_types,0))) |
|
|
272 | goto ERROR5; |
|
|
273 | if ((res = psiconv_write_u32(buf_types,0))) |
|
|
274 | goto ERROR5; |
|
|
275 | |
|
|
276 | if ((res = psiconv_write_u32(buf_elements,1))) |
|
|
277 | goto ERROR5; |
|
|
278 | if ((res = psiconv_write_u8(buf_elements,1))) |
|
|
279 | goto ERROR5; |
|
|
280 | pel_length = 1; |
|
|
281 | ptl_length = 1; |
|
|
282 | } else { |
|
|
283 | pel_length = psiconv_list_length(value); |
|
|
284 | ptl_length = psiconv_list_length(paragraph_type_list); |
|
|
285 | } |
|
|
286 | |
260 | /* Now append everything */ |
287 | /* Now append everything */ |
261 | if ((res = psiconv_write_u8(buf,with_styles?0x00:0x01))) |
288 | if ((res = psiconv_write_u16(buf,with_styles?0x0001:0x0000))) |
262 | goto ERROR5; |
289 | goto ERROR5; |
263 | if ((res = psiconv_write_u8(buf,0x00))) |
290 | if ((res = psiconv_write_u8(buf, ptl_length))) |
264 | goto ERROR5; |
|
|
265 | if ((res = psiconv_write_u8(buf,psiconv_list_length(paragraph_type_list)))) |
|
|
266 | goto ERROR5; |
291 | goto ERROR5; |
267 | if ((res = psiconv_buffer_concat(buf,buf_types))) |
292 | if ((res = psiconv_buffer_concat(buf,buf_types))) |
268 | goto ERROR5; |
293 | goto ERROR5; |
269 | if ((res = psiconv_write_u32(buf,psiconv_list_length(value)))) |
294 | if ((res = psiconv_write_u32(buf,pel_length))) |
270 | goto ERROR5; |
295 | goto ERROR5; |
271 | if ((res = psiconv_buffer_concat(buf,buf_elements))) |
296 | if ((res = psiconv_buffer_concat(buf,buf_elements))) |
272 | goto ERROR5; |
297 | goto ERROR5; |
273 | if ((res = psiconv_write_u32(buf,nr_of_inlines))) |
298 | if ((res = psiconv_write_u32(buf,nr_of_inlines))) |
274 | goto ERROR5; |
299 | goto ERROR5; |