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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 231 - (show annotations)
Wed Feb 25 20:57:10 2004 UTC (20 years, 1 month ago) by frodo
File MIME type: text/plain
File size: 5002 byte(s)
(Frodo) Progress information while generating update

Much better progress information now, and better error reporting.

1 /*
2 generate_page.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 #include <string.h>
25
26 #include "generate_routines.h"
27 #include "error.h"
28
29 #ifdef DMALLOC
30 #include <dmalloc.h>
31 #endif
32
33
34
35 int psiconv_write_page_header(const psiconv_config config,
36 psiconv_buffer buf, int lev,
37 const psiconv_page_header value,
38 psiconv_buffer *extra_buf)
39 {
40 int res;
41 psiconv_paragraph_layout basepara;
42 psiconv_character_layout basechar;
43
44 psiconv_progress(config,lev,0,"Writing page header");
45
46 if (!value) {
47 psiconv_error(config,lev,0,"Null page header");
48 res = -PSICONV_E_GENERATE;
49 goto ERROR1;
50 }
51
52 if (!(basepara=psiconv_basic_paragraph_layout())) {
53 res = -PSICONV_E_NOMEM;
54 goto ERROR1;
55 }
56 if (!(basechar=psiconv_basic_character_layout())) {
57 res = -PSICONV_E_NOMEM;
58 goto ERROR2;
59 }
60
61 /* Unknown byte */
62 if ((res = psiconv_write_u8(config,buf,lev+1,0x01)))
63 goto ERROR3;
64 if ((res = psiconv_write_bool(config,buf,lev+1,value->on_first_page)))
65 goto ERROR3;
66 /* Three unknown bytes */
67 if ((res = psiconv_write_u8(config,buf,lev+1,0x00)))
68 goto ERROR3;
69 if ((res = psiconv_write_u8(config,buf,lev+1,0x00)))
70 goto ERROR3;
71 if ((res = psiconv_write_u8(config,buf,lev+1,0x00)))
72 goto ERROR3;
73 if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1,
74 value->base_paragraph_layout,basepara)))
75 goto ERROR3;
76 if ((res = psiconv_write_character_layout_list(config,buf,lev+1,
77 value->base_character_layout,basechar)))
78 goto ERROR3;
79 res = psiconv_write_texted_section(config,buf,lev+1,value->text,
80 value->base_character_layout,
81 value->base_paragraph_layout,extra_buf);
82 ERROR3:
83 psiconv_free_character_layout(basechar);
84 ERROR2:
85 psiconv_free_paragraph_layout(basepara);
86 ERROR1:
87 if (res)
88 psiconv_error(config,lev,0,"Writing of page header failed");
89 else
90 psiconv_progress(config,lev,0,"End of page header");
91 return res;
92 }
93
94 int psiconv_write_page_layout_section(const psiconv_config config,
95 psiconv_buffer buf, int lev,
96 const psiconv_page_layout_section value)
97 {
98 int res;
99 psiconv_buffer header_buf,footer_buf;
100
101 psiconv_progress(config,lev,0,"Writing page layout section");
102
103 if (!value) {
104 psiconv_error(config,lev,0,"Null page section");
105 res = -PSICONV_E_GENERATE;
106 goto ERROR1;
107 }
108
109 if ((res = psiconv_write_u32(config,buf,lev+1,value->first_page_nr)))
110 goto ERROR1;
111 if ((res = psiconv_write_length(config,buf,lev+1,value->header_dist)))
112 goto ERROR1;
113 if ((res = psiconv_write_length(config,buf,lev+1,value->footer_dist)))
114 goto ERROR1;
115 if ((res = psiconv_write_length(config,buf,lev+1,value->left_margin)))
116 goto ERROR1;
117 if ((res = psiconv_write_length(config,buf,lev+1,value->right_margin)))
118 goto ERROR1;
119 if ((res = psiconv_write_length(config,buf,lev+1,value->top_margin)))
120 goto ERROR1;
121 if ((res = psiconv_write_length(config,buf,lev+1,value->bottom_margin)))
122 goto ERROR1;
123 if ((res = psiconv_write_page_header(config,buf,lev+1,value->header,&header_buf)))
124 goto ERROR1;
125 if ((res = psiconv_write_page_header(config,buf,lev+1,value->footer,&footer_buf)))
126 goto ERROR2;
127 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_PAGE_DIMENSIONS2)))
128 goto ERROR3;
129 if ((res = psiconv_write_length(config,buf,lev+1,value->page_width)))
130 goto ERROR3;
131 if ((res = psiconv_write_length(config,buf,lev+1,value->page_height)))
132 goto ERROR3;
133 if ((res = psiconv_write_bool(config,buf,lev+1,value->landscape)))
134 goto ERROR3;
135 if ((res = psiconv_buffer_concat(buf,header_buf)))
136 goto ERROR3;
137 res = psiconv_buffer_concat(buf,footer_buf);
138
139
140 ERROR3:
141 psiconv_buffer_free(footer_buf);
142 ERROR2:
143 psiconv_buffer_free(header_buf);
144 ERROR1:
145 if (res)
146 psiconv_error(config,lev,0,"Writing of page layout section failed");
147 else
148 psiconv_progress(config,lev,0,"End of page layout section");
149 return res;
150 }

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