/[public]/psiconv/trunk/lib/psiconv/generate_word.c
ViewVC logotype

Contents of /psiconv/trunk/lib/psiconv/generate_word.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 224 - (show annotations)
Mon Feb 23 17:23:58 2004 UTC (20 years, 1 month ago) by frodo
File MIME type: text/plain
File size: 6335 byte(s)
(Frodo) Solve a few small buglets

1 /*
2 generate_word.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 2000-2004 Frodo Looijaard <frodol@dds.nl>
4
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 #ifdef DMALLOC
29 #include <dmalloc.h>
30 #endif
31
32
33 int psiconv_write_word_status_section(const psiconv_config config,
34 psiconv_buffer buf, int lev,
35 psiconv_word_status_section value)
36 {
37 int res;
38
39 psiconv_progress(config,lev,0,"Writing word status section");
40
41 if (!value) {
42 psiconv_error(config,0,psiconv_buffer_length(buf),"Null word status section");
43 return -PSICONV_E_GENERATE;
44 }
45
46 if ((res = psiconv_write_u8(config,buf,lev+1,0x02)))
47 return res;
48 if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_tabs?0x01:0x00) |
49 (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 if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_full_pictures?0x01:0x00) |
56 (value->show_full_graphs?0x02:0x00))))
57 return res;
58 if ((res = psiconv_write_bool(config,buf,lev+1,value->show_top_toolbar)))
59 return res;
60 if ((res = psiconv_write_bool(config,buf,lev+1,value->show_side_toolbar)))
61 return res;
62 if ((res = psiconv_write_u8(config,buf,lev+1,(value->fit_lines_to_screen?0x08:0x00))))
63 return res;
64 if ((res = psiconv_write_u32(config,buf,lev+1,value->cursor_position)))
65 return res;
66 return psiconv_write_u32(config,buf,lev+1,value->display_size);
67 }
68
69 int psiconv_write_word_styles_section(const psiconv_config config,
70 psiconv_buffer buf, int lev,
71 psiconv_word_styles_section value)
72 {
73 int res,i,j;
74 psiconv_word_style style;
75 psiconv_paragraph_layout basepara;
76 psiconv_character_layout basechar;
77 psiconv_font font;
78 psiconv_u32 buflen;
79
80 psiconv_progress(config,lev,0,"Writing word styles section");
81
82 if (!value || !value->normal || !value->styles) {
83 psiconv_error(config,0,psiconv_buffer_length(buf),"Null word styles section");
84 res = -PSICONV_E_GENERATE;
85 goto ERROR1;
86 }
87
88 if (!(basepara=psiconv_basic_paragraph_layout())) {
89 res = -PSICONV_E_NOMEM;
90 goto ERROR1;
91 }
92
93 if (!(basechar=psiconv_basic_character_layout())) {
94 res = -PSICONV_E_NOMEM;
95 goto ERROR2;
96 }
97
98
99 if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1,value->normal->paragraph,
100 basepara)))
101 goto ERROR3;
102 /* Always generate the font for Normal */
103 font = basechar->font;
104 basechar->font = NULL;
105 res = psiconv_write_character_layout_list(config,buf,lev+1,value->normal->character,
106 basechar);
107 basechar->font = font;
108 if (res)
109 goto ERROR3;
110 buflen = psiconv_buffer_length(buf);
111 if ((res = psiconv_unicode_write_char(config,buf,lev+1,
112 value->normal->hotkey)))
113 goto ERROR3;
114 for (j = psiconv_buffer_length(buf) - buflen; j < 4; j++)
115 if ((res = psiconv_write_u8(config,buf,lev+1,0)))
116 goto ERROR3;
117
118 if ((res = psiconv_write_u8(config,buf,lev+1,psiconv_list_length(value->styles))))
119 goto ERROR3;
120
121
122
123 for (i = 0; i < psiconv_list_length(value->styles); i++) {
124 if (!(style = psiconv_list_get(value->styles,i))) {
125 psiconv_error(config,0,psiconv_buffer_length(buf),"Massive memory corruption");
126 res = -PSICONV_E_NOMEM;
127 goto ERROR3;
128 }
129 buflen = psiconv_buffer_length(buf);
130 if ((res = psiconv_unicode_write_char(config,buf,lev+1,style->hotkey)))
131 goto ERROR3;
132 for (j = psiconv_buffer_length(buf) - buflen; j < 4; j++)
133 if ((res = psiconv_write_u8(config,buf,lev+1,0)))
134 goto ERROR3;
135 }
136 if ((res = psiconv_write_u8(config,buf,lev+1,psiconv_list_length(value->styles))))
137 goto ERROR3;
138 for (i = 0; i < psiconv_list_length(value->styles); i++) {
139 if (!(style = psiconv_list_get(value->styles,i))) {
140 psiconv_error(config,0,psiconv_buffer_length(buf),"Massive memory corruption");
141 res = -PSICONV_E_NOMEM;
142 goto ERROR3;
143 }
144 if (!style->name) {
145 psiconv_error(config,0,psiconv_buffer_length(buf),"Null style name");
146 res = -PSICONV_E_GENERATE;
147 goto ERROR3;
148 }
149 if ((res = psiconv_write_string(config,buf,lev+1,style->name)))
150 goto ERROR3;
151 if ((res = psiconv_write_u32(config,buf,lev+1,style->built_in?PSICONV_ID_STYLE_BUILT_IN:
152 PSICONV_ID_STYLE_REMOVABLE)))
153 goto ERROR3;
154 if ((res = psiconv_write_u32(config,buf,lev+1,style->outline_level)))
155 goto ERROR3;
156 if ((res = psiconv_write_character_layout_list(config,buf,lev+1,style->character,
157 value->normal->character)))
158 goto ERROR3;
159 if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1,style->paragraph,
160 value->normal->paragraph)))
161 goto ERROR3;
162 }
163
164 for (i = 0; i < psiconv_list_length(value->styles); i++)
165 if ((res = psiconv_write_u8(config,buf,lev+1,0xff)))
166 goto ERROR3;
167 res = -PSICONV_E_OK;
168
169 ERROR3:
170 psiconv_free_character_layout(basechar);
171 ERROR2:
172 psiconv_free_paragraph_layout(basepara);
173 ERROR1:
174 return res;
175 }

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26