/[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 14 - (hide annotations)
Mon Oct 11 19:17:17 1999 UTC (24 years, 6 months ago) by frodo
File MIME type: text/plain
File size: 6082 byte(s)
(Frodo) Moved generation stuff out of the library into psiconv

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     * Portions Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl>
5     *
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     #include "data.h"
25     #include "list.h"
26     #include "gen.h"
27    
28    
29     /*
30     * Various string tables for HTML4 settings
31     */
32    
33     /* Character conversion table */
34     static const char *char_table[0x100] = {
35     /* 0x00 */ "", "", "", "", "", "", "\n", "\n",
36     /* 0x08 */ "\n", "\t", "", "", "", "", "", "",
37     /* 0x10 */ " ", "", "", "", "", "", "", "",
38     /* 0x18 */ "", "", "", "", "", "", "", "",
39     /* 0x20 */ " ", "!", "\"", "#", "$", "%", "&", "'",
40     /* 0x28 */ "(", ")", "*", "+", ",", "-", ".", "/",
41     /* 0x30 */ "0", "1", "2", "3", "4", "5", "6", "7",
42     /* 0x38 */ "8", "9", ":", ";", "<", "=", ">", "?",
43     /* 0x40 */ "@", "A", "B", "C", "D", "E", "F", "G",
44     /* 0x48 */ "H", "I", "J", "K", "L", "M", "N", "O",
45     /* 0x50 */ "P", "Q", "R", "S", "T", "U", "V", "W",
46     /* 0x58 */ "X", "Y", "Z", "[", "\\", "]", "^", "_",
47     /* 0x60 */ "`", "a", "b", "c", "d", "e", "f", "g",
48     /* 0x68 */ "h", "i", "j", "k", "l", "m", "n", "o",
49     /* 0x70 */ "p", "q", "r", "s", "t", "u", "v", "w",
50     /* 0x78 */ "x", "y", "z", "{", "|", "}", "~", "",
51     /* 0x80 */ "", "", ",", "f", ",,", "...", "+", "#",
52     /* 0x88 */ "^", "\176/oo","S", "<", "OE", "", "", "",
53     /* 0x90 */ "", "`", "'", "``", "''", "*", "-", "--",
54     /* 0x98 */ "~", "(TM)", "s", ">", "oe", "", "", "Y",
55     /* 0xa0 */ "\xa0", "\xa1", "\xa2", "\xa3", "\xa4", "\xa5", "\xa6", "\xa7",
56     /* 0xa8 */ "\xa8", "\xa9", "\xaa", "\xab", "\xac", "\xad", "\xae", "\xaf",
57     /* 0xb0 */ "\xb0", "\xb1", "\xb2", "\xb3", "\xb4", "\xb5", "\xb6", "\xb7",
58     /* 0xb8 */ "\xb8", "\xb9", "\xba", "\xbb", "\xbc", "\xbd", "\xbe", "\xbf",
59     /* 0xc0 */ "\xc0", "\xc1", "\xc2", "\xc3", "\xc4", "\xc5", "\xc6", "\xc7",
60     /* 0xc8 */ "\xc8", "\xc9", "\xca", "\xcb", "\xcc", "\xcd", "\xce", "\xcf",
61     /* 0xd0 */ "\xd0", "\xd1", "\xd2", "\xd3", "\xd4", "\xd5", "\xd6", "\xd7",
62     /* 0xd8 */ "\xd8", "\xd9", "\xda", "\xdb", "\xdc", "\xdd", "\xde", "\xdf",
63     /* 0xe0 */ "\xe0", "\xe1", "\xe2", "\xe3", "\xe4", "\xe5", "\xe6", "\xe7",
64     /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef",
65     /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7",
66     /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff",
67     };
68    
69    
70     /* Output a string, doing character conversions */
71     static void fput_text(FILE * of, const char *text, int length) {
72     int j;
73    
74     for (j = 0; j < length; j++) {
75     fputs(char_table[(unsigned char) (text[j])], of);
76     }
77     }
78    
79    
80     /* Output a paragraph */
81     static void fput_para(FILE * of,
82     const psiconv_paragraph para,int extra_nl)
83     {
84     if (para->base_paragraph->bullet->on) {
85     fprintf(of, "%s ", char_table[para->base_paragraph->bullet->character]);
86     }
87     fput_text(of, para->text, strlen(para->text));
88     fputs("\n", of);
89     if (extra_nl)
90     fputs("\n", of);
91     }
92    
93     static void psiconv_gen_txt_texted(FILE * of, psiconv_texted_f tf)
94     {
95     int i;
96     psiconv_paragraph para;
97    
98     if (tf->page_sec->header->on_first_page) {
99     for (i=0; i < psiconv_list_length(tf->page_sec->header->text->paragraphs); i++) {
100     para = psiconv_list_get(tf->page_sec->header->text->paragraphs, i);
101     fput_text(of, para->text, strlen(para->text));
102     fputs("\n", of);
103     }
104     }
105     fputs("\n",of);
106    
107     for (i=0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) {
108     para = psiconv_list_get(tf->texted_sec->paragraphs, i);
109     fput_para(of, para,0);
110     }
111    
112     fputs("\n",of);
113     for (i=0; i < psiconv_list_length(tf->page_sec->footer->text->paragraphs); i++) {
114     para = psiconv_list_get(tf->page_sec->footer->text->paragraphs, i);
115     fput_text(of, para->text, strlen(para->text));
116     fputs("\n", of);
117     }
118     }
119    
120     static void psiconv_gen_txt_word(FILE * of, psiconv_word_f wf)
121     {
122     int i;
123     psiconv_paragraph para;
124    
125     if (wf->page_sec->header->on_first_page) {
126     for (i=0; i < psiconv_list_length(wf->page_sec->header->text->paragraphs); i++) {
127     para = psiconv_list_get(wf->page_sec->header->text->paragraphs, i);
128     fput_text(of, para->text, strlen(para->text));
129     fputs("\n\n", of);
130     }
131     }
132     fputs("\n\n", of);
133    
134     for (i=0; i < psiconv_list_length(wf->paragraphs); i++) {
135     para = psiconv_list_get(wf->paragraphs, i);
136     fput_para(of, para,1);
137     }
138    
139     fputs("\n\n", of);
140     for (i=0; i < psiconv_list_length(wf->page_sec->footer->text->paragraphs); i++) {
141     para = psiconv_list_get(wf->page_sec->footer->text->paragraphs, i);
142     fput_text(of, para->text, strlen(para->text));
143     fputs("\n\n", of);
144     }
145     }
146    
147     void psiconv_gen_txt(FILE * of, psiconv_file file)
148     {
149     if (file->type == psiconv_word_file)
150     psiconv_gen_txt_word(of,(psiconv_word_f) file->file);
151     else if (file->type == psiconv_texted_file)
152     psiconv_gen_txt_texted(of,(psiconv_texted_f) file->file);
153     else
154     return;
155     }
156    

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