/[public]/psiconv/trunk/lib/psiconv/generate_common.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/generate_common.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 88 Revision 142
22#include <stdlib.h> 22#include <stdlib.h>
23#include <string.h> 23#include <string.h>
24 24
25#include "generate_routines.h" 25#include "generate_routines.h"
26#include "error.h" 26#include "error.h"
27
28#ifdef DMALLOC
29#include <dmalloc.h>
30#endif
27 31
28static int psiconv_write_layout_section(psiconv_buffer buf, 32static int psiconv_write_layout_section(psiconv_buffer buf,
29 const psiconv_text_and_layout value, 33 const psiconv_text_and_layout value,
30 const psiconv_word_styles_section styles, 34 const psiconv_word_styles_section styles,
31 int with_styles); 35 int with_styles);
135 struct psiconv_paragraph_type_list_s new_type; 139 struct psiconv_paragraph_type_list_s new_type;
136 psiconv_buffer buf_types,buf_elements,buf_inlines; 140 psiconv_buffer buf_types,buf_elements,buf_inlines;
137 psiconv_paragraph paragraph; 141 psiconv_paragraph paragraph;
138 psiconv_in_line_layout in_line; 142 psiconv_in_line_layout in_line;
139 psiconv_word_style style; 143 psiconv_word_style style;
144 psiconv_character_layout para_charlayout;
140 int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length; 145 int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length,thislen,paralen;
141 146
142 if (!value) { 147 if (!value) {
143 psiconv_warn(0,psiconv_buffer_length(buf),"Null text section"); 148 psiconv_warn(0,psiconv_buffer_length(buf),"Null text section");
144 return -PSICONV_E_GENERATE; 149 return -PSICONV_E_GENERATE;
145 } 150 }
171 goto ERROR5; 176 goto ERROR5;
172 } 177 }
173 if ((res = psiconv_write_u32(buf_elements,strlen(paragraph->text)+1))) 178 if ((res = psiconv_write_u32(buf_elements,strlen(paragraph->text)+1)))
174 goto ERROR5; 179 goto ERROR5;
175 180
176 if (psiconv_list_length(paragraph->in_lines)) { 181 if (psiconv_list_length(paragraph->in_lines) > 1) {
177 /* Inline layouts, so we generate a paragraph element and inline 182 /* Inline layouts, so we generate a paragraph element and inline
178 elements */ 183 elements */
179 if ((res = psiconv_write_u8(buf_elements,0x00))) 184 if ((res = psiconv_write_u8(buf_elements,0x00)))
180 goto ERROR5; 185 goto ERROR5;
181 if (!(style = psiconv_get_style(styles,paragraph->base_style))) { 186 if (!(style = psiconv_get_style(styles,paragraph->base_style))) {
193 if ((res = psiconv_write_u32(buf_elements, 198 if ((res = psiconv_write_u32(buf_elements,
194 psiconv_list_length(paragraph->in_lines)))) 199 psiconv_list_length(paragraph->in_lines))))
195 goto ERROR5; 200 goto ERROR5;
196 201
197 /* Generate the inlines. NB: Against what are all settings relative?!? */ 202 /* Generate the inlines. NB: Against what are all settings relative?!? */
203 paralen = 0;
198 for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) { 204 for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) {
199 nr_of_inlines ++; 205 nr_of_inlines ++;
200 if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) { 206 if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) {
201 psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); 207 psiconv_warn(0,psiconv_buffer_length(buf),
208 "Massive memory corruption");
202 res = -PSICONV_E_OTHER; 209 res = -PSICONV_E_OTHER;
203 goto ERROR5; 210 goto ERROR5;
204 } 211 }
205 if ((res = psiconv_write_u8(buf_inlines,0x00))) 212 if ((res = psiconv_write_u8(buf_inlines,0x00)))
206 goto ERROR5; 213 goto ERROR5;
214 thislen = in_line->length;
215 paralen += thislen;
216 /* If this is the last in_line, we need to make sure that the
217 complete length of all inlines equals the text length */
218 if (j == psiconv_list_length(paragraph->in_lines)-1) {
219 if (paralen > strlen(paragraph->text)+1) {
220 res = -PSICONV_E_GENERATE;
221 goto ERROR5;
222 }
223 thislen += strlen(paragraph->text)+1-paralen;
224 }
207 if ((res = psiconv_write_u32(buf_inlines,in_line->length))) 225 if ((res = psiconv_write_u32(buf_inlines,thislen)))
208 goto ERROR5; 226 goto ERROR5;
209 if ((res = psiconv_write_character_layout_list(buf_inlines, 227 if ((res = psiconv_write_character_layout_list(buf_inlines,
210 in_line->layout, 228 in_line->layout,
211 style->character))) 229 style->character)))
212 goto ERROR5; 230 goto ERROR5;
213 } 231 }
214 } else { 232 } else {
215 /* No inline layouts, so we generate a paragraph type list */ 233 /* No inline layouts (or only 1), so we generate a paragraph type list */
216 para_type = 0; 234 para_type = 0;
235 /* Set para_charlayout to the correct character-level layout */
236 if (psiconv_list_length(paragraph->in_lines) == 0)
237 para_charlayout = paragraph->base_character;
238 else {
239 if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) {
240 psiconv_warn(0,psiconv_buffer_length(buf),
241 "Massive memory corruption");
242 res = -PSICONV_E_OTHER;
243 goto ERROR5;
244 }
245 para_charlayout = in_line->layout;
246 }
217 for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) { 247 for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) {
218 if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) { 248 if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) {
219 psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); 249 psiconv_warn(0,psiconv_buffer_length(buf),
250 "Massive memory corruption");
220 res = -PSICONV_E_OTHER; 251 res = -PSICONV_E_OTHER;
221 goto ERROR5; 252 goto ERROR5;
222 } 253 }
223 if ((paragraph->base_style == paragraph_type->style) && 254 if ((paragraph->base_style == paragraph_type->style) &&
224 !psiconv_compare_character_layout(paragraph->base_character, 255 !psiconv_compare_character_layout(para_charlayout,
225 paragraph_type->character) && 256 paragraph_type->character) &&
226 !psiconv_compare_paragraph_layout(paragraph->base_paragraph, 257 !psiconv_compare_paragraph_layout(paragraph->base_paragraph,
227 paragraph_type->paragraph)) { 258 paragraph_type->paragraph)) {
228 para_type = paragraph_type->nr; 259 para_type = paragraph_type->nr;
229 break; 260 break;
232 if (!para_type) { 263 if (!para_type) {
233 /* We need to add a new entry */ 264 /* We need to add a new entry */
234 para_type = new_type.nr = j+1; 265 para_type = new_type.nr = j+1;
235 /* No need to copy them, we won't change them anyway */ 266 /* No need to copy them, we won't change them anyway */
236 new_type.paragraph = paragraph->base_paragraph; 267 new_type.paragraph = paragraph->base_paragraph;
237 new_type.character = paragraph->base_character; 268 new_type.character = para_charlayout;
238 new_type.style = paragraph->base_style; 269 new_type.style = paragraph->base_style;
239 paragraph_type = &new_type; 270 paragraph_type = &new_type;
240 if ((res = psiconv_list_add(paragraph_type_list,paragraph_type))) 271 if ((res = psiconv_list_add(paragraph_type_list,paragraph_type)))
241 goto ERROR5; 272 goto ERROR5;
242 if ((res = psiconv_write_u32(buf_types,paragraph_type->nr))) 273 if ((res = psiconv_write_u32(buf_types,paragraph_type->nr)))

Legend:
Removed from v.88  
changed lines
  Added in v.142

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26