… | |
… | |
16 | * You should have received a copy of the GNU General Public License |
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 |
17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | */ |
19 | */ |
20 | |
20 | |
|
|
21 | /* |
|
|
22 | 2002/Apr. Keita KAWABE |
|
|
23 | Support for narrow build Asian Psions added. |
|
|
24 | |
|
|
25 | If the encoding_type is PSICONV_ENCODING_UTF8, use utf8_table for |
|
|
26 | character conversion. Otherwise use char_table. |
|
|
27 | */ |
|
|
28 | |
21 | #include "config.h" |
29 | #include "config.h" |
22 | #include <stdio.h> |
30 | #include <stdio.h> |
23 | #include <string.h> |
31 | #include <string.h> |
24 | #include "data.h" |
32 | #include "psiconv/data.h" |
25 | #include "list.h" |
33 | #include "psiconv/list.h" |
26 | #include "gen.h" |
34 | #include "gen.h" |
27 | #include "psiconv.h" |
35 | #include "psiconv.h" |
|
|
36 | |
|
|
37 | #ifdef DMALLOC |
|
|
38 | #include "dmalloc.h" |
|
|
39 | #endif |
28 | |
40 | |
29 | |
41 | |
30 | /* |
42 | /* |
31 | * Various string tables for HTML4 settings |
43 | * Various string tables for HTML4 settings |
32 | */ |
44 | */ |
… | |
… | |
65 | /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef", |
77 | /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef", |
66 | /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7", |
78 | /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7", |
67 | /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff", |
79 | /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff", |
68 | }; |
80 | }; |
69 | |
81 | |
|
|
82 | static const char *utf_table[0x100] = { |
|
|
83 | /* 0x00 */ "", "", "", "", "", "", "\n", "\n", |
|
|
84 | /* 0x08 */ "\n", "\t", "", "", "", "", "", "", |
|
|
85 | /* 0x10 */ " ", "", "", "", "", "", "", "", |
|
|
86 | /* 0x18 */ "", "", "", "", "", "", "", "", |
|
|
87 | /* 0x20 */ " ", "!", "\"", "#", "$", "%", "&", "'", |
|
|
88 | /* 0x28 */ "(", ")", "*", "+", ",", "-", ".", "/", |
|
|
89 | /* 0x30 */ "0", "1", "2", "3", "4", "5", "6", "7", |
|
|
90 | /* 0x38 */ "8", "9", ":", ";", "<", "=", ">", "?", |
|
|
91 | /* 0x40 */ "@", "A", "B", "C", "D", "E", "F", "G", |
|
|
92 | /* 0x48 */ "H", "I", "J", "K", "L", "M", "N", "O", |
|
|
93 | /* 0x50 */ "P", "Q", "R", "S", "T", "U", "V", "W", |
|
|
94 | /* 0x58 */ "X", "Y", "Z", "[", "\\", "]", "^", "_", |
|
|
95 | /* 0x60 */ "`", "a", "b", "c", "d", "e", "f", "g", |
|
|
96 | /* 0x68 */ "h", "i", "j", "k", "l", "m", "n", "o", |
|
|
97 | /* 0x70 */ "p", "q", "r", "s", "t", "u", "v", "w", |
|
|
98 | /* 0x78 */ "x", "y", "z", "{", "|", "}", "~", "\x7f", |
|
|
99 | /* 0x80 */ "\x80", "\x81", "\x82", "\x83", "\x84", "\x85", "\x86", "\x87", |
|
|
100 | /* 0x88 */ "\x88", "\x89", "\x8a", "\x8b", "\x8c", "\x8d", "\x8e", "\x8f", |
|
|
101 | /* 0x90 */ "\x90", "\x91", "\x92", "\x93", "\x94", "\x95", "\x96", "\x97", |
|
|
102 | /* 0x98 */ "\x98", "\x99", "\x9a", "\x9b", "\x9c", "\x9d", "\x9e", "\x9f", |
|
|
103 | /* 0xa0 */ "\xa0", "\xa1", "\xa2", "\xa3", "\xa4", "\xa5", "\xa6", "\xa7", |
|
|
104 | /* 0xa8 */ "\xa8", "\xa9", "\xaa", "\xab", "\xac", "\xad", "\xae", "\xaf", |
|
|
105 | /* 0xb0 */ "\xb0", "\xb1", "\xb2", "\xb3", "\xb4", "\xb5", "\xb6", "\xb7", |
|
|
106 | /* 0xb8 */ "\xb8", "\xb9", "\xba", "\xbb", "\xbc", "\xbd", "\xbe", "\xbf", |
|
|
107 | /* 0xc0 */ "\xc0", "\xc1", "\xc2", "\xc3", "\xc4", "\xc5", "\xc6", "\xc7", |
|
|
108 | /* 0xc8 */ "\xc8", "\xc9", "\xca", "\xcb", "\xcc", "\xcd", "\xce", "\xcf", |
|
|
109 | /* 0xd0 */ "\xd0", "\xd1", "\xd2", "\xd3", "\xd4", "\xd5", "\xd6", "\xd7", |
|
|
110 | /* 0xd8 */ "\xd8", "\xd9", "\xda", "\xdb", "\xdc", "\xdd", "\xde", "\xdf", |
|
|
111 | /* 0xe0 */ "\xe0", "\xe1", "\xe2", "\xe3", "\xe4", "\xe5", "\xe6", "\xe7", |
|
|
112 | /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef", |
|
|
113 | /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7", |
|
|
114 | /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff", |
|
|
115 | }; |
|
|
116 | |
|
|
117 | /* a flag to indicate the use of UTF8 */ |
|
|
118 | static psiconv_encoding encoding = PSICONV_ENCODING_CP1252; |
70 | |
119 | |
71 | /* Output a string, doing character conversions */ |
120 | /* Output a string, doing character conversions */ |
72 | static void fput_text(FILE * of, const char *text, int length) { |
121 | static void fput_text(FILE * of, const char *text, int length) { |
73 | int j; |
122 | int j; |
|
|
123 | char **table; |
|
|
124 | |
|
|
125 | if (encoding == PSICONV_ENCODING_UTF8){ |
|
|
126 | table=(char**)utf_table; |
|
|
127 | }else{ |
|
|
128 | table=(char**)char_table; |
|
|
129 | } |
74 | |
130 | |
75 | for (j = 0; j < length; j++) { |
131 | for (j = 0; j < length; j++) { |
76 | fputs(char_table[(unsigned char) (text[j])], of); |
132 | fputs(table[(unsigned char) (text[j])], of); |
77 | } |
133 | } |
78 | } |
134 | } |
79 | |
135 | |
80 | |
136 | |
81 | /* Output a paragraph */ |
137 | /* Output a paragraph */ |
… | |
… | |
94 | static void psiconv_gen_txt_texted(FILE * of, psiconv_texted_f tf) |
150 | static void psiconv_gen_txt_texted(FILE * of, psiconv_texted_f tf) |
95 | { |
151 | { |
96 | int i; |
152 | int i; |
97 | psiconv_paragraph para; |
153 | psiconv_paragraph para; |
98 | |
154 | |
|
|
155 | if (tf->page_sec->header->text) { |
99 | if (tf->page_sec->header->on_first_page) { |
156 | if (tf->page_sec->header->on_first_page) { |
100 | for (i=0; i < psiconv_list_length(tf->page_sec->header->text->paragraphs); i++) { |
157 | for (i=0; i < psiconv_list_length(tf->page_sec->header->text->paragraphs); i++) { |
101 | para = psiconv_list_get(tf->page_sec->header->text->paragraphs, i); |
158 | para = psiconv_list_get(tf->page_sec->header->text->paragraphs, i); |
102 | fput_text(of, para->text, strlen(para->text)); |
159 | fput_text(of, para->text, strlen(para->text)); |
103 | fputs("\n", of); |
160 | fputs("\n", of); |
|
|
161 | } |
104 | } |
162 | } |
105 | } |
163 | } |
106 | fputs("\n",of); |
164 | fputs("\n",of); |
107 | |
165 | |
108 | for (i=0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) { |
166 | for (i=0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) { |
109 | para = psiconv_list_get(tf->texted_sec->paragraphs, i); |
167 | para = psiconv_list_get(tf->texted_sec->paragraphs, i); |
110 | fput_para(of, para,0); |
168 | fput_para(of, para,0); |
111 | } |
169 | } |
112 | |
170 | |
113 | fputs("\n",of); |
171 | fputs("\n",of); |
|
|
172 | if (tf->page_sec->header->text) { |
114 | for (i=0; i < psiconv_list_length(tf->page_sec->footer->text->paragraphs); i++) { |
173 | for (i=0; i < psiconv_list_length(tf->page_sec->footer->text->paragraphs); i++) { |
115 | para = psiconv_list_get(tf->page_sec->footer->text->paragraphs, i); |
174 | para = psiconv_list_get(tf->page_sec->footer->text->paragraphs, i); |
116 | fput_text(of, para->text, strlen(para->text)); |
175 | fput_text(of, para->text, strlen(para->text)); |
117 | fputs("\n", of); |
176 | fputs("\n", of); |
|
|
177 | } |
118 | } |
178 | } |
119 | } |
179 | } |
120 | |
180 | |
121 | static void psiconv_gen_txt_word(FILE * of, psiconv_word_f wf) |
181 | static void psiconv_gen_txt_word(FILE * of, psiconv_word_f wf) |
122 | { |
182 | { |
… | |
… | |
143 | fput_text(of, para->text, strlen(para->text)); |
203 | fput_text(of, para->text, strlen(para->text)); |
144 | fputs("\n\n", of); |
204 | fputs("\n\n", of); |
145 | } |
205 | } |
146 | } |
206 | } |
147 | |
207 | |
148 | static int psiconv_gen_txt(FILE * of, const psiconv_file file, |
208 | static int psiconv_gen_txt(const char *filename, const psiconv_file file, |
149 | const char *dest) |
209 | const char *dest, |
|
|
210 | const psiconv_encoding encoding_type) |
150 | { |
211 | { |
|
|
212 | FILE *of = fopen(filename,"w"); |
|
|
213 | if (! of) |
|
|
214 | return -1; |
|
|
215 | |
|
|
216 | encoding=encoding_type; |
|
|
217 | |
151 | if (file->type == psiconv_word_file) { |
218 | if (file->type == psiconv_word_file) { |
152 | psiconv_gen_txt_word(of,(psiconv_word_f) file->file); |
219 | psiconv_gen_txt_word(of,(psiconv_word_f) file->file); |
153 | return 0; |
|
|
154 | } else if (file->type == psiconv_texted_file) { |
220 | } else if (file->type == psiconv_texted_file) { |
155 | psiconv_gen_txt_texted(of,(psiconv_texted_f) file->file); |
221 | psiconv_gen_txt_texted(of,(psiconv_texted_f) file->file); |
156 | return 0; |
|
|
157 | } else |
222 | } else { |
|
|
223 | fclose(of); |
158 | return 1; |
224 | return -1; |
|
|
225 | } |
|
|
226 | return fclose(of); |
159 | } |
227 | } |
160 | |
228 | |
161 | static struct psiconv_fileformat ff = |
229 | static struct psiconv_fileformat_s ff = |
162 | { |
230 | { |
163 | "ASCII", |
231 | "ASCII", |
164 | "Plain text without much layout", |
232 | "Plain text without much layout", |
165 | psiconv_gen_txt |
233 | psiconv_gen_txt |
166 | }; |
234 | }; |