/[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 73 - (hide annotations)
Sun Dec 24 16:03:57 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 4910 byte(s)
(Frodo) We should now have enough to generate TextEd sections!

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 allocated = 0;
32     int res;
33    
34     if (!value) {
35     psiconv_warn(0,0,"Can't parse to an empty buffer!");
36     return -PSICONV_E_OTHER;
37     }
38     if (!*buf) {
39     if (!(*buf = psiconv_new_buffer()))
40     return -PSICONV_E_NOMEM;
41     allocated = 1;
42     }
43    
44     #if 0
45     if (value->type == psiconv_word_file) {
46     if ((res =psiconv_write_word_file(*buf,(psiconv_word_f) (value->file))))
47     goto ERROR;
48     } else
49     #endif
50     if (value->type == psiconv_texted_file) {
51     if ((res =psiconv_write_texted_file(*buf,
52     (psiconv_texted_f) (value->file))))
53     goto ERROR;
54     #if 0
55     } else if (value->type == psiconv_sketch_file) {
56     if ((res =psiconv_write_texted_file(*buf,
57     (psiconv_sketch_f) (value->file))))
58     goto ERROR;
59     } else if (value->type == psiconv_mbm_file) {
60     if ((res =psiconv_write_texted_file(*buf,
61     (psiconv_mbm_f) (value->file))))
62     goto ERROR;
63     } else if (value->type == psiconv_clipart_file) {
64     if ((res =psiconv_write_texted_file(*buf,
65     (psiconv_clipart_f) (value->file))))
66     goto ERROR;
67     #endif
68     } else {
69     psiconv_warn(0,0,"Unknown or unsupported file type");
70     res = -PSICONV_E_GENERATE;
71     goto ERROR;
72     }
73     return -PSICONV_E_OK;
74    
75     ERROR:
76     if (allocated)
77     psiconv_free_buffer(*buf);
78     return res;
79     }
80    
81     int psiconv_write_texted_file(psiconv_buffer buf,psiconv_texted_f value)
82     {
83     psiconv_character_layout base_char;
84     psiconv_paragraph_layout base_para;
85     int res;
86     psiconv_buffer extra_buf;
87     psiconv_section_table_section section_table;
88     psiconv_section_table_entry entry;
89    
90     if (!value) {
91     psiconv_warn(0,0,"Null TextEd file");
92     return -PSICONV_E_GENERATE;
93     }
94    
95     if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
96     res = -PSICONV_E_NOMEM;
97     goto ERROR1;
98     }
99    
100     if (!(entry = malloc(sizeof(*entry)))) {
101     res = -PSICONV_E_NOMEM;
102     goto ERROR2;
103     }
104    
105     if (!(extra_buf = psiconv_new_buffer())) {
106     res = -PSICONV_E_NOMEM;
107     goto ERROR3;
108     }
109    
110     if (!(base_char = psiconv_basic_character_layout())) {
111     res = -PSICONV_E_NOMEM;
112     goto ERROR4;
113     }
114     if (!(base_para = psiconv_basic_paragraph_layout())) {
115     res = -PSICONV_E_NOMEM;
116     goto ERROR5;
117     }
118    
119     if ((res = psiconv_write_header_section(buf,PSICONV_ID_PSION5,
120     PSICONV_ID_DATA_FILE,
121     PSICONV_ID_TEXTED)))
122     goto ERROR6;
123    
124    
125     entry->id = PSICONV_ID_APPL_ID_SECTION;
126     entry->offset = psiconv_list_length(extra_buf) + 0x14;
127     if ((res = psiconv_list_add(section_table,&entry)))
128     goto ERROR6;
129     if ((res=psiconv_write_application_id_section(extra_buf,
130     PSICONV_ID_TEXTED,"TextEd.app")))
131     goto ERROR6;
132    
133     entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
134     entry->offset = psiconv_list_length(extra_buf) + 0x14;
135     if ((res = psiconv_list_add(section_table,&entry)))
136     goto ERROR6;
137     if ((res = psiconv_write_page_layout_section(extra_buf,value->page_sec)))
138     goto ERROR6;
139    
140     entry->id = PSICONV_ID_TEXTED;
141     entry->offset = psiconv_list_length(extra_buf) + 0x14;
142     if ((res = psiconv_list_add(section_table,&entry)))
143     goto ERROR6;
144     if ((res = psiconv_write_texted_section(extra_buf,value->texted_sec,
145     base_char,base_para)))
146     goto ERROR6;
147    
148     if ((res = psiconv_write_u32(buf,psiconv_list_length(extra_buf) + 0x14)))
149     goto ERROR6;
150    
151     if ((res = psiconv_list_concat(buf,extra_buf)))
152     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     psiconv_free_buffer(extra_buf);
162     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