/[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 73 Revision 142
23#include <stdlib.h> 23#include <stdlib.h>
24 24
25#include "error.h" 25#include "error.h"
26#include "generate_routines.h" 26#include "generate_routines.h"
27 27
28#ifdef DMALLOC
29#include <dmalloc.h>
30#endif
31
28 32
29int psiconv_write(psiconv_buffer *buf,const psiconv_file value) 33int psiconv_write(psiconv_buffer *buf,const psiconv_file value)
30{ 34{
31 int allocated = 0;
32 int res; 35 int res;
33 36
34 if (!value) { 37 if (!value) {
35 psiconv_warn(0,0,"Can't parse to an empty buffer!"); 38 psiconv_warn(0,0,"Can't parse to an empty buffer!");
36 return -PSICONV_E_OTHER; 39 return -PSICONV_E_OTHER;
37 } 40 }
38 if (!*buf) {
39 if (!(*buf = psiconv_new_buffer())) 41 if (!(*buf = psiconv_buffer_new()))
40 return -PSICONV_E_NOMEM; 42 return -PSICONV_E_NOMEM;
41 allocated = 1;
42 }
43 43
44#if 0
45 if (value->type == psiconv_word_file) { 44 if (value->type == psiconv_word_file) {
46 if ((res =psiconv_write_word_file(*buf,(psiconv_word_f) (value->file)))) 45 if ((res =psiconv_write_word_file(*buf,(psiconv_word_f) (value->file))))
47 goto ERROR; 46 goto ERROR;
48 } else
49#endif
50 if (value->type == psiconv_texted_file) { 47 } else if (value->type == psiconv_texted_file) {
51 if ((res =psiconv_write_texted_file(*buf, 48 if ((res =psiconv_write_texted_file(*buf,
52 (psiconv_texted_f) (value->file)))) 49 (psiconv_texted_f) (value->file))))
53 goto ERROR; 50 goto ERROR;
54#if 0 51#if 0
55 } else if (value->type == psiconv_sketch_file) { 52 } else if (value->type == psiconv_sketch_file) {
56 if ((res =psiconv_write_texted_file(*buf, 53 if ((res =psiconv_write_sketch_file(*buf,
57 (psiconv_sketch_f) (value->file)))) 54 (psiconv_sketch_f) (value->file))))
58 goto ERROR; 55 goto ERROR;
59 } else if (value->type == psiconv_mbm_file) { 56 } else if (value->type == psiconv_mbm_file) {
60 if ((res =psiconv_write_texted_file(*buf, 57 if ((res =psiconv_write_mbm_file(*buf,
61 (psiconv_mbm_f) (value->file)))) 58 (psiconv_mbm_f) (value->file))))
62 goto ERROR; 59 goto ERROR;
63 } else if (value->type == psiconv_clipart_file) { 60 } else if (value->type == psiconv_clipart_file) {
64 if ((res =psiconv_write_texted_file(*buf, 61 if ((res =psiconv_write_clipart_file(*buf,
65 (psiconv_clipart_f) (value->file)))) 62 (psiconv_clipart_f) (value->file))))
66 goto ERROR; 63 goto ERROR;
67#endif 64#endif
68 } else { 65 } else {
69 psiconv_warn(0,0,"Unknown or unsupported file type"); 66 psiconv_warn(0,0,"Unknown or unsupported file type");
70 res = -PSICONV_E_GENERATE; 67 res = -PSICONV_E_GENERATE;
71 goto ERROR; 68 goto ERROR;
72 } 69 }
70 if ((res = psiconv_buffer_resolve(*buf)))
71 goto ERROR;
73 return -PSICONV_E_OK; 72 return -PSICONV_E_OK;
74 73
75ERROR: 74ERROR:
76 if (allocated)
77 psiconv_free_buffer(*buf); 75 psiconv_buffer_free(*buf);
78 return res; 76 return res;
79} 77}
80 78
81int psiconv_write_texted_file(psiconv_buffer buf,psiconv_texted_f value) 79int psiconv_write_texted_file(psiconv_buffer buf,psiconv_texted_f value)
82{ 80{
83 psiconv_character_layout base_char; 81 psiconv_character_layout base_char;
84 psiconv_paragraph_layout base_para; 82 psiconv_paragraph_layout base_para;
85 int res; 83 int res;
86 psiconv_buffer extra_buf;
87 psiconv_section_table_section section_table; 84 psiconv_section_table_section section_table;
88 psiconv_section_table_entry entry; 85 psiconv_section_table_entry entry;
86 psiconv_u32 section_table_id;
87 psiconv_buffer buf_texted;
89 88
90 if (!value) { 89 if (!value) {
91 psiconv_warn(0,0,"Null TextEd file"); 90 psiconv_warn(0,0,"Null TextEd file");
92 return -PSICONV_E_GENERATE; 91 return -PSICONV_E_GENERATE;
93 } 92 }
100 if (!(entry = malloc(sizeof(*entry)))) { 99 if (!(entry = malloc(sizeof(*entry)))) {
101 res = -PSICONV_E_NOMEM; 100 res = -PSICONV_E_NOMEM;
102 goto ERROR2; 101 goto ERROR2;
103 } 102 }
104 103
105 if (!(extra_buf = psiconv_new_buffer())) {
106 res = -PSICONV_E_NOMEM;
107 goto ERROR3;
108 }
109
110 if (!(base_char = psiconv_basic_character_layout())) { 104 if (!(base_char = psiconv_basic_character_layout())) {
111 res = -PSICONV_E_NOMEM; 105 res = -PSICONV_E_NOMEM;
106 goto ERROR3;
107 }
108 if (!(base_para = psiconv_basic_paragraph_layout())) {
109 res = -PSICONV_E_NOMEM;
112 goto ERROR4; 110 goto ERROR4;
113 }
114 if (!(base_para = psiconv_basic_paragraph_layout())) {
115 res = -PSICONV_E_NOMEM;
116 goto ERROR5;
117 } 111 }
118 112
119 if ((res = psiconv_write_header_section(buf,PSICONV_ID_PSION5, 113 if ((res = psiconv_write_header_section(buf,PSICONV_ID_PSION5,
120 PSICONV_ID_DATA_FILE, 114 PSICONV_ID_DATA_FILE,
121 PSICONV_ID_TEXTED))) 115 PSICONV_ID_TEXTED)))
116 goto ERROR5;
117
118 section_table_id = psiconv_buffer_unique_id();
119 if ((res = psiconv_write_offset(buf,section_table_id)))
120 goto ERROR5;
121
122 entry->id = PSICONV_ID_APPL_ID_SECTION;
123 entry->offset = psiconv_buffer_unique_id();
124 if ((res = psiconv_list_add(section_table,entry)))
125 goto ERROR5;
126 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
127 goto ERROR5;
128 if ((res=psiconv_write_application_id_section(buf,
129 PSICONV_ID_TEXTED,"TextEd.app")))
130 goto ERROR5;
131
132 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
133 entry->offset = psiconv_buffer_unique_id();
134 if ((res = psiconv_list_add(section_table,entry)))
135 goto ERROR5;
136 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
137 goto ERROR5;
138 if ((res = psiconv_write_page_layout_section(buf,value->page_sec)))
139 goto ERROR5;
140
141 entry->id = PSICONV_ID_TEXTED;
142 entry->offset = psiconv_buffer_unique_id();
143 if ((res = psiconv_list_add(section_table,entry)))
144 goto ERROR5;
145 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
146 goto ERROR5;
147 if ((res = psiconv_write_texted_section(buf,value->texted_sec,
148 base_char,base_para,&buf_texted)))
149 goto ERROR5;
150
151 if ((res = psiconv_buffer_concat(buf,buf_texted)))
122 goto ERROR6; 152 goto ERROR6;
123 153
124 154
125 entry->id = PSICONV_ID_APPL_ID_SECTION; 155 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
126 entry->offset = psiconv_list_length(extra_buf) + 0x14;
127 if ((res = psiconv_list_add(section_table,&entry)))
128 goto ERROR6; 156 goto ERROR6;
129 if ((res=psiconv_write_application_id_section(extra_buf,
130 PSICONV_ID_TEXTED,"TextEd.app")))
131 goto ERROR6;
132
133 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
134 entry->offset = psiconv_list_length(extra_buf) + 0x14;
135 if ((res = psiconv_list_add(section_table,&entry)))
136 goto ERROR6;
137 if ((res = psiconv_write_page_layout_section(extra_buf,value->page_sec)))
138 goto ERROR6;
139
140 entry->id = PSICONV_ID_TEXTED;
141 entry->offset = psiconv_list_length(extra_buf) + 0x14;
142 if ((res = psiconv_list_add(section_table,&entry)))
143 goto ERROR6;
144 if ((res = psiconv_write_texted_section(extra_buf,value->texted_sec,
145 base_char,base_para)))
146 goto ERROR6;
147
148 if ((res = psiconv_write_u32(buf,psiconv_list_length(extra_buf) + 0x14)))
149 goto ERROR6;
150
151 if ((res = psiconv_list_concat(buf,extra_buf)))
152 goto ERROR6;
153 157
154 res = psiconv_write_section_table_section(buf,section_table); 158 res = psiconv_write_section_table_section(buf,section_table);
155 159
156ERROR6: 160ERROR6:
161 psiconv_buffer_free(buf_texted);
162ERROR5:
157 psiconv_free_paragraph_layout(base_para); 163 psiconv_free_paragraph_layout(base_para);
158ERROR5: 164ERROR4:
159 psiconv_free_character_layout(base_char); 165 psiconv_free_character_layout(base_char);
160ERROR4:
161 psiconv_free_buffer(extra_buf);
162ERROR3: 166ERROR3:
163 free(entry); 167 free(entry);
164ERROR2: 168ERROR2:
165 psiconv_list_free(section_table); 169 psiconv_list_free(section_table);
166ERROR1: 170ERROR1:
167 return res; 171 return res;
168} 172}
173
174int psiconv_write_word_file(psiconv_buffer buf,psiconv_word_f value)
175{
176 int res;
177 psiconv_section_table_section section_table;
178 psiconv_section_table_entry entry;
179 psiconv_u32 section_table_id;
180
181 if (!value) {
182 psiconv_warn(0,0,"Null Word file");
183 return -PSICONV_E_GENERATE;
184 }
185
186 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
187 res = -PSICONV_E_NOMEM;
188 goto ERROR1;
189 }
190
191 if (!(entry = malloc(sizeof(*entry)))) {
192 res = -PSICONV_E_NOMEM;
193 goto ERROR2;
194 }
195
196 if ((res = psiconv_write_header_section(buf,PSICONV_ID_PSION5,
197 PSICONV_ID_DATA_FILE,
198 PSICONV_ID_WORD)))
199 goto ERROR3;
200
201 section_table_id = psiconv_buffer_unique_id();
202 if ((res = psiconv_write_offset(buf,section_table_id)))
203 goto ERROR3;
204
205 entry->id = PSICONV_ID_APPL_ID_SECTION;
206 entry->offset = psiconv_buffer_unique_id();
207 if ((res = psiconv_list_add(section_table,entry)))
208 goto ERROR3;
209 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
210 goto ERROR3;
211 if ((res=psiconv_write_application_id_section(buf,
212 PSICONV_ID_WORD,"Word.app")))
213 goto ERROR3;
214
215 entry->id = PSICONV_ID_WORD_STATUS_SECTION;
216 entry->offset = psiconv_buffer_unique_id();
217 if ((res = psiconv_list_add(section_table,entry)))
218 goto ERROR3;
219 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
220 goto ERROR3;
221 if ((res = psiconv_write_word_status_section(buf,value->status_sec)))
222 goto ERROR3;
223
224 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
225 entry->offset = psiconv_buffer_unique_id();
226 if ((res = psiconv_list_add(section_table,entry)))
227 goto ERROR3;
228 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
229 goto ERROR3;
230 if ((res = psiconv_write_page_layout_section(buf,value->page_sec)))
231 goto ERROR3;
232
233 entry->id = PSICONV_ID_WORD_STYLES_SECTION;
234 entry->offset = psiconv_buffer_unique_id();
235 if ((res = psiconv_list_add(section_table,entry)))
236 goto ERROR3;
237 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
238 goto ERROR3;
239 if ((res = psiconv_write_word_styles_section(buf,value->styles_sec)))
240 goto ERROR3;
241
242 entry->id = PSICONV_ID_TEXT_SECTION;
243 entry->offset = psiconv_buffer_unique_id();
244 if ((res = psiconv_list_add(section_table,entry)))
245 goto ERROR3;
246 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
247 goto ERROR3;
248 if ((res = psiconv_write_text_section(buf,value->paragraphs)))
249 goto ERROR3;
250
251 entry->id = PSICONV_ID_LAYOUT_SECTION;
252 entry->offset = psiconv_buffer_unique_id();
253 if ((res = psiconv_list_add(section_table,entry)))
254 goto ERROR3;
255 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
256 goto ERROR3;
257 if ((res = psiconv_write_styled_layout_section(buf,value->paragraphs,
258 value->styles_sec)))
259 goto ERROR3;
260
261 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
262 goto ERROR3;
263
264 res = psiconv_write_section_table_section(buf,section_table);
265
266ERROR3:
267 free(entry);
268ERROR2:
269 psiconv_list_free(section_table);
270ERROR1:
271 return res;
272}

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

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