1 | /* |
1 | /* |
2 | generate_word.c - Part of psiconv, a PSION 5 file formats converter |
2 | generate_word.c - Part of psiconv, a PSION 5 file formats converter |
3 | Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 2000-2005 Frodo Looijaard <frodo@frodo.looijaard.name> |
4 | |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
29 | #include <dmalloc.h> |
29 | #include <dmalloc.h> |
30 | #endif |
30 | #endif |
31 | |
31 | |
32 | |
32 | |
33 | int psiconv_write_word_status_section(const psiconv_config config, |
33 | int psiconv_write_word_status_section(const psiconv_config config, |
34 | psiconv_buffer buf, |
34 | psiconv_buffer buf, int lev, |
35 | psiconv_word_status_section value) |
35 | psiconv_word_status_section value) |
36 | { |
36 | { |
37 | int res; |
37 | int res; |
38 | |
38 | |
|
|
39 | psiconv_progress(config,lev,0,"Writing word status section"); |
|
|
40 | |
39 | if (!value) { |
41 | if (!value) { |
40 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null word status section"); |
42 | psiconv_error(config,lev,0,"Null word status section"); |
41 | return -PSICONV_E_GENERATE; |
43 | res = -PSICONV_E_GENERATE; |
|
|
44 | goto ERROR; |
42 | } |
45 | } |
43 | |
46 | |
44 | if ((res = psiconv_write_u8(config,buf,0x02))) |
47 | if ((res = psiconv_write_u8(config,buf,lev+1,0x02))) |
45 | return res; |
48 | goto ERROR; |
46 | if ((res = psiconv_write_u8(config,buf,(value->show_tabs?0x01:0x00) | |
49 | if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_tabs?0x01:0x00) | |
47 | (value->show_spaces?0x02:0x00) | |
50 | (value->show_spaces?0x02:0x00) | |
48 | (value->show_paragraph_ends?0x04:0x00) | |
51 | (value->show_paragraph_ends?0x04:0x00) | |
49 | (value->show_line_breaks?0x08:0x00) | |
52 | (value->show_line_breaks?0x08:0x00) | |
50 | (value->show_hard_minus?0x20:0x00) | |
53 | (value->show_hard_minus?0x20:0x00) | |
51 | (value->show_hard_space?0x40:0x00)))) |
54 | (value->show_hard_space?0x40:0x00)))) |
52 | return res; |
55 | goto ERROR; |
53 | if ((res = psiconv_write_u8(config,buf,(value->show_full_pictures?0x01:0x00) | |
56 | if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_full_pictures?0x01:0x00) | |
54 | (value->show_full_graphs?0x02:0x00)))) |
57 | (value->show_full_graphs?0x02:0x00)))) |
55 | return res; |
58 | goto ERROR; |
56 | if ((res = psiconv_write_bool(config,buf,value->show_top_toolbar))) |
59 | if ((res = psiconv_write_bool(config,buf,lev+1,value->show_top_toolbar))) |
57 | return res; |
60 | goto ERROR; |
58 | if ((res = psiconv_write_bool(config,buf,value->show_side_toolbar))) |
61 | if ((res = psiconv_write_bool(config,buf,lev+1,value->show_side_toolbar))) |
59 | return res; |
62 | goto ERROR; |
60 | if ((res = psiconv_write_u8(config,buf,(value->fit_lines_to_screen?0x08:0x00)))) |
63 | if ((res = psiconv_write_u8(config,buf,lev+1,(value->fit_lines_to_screen?0x08:0x00)))) |
61 | return res; |
64 | goto ERROR; |
62 | if ((res = psiconv_write_u32(config,buf,value->cursor_position))) |
65 | if ((res = psiconv_write_u32(config,buf,lev+1,value->cursor_position))) |
|
|
66 | goto ERROR; |
|
|
67 | if ((res = psiconv_write_u32(config,buf,lev+1,value->display_size))) |
|
|
68 | goto ERROR; |
|
|
69 | psiconv_progress(config,lev,0,"End of word status section"); |
|
|
70 | return 0; |
|
|
71 | |
|
|
72 | ERROR: |
|
|
73 | psiconv_error(config,lev,0,"Writing of word status section failed"); |
63 | return res; |
74 | return res; |
64 | return psiconv_write_u32(config,buf,value->display_size); |
|
|
65 | } |
75 | } |
66 | |
76 | |
67 | int psiconv_write_word_styles_section(const psiconv_config config, |
77 | int psiconv_write_word_styles_section(const psiconv_config config, |
68 | psiconv_buffer buf, |
78 | psiconv_buffer buf, int lev, |
69 | psiconv_word_styles_section value) |
79 | psiconv_word_styles_section value) |
70 | { |
80 | { |
71 | int res,i; |
81 | int res,i,j; |
72 | psiconv_word_style style; |
82 | psiconv_word_style style; |
73 | psiconv_paragraph_layout basepara; |
83 | psiconv_paragraph_layout basepara; |
74 | psiconv_character_layout basechar; |
84 | psiconv_character_layout basechar; |
75 | psiconv_font font; |
85 | psiconv_font font; |
|
|
86 | psiconv_u32 buflen; |
76 | |
87 | |
|
|
88 | psiconv_progress(config,lev,0,"Writing word styles section"); |
77 | |
89 | |
78 | if (!value || !value->normal || !value->styles) { |
90 | if (!value || !value->normal || !value->styles) { |
79 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null word styles section"); |
91 | psiconv_error(config,lev,0,"Null word styles section"); |
80 | res = -PSICONV_E_GENERATE; |
92 | res = -PSICONV_E_GENERATE; |
81 | goto ERROR1; |
93 | goto ERROR1; |
82 | } |
94 | } |
83 | |
95 | |
84 | if (!(basepara=psiconv_basic_paragraph_layout())) { |
96 | if (!(basepara=psiconv_basic_paragraph_layout())) { |
|
|
97 | psiconv_error(config,lev+1,0,"Out of memory error"); |
85 | res = -PSICONV_E_NOMEM; |
98 | res = -PSICONV_E_NOMEM; |
86 | goto ERROR1; |
99 | goto ERROR1; |
87 | } |
100 | } |
88 | |
101 | |
89 | if (!(basechar=psiconv_basic_character_layout())) { |
102 | if (!(basechar=psiconv_basic_character_layout())) { |
|
|
103 | psiconv_error(config,lev+1,0,"Out of memory error"); |
90 | res = -PSICONV_E_NOMEM; |
104 | res = -PSICONV_E_NOMEM; |
91 | goto ERROR2; |
105 | goto ERROR2; |
92 | } |
106 | } |
93 | |
107 | |
94 | |
108 | |
95 | if ((res = psiconv_write_paragraph_layout_list(config,buf,value->normal->paragraph, |
109 | if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1, |
|
|
110 | value->normal->paragraph, |
96 | basepara))) |
111 | basepara))) |
97 | goto ERROR3; |
112 | goto ERROR3; |
98 | /* Always generate the font for Normal */ |
113 | /* Always generate the font for Normal */ |
99 | font = basechar->font; |
114 | font = basechar->font; |
100 | basechar->font = NULL; |
115 | basechar->font = NULL; |
101 | res = psiconv_write_character_layout_list(config,buf,value->normal->character, |
116 | res = psiconv_write_character_layout_list(config,buf,lev+1, |
|
|
117 | value->normal->character, |
102 | basechar); |
118 | basechar); |
103 | basechar->font = font; |
119 | basechar->font = font; |
104 | if (res) |
120 | if (res) |
105 | goto ERROR3; |
121 | goto ERROR3; |
106 | if ((res = psiconv_write_u32(config,buf,value->normal->hotkey))) |
122 | buflen = psiconv_buffer_length(buf); |
|
|
123 | if ((res = psiconv_unicode_write_char(config,buf,lev+1, |
|
|
124 | value->normal->hotkey))) |
107 | goto ERROR3; |
125 | goto ERROR3; |
108 | if ((res = psiconv_write_u8(config,buf,psiconv_list_length(value->styles)))) |
126 | for (j = psiconv_buffer_length(buf) - buflen; j < 4; j++) |
|
|
127 | if ((res = psiconv_write_u8(config,buf,lev+1,0))) |
|
|
128 | goto ERROR3; |
|
|
129 | |
|
|
130 | if ((res = psiconv_write_u8(config,buf,lev+1, |
|
|
131 | psiconv_list_length(value->styles)))) |
109 | goto ERROR3; |
132 | goto ERROR3; |
110 | |
133 | |
111 | |
134 | |
112 | |
135 | |
113 | for (i = 0; i < psiconv_list_length(value->styles); i++) { |
136 | for (i = 0; i < psiconv_list_length(value->styles); i++) { |
114 | if (!(style = psiconv_list_get(value->styles,i))) { |
137 | if (!(style = psiconv_list_get(value->styles,i))) { |
115 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
138 | psiconv_error(config,lev,0,"Data structure corruption"); |
116 | res = -PSICONV_E_OTHER; |
139 | res = -PSICONV_E_NOMEM; |
117 | goto ERROR3; |
140 | goto ERROR3; |
118 | } |
141 | } |
|
|
142 | buflen = psiconv_buffer_length(buf); |
119 | if ((res = psiconv_write_u32(config,buf,style->hotkey))) |
143 | if ((res = psiconv_unicode_write_char(config,buf,lev+1,style->hotkey))) |
120 | goto ERROR3; |
144 | goto ERROR3; |
|
|
145 | for (j = psiconv_buffer_length(buf) - buflen; j < 4; j++) |
|
|
146 | if ((res = psiconv_write_u8(config,buf,lev+1,0))) |
|
|
147 | goto ERROR3; |
121 | } |
148 | } |
122 | if ((res = psiconv_write_u8(config,buf,psiconv_list_length(value->styles)))) |
149 | if ((res = psiconv_write_u8(config,buf,lev+1,psiconv_list_length(value->styles)))) |
123 | goto ERROR3; |
150 | goto ERROR3; |
124 | for (i = 0; i < psiconv_list_length(value->styles); i++) { |
151 | for (i = 0; i < psiconv_list_length(value->styles); i++) { |
125 | if (!(style = psiconv_list_get(value->styles,i))) { |
152 | if (!(style = psiconv_list_get(value->styles,i))) { |
126 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
153 | psiconv_error(config,lev,0,"Data structure corruption"); |
127 | res = -PSICONV_E_OTHER; |
154 | res = -PSICONV_E_NOMEM; |
128 | goto ERROR3; |
155 | goto ERROR3; |
129 | } |
156 | } |
130 | if (!style->name) { |
157 | if (!style->name) { |
131 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null style name"); |
158 | psiconv_error(config,lev,0,"Null style name"); |
132 | res = -PSICONV_E_GENERATE; |
159 | res = -PSICONV_E_GENERATE; |
133 | goto ERROR3; |
160 | goto ERROR3; |
134 | } |
161 | } |
135 | if ((res = psiconv_write_string(config,buf,style->name))) |
162 | if ((res = psiconv_write_string(config,buf,lev+1,style->name))) |
136 | goto ERROR3; |
163 | goto ERROR3; |
137 | if ((res = psiconv_write_u32(config,buf,style->built_in?PSICONV_ID_STYLE_BUILT_IN: |
164 | if ((res = psiconv_write_u32(config,buf,lev+1,style->built_in?PSICONV_ID_STYLE_BUILT_IN: |
138 | PSICONV_ID_STYLE_REMOVABLE))) |
165 | PSICONV_ID_STYLE_REMOVABLE))) |
139 | goto ERROR3; |
166 | goto ERROR3; |
140 | if ((res = psiconv_write_u32(config,buf,style->outline_level))) |
167 | if ((res = psiconv_write_u32(config,buf,lev+1,style->outline_level))) |
141 | goto ERROR3; |
168 | goto ERROR3; |
142 | if ((res = psiconv_write_character_layout_list(config,buf,style->character, |
169 | if ((res = psiconv_write_character_layout_list(config,buf,lev+1,style->character, |
143 | value->normal->character))) |
170 | value->normal->character))) |
144 | goto ERROR3; |
171 | goto ERROR3; |
145 | if ((res = psiconv_write_paragraph_layout_list(config,buf,style->paragraph, |
172 | if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1,style->paragraph, |
146 | value->normal->paragraph))) |
173 | value->normal->paragraph))) |
147 | goto ERROR3; |
174 | goto ERROR3; |
148 | } |
175 | } |
149 | |
176 | |
150 | for (i = 0; i < psiconv_list_length(value->styles); i++) |
177 | for (i = 0; i < psiconv_list_length(value->styles); i++) |
151 | if ((res = psiconv_write_u8(config,buf,0xff))) |
178 | if ((res = psiconv_write_u8(config,buf,lev+1,0xff))) |
152 | goto ERROR3; |
179 | goto ERROR3; |
153 | res = -PSICONV_E_OK; |
180 | res = -PSICONV_E_OK; |
154 | |
181 | |
155 | ERROR3: |
182 | ERROR3: |
156 | psiconv_free_character_layout(basechar); |
183 | psiconv_free_character_layout(basechar); |
157 | ERROR2: |
184 | ERROR2: |
158 | psiconv_free_paragraph_layout(basepara); |
185 | psiconv_free_paragraph_layout(basepara); |
159 | ERROR1: |
186 | ERROR1: |
|
|
187 | if (res) |
|
|
188 | psiconv_error(config,lev,0,"Writing of word styles section failed"); |
|
|
189 | else |
|
|
190 | psiconv_progress(config,lev,0,"End of word styles section"); |
160 | return res; |
191 | return res; |
161 | } |
192 | } |