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