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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 79 - (hide annotations)
Mon Dec 25 22:25:33 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 5139 byte(s)
(Frodo) Added a complete buffer abstraction

1 frodo 73 /*
2     generate_driver.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 "error.h"
26     #include "generate_routines.h"
27    
28    
29     int psiconv_write(psiconv_buffer *buf,const psiconv_file value)
30     {
31     int res;
32    
33     if (!value) {
34     psiconv_warn(0,0,"Can't parse to an empty buffer!");
35     return -PSICONV_E_OTHER;
36     }
37 frodo 79 if (!(*buf = psiconv_buffer_new(0)))
38 frodo 75 return -PSICONV_E_NOMEM;
39 frodo 73
40     #if 0
41     if (value->type == psiconv_word_file) {
42     if ((res =psiconv_write_word_file(*buf,(psiconv_word_f) (value->file))))
43     goto ERROR;
44     } else
45     #endif
46     if (value->type == psiconv_texted_file) {
47     if ((res =psiconv_write_texted_file(*buf,
48     (psiconv_texted_f) (value->file))))
49     goto ERROR;
50     #if 0
51     } else if (value->type == psiconv_sketch_file) {
52     if ((res =psiconv_write_texted_file(*buf,
53     (psiconv_sketch_f) (value->file))))
54     goto ERROR;
55     } else if (value->type == psiconv_mbm_file) {
56     if ((res =psiconv_write_texted_file(*buf,
57     (psiconv_mbm_f) (value->file))))
58     goto ERROR;
59     } else if (value->type == psiconv_clipart_file) {
60     if ((res =psiconv_write_texted_file(*buf,
61     (psiconv_clipart_f) (value->file))))
62     goto ERROR;
63     #endif
64     } else {
65     psiconv_warn(0,0,"Unknown or unsupported file type");
66     res = -PSICONV_E_GENERATE;
67     goto ERROR;
68     }
69     return -PSICONV_E_OK;
70    
71     ERROR:
72 frodo 79 psiconv_buffer_free(*buf);
73 frodo 73 return res;
74     }
75    
76     int psiconv_write_texted_file(psiconv_buffer buf,psiconv_texted_f value)
77     {
78     psiconv_character_layout base_char;
79     psiconv_paragraph_layout base_para;
80     int res;
81     psiconv_buffer extra_buf;
82     psiconv_section_table_section section_table;
83     psiconv_section_table_entry entry;
84    
85     if (!value) {
86     psiconv_warn(0,0,"Null TextEd file");
87     return -PSICONV_E_GENERATE;
88     }
89    
90     if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
91     res = -PSICONV_E_NOMEM;
92     goto ERROR1;
93     }
94    
95     if (!(entry = malloc(sizeof(*entry)))) {
96     res = -PSICONV_E_NOMEM;
97     goto ERROR2;
98     }
99    
100 frodo 79 /* Base offset is 0x18: 0x10 header section plus the section table offset */
101     if (!(extra_buf = psiconv_buffer_new(0x14))) {
102 frodo 73 res = -PSICONV_E_NOMEM;
103     goto ERROR3;
104     }
105    
106     if (!(base_char = psiconv_basic_character_layout())) {
107     res = -PSICONV_E_NOMEM;
108     goto ERROR4;
109     }
110     if (!(base_para = psiconv_basic_paragraph_layout())) {
111     res = -PSICONV_E_NOMEM;
112     goto ERROR5;
113     }
114    
115     if ((res = psiconv_write_header_section(buf,PSICONV_ID_PSION5,
116     PSICONV_ID_DATA_FILE,
117     PSICONV_ID_TEXTED)))
118     goto ERROR6;
119    
120    
121     entry->id = PSICONV_ID_APPL_ID_SECTION;
122 frodo 79 entry->offset = psiconv_buffer_length(extra_buf) +
123     psiconv_buffer_base_offset(extra_buf);
124 frodo 76 if ((res = psiconv_list_add(section_table,entry)))
125 frodo 73 goto ERROR6;
126     if ((res=psiconv_write_application_id_section(extra_buf,
127     PSICONV_ID_TEXTED,"TextEd.app")))
128     goto ERROR6;
129    
130     entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
131 frodo 79 entry->offset = psiconv_buffer_length(extra_buf) +
132     psiconv_buffer_base_offset(extra_buf);
133 frodo 76 if ((res = psiconv_list_add(section_table,entry)))
134 frodo 73 goto ERROR6;
135     if ((res = psiconv_write_page_layout_section(extra_buf,value->page_sec)))
136     goto ERROR6;
137    
138     entry->id = PSICONV_ID_TEXTED;
139 frodo 79 entry->offset = psiconv_buffer_length(extra_buf) +
140     psiconv_buffer_base_offset(extra_buf);
141 frodo 76 if ((res = psiconv_list_add(section_table,entry)))
142 frodo 73 goto ERROR6;
143     if ((res = psiconv_write_texted_section(extra_buf,value->texted_sec,
144     base_char,base_para)))
145     goto ERROR6;
146    
147 frodo 79 if ((res = psiconv_write_u32(buf,psiconv_buffer_length(extra_buf) +
148     psiconv_buffer_base_offset(extra_buf))))
149 frodo 73 goto ERROR6;
150    
151 frodo 79 if ((res = psiconv_buffer_concat(buf,extra_buf)))
152 frodo 73 goto ERROR6;
153    
154     res = psiconv_write_section_table_section(buf,section_table);
155    
156     ERROR6:
157     psiconv_free_paragraph_layout(base_para);
158     ERROR5:
159     psiconv_free_character_layout(base_char);
160     ERROR4:
161 frodo 79 psiconv_buffer_free(extra_buf);
162 frodo 73 ERROR3:
163     free(entry);
164     ERROR2:
165     psiconv_list_free(section_table);
166     ERROR1:
167     return res;
168     }

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