| … | |
… | |
| 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())) |
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 | } |
| … | |
… | |
| 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_u16(buf,with_styles?0x0001:0x0000))) |
288 | if ((res = psiconv_write_u16(buf,with_styles?0x0001:0x0000))) |
| 262 | goto ERROR5; |
289 | goto ERROR5; |
| 263 | if ((res = psiconv_write_u8(buf,psiconv_list_length(paragraph_type_list)))) |
290 | if ((res = psiconv_write_u8(buf, ptl_length))) |
| 264 | goto ERROR5; |
291 | goto ERROR5; |
| 265 | if ((res = psiconv_buffer_concat(buf,buf_types))) |
292 | if ((res = psiconv_buffer_concat(buf,buf_types))) |
| 266 | goto ERROR5; |
293 | goto ERROR5; |
| 267 | if ((res = psiconv_write_u32(buf,psiconv_list_length(value)))) |
294 | if ((res = psiconv_write_u32(buf,pel_length))) |
| 268 | goto ERROR5; |
295 | goto ERROR5; |
| 269 | if ((res = psiconv_buffer_concat(buf,buf_elements))) |
296 | if ((res = psiconv_buffer_concat(buf,buf_elements))) |
| 270 | goto ERROR5; |
297 | goto ERROR5; |
| 271 | if ((res = psiconv_write_u32(buf,nr_of_inlines))) |
298 | if ((res = psiconv_write_u32(buf,nr_of_inlines))) |
| 272 | goto ERROR5; |
299 | goto ERROR5; |