1 | /* |
1 | /* |
2 | generate_page.c - Part of psiconv, a PSION 5 file formats converter |
2 | generate_page.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. |
… | |
… | |
42 | psiconv_character_layout basechar; |
42 | psiconv_character_layout basechar; |
43 | |
43 | |
44 | psiconv_progress(config,lev,0,"Writing page header"); |
44 | psiconv_progress(config,lev,0,"Writing page header"); |
45 | |
45 | |
46 | if (!value) { |
46 | if (!value) { |
47 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null page header"); |
47 | psiconv_error(config,lev,0,"Null page header"); |
48 | res = -PSICONV_E_GENERATE; |
48 | res = -PSICONV_E_GENERATE; |
49 | goto ERROR1; |
49 | goto ERROR1; |
50 | } |
50 | } |
51 | |
51 | |
52 | if (!(basepara=psiconv_basic_paragraph_layout())) { |
52 | if (!(basepara=psiconv_basic_paragraph_layout())) { |
|
|
53 | psiconv_error(config,lev+1,0,"Out of memory error"); |
53 | res = -PSICONV_E_NOMEM; |
54 | res = -PSICONV_E_NOMEM; |
54 | goto ERROR1; |
55 | goto ERROR1; |
55 | } |
56 | } |
56 | if (!(basechar=psiconv_basic_character_layout())) { |
57 | if (!(basechar=psiconv_basic_character_layout())) { |
|
|
58 | psiconv_error(config,lev+1,0,"Out of memory error"); |
57 | res = -PSICONV_E_NOMEM; |
59 | res = -PSICONV_E_NOMEM; |
58 | goto ERROR2; |
60 | goto ERROR2; |
59 | } |
61 | } |
60 | |
62 | |
61 | /* Unknown byte */ |
63 | /* Unknown byte */ |
… | |
… | |
82 | ERROR3: |
84 | ERROR3: |
83 | psiconv_free_character_layout(basechar); |
85 | psiconv_free_character_layout(basechar); |
84 | ERROR2: |
86 | ERROR2: |
85 | psiconv_free_paragraph_layout(basepara); |
87 | psiconv_free_paragraph_layout(basepara); |
86 | ERROR1: |
88 | ERROR1: |
|
|
89 | if (res) |
|
|
90 | psiconv_error(config,lev,0,"Writing of page header failed"); |
|
|
91 | else |
|
|
92 | psiconv_progress(config,lev,0,"End of page header"); |
87 | return res; |
93 | return res; |
88 | } |
94 | } |
89 | |
95 | |
90 | int psiconv_write_page_layout_section(const psiconv_config config, |
96 | int psiconv_write_page_layout_section(const psiconv_config config, |
91 | psiconv_buffer buf, int lev, |
97 | psiconv_buffer buf, int lev, |
… | |
… | |
95 | psiconv_buffer header_buf,footer_buf; |
101 | psiconv_buffer header_buf,footer_buf; |
96 | |
102 | |
97 | psiconv_progress(config,lev,0,"Writing page layout section"); |
103 | psiconv_progress(config,lev,0,"Writing page layout section"); |
98 | |
104 | |
99 | if (!value) { |
105 | if (!value) { |
100 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null page section"); |
106 | psiconv_error(config,lev,0,"Null page section"); |
101 | res = -PSICONV_E_GENERATE; |
107 | res = -PSICONV_E_GENERATE; |
102 | goto ERROR1; |
108 | goto ERROR1; |
103 | } |
109 | } |
104 | |
110 | |
105 | if ((res = psiconv_write_u32(config,buf,lev+1,value->first_page_nr))) |
111 | if ((res = psiconv_write_u32(config,buf,lev+1,value->first_page_nr))) |
… | |
… | |
126 | goto ERROR3; |
132 | goto ERROR3; |
127 | if ((res = psiconv_write_length(config,buf,lev+1,value->page_height))) |
133 | if ((res = psiconv_write_length(config,buf,lev+1,value->page_height))) |
128 | goto ERROR3; |
134 | goto ERROR3; |
129 | if ((res = psiconv_write_bool(config,buf,lev+1,value->landscape))) |
135 | if ((res = psiconv_write_bool(config,buf,lev+1,value->landscape))) |
130 | goto ERROR3; |
136 | goto ERROR3; |
131 | if ((res = psiconv_buffer_concat(buf,header_buf))) |
137 | if ((res = psiconv_buffer_concat(buf,header_buf))) { |
|
|
138 | psiconv_error(config,lev+1,0,"Out of memory error"); |
132 | goto ERROR3; |
139 | goto ERROR3; |
|
|
140 | } |
133 | res = psiconv_buffer_concat(buf,footer_buf); |
141 | if ((res = psiconv_buffer_concat(buf,footer_buf))) { |
|
|
142 | psiconv_error(config,lev+1,0,"Out of memory error"); |
|
|
143 | goto ERROR3; |
|
|
144 | } |
134 | |
145 | |
135 | |
146 | |
136 | ERROR3: |
147 | ERROR3: |
137 | psiconv_buffer_free(footer_buf); |
148 | psiconv_buffer_free(footer_buf); |
138 | ERROR2: |
149 | ERROR2: |
139 | psiconv_buffer_free(header_buf); |
150 | psiconv_buffer_free(header_buf); |
140 | ERROR1: |
151 | ERROR1: |
|
|
152 | if (res) |
|
|
153 | psiconv_error(config,lev,0,"Writing of page layout section failed"); |
|
|
154 | else |
|
|
155 | psiconv_progress(config,lev,0,"End of page layout section"); |
141 | return res; |
156 | return res; |
142 | } |
157 | } |