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

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

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

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

Legend:
Removed from v.73  
changed lines
  Added in v.270

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