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

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

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

Revision 140 Revision 147
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 A: <META HTTP-EQUIV="Content-Type" CONTENT="text/html"> header
24 was added.
25
26 B: Support for narrow build Asian Psions added.
27 If the encoding_type is PSICONV_ENCODING_UTF8,
28 B-1: use utf8_table for character conversion.
29 B-2: add the "Charset=UTF-8" in the Content-Type header.
30 Otherwise proceed as normal.
31*/
32
21#include "config.h" 33#include "config.h"
22#include <stdio.h> 34#include <stdio.h>
23#include <string.h> 35#include <string.h>
24#include <ctype.h> 36#include <ctype.h>
25#include <stdlib.h> 37#include <stdlib.h>
28#include "gen.h" 40#include "gen.h"
29#include "psiconv.h" 41#include "psiconv.h"
30 42
31#ifndef TRUE 43#ifndef TRUE
32#define TRUE (0==0) 44#define TRUE (0==0)
45#endif
46
47#ifdef DMALLOC
48#include "dmalloc.h"
33#endif 49#endif
34 50
35/* 51/*
36 * Various string tables for HTML4 settings 52 * Various string tables for HTML4 settings
37 */ 53 */
86 "&ocirc;", "&otilde;", "&ouml;", "&divide;", 102 "&ocirc;", "&otilde;", "&ouml;", "&divide;",
87 /* 0xf8 */ "&oslash;", "&ugrave;", "&uacute;", "&ucirc;", 103 /* 0xf8 */ "&oslash;", "&ugrave;", "&uacute;", "&ucirc;",
88 "&uuml;", "&yacute;", "&thorn;", "&yuml;" 104 "&uuml;", "&yacute;", "&thorn;", "&yuml;"
89}; 105};
90 106
107static const char *utf_table[0x100] = {
108 /* 0x00 */ "", "", "", "", "", "", "<BR>\n", "<BR>\n",
109 /* 0x08 */ "\n<HR>\n", "\t", "", "", "", "", "", "",
110 /* 0x10 */ " ", "", "", "", "", "", "", "",
111 /* 0x18 */ "", "", "", "", "", "", "", "",
112 /* 0x20 */ " ", "!", "&quot;", "#", "$", "%", "&amp;", "'",
113 /* 0x28 */ "(", ")", "*", "+", ",", "-", ".", "/",
114 /* 0x30 */ "0", "1", "2", "3", "4", "5", "6", "7",
115 /* 0x38 */ "8", "9", ":", ";", "&lt;", "=", "&gt;", "?",
116 /* 0x40 */ "@", "A", "B", "C", "D", "E", "F", "G",
117 /* 0x48 */ "H", "I", "J", "K", "L", "M", "N", "O",
118 /* 0x50 */ "P", "Q", "R", "S", "T", "U", "V", "W",
119 /* 0x58 */ "X", "Y", "Z", "[", "\\", "]", "^", "_",
120 /* 0x60 */ "`", "a", "b", "c", "d", "e", "f", "g",
121 /* 0x68 */ "h", "i", "j", "k", "l", "m", "n", "o",
122 /* 0x70 */ "p", "q", "r", "s", "t", "u", "v", "w",
123 /* 0x78 */ "x", "y", "z", "{", "|", "}", "~", "",
124 /* 0x80 */ "\x80", "\x81", "\x82", "\x83", "\x84", "\x85", "\x86", "\x87",
125 /* 0x88 */ "\x88", "\x89", "\x8a", "\x8b", "\x8c", "\x8d", "\x8e", "\x8f",
126 /* 0x90 */ "\x90", "\x91", "\x92", "\x93", "\x94", "\x95", "\x96", "\x97",
127 /* 0x98 */ "\x98", "\x99", "\x9a", "\x9b", "\x9c", "\x9d", "\x9e", "\x9f",
128 /* 0xa0 */ "\xa0", "\xa1", "\xa2", "\xa3", "\xa4", "\xa5", "\xa6", "\xa7",
129 /* 0xa8 */ "\xa8", "\xa9", "\xaa", "\xab", "\xac", "\xad", "\xae", "\xaf",
130 /* 0xb0 */ "\xb0", "\xb1", "\xb2", "\xb3", "\xb4", "\xb5", "\xb6", "\xb7",
131 /* 0xb8 */ "\xb8", "\xb9", "\xba", "\xbb", "\xbc", "\xbd", "\xbe", "\xbf",
132 /* 0xc0 */ "\xc0", "\xc1", "\xc2", "\xc3", "\xc4", "\xc5", "\xc6", "\xc7",
133 /* 0xc8 */ "\xc8", "\xc9", "\xca", "\xcb", "\xcc", "\xcd", "\xce", "\xcf",
134 /* 0xd0 */ "\xd0", "\xd1", "\xd2", "\xd3", "\xd4", "\xd5", "\xd6", "\xd7",
135 /* 0xd8 */ "\xd8", "\xd9", "\xda", "\xdb", "\xdc", "\xdd", "\xde", "\xdf",
136 /* 0xe0 */ "\xe0", "\xe1", "\xe2", "\xe3", "\xe4", "\xe5", "\xe6", "\xe7",
137 /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef",
138 /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7",
139 /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff",
140};
141
142/* a flag to indicate the use of UTF8 */
143static psiconv_encoding encoding=PSICONV_ENCODING_CP1252;
144
145
91/* The order of these must match the enum psiconv_border_kind (data.h) */ 146/* The order of these must match the enum psiconv_border_kind (data.h) */
92static const char *border_strings[] = { 147static const char *border_strings[] = {
93 "none", "solid", "double", "dotted", "dashed", "dashed", "dotted" 148 "none", "solid", "double", "dotted", "dashed", "dashed", "dotted"
94}; 149};
95 150
117} 172}
118 173
119static void fput_text(FILE * of, const char *text, int length, int *pwasspace) { 174static void fput_text(FILE * of, const char *text, int length, int *pwasspace) {
120 int j; 175 int j;
121 int space; 176 int space;
177 char ** table;
178 if (encoding == PSICONV_ENCODING_UTF8){
179 table = (char**) utf_table;
180 }else{
181 table=(char**) char_table;
182 }
122 183
123 for (j = 0; j < length; j++) { 184 for (j = 0; j < length; j++) {
124 space = (text[j] == ' '); 185 space = (text[j] == ' ');
125 if (*pwasspace && space) 186 if (*pwasspace && space)
126 fputs("&nbsp;", of); 187 fputs("&nbsp;", of);
127 else 188 else
128 fputs(char_table[(unsigned char) (text[j])], of); 189 fputs(table[(unsigned char) (text[j])], of);
129 *pwasspace = space; 190 *pwasspace = space;
130 } 191 }
131} 192}
132 193
133static const char *screenfont_name(psiconv_u8 screenfont) 194static const char *screenfont_name(psiconv_u8 screenfont)
342 psiconv_in_line_layout inl; 403 psiconv_in_line_layout inl;
343 psiconv_word_style sty; 404 psiconv_word_style sty;
344 int spans = 0; 405 int spans = 0;
345 int wasspace = 0; 406 int wasspace = 0;
346 int i, j, loc; 407 int i, j, loc;
408 char ** table;
409
410 if (encoding == PSICONV_ENCODING_UTF8){
411 table= (char**) utf_table;
412 }else{
413 table= (char**) char_table;
414 }
347 415
348 layout_stack = calloc(psiconv_list_length(para->in_lines), 416 layout_stack = calloc(psiconv_list_length(para->in_lines),
349 sizeof(*layout_stack)); 417 sizeof(*layout_stack));
350 fputs("<P", of); 418 fputs("<P", of);
351 sty = psiconv_get_style(wf->styles_sec, para->base_style); 419 sty = psiconv_get_style(wf->styles_sec, para->base_style);
384 fprintf(of, "color:#%02x%02x%02x;", 452 fprintf(of, "color:#%02x%02x%02x;",
385 base_para->bullet->color->red, 453 base_para->bullet->color->red,
386 base_para->bullet->color->green, 454 base_para->bullet->color->green,
387 base_para->bullet->color->blue); 455 base_para->bullet->color->blue);
388 fprintf(of, "\">%s </SPAN>", 456 fprintf(of, "\">%s </SPAN>",
389 char_table[base_para->bullet->character]); 457 table[base_para->bullet->character]);
390 wasspace = TRUE; 458 wasspace = TRUE;
391 } 459 }
392 460
393 loc = 0; 461 loc = 0;
394 for (i = 0; i < psiconv_list_length(para->in_lines); i++) { 462 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
446 fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf); 514 fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf);
447 fputs("}\n", of); 515 fputs("}\n", of);
448} 516}
449 517
450static int psiconv_gen_html4(const char *filename, const psiconv_file file, 518static int psiconv_gen_html4(const char *filename, const psiconv_file file,
451 const char *dest) 519 const char *dest, const psiconv_encoding encoding_type)
452{ 520{
453 FILE * of; 521 FILE * of;
454 int i; 522 int i;
455 psiconv_paragraph para; 523 psiconv_paragraph para;
456 psiconv_word_style normal, sty; 524 psiconv_word_style normal, sty;
457 psiconv_word_f wf; 525 psiconv_word_f wf;
526
527 encoding=encoding_type;
458 528
459 if (file->type == psiconv_word_file) 529 if (file->type == psiconv_word_file)
460 wf = file->file; 530 wf = file->file;
461 else { 531 else {
462 /* Fall back on the normal HTML generator */ 532 /* Fall back on the normal HTML generator */
463 return psiconv_gen_html(filename,file,dest); 533 return psiconv_gen_html(filename,file,dest,encoding_type);
464 } 534 }
465 535
466 if (! (of = fopen(filename,"w"))) 536 if (! (of = fopen(filename,"w")))
467 return -1; 537 return -1;
468 538
469 fputs("<!doctype html public \"-//W3C//DTD HTML 4.0 STRICT//EN\">", of); 539 fputs("<!doctype html public \"-//W3C//DTD HTML 4.0 STRICT//EN\">", of);
470 fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); 540 fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of);
471 fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); 541 fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of);
542
543 fputs(" <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html", of);
544 if (encoding == PSICONV_ENCODING_UTF8)
545 fputs("; CHARSET=UTF-8", of);
546 fputs("\">\n", of);
472 547
473 if (wf->page_sec->header->text) { 548 if (wf->page_sec->header->text) {
474 if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) { 549 if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) {
475 fputs(" <TITLE>", of); 550 fputs(" <TITLE>", of);
476 para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0); 551 para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0);

Legend:
Removed from v.140  
changed lines
  Added in v.147

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