1 |
frodo |
76 |
/* |
2 |
|
|
generate_word.c - Part of psiconv, a PSION 5 file formats converter |
3 |
frodo |
196 |
Copyright (c) 2000-2004 Frodo Looijaard <frodol@dds.nl> |
4 |
frodo |
76 |
|
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 |
7 |
|
|
the Free Software Foundation; either version 2 of the License, or |
8 |
|
|
(at your option) any later version. |
9 |
|
|
|
10 |
|
|
This program is distributed in the hope that it will be useful, |
11 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
GNU General Public License for more details. |
14 |
|
|
|
15 |
|
|
You should have received a copy of the GNU General Public License |
16 |
|
|
along with this program; if not, write to the Free Software |
17 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 |
|
|
*/ |
19 |
|
|
|
20 |
|
|
#include "config.h" |
21 |
|
|
#include "compat.h" |
22 |
|
|
|
23 |
|
|
#include <stdlib.h> |
24 |
|
|
|
25 |
|
|
#include "generate_routines.h" |
26 |
|
|
#include "error.h" |
27 |
|
|
|
28 |
frodo |
142 |
#ifdef DMALLOC |
29 |
|
|
#include <dmalloc.h> |
30 |
|
|
#endif |
31 |
|
|
|
32 |
|
|
|
33 |
frodo |
168 |
int psiconv_write_word_status_section(const psiconv_config config, |
34 |
frodo |
184 |
psiconv_buffer buf, int lev, |
35 |
frodo |
168 |
psiconv_word_status_section value) |
36 |
frodo |
76 |
{ |
37 |
|
|
int res; |
38 |
|
|
|
39 |
frodo |
184 |
psiconv_progress(config,lev,0,"Writing word status section"); |
40 |
|
|
|
41 |
frodo |
76 |
if (!value) { |
42 |
frodo |
184 |
psiconv_error(config,0,psiconv_buffer_length(buf),"Null word status section"); |
43 |
frodo |
76 |
return -PSICONV_E_GENERATE; |
44 |
|
|
} |
45 |
|
|
|
46 |
frodo |
184 |
if ((res = psiconv_write_u8(config,buf,lev+1,0x02))) |
47 |
frodo |
76 |
return res; |
48 |
frodo |
184 |
if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_tabs?0x01:0x00) | |
49 |
frodo |
76 |
(value->show_spaces?0x02:0x00) | |
50 |
|
|
(value->show_paragraph_ends?0x04:0x00) | |
51 |
|
|
(value->show_line_breaks?0x08:0x00) | |
52 |
|
|
(value->show_hard_minus?0x20:0x00) | |
53 |
|
|
(value->show_hard_space?0x40:0x00)))) |
54 |
|
|
return res; |
55 |
frodo |
184 |
if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_full_pictures?0x01:0x00) | |
56 |
frodo |
76 |
(value->show_full_graphs?0x02:0x00)))) |
57 |
|
|
return res; |
58 |
frodo |
184 |
if ((res = psiconv_write_bool(config,buf,lev+1,value->show_top_toolbar))) |
59 |
frodo |
76 |
return res; |
60 |
frodo |
184 |
if ((res = psiconv_write_bool(config,buf,lev+1,value->show_side_toolbar))) |
61 |
frodo |
76 |
return res; |
62 |
frodo |
184 |
if ((res = psiconv_write_u8(config,buf,lev+1,(value->fit_lines_to_screen?0x08:0x00)))) |
63 |
frodo |
76 |
return res; |
64 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,value->cursor_position))) |
65 |
frodo |
76 |
return res; |
66 |
frodo |
184 |
return psiconv_write_u32(config,buf,lev+1,value->display_size); |
67 |
frodo |
76 |
} |
68 |
|
|
|
69 |
frodo |
168 |
int psiconv_write_word_styles_section(const psiconv_config config, |
70 |
frodo |
184 |
psiconv_buffer buf, int lev, |
71 |
frodo |
76 |
psiconv_word_styles_section value) |
72 |
|
|
{ |
73 |
|
|
int res,i; |
74 |
|
|
psiconv_word_style style; |
75 |
|
|
psiconv_paragraph_layout basepara; |
76 |
|
|
psiconv_character_layout basechar; |
77 |
frodo |
85 |
psiconv_font font; |
78 |
frodo |
76 |
|
79 |
frodo |
184 |
psiconv_progress(config,lev,0,"Writing word styles section"); |
80 |
frodo |
76 |
|
81 |
|
|
if (!value || !value->normal || !value->styles) { |
82 |
frodo |
184 |
psiconv_error(config,0,psiconv_buffer_length(buf),"Null word styles section"); |
83 |
frodo |
76 |
res = -PSICONV_E_GENERATE; |
84 |
|
|
goto ERROR1; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
if (!(basepara=psiconv_basic_paragraph_layout())) { |
88 |
|
|
res = -PSICONV_E_NOMEM; |
89 |
|
|
goto ERROR1; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
if (!(basechar=psiconv_basic_character_layout())) { |
93 |
|
|
res = -PSICONV_E_NOMEM; |
94 |
|
|
goto ERROR2; |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
|
98 |
frodo |
184 |
if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1,value->normal->paragraph, |
99 |
frodo |
76 |
basepara))) |
100 |
|
|
goto ERROR3; |
101 |
frodo |
85 |
/* Always generate the font for Normal */ |
102 |
|
|
font = basechar->font; |
103 |
|
|
basechar->font = NULL; |
104 |
frodo |
184 |
res = psiconv_write_character_layout_list(config,buf,lev+1,value->normal->character, |
105 |
frodo |
85 |
basechar); |
106 |
|
|
basechar->font = font; |
107 |
|
|
if (res) |
108 |
frodo |
76 |
goto ERROR3; |
109 |
frodo |
217 |
if ((res = psiconv_unicode_write_char(config,buf,lev+1, |
110 |
|
|
value->normal->hotkey))) |
111 |
frodo |
76 |
goto ERROR3; |
112 |
frodo |
184 |
if ((res = psiconv_write_u8(config,buf,lev+1,psiconv_list_length(value->styles)))) |
113 |
frodo |
76 |
goto ERROR3; |
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
for (i = 0; i < psiconv_list_length(value->styles); i++) { |
118 |
|
|
if (!(style = psiconv_list_get(value->styles,i))) { |
119 |
frodo |
184 |
psiconv_error(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
120 |
|
|
res = -PSICONV_E_NOMEM; |
121 |
frodo |
76 |
goto ERROR3; |
122 |
|
|
} |
123 |
frodo |
217 |
if ((res = psiconv_unicode_write_char(config,buf,lev+1,style->hotkey))) |
124 |
frodo |
76 |
goto ERROR3; |
125 |
|
|
} |
126 |
frodo |
184 |
if ((res = psiconv_write_u8(config,buf,lev+1,psiconv_list_length(value->styles)))) |
127 |
frodo |
76 |
goto ERROR3; |
128 |
|
|
for (i = 0; i < psiconv_list_length(value->styles); i++) { |
129 |
|
|
if (!(style = psiconv_list_get(value->styles,i))) { |
130 |
frodo |
184 |
psiconv_error(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
131 |
|
|
res = -PSICONV_E_NOMEM; |
132 |
frodo |
76 |
goto ERROR3; |
133 |
|
|
} |
134 |
|
|
if (!style->name) { |
135 |
frodo |
184 |
psiconv_error(config,0,psiconv_buffer_length(buf),"Null style name"); |
136 |
frodo |
76 |
res = -PSICONV_E_GENERATE; |
137 |
|
|
goto ERROR3; |
138 |
|
|
} |
139 |
frodo |
184 |
if ((res = psiconv_write_string(config,buf,lev+1,style->name))) |
140 |
frodo |
76 |
goto ERROR3; |
141 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,style->built_in?PSICONV_ID_STYLE_BUILT_IN: |
142 |
frodo |
76 |
PSICONV_ID_STYLE_REMOVABLE))) |
143 |
|
|
goto ERROR3; |
144 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,style->outline_level))) |
145 |
frodo |
76 |
goto ERROR3; |
146 |
frodo |
184 |
if ((res = psiconv_write_character_layout_list(config,buf,lev+1,style->character, |
147 |
frodo |
76 |
value->normal->character))) |
148 |
|
|
goto ERROR3; |
149 |
frodo |
184 |
if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1,style->paragraph, |
150 |
frodo |
76 |
value->normal->paragraph))) |
151 |
|
|
goto ERROR3; |
152 |
|
|
} |
153 |
|
|
|
154 |
frodo |
83 |
for (i = 0; i < psiconv_list_length(value->styles); i++) |
155 |
frodo |
184 |
if ((res = psiconv_write_u8(config,buf,lev+1,0xff))) |
156 |
frodo |
83 |
goto ERROR3; |
157 |
|
|
res = -PSICONV_E_OK; |
158 |
|
|
|
159 |
frodo |
76 |
ERROR3: |
160 |
|
|
psiconv_free_character_layout(basechar); |
161 |
|
|
ERROR2: |
162 |
|
|
psiconv_free_paragraph_layout(basepara); |
163 |
|
|
ERROR1: |
164 |
|
|
return res; |
165 |
|
|
} |