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-2004 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. |
… | |
… | |
37 | int res; |
37 | int res; |
38 | |
38 | |
39 | psiconv_progress(config,lev,0,"Writing word status section"); |
39 | psiconv_progress(config,lev,0,"Writing word status section"); |
40 | |
40 | |
41 | if (!value) { |
41 | if (!value) { |
42 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null word status section"); |
42 | psiconv_error(config,lev,0,"Null word status section"); |
43 | return -PSICONV_E_GENERATE; |
43 | res = -PSICONV_E_GENERATE; |
|
|
44 | goto ERROR; |
44 | } |
45 | } |
45 | |
46 | |
46 | if ((res = psiconv_write_u8(config,buf,lev+1,0x02))) |
47 | if ((res = psiconv_write_u8(config,buf,lev+1,0x02))) |
47 | return res; |
48 | goto ERROR; |
48 | if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_tabs?0x01:0x00) | |
49 | if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_tabs?0x01:0x00) | |
49 | (value->show_spaces?0x02:0x00) | |
50 | (value->show_spaces?0x02:0x00) | |
50 | (value->show_paragraph_ends?0x04:0x00) | |
51 | (value->show_paragraph_ends?0x04:0x00) | |
51 | (value->show_line_breaks?0x08:0x00) | |
52 | (value->show_line_breaks?0x08:0x00) | |
52 | (value->show_hard_minus?0x20:0x00) | |
53 | (value->show_hard_minus?0x20:0x00) | |
53 | (value->show_hard_space?0x40:0x00)))) |
54 | (value->show_hard_space?0x40:0x00)))) |
54 | return res; |
55 | goto ERROR; |
55 | if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_full_pictures?0x01:0x00) | |
56 | if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_full_pictures?0x01:0x00) | |
56 | (value->show_full_graphs?0x02:0x00)))) |
57 | (value->show_full_graphs?0x02:0x00)))) |
57 | return res; |
58 | goto ERROR; |
58 | if ((res = psiconv_write_bool(config,buf,lev+1,value->show_top_toolbar))) |
59 | if ((res = psiconv_write_bool(config,buf,lev+1,value->show_top_toolbar))) |
59 | return res; |
60 | goto ERROR; |
60 | if ((res = psiconv_write_bool(config,buf,lev+1,value->show_side_toolbar))) |
61 | if ((res = psiconv_write_bool(config,buf,lev+1,value->show_side_toolbar))) |
61 | return res; |
62 | goto ERROR; |
62 | if ((res = psiconv_write_u8(config,buf,lev+1,(value->fit_lines_to_screen?0x08:0x00)))) |
63 | if ((res = psiconv_write_u8(config,buf,lev+1,(value->fit_lines_to_screen?0x08:0x00)))) |
63 | return res; |
64 | goto ERROR; |
64 | if ((res = psiconv_write_u32(config,buf,lev+1,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"); |
65 | return res; |
74 | return res; |
66 | return psiconv_write_u32(config,buf,lev+1,value->display_size); |
|
|
67 | } |
75 | } |
68 | |
76 | |
69 | int psiconv_write_word_styles_section(const psiconv_config config, |
77 | int psiconv_write_word_styles_section(const psiconv_config config, |
70 | psiconv_buffer buf, int lev, |
78 | psiconv_buffer buf, int lev, |
71 | psiconv_word_styles_section value) |
79 | psiconv_word_styles_section value) |
… | |
… | |
78 | psiconv_u32 buflen; |
86 | psiconv_u32 buflen; |
79 | |
87 | |
80 | psiconv_progress(config,lev,0,"Writing word styles section"); |
88 | psiconv_progress(config,lev,0,"Writing word styles section"); |
81 | |
89 | |
82 | if (!value || !value->normal || !value->styles) { |
90 | if (!value || !value->normal || !value->styles) { |
83 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null word styles section"); |
91 | psiconv_error(config,lev,0,"Null word styles section"); |
84 | res = -PSICONV_E_GENERATE; |
92 | res = -PSICONV_E_GENERATE; |
85 | goto ERROR1; |
93 | goto ERROR1; |
86 | } |
94 | } |
87 | |
95 | |
88 | if (!(basepara=psiconv_basic_paragraph_layout())) { |
96 | if (!(basepara=psiconv_basic_paragraph_layout())) { |
|
|
97 | psiconv_error(config,lev+1,0,"Out of memory error"); |
89 | res = -PSICONV_E_NOMEM; |
98 | res = -PSICONV_E_NOMEM; |
90 | goto ERROR1; |
99 | goto ERROR1; |
91 | } |
100 | } |
92 | |
101 | |
93 | if (!(basechar=psiconv_basic_character_layout())) { |
102 | if (!(basechar=psiconv_basic_character_layout())) { |
|
|
103 | psiconv_error(config,lev+1,0,"Out of memory error"); |
94 | res = -PSICONV_E_NOMEM; |
104 | res = -PSICONV_E_NOMEM; |
95 | goto ERROR2; |
105 | goto ERROR2; |
96 | } |
106 | } |
97 | |
107 | |
98 | |
108 | |
99 | if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1,value->normal->paragraph, |
109 | if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1, |
|
|
110 | value->normal->paragraph, |
100 | basepara))) |
111 | basepara))) |
101 | goto ERROR3; |
112 | goto ERROR3; |
102 | /* Always generate the font for Normal */ |
113 | /* Always generate the font for Normal */ |
103 | font = basechar->font; |
114 | font = basechar->font; |
104 | basechar->font = NULL; |
115 | basechar->font = NULL; |
105 | res = psiconv_write_character_layout_list(config,buf,lev+1,value->normal->character, |
116 | res = psiconv_write_character_layout_list(config,buf,lev+1, |
|
|
117 | value->normal->character, |
106 | basechar); |
118 | basechar); |
107 | basechar->font = font; |
119 | basechar->font = font; |
108 | if (res) |
120 | if (res) |
109 | goto ERROR3; |
121 | goto ERROR3; |
110 | buflen = psiconv_buffer_length(buf); |
122 | buflen = psiconv_buffer_length(buf); |
111 | if ((res = psiconv_unicode_write_char(config,buf,lev+1, |
123 | if ((res = psiconv_unicode_write_char(config,buf,lev+1, |
… | |
… | |
113 | goto ERROR3; |
125 | goto ERROR3; |
114 | for (j = psiconv_buffer_length(buf) - buflen; j < 4; j++) |
126 | for (j = psiconv_buffer_length(buf) - buflen; j < 4; j++) |
115 | if ((res = psiconv_write_u8(config,buf,lev+1,0))) |
127 | if ((res = psiconv_write_u8(config,buf,lev+1,0))) |
116 | goto ERROR3; |
128 | goto ERROR3; |
117 | |
129 | |
118 | if ((res = psiconv_write_u8(config,buf,lev+1,psiconv_list_length(value->styles)))) |
130 | if ((res = psiconv_write_u8(config,buf,lev+1, |
|
|
131 | psiconv_list_length(value->styles)))) |
119 | goto ERROR3; |
132 | goto ERROR3; |
120 | |
133 | |
121 | |
134 | |
122 | |
135 | |
123 | for (i = 0; i < psiconv_list_length(value->styles); i++) { |
136 | for (i = 0; i < psiconv_list_length(value->styles); i++) { |
124 | if (!(style = psiconv_list_get(value->styles,i))) { |
137 | if (!(style = psiconv_list_get(value->styles,i))) { |
125 | psiconv_error(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
138 | psiconv_error(config,lev,0,"Data structure corruption"); |
126 | res = -PSICONV_E_NOMEM; |
139 | res = -PSICONV_E_NOMEM; |
127 | goto ERROR3; |
140 | goto ERROR3; |
128 | } |
141 | } |
129 | buflen = psiconv_buffer_length(buf); |
142 | buflen = psiconv_buffer_length(buf); |
130 | if ((res = psiconv_unicode_write_char(config,buf,lev+1,style->hotkey))) |
143 | if ((res = psiconv_unicode_write_char(config,buf,lev+1,style->hotkey))) |
… | |
… | |
135 | } |
148 | } |
136 | if ((res = psiconv_write_u8(config,buf,lev+1,psiconv_list_length(value->styles)))) |
149 | if ((res = psiconv_write_u8(config,buf,lev+1,psiconv_list_length(value->styles)))) |
137 | goto ERROR3; |
150 | goto ERROR3; |
138 | for (i = 0; i < psiconv_list_length(value->styles); i++) { |
151 | for (i = 0; i < psiconv_list_length(value->styles); i++) { |
139 | if (!(style = psiconv_list_get(value->styles,i))) { |
152 | if (!(style = psiconv_list_get(value->styles,i))) { |
140 | psiconv_error(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
153 | psiconv_error(config,lev,0,"Data structure corruption"); |
141 | res = -PSICONV_E_NOMEM; |
154 | res = -PSICONV_E_NOMEM; |
142 | goto ERROR3; |
155 | goto ERROR3; |
143 | } |
156 | } |
144 | if (!style->name) { |
157 | if (!style->name) { |
145 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null style name"); |
158 | psiconv_error(config,lev,0,"Null style name"); |
146 | res = -PSICONV_E_GENERATE; |
159 | res = -PSICONV_E_GENERATE; |
147 | goto ERROR3; |
160 | goto ERROR3; |
148 | } |
161 | } |
149 | if ((res = psiconv_write_string(config,buf,lev+1,style->name))) |
162 | if ((res = psiconv_write_string(config,buf,lev+1,style->name))) |
150 | goto ERROR3; |
163 | goto ERROR3; |
… | |
… | |
169 | ERROR3: |
182 | ERROR3: |
170 | psiconv_free_character_layout(basechar); |
183 | psiconv_free_character_layout(basechar); |
171 | ERROR2: |
184 | ERROR2: |
172 | psiconv_free_paragraph_layout(basepara); |
185 | psiconv_free_paragraph_layout(basepara); |
173 | 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"); |
174 | return res; |
191 | return res; |
175 | } |
192 | } |