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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.142  
changed lines
  Added in v.231

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