/[public]/psiconv/trunk/program/psiconv/gen_txt.c
ViewVC logotype

Annotation of /psiconv/trunk/program/psiconv/gen_txt.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 351 - (hide annotations)
Wed Oct 22 19:53:40 2014 UTC (9 years, 5 months ago) by frodo
File MIME type: text/plain
File size: 6226 byte(s)
(Frodo) Update copyright year in all source files

1 frodo 14 /*
2     * gen_text.c - Part of psiconv, a PSION 5 file formats converter
3     * Copyright (c) 1999 Andrew Johnson <anjohnson@iee.org>
4 frodo 351 * Portions Copyright (c) 1999-2014 Frodo Looijaard <frodo@frodo.looijaard.name>
5 frodo 14 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21     #include "config.h"
22     #include <stdio.h>
23     #include <string.h>
24 frodo 185 #include <psiconv/data.h>
25     #include <psiconv/list.h>
26     #include <psiconv/unicode.h>
27     #include "general.h"
28 frodo 14 #include "gen.h"
29 frodo 34 #include "psiconv.h"
30 frodo 14
31 frodo 142 #ifdef DMALLOC
32     #include "dmalloc.h"
33     #endif
34 frodo 14
35 frodo 185 static void output_para(const psiconv_config config,psiconv_list list,
36     const psiconv_paragraph para,encoding encoding_type);
37 frodo 192 static void gen_word(const psiconv_config config, psiconv_list list,
38 frodo 185 psiconv_word_f wf, encoding encoding_type);
39 frodo 192 static void gen_texted(const psiconv_config config, psiconv_list list,
40 frodo 185 psiconv_texted_f tf, encoding encoding_type);
41     static int gen_txt(const psiconv_config config, psiconv_list list,
42     const psiconv_file file, const char *dest,
43     const encoding encoding_type);
44 frodo 142
45 frodo 185 static struct fileformat_s ff =
46     {
47     "ASCII",
48     "Plain text without much layout",
49 frodo 192 FORMAT_WORD | FORMAT_TEXTED,
50 frodo 185 gen_txt
51     };
52 frodo 14
53    
54 frodo 185 void output_para(const psiconv_config config,psiconv_list list,
55     const psiconv_paragraph para,encoding encoding_type)
56     {
57     int i;
58     if (para && para->base_paragraph && para->base_paragraph->bullet &&
59     para->base_paragraph->bullet->on) {
60     output_char(config,list,para->base_paragraph->bullet->character,
61     encoding_type);
62     output_char(config,list,' ', encoding_type);
63     output_char(config,list,' ', encoding_type);
64     output_char(config,list,' ', encoding_type);
65     }
66     if (para && para->text) {
67     for (i = 0; i < psiconv_unicode_strlen(para->text); i++)
68     switch (para->text[i]) {
69     case 0x06:
70     case 0x07:
71     case 0x08:
72     output_char(config,list,'\n',encoding_type);
73     break;
74     case 0x09:
75     case 0x0a:
76     output_char(config,list,'\t',encoding_type);
77     break;
78     case 0x0b:
79     case 0x0c:
80     output_char(config,list,'-',encoding_type);
81     break;
82     case 0x0f:
83     output_char(config,list,' ',encoding_type);
84     break;
85     case 0x00:
86     case 0x01:
87     case 0x02:
88     case 0x03:
89     case 0x04:
90     case 0x05:
91     case 0x0e:
92     case 0x10:
93     case 0x11:
94     case 0x12:
95     case 0x13:
96     case 0x14:
97     case 0x15:
98     case 0x16:
99     case 0x17:
100     case 0x18:
101     case 0x19:
102     case 0x1a:
103     case 0x1c:
104     case 0x1d:
105     case 0x1e:
106     case 0x1f:
107     break;
108     default:
109     output_char(config,list,para->text[i],encoding_type);
110     break;
111     }
112     output_char(config,list,'\n',encoding_type);
113     }
114     }
115 frodo 14
116 frodo 192 void gen_word(const psiconv_config config, psiconv_list list,
117 frodo 185 psiconv_word_f wf, encoding encoding_type)
118     {
119     int i;
120     psiconv_paragraph para;
121 frodo 147
122 frodo 185 if (wf && wf->page_sec && wf->page_sec->header &&
123     wf->page_sec->header->text && wf->page_sec->header->text->paragraphs) {
124     for (i=0;
125     i < psiconv_list_length(wf->page_sec->header->
126     text->paragraphs); i++) {
127     para = psiconv_list_get(wf->page_sec->header->text->paragraphs,
128     i);
129     output_para(config,list,para,encoding_type);
130 frodo 147 }
131 frodo 185 }
132     output_char(config,list,'\n',encoding_type);
133 frodo 14
134 frodo 185 if (wf && wf->paragraphs)
135     for (i=0; i < psiconv_list_length(wf->paragraphs); i++) {
136     para = psiconv_list_get(wf->paragraphs, i);
137     output_para(config, list,para,encoding_type);
138     }
139    
140     output_char(config,list,'\n',encoding_type);
141 frodo 14
142 frodo 185 if (wf && wf->page_sec && wf->page_sec->footer &&
143     wf->page_sec->footer->text && wf->page_sec->footer->text->paragraphs) {
144     for (i=0;
145     i < psiconv_list_length(wf->page_sec->footer->
146     text->paragraphs); i++) {
147     para = psiconv_list_get(wf->page_sec->footer->text->paragraphs, i);
148     output_para(config,list,para,encoding_type);
149 frodo 14 }
150 frodo 185 }
151 frodo 14 }
152    
153 frodo 192 void gen_texted(const psiconv_config config, psiconv_list list,
154 frodo 185 psiconv_texted_f tf, encoding encoding_type)
155 frodo 14 {
156 frodo 185 int i;
157     psiconv_paragraph para;
158 frodo 14
159 frodo 185 if (tf && tf->page_sec && tf->page_sec->header &&
160     tf->page_sec->header->text && tf->page_sec->header->text->paragraphs) {
161     for (i=0;
162     i < psiconv_list_length(tf->page_sec->header->
163     text->paragraphs); i++) {
164     para = psiconv_list_get(tf->page_sec->header->text->paragraphs,
165     i);
166     output_para(config,list,para,encoding_type);
167 frodo 14 }
168 frodo 185 }
169     output_char(config,list,'\n',encoding_type);
170 frodo 14
171 frodo 185 if (tf && tf->texted_sec && tf->texted_sec->paragraphs)
172 frodo 14 for (i=0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) {
173 frodo 185 para = psiconv_list_get(tf->texted_sec->paragraphs, i);
174     output_para(config, list,para,encoding_type);
175     }
176 frodo 14
177 frodo 185 output_char(config,list,'\n',encoding_type);
178 frodo 14
179 frodo 185 if (tf && tf->page_sec && tf->page_sec->footer &&
180     tf->page_sec->footer->text && tf->page_sec->footer->text->paragraphs) {
181     for (i=0;
182     i < psiconv_list_length(tf->page_sec->footer->
183     text->paragraphs); i++) {
184     para = psiconv_list_get(tf->page_sec->footer->text->paragraphs, i);
185     output_para(config,list,para,encoding_type);
186 frodo 14 }
187 frodo 185 }
188 frodo 14 }
189    
190 frodo 185 int gen_txt(const psiconv_config config, psiconv_list list,
191     const psiconv_file file, const char *dest,
192     const encoding encoding_type)
193 frodo 14 {
194 frodo 34 if (file->type == psiconv_word_file) {
195 frodo 192 gen_word(config,list,(psiconv_word_f) file->file,encoding_type);
196 frodo 185 return 0;
197 frodo 34 } else if (file->type == psiconv_texted_file) {
198 frodo 192 gen_texted(config,list,(psiconv_texted_f) file->file,encoding_type);
199 frodo 185 return 0;
200     } else
201 frodo 53 return -1;
202 frodo 14 }
203    
204 frodo 34 void init_txt(void)
205     {
206     psiconv_list_add(fileformat_list,&ff);
207     }
208    

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