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

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

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

Revision 166 Revision 170
28#ifdef DMALLOC 28#ifdef DMALLOC
29#include <dmalloc.h> 29#include <dmalloc.h>
30#endif 30#endif
31 31
32 32
33int psiconv_write(psiconv_buffer *buf,const psiconv_file value) 33int psiconv_write(const psiconv_config config, psiconv_buffer *buf,
34 const psiconv_file value)
34{ 35{
35 int res; 36 int res;
36 37
37 if (!value) { 38 if (!value) {
38 psiconv_warn(0,0,"Can't parse to an empty buffer!"); 39 psiconv_warn(config,0,0,"Can't parse to an empty buffer!");
39 return -PSICONV_E_OTHER; 40 return -PSICONV_E_OTHER;
40 } 41 }
41 if (!(*buf = psiconv_buffer_new())) 42 if (!(*buf = psiconv_buffer_new()))
42 return -PSICONV_E_NOMEM; 43 return -PSICONV_E_NOMEM;
43 44
44 if (value->type == psiconv_word_file) { 45 if (value->type == psiconv_word_file) {
45 if ((res = psiconv_write_header_section(*buf,PSICONV_ID_PSION5, 46 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5,
46 PSICONV_ID_DATA_FILE, 47 PSICONV_ID_DATA_FILE,
47 PSICONV_ID_WORD))) 48 PSICONV_ID_WORD)))
48 goto ERROR; 49 goto ERROR;
49 if ((res =psiconv_write_word_file(*buf,(psiconv_word_f) (value->file)))) 50 if ((res =psiconv_write_word_file(config,*buf,(psiconv_word_f) (value->file))))
50 goto ERROR; 51 goto ERROR;
51 } else if (value->type == psiconv_texted_file) { 52 } else if (value->type == psiconv_texted_file) {
52 if ((res = psiconv_write_header_section(*buf,PSICONV_ID_PSION5, 53 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5,
53 PSICONV_ID_DATA_FILE, 54 PSICONV_ID_DATA_FILE,
54 PSICONV_ID_TEXTED))) 55 PSICONV_ID_TEXTED)))
55 goto ERROR; 56 goto ERROR;
56 if ((res =psiconv_write_texted_file(*buf, 57 if ((res =psiconv_write_texted_file(config,*buf,
57 (psiconv_texted_f) (value->file)))) 58 (psiconv_texted_f) (value->file))))
58 goto ERROR; 59 goto ERROR;
60 } else if (value->type == psiconv_sketch_file) {
61 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5,
62 PSICONV_ID_DATA_FILE,
63 PSICONV_ID_SKETCH)))
64 goto ERROR;
65 if ((res =psiconv_write_sketch_file(config,*buf,
66 (psiconv_sketch_f) (value->file))))
67 goto ERROR;
59#if 0 68#if 0
60 } else if (value->type == psiconv_sketch_file) {
61 if ((res =psiconv_write_sketch_file(*buf,
62 (psiconv_sketch_f) (value->file))))
63 goto ERROR;
64 } else if (value->type == psiconv_mbm_file) { 69 } else if (value->type == psiconv_mbm_file) {
65 if ((res =psiconv_write_mbm_file(*buf, 70 if ((res =psiconv_write_mbm_file(config,*buf,
66 (psiconv_mbm_f) (value->file)))) 71 (psiconv_mbm_f) (value->file))))
67 goto ERROR; 72 goto ERROR;
68 } else if (value->type == psiconv_clipart_file) { 73 } else if (value->type == psiconv_clipart_file) {
69 if ((res =psiconv_write_clipart_file(*buf, 74 if ((res =psiconv_write_clipart_file(config,*buf,
70 (psiconv_clipart_f) (value->file)))) 75 (psiconv_clipart_f) (value->file))))
71 goto ERROR; 76 goto ERROR;
72#endif 77#endif
73 } else { 78 } else {
74 psiconv_warn(0,0,"Unknown or unsupported file type"); 79 psiconv_warn(config,0,0,"Unknown or unsupported file type");
75 res = -PSICONV_E_GENERATE; 80 res = -PSICONV_E_GENERATE;
76 goto ERROR; 81 goto ERROR;
77 } 82 }
78 if ((res = psiconv_buffer_resolve(*buf))) 83 if ((res = psiconv_buffer_resolve(*buf)))
79 goto ERROR; 84 goto ERROR;
82ERROR: 87ERROR:
83 psiconv_buffer_free(*buf); 88 psiconv_buffer_free(*buf);
84 return res; 89 return res;
85} 90}
86 91
87int psiconv_write_texted_file(psiconv_buffer buf,psiconv_texted_f value) 92int psiconv_write_texted_file(const psiconv_config config,
93 psiconv_buffer buf,psiconv_texted_f value)
88{ 94{
89 psiconv_character_layout base_char; 95 psiconv_character_layout base_char;
90 psiconv_paragraph_layout base_para; 96 psiconv_paragraph_layout base_para;
91 int res; 97 int res;
92 psiconv_section_table_section section_table; 98 psiconv_section_table_section section_table;
93 psiconv_section_table_entry entry; 99 psiconv_section_table_entry entry;
94 psiconv_u32 section_table_id; 100 psiconv_u32 section_table_id;
95 psiconv_buffer buf_texted; 101 psiconv_buffer buf_texted;
96 102
97 if (!value) { 103 if (!value) {
98 psiconv_warn(0,0,"Null TextEd file"); 104 psiconv_warn(config,0,0,"Null TextEd file");
99 return -PSICONV_E_GENERATE; 105 return -PSICONV_E_GENERATE;
100 } 106 }
101 107
102 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 108 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
103 res = -PSICONV_E_NOMEM; 109 res = -PSICONV_E_NOMEM;
117 res = -PSICONV_E_NOMEM; 123 res = -PSICONV_E_NOMEM;
118 goto ERROR4; 124 goto ERROR4;
119 } 125 }
120 126
121 section_table_id = psiconv_buffer_unique_id(); 127 section_table_id = psiconv_buffer_unique_id();
122 if ((res = psiconv_write_offset(buf,section_table_id))) 128 if ((res = psiconv_write_offset(config,buf,section_table_id)))
123 goto ERROR5; 129 goto ERROR5;
124 130
125 entry->id = PSICONV_ID_APPL_ID_SECTION; 131 entry->id = PSICONV_ID_APPL_ID_SECTION;
126 entry->offset = psiconv_buffer_unique_id(); 132 entry->offset = psiconv_buffer_unique_id();
127 if ((res = psiconv_list_add(section_table,entry))) 133 if ((res = psiconv_list_add(section_table,entry)))
128 goto ERROR5; 134 goto ERROR5;
129 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 135 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
130 goto ERROR5; 136 goto ERROR5;
131 if ((res=psiconv_write_application_id_section(buf, 137 if ((res=psiconv_write_application_id_section(config,buf,
132 PSICONV_ID_TEXTED,"TextEd.app"))) 138 PSICONV_ID_TEXTED,"TextEd.app")))
133 goto ERROR5; 139 goto ERROR5;
134 140
135 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; 141 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
136 entry->offset = psiconv_buffer_unique_id(); 142 entry->offset = psiconv_buffer_unique_id();
137 if ((res = psiconv_list_add(section_table,entry))) 143 if ((res = psiconv_list_add(section_table,entry)))
138 goto ERROR5; 144 goto ERROR5;
139 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 145 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
140 goto ERROR5; 146 goto ERROR5;
141 if ((res = psiconv_write_page_layout_section(buf,value->page_sec))) 147 if ((res = psiconv_write_page_layout_section(config,buf,value->page_sec)))
142 goto ERROR5; 148 goto ERROR5;
143 149
144 entry->id = PSICONV_ID_TEXTED; 150 entry->id = PSICONV_ID_TEXTED;
145 entry->offset = psiconv_buffer_unique_id(); 151 entry->offset = psiconv_buffer_unique_id();
146 if ((res = psiconv_list_add(section_table,entry))) 152 if ((res = psiconv_list_add(section_table,entry)))
147 goto ERROR5; 153 goto ERROR5;
148 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 154 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
149 goto ERROR5; 155 goto ERROR5;
150 if ((res = psiconv_write_texted_section(buf,value->texted_sec, 156 if ((res = psiconv_write_texted_section(config,buf,value->texted_sec,
151 base_char,base_para,&buf_texted))) 157 base_char,base_para,&buf_texted)))
152 goto ERROR5; 158 goto ERROR5;
153 159
154 if ((res = psiconv_buffer_concat(buf,buf_texted))) 160 if ((res = psiconv_buffer_concat(buf,buf_texted)))
155 goto ERROR6; 161 goto ERROR6;
156 162
157 163
158 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 164 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
159 goto ERROR6; 165 goto ERROR6;
160 166
161 res = psiconv_write_section_table_section(buf,section_table); 167 res = psiconv_write_section_table_section(config,buf,section_table);
162 168
163ERROR6: 169ERROR6:
164 psiconv_buffer_free(buf_texted); 170 psiconv_buffer_free(buf_texted);
165ERROR5: 171ERROR5:
166 psiconv_free_paragraph_layout(base_para); 172 psiconv_free_paragraph_layout(base_para);
172 psiconv_list_free(section_table); 178 psiconv_list_free(section_table);
173ERROR1: 179ERROR1:
174 return res; 180 return res;
175} 181}
176 182
177int psiconv_write_word_file(psiconv_buffer buf,psiconv_word_f value) 183int psiconv_write_word_file(const psiconv_config config,
184 psiconv_buffer buf,psiconv_word_f value)
178{ 185{
179 int res; 186 int res;
180 psiconv_section_table_section section_table; 187 psiconv_section_table_section section_table;
181 psiconv_section_table_entry entry; 188 psiconv_section_table_entry entry;
182 psiconv_u32 section_table_id; 189 psiconv_u32 section_table_id;
183 190
184 if (!value) { 191 if (!value) {
185 psiconv_warn(0,0,"Null Word file"); 192 psiconv_warn(config,0,0,"Null Word file");
186 return -PSICONV_E_GENERATE; 193 return -PSICONV_E_GENERATE;
187 } 194 }
188 195
189 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 196 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
190 res = -PSICONV_E_NOMEM; 197 res = -PSICONV_E_NOMEM;
195 res = -PSICONV_E_NOMEM; 202 res = -PSICONV_E_NOMEM;
196 goto ERROR2; 203 goto ERROR2;
197 } 204 }
198 205
199 section_table_id = psiconv_buffer_unique_id(); 206 section_table_id = psiconv_buffer_unique_id();
200 if ((res = psiconv_write_offset(buf,section_table_id))) 207 if ((res = psiconv_write_offset(config,buf,section_table_id)))
201 goto ERROR3; 208 goto ERROR3;
202 209
203 entry->id = PSICONV_ID_APPL_ID_SECTION; 210 entry->id = PSICONV_ID_APPL_ID_SECTION;
204 entry->offset = psiconv_buffer_unique_id(); 211 entry->offset = psiconv_buffer_unique_id();
205 if ((res = psiconv_list_add(section_table,entry))) 212 if ((res = psiconv_list_add(section_table,entry)))
206 goto ERROR3; 213 goto ERROR3;
207 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 214 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
208 goto ERROR3; 215 goto ERROR3;
209 if ((res=psiconv_write_application_id_section(buf, 216 if ((res=psiconv_write_application_id_section(config,buf,
210 PSICONV_ID_WORD,"Word.app"))) 217 PSICONV_ID_WORD,"Word.app")))
211 goto ERROR3; 218 goto ERROR3;
212 219
213 entry->id = PSICONV_ID_WORD_STATUS_SECTION; 220 entry->id = PSICONV_ID_WORD_STATUS_SECTION;
214 entry->offset = psiconv_buffer_unique_id(); 221 entry->offset = psiconv_buffer_unique_id();
215 if ((res = psiconv_list_add(section_table,entry))) 222 if ((res = psiconv_list_add(section_table,entry)))
216 goto ERROR3; 223 goto ERROR3;
217 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 224 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
218 goto ERROR3; 225 goto ERROR3;
219 if ((res = psiconv_write_word_status_section(buf,value->status_sec))) 226 if ((res = psiconv_write_word_status_section(config,buf,value->status_sec)))
220 goto ERROR3; 227 goto ERROR3;
221 228
222 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; 229 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
223 entry->offset = psiconv_buffer_unique_id(); 230 entry->offset = psiconv_buffer_unique_id();
224 if ((res = psiconv_list_add(section_table,entry))) 231 if ((res = psiconv_list_add(section_table,entry)))
225 goto ERROR3; 232 goto ERROR3;
226 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 233 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
227 goto ERROR3; 234 goto ERROR3;
228 if ((res = psiconv_write_page_layout_section(buf,value->page_sec))) 235 if ((res = psiconv_write_page_layout_section(config,buf,value->page_sec)))
229 goto ERROR3; 236 goto ERROR3;
230 237
231 entry->id = PSICONV_ID_WORD_STYLES_SECTION; 238 entry->id = PSICONV_ID_WORD_STYLES_SECTION;
232 entry->offset = psiconv_buffer_unique_id(); 239 entry->offset = psiconv_buffer_unique_id();
233 if ((res = psiconv_list_add(section_table,entry))) 240 if ((res = psiconv_list_add(section_table,entry)))
234 goto ERROR3; 241 goto ERROR3;
235 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 242 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
236 goto ERROR3; 243 goto ERROR3;
237 if ((res = psiconv_write_word_styles_section(buf,value->styles_sec))) 244 if ((res = psiconv_write_word_styles_section(config,buf,value->styles_sec)))
238 goto ERROR3; 245 goto ERROR3;
239 246
240 entry->id = PSICONV_ID_TEXT_SECTION; 247 entry->id = PSICONV_ID_TEXT_SECTION;
241 entry->offset = psiconv_buffer_unique_id(); 248 entry->offset = psiconv_buffer_unique_id();
242 if ((res = psiconv_list_add(section_table,entry))) 249 if ((res = psiconv_list_add(section_table,entry)))
243 goto ERROR3; 250 goto ERROR3;
244 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 251 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
245 goto ERROR3; 252 goto ERROR3;
246 if ((res = psiconv_write_text_section(buf,value->paragraphs))) 253 if ((res = psiconv_write_text_section(config,buf,value->paragraphs)))
247 goto ERROR3; 254 goto ERROR3;
248 255
249 entry->id = PSICONV_ID_LAYOUT_SECTION; 256 entry->id = PSICONV_ID_LAYOUT_SECTION;
250 entry->offset = psiconv_buffer_unique_id(); 257 entry->offset = psiconv_buffer_unique_id();
251 if ((res = psiconv_list_add(section_table,entry))) 258 if ((res = psiconv_list_add(section_table,entry)))
252 goto ERROR3; 259 goto ERROR3;
253 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 260 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
254 goto ERROR3; 261 goto ERROR3;
255 if ((res = psiconv_write_styled_layout_section(buf,value->paragraphs, 262 if ((res = psiconv_write_styled_layout_section(config,buf,value->paragraphs,
256 value->styles_sec))) 263 value->styles_sec)))
257 goto ERROR3; 264 goto ERROR3;
258 265
259 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 266 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
260 goto ERROR3; 267 goto ERROR3;
261 268
262 res = psiconv_write_section_table_section(buf,section_table); 269 res = psiconv_write_section_table_section(config,buf,section_table);
263 270
264ERROR3: 271ERROR3:
265 free(entry); 272 free(entry);
266ERROR2: 273ERROR2:
267 psiconv_list_free(section_table); 274 psiconv_list_free(section_table);
268ERROR1: 275ERROR1:
269 return res; 276 return res;
270} 277}
278
279int psiconv_write_sketch_file(const psiconv_config config,
280 psiconv_buffer buf,psiconv_sketch_f value)
281{
282 int res;
283 psiconv_section_table_section section_table;
284 psiconv_section_table_entry entry;
285 psiconv_u32 section_table_id;
286
287 if (!value) {
288 psiconv_warn(config,0,0,"Null Sketch file");
289 return -PSICONV_E_GENERATE;
290 }
291
292 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
293 res = -PSICONV_E_NOMEM;
294 goto ERROR1;
295 }
296
297 if (!(entry = malloc(sizeof(*entry)))) {
298 res = -PSICONV_E_NOMEM;
299 goto ERROR2;
300 }
301
302 section_table_id = psiconv_buffer_unique_id();
303 if ((res = psiconv_write_offset(config,buf,section_table_id)))
304 goto ERROR3;
305
306 entry->id = PSICONV_ID_APPL_ID_SECTION;
307 entry->offset = psiconv_buffer_unique_id();
308 if ((res = psiconv_list_add(section_table,entry)))
309 goto ERROR3;
310 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
311 goto ERROR3;
312 if ((res=psiconv_write_application_id_section(config,buf,
313 PSICONV_ID_SKETCH,"Paint.app")))
314 goto ERROR3;
315
316 entry->id = PSICONV_ID_SKETCH_SECTION;
317 entry->offset = psiconv_buffer_unique_id();
318 if ((res = psiconv_list_add(section_table,entry)))
319 goto ERROR3;
320 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
321 goto ERROR3;
322 if ((res = psiconv_write_sketch_section(config,buf,value->sketch_sec)))
323 goto ERROR3;
324
325 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
326 goto ERROR3;
327 res = psiconv_write_section_table_section(config,buf,section_table);
328
329ERROR3:
330 free(entry);
331ERROR2:
332 psiconv_list_free(section_table);
333ERROR1:
334 return res;
335}

Legend:
Removed from v.166  
changed lines
  Added in v.170

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