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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 168 - (hide annotations)
Tue Nov 25 17:57:05 2003 UTC (20 years, 4 months ago) by frodo
File MIME type: text/plain
File size: 5634 byte(s)
(Frodo) config stuff and image generation stuff

* All parse and generate functions have a new config parameter
* New files configuration.[ch] in the psiconv lib
* Some image generation stuff (not ready, but won't do any harm)

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

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