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

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

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

Revision 14 Revision 185
1/* 1/*
2 * gen_text.c - Part of psiconv, a PSION 5 file formats converter 2 * gen_text.c - Part of psiconv, a PSION 5 file formats converter
3 * Copyright (c) 1999 Andrew Johnson <anjohnson@iee.org> 3 * Copyright (c) 1999 Andrew Johnson <anjohnson@iee.org>
4 * Portions Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> 4 * Portions Copyright (c) 1999,2003 Frodo Looijaard <frodol@dds.nl>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 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 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 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
19 */ 19 */
20 20
21#include "config.h" 21#include "config.h"
22#include <stdio.h> 22#include <stdio.h>
23#include <string.h> 23#include <string.h>
24#include <psiconv/data.h>
25#include <psiconv/list.h>
26#include <psiconv/unicode.h>
24#include "data.h" 27#include "general.h"
25#include "list.h"
26#include "gen.h" 28#include "gen.h"
29#include "psiconv.h"
27 30
31#ifdef DMALLOC
32#include "dmalloc.h"
33#endif
28 34
29/* 35static void output_para(const psiconv_config config,psiconv_list list,
30 * Various string tables for HTML4 settings 36 const psiconv_paragraph para,encoding encoding_type);
31 */ 37static void gen_txt_word(const psiconv_config config, psiconv_list list,
38 psiconv_word_f wf, encoding encoding_type);
39static void gen_txt_texted(const psiconv_config config, psiconv_list list,
40 psiconv_texted_f tf, encoding encoding_type);
41static int gen_txt(const psiconv_config config, psiconv_list list,
42 const psiconv_file file, const char *dest,
43 const encoding encoding_type);
32 44
33/* Character conversion table */ 45static struct fileformat_s ff =
34static const char *char_table[0x100] = { 46 {
35 /* 0x00 */ "", "", "", "", "", "", "\n", "\n", 47 "ASCII",
36 /* 0x08 */ "\n", "\t", "", "", "", "", "", "", 48 "Plain text without much layout",
37 /* 0x10 */ " ", "", "", "", "", "", "", "", 49 gen_txt
38 /* 0x18 */ "", "", "", "", "", "", "", "", 50 };
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 51
69 52
70/* Output a string, doing character conversions */ 53void output_para(const psiconv_config config,psiconv_list list,
71static void fput_text(FILE * of, const char *text, int length) { 54 const psiconv_paragraph para,encoding encoding_type)
55{
72 int j; 56 int i;
73 57 if (para && para->base_paragraph && para->base_paragraph->bullet &&
74 for (j = 0; j < length; j++) {
75 fputs(char_table[(unsigned char) (text[j])], of);
76 }
77}
78
79
80/* Output a paragraph */
81static void fput_para(FILE * of,
82 const psiconv_paragraph para,int extra_nl)
83{
84 if (para->base_paragraph->bullet->on) { 58 para->base_paragraph->bullet->on) {
85 fprintf(of, "%s ", char_table[para->base_paragraph->bullet->character]); 59 output_char(config,list,para->base_paragraph->bullet->character,
60 encoding_type);
61 output_char(config,list,' ', encoding_type);
62 output_char(config,list,' ', encoding_type);
63 output_char(config,list,' ', encoding_type);
64 }
65 if (para && para->text) {
66 for (i = 0; i < psiconv_unicode_strlen(para->text); i++)
67 switch (para->text[i]) {
68 case 0x06:
69 case 0x07:
70 case 0x08:
71 output_char(config,list,'\n',encoding_type);
72 break;
73 case 0x09:
74 case 0x0a:
75 output_char(config,list,'\t',encoding_type);
76 break;
77 case 0x0b:
78 case 0x0c:
79 output_char(config,list,'-',encoding_type);
80 break;
81 case 0x0f:
82 output_char(config,list,' ',encoding_type);
83 break;
84 case 0x00:
85 case 0x01:
86 case 0x02:
87 case 0x03:
88 case 0x04:
89 case 0x05:
90 case 0x0e:
91 case 0x10:
92 case 0x11:
93 case 0x12:
94 case 0x13:
95 case 0x14:
96 case 0x15:
97 case 0x16:
98 case 0x17:
99 case 0x18:
100 case 0x19:
101 case 0x1a:
102 case 0x1c:
103 case 0x1d:
104 case 0x1e:
105 case 0x1f:
106 break;
107 default:
108 output_char(config,list,para->text[i],encoding_type);
109 break;
86 } 110 }
87 fput_text(of, para->text, strlen(para->text)); 111 output_char(config,list,'\n',encoding_type);
88 fputs("\n", of); 112 }
89 if (extra_nl)
90 fputs("\n", of);
91} 113}
92 114
93static void psiconv_gen_txt_texted(FILE * of, psiconv_texted_f tf) 115void gen_txt_word(const psiconv_config config, psiconv_list list,
116 psiconv_word_f wf, encoding encoding_type)
94{ 117{
95 int i; 118 int i;
96 psiconv_paragraph para; 119 psiconv_paragraph para;
97 120
98 if (tf->page_sec->header->on_first_page) { 121 if (wf && wf->page_sec && wf->page_sec->header &&
122 wf->page_sec->header->text && wf->page_sec->header->text->paragraphs) {
123 for (i=0;
124 i < psiconv_list_length(wf->page_sec->header->
125 text->paragraphs); i++) {
126 para = psiconv_list_get(wf->page_sec->header->text->paragraphs,
127 i);
128 output_para(config,list,para,encoding_type);
129 }
130 }
131 output_char(config,list,'\n',encoding_type);
132
133 if (wf && wf->paragraphs)
99 for (i=0; i < psiconv_list_length(tf->page_sec->header->text->paragraphs); i++) { 134 for (i=0; i < psiconv_list_length(wf->paragraphs); i++) {
135 para = psiconv_list_get(wf->paragraphs, i);
136 output_para(config, list,para,encoding_type);
137 }
138
139 output_char(config,list,'\n',encoding_type);
140
141 if (wf && wf->page_sec && wf->page_sec->footer &&
142 wf->page_sec->footer->text && wf->page_sec->footer->text->paragraphs) {
143 for (i=0;
144 i < psiconv_list_length(wf->page_sec->footer->
145 text->paragraphs); i++) {
146 para = psiconv_list_get(wf->page_sec->footer->text->paragraphs, i);
147 output_para(config,list,para,encoding_type);
148 }
149 }
150}
151
152void gen_txt_texted(const psiconv_config config, psiconv_list list,
153 psiconv_texted_f tf, encoding encoding_type)
154{
155 int i;
156 psiconv_paragraph para;
157
158 if (tf && tf->page_sec && tf->page_sec->header &&
159 tf->page_sec->header->text && tf->page_sec->header->text->paragraphs) {
160 for (i=0;
161 i < psiconv_list_length(tf->page_sec->header->
162 text->paragraphs); i++) {
100 para = psiconv_list_get(tf->page_sec->header->text->paragraphs, i); 163 para = psiconv_list_get(tf->page_sec->header->text->paragraphs,
101 fput_text(of, para->text, strlen(para->text)); 164 i);
102 fputs("\n", of); 165 output_para(config,list,para,encoding_type);
103 }
104 }
105 fputs("\n",of);
106 166 }
167 }
168 output_char(config,list,'\n',encoding_type);
169
170 if (tf && tf->texted_sec && tf->texted_sec->paragraphs)
107 for (i=0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) { 171 for (i=0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) {
108 para = psiconv_list_get(tf->texted_sec->paragraphs, i); 172 para = psiconv_list_get(tf->texted_sec->paragraphs, i);
109 fput_para(of, para,0); 173 output_para(config, list,para,encoding_type);
174 }
110 } 175
111 176 output_char(config,list,'\n',encoding_type);
112 fputs("\n",of); 177
113 for (i=0; i < psiconv_list_length(tf->page_sec->footer->text->paragraphs); i++) { 178 if (tf && tf->page_sec && tf->page_sec->footer &&
179 tf->page_sec->footer->text && tf->page_sec->footer->text->paragraphs) {
180 for (i=0;
181 i < psiconv_list_length(tf->page_sec->footer->
182 text->paragraphs); i++) {
114 para = psiconv_list_get(tf->page_sec->footer->text->paragraphs, i); 183 para = psiconv_list_get(tf->page_sec->footer->text->paragraphs, i);
115 fput_text(of, para->text, strlen(para->text)); 184 output_para(config,list,para,encoding_type);
116 fputs("\n", of);
117 }
118}
119
120static void psiconv_gen_txt_word(FILE * of, psiconv_word_f wf)
121{
122 int i;
123 psiconv_paragraph para;
124 185 }
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 } 186 }
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} 187}
146 188
147void psiconv_gen_txt(FILE * of, psiconv_file file) 189int gen_txt(const psiconv_config config, psiconv_list list,
190 const psiconv_file file, const char *dest,
191 const encoding encoding_type)
148{ 192{
149 if (file->type == psiconv_word_file) 193 if (file->type == psiconv_word_file) {
150 psiconv_gen_txt_word(of,(psiconv_word_f) file->file); 194 gen_txt_word(config,list,(psiconv_word_f) file->file,encoding_type);
195 return 0;
151 else if (file->type == psiconv_texted_file) 196 } else if (file->type == psiconv_texted_file) {
152 psiconv_gen_txt_texted(of,(psiconv_texted_f) file->file); 197 gen_txt_texted(config,list,(psiconv_texted_f) file->file,encoding_type);
153 else
154 return; 198 return 0;
199 } else
200 return -1;
155} 201}
156 202
203void init_txt(void)
204{
205 psiconv_list_add(fileformat_list,&ff);
206}
207

Legend:
Removed from v.14  
changed lines
  Added in v.185

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