… | |
… | |
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_new_buffer())) |
37 | if (!(*buf = psiconv_buffer_new())) |
38 | return -PSICONV_E_NOMEM; |
38 | return -PSICONV_E_NOMEM; |
39 | |
39 | |
40 | #if 0 |
40 | #if 0 |
41 | if (value->type == psiconv_word_file) { |
41 | if (value->type == psiconv_word_file) { |
42 | if ((res =psiconv_write_word_file(*buf,(psiconv_word_f) (value->file)))) |
42 | if ((res =psiconv_write_word_file(*buf,(psiconv_word_f) (value->file)))) |
… | |
… | |
47 | if ((res =psiconv_write_texted_file(*buf, |
47 | if ((res =psiconv_write_texted_file(*buf, |
48 | (psiconv_texted_f) (value->file)))) |
48 | (psiconv_texted_f) (value->file)))) |
49 | goto ERROR; |
49 | goto ERROR; |
50 | #if 0 |
50 | #if 0 |
51 | } else if (value->type == psiconv_sketch_file) { |
51 | } else if (value->type == psiconv_sketch_file) { |
52 | if ((res =psiconv_write_texted_file(*buf, |
52 | if ((res =psiconv_write_sketch_file(*buf, |
53 | (psiconv_sketch_f) (value->file)))) |
53 | (psiconv_sketch_f) (value->file)))) |
54 | goto ERROR; |
54 | goto ERROR; |
55 | } else if (value->type == psiconv_mbm_file) { |
55 | } else if (value->type == psiconv_mbm_file) { |
56 | if ((res =psiconv_write_texted_file(*buf, |
56 | if ((res =psiconv_write_mbm_file(*buf, |
57 | (psiconv_mbm_f) (value->file)))) |
57 | (psiconv_mbm_f) (value->file)))) |
58 | goto ERROR; |
58 | goto ERROR; |
59 | } else if (value->type == psiconv_clipart_file) { |
59 | } else if (value->type == psiconv_clipart_file) { |
60 | if ((res =psiconv_write_texted_file(*buf, |
60 | if ((res =psiconv_write_clipart_file(*buf, |
61 | (psiconv_clipart_f) (value->file)))) |
61 | (psiconv_clipart_f) (value->file)))) |
62 | goto ERROR; |
62 | goto ERROR; |
63 | #endif |
63 | #endif |
64 | } else { |
64 | } else { |
65 | psiconv_warn(0,0,"Unknown or unsupported file type"); |
65 | psiconv_warn(0,0,"Unknown or unsupported file type"); |
66 | res = -PSICONV_E_GENERATE; |
66 | res = -PSICONV_E_GENERATE; |
67 | goto ERROR; |
67 | goto ERROR; |
68 | } |
68 | } |
|
|
69 | if ((res = psiconv_buffer_resolve(*buf))) |
|
|
70 | goto ERROR; |
69 | return -PSICONV_E_OK; |
71 | return -PSICONV_E_OK; |
70 | |
72 | |
71 | ERROR: |
73 | ERROR: |
72 | psiconv_free_buffer(*buf); |
74 | psiconv_buffer_free(*buf); |
73 | return res; |
75 | return res; |
74 | } |
76 | } |
75 | |
77 | |
76 | int psiconv_write_texted_file(psiconv_buffer buf,psiconv_texted_f value) |
78 | int psiconv_write_texted_file(psiconv_buffer buf,psiconv_texted_f value) |
77 | { |
79 | { |
78 | psiconv_character_layout base_char; |
80 | psiconv_character_layout base_char; |
79 | psiconv_paragraph_layout base_para; |
81 | psiconv_paragraph_layout base_para; |
80 | int res; |
82 | int res; |
81 | psiconv_buffer extra_buf; |
|
|
82 | psiconv_section_table_section section_table; |
83 | psiconv_section_table_section section_table; |
83 | psiconv_section_table_entry entry; |
84 | psiconv_section_table_entry entry; |
|
|
85 | psiconv_u32 section_table_id; |
|
|
86 | psiconv_buffer buf_texted; |
84 | |
87 | |
85 | if (!value) { |
88 | if (!value) { |
86 | psiconv_warn(0,0,"Null TextEd file"); |
89 | psiconv_warn(0,0,"Null TextEd file"); |
87 | return -PSICONV_E_GENERATE; |
90 | return -PSICONV_E_GENERATE; |
88 | } |
91 | } |
… | |
… | |
95 | if (!(entry = malloc(sizeof(*entry)))) { |
98 | if (!(entry = malloc(sizeof(*entry)))) { |
96 | res = -PSICONV_E_NOMEM; |
99 | res = -PSICONV_E_NOMEM; |
97 | goto ERROR2; |
100 | goto ERROR2; |
98 | } |
101 | } |
99 | |
102 | |
100 | if (!(extra_buf = psiconv_new_buffer())) { |
103 | if (!(base_char = psiconv_basic_character_layout())) { |
101 | res = -PSICONV_E_NOMEM; |
104 | res = -PSICONV_E_NOMEM; |
102 | goto ERROR3; |
105 | goto ERROR3; |
103 | } |
106 | } |
104 | |
|
|
105 | if (!(base_char = psiconv_basic_character_layout())) { |
107 | if (!(base_para = psiconv_basic_paragraph_layout())) { |
106 | res = -PSICONV_E_NOMEM; |
108 | res = -PSICONV_E_NOMEM; |
107 | goto ERROR4; |
109 | goto ERROR4; |
108 | } |
|
|
109 | if (!(base_para = psiconv_basic_paragraph_layout())) { |
|
|
110 | res = -PSICONV_E_NOMEM; |
|
|
111 | goto ERROR5; |
|
|
112 | } |
110 | } |
113 | |
111 | |
114 | if ((res = psiconv_write_header_section(buf,PSICONV_ID_PSION5, |
112 | if ((res = psiconv_write_header_section(buf,PSICONV_ID_PSION5, |
115 | PSICONV_ID_DATA_FILE, |
113 | PSICONV_ID_DATA_FILE, |
116 | PSICONV_ID_TEXTED))) |
114 | PSICONV_ID_TEXTED))) |
|
|
115 | goto ERROR5; |
|
|
116 | |
|
|
117 | section_table_id = psiconv_buffer_unique_id(); |
|
|
118 | if ((res = psiconv_write_offset(buf,section_table_id))) |
|
|
119 | goto ERROR5; |
|
|
120 | |
|
|
121 | entry->id = PSICONV_ID_APPL_ID_SECTION; |
|
|
122 | entry->offset = psiconv_buffer_unique_id(); |
|
|
123 | if ((res = psiconv_list_add(section_table,entry))) |
|
|
124 | goto ERROR5; |
|
|
125 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
|
|
126 | goto ERROR5; |
|
|
127 | if ((res=psiconv_write_application_id_section(buf, |
|
|
128 | PSICONV_ID_TEXTED,"TextEd.app"))) |
|
|
129 | goto ERROR5; |
|
|
130 | |
|
|
131 | entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; |
|
|
132 | entry->offset = psiconv_buffer_unique_id(); |
|
|
133 | if ((res = psiconv_list_add(section_table,entry))) |
|
|
134 | goto ERROR5; |
|
|
135 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
|
|
136 | goto ERROR5; |
|
|
137 | if ((res = psiconv_write_page_layout_section(buf,value->page_sec))) |
|
|
138 | goto ERROR5; |
|
|
139 | |
|
|
140 | entry->id = PSICONV_ID_TEXTED; |
|
|
141 | entry->offset = psiconv_buffer_unique_id(); |
|
|
142 | if ((res = psiconv_list_add(section_table,entry))) |
|
|
143 | goto ERROR5; |
|
|
144 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
|
|
145 | goto ERROR5; |
|
|
146 | if ((res = psiconv_write_texted_section(buf,value->texted_sec, |
|
|
147 | base_char,base_para,&buf_texted))) |
|
|
148 | goto ERROR5; |
|
|
149 | |
|
|
150 | if ((res = psiconv_buffer_concat(buf,buf_texted))) |
117 | goto ERROR6; |
151 | goto ERROR6; |
118 | |
152 | |
119 | |
153 | |
120 | entry->id = PSICONV_ID_APPL_ID_SECTION; |
154 | if ((res = psiconv_buffer_add_target(buf,section_table_id))) |
121 | entry->offset = psiconv_list_length(extra_buf) + 0x14; |
|
|
122 | if ((res = psiconv_list_add(section_table,entry))) |
|
|
123 | goto ERROR6; |
|
|
124 | if ((res=psiconv_write_application_id_section(extra_buf, |
|
|
125 | PSICONV_ID_TEXTED,"TextEd.app"))) |
|
|
126 | goto ERROR6; |
|
|
127 | |
|
|
128 | entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; |
|
|
129 | entry->offset = psiconv_list_length(extra_buf) + 0x14; |
|
|
130 | if ((res = psiconv_list_add(section_table,entry))) |
|
|
131 | goto ERROR6; |
|
|
132 | if ((res = psiconv_write_page_layout_section(extra_buf,value->page_sec))) |
|
|
133 | goto ERROR6; |
|
|
134 | |
|
|
135 | entry->id = PSICONV_ID_TEXTED; |
|
|
136 | entry->offset = psiconv_list_length(extra_buf) + 0x14; |
|
|
137 | if ((res = psiconv_list_add(section_table,entry))) |
|
|
138 | goto ERROR6; |
|
|
139 | if ((res = psiconv_write_texted_section(extra_buf,value->texted_sec, |
|
|
140 | base_char,base_para))) |
|
|
141 | goto ERROR6; |
|
|
142 | |
|
|
143 | if ((res = psiconv_write_u32(buf,psiconv_list_length(extra_buf) + 0x14))) |
|
|
144 | goto ERROR6; |
|
|
145 | |
|
|
146 | if ((res = psiconv_list_concat(buf,extra_buf))) |
|
|
147 | goto ERROR6; |
155 | goto ERROR6; |
148 | |
156 | |
149 | res = psiconv_write_section_table_section(buf,section_table); |
157 | res = psiconv_write_section_table_section(buf,section_table); |
150 | |
158 | |
151 | ERROR6: |
159 | ERROR6: |
|
|
160 | psiconv_buffer_free(buf_texted); |
|
|
161 | ERROR5: |
152 | psiconv_free_paragraph_layout(base_para); |
162 | psiconv_free_paragraph_layout(base_para); |
153 | ERROR5: |
163 | ERROR4: |
154 | psiconv_free_character_layout(base_char); |
164 | psiconv_free_character_layout(base_char); |
155 | ERROR4: |
|
|
156 | psiconv_free_buffer(extra_buf); |
|
|
157 | ERROR3: |
165 | ERROR3: |
158 | free(entry); |
166 | free(entry); |
159 | ERROR2: |
167 | ERROR2: |
160 | psiconv_list_free(section_table); |
168 | psiconv_list_free(section_table); |
161 | ERROR1: |
169 | ERROR1: |