OSDN Git Service

8c8b7b29f9a6991a169b585f1f51fa18e209e518
[modchxj/mod_chxj.git] / src / chxj_chtml40.c
1 /*
2  * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
3  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include <apr_time.h>
18 #include "chxj_chtml40.h"
19 #include "chxj_hdml.h"
20 #include "chxj_str_util.h"
21 #include "chxj_dump.h"
22 #include "chxj_img_conv.h"
23 #include "chxj_qr_code.h"
24 #include "chxj_encoding.h"
25 #include "chxj_header_inf.h"
26
27 #define GET_CHTML40(X) ((chtml40_t *)(X))
28 #undef W_L
29 #undef W_V
30 #define W_L(X)          do { chtml40->out = BUFFERED_WRITE_LITERAL(chtml40->out, &doc->buf, (X)); } while(0)
31 #define W_V(X)          do { chtml40->out = (X) ? BUFFERED_WRITE_VALUE(chtml40->out, &doc->buf, (X))  \
32                                                 : BUFFERED_WRITE_LITERAL(chtml40->out, &doc->buf, ""); } while(0)
33 #undef W_NLCODE
34 #define W_NLCODE()     do { char *nlcode = TO_NLCODE(chtml40->conf); W_V(nlcode); } while (0)
35
36 static char *s_chtml40_start_html_tag     (void *pdoc, Node *node);
37 static char *s_chtml40_end_html_tag       (void *pdoc, Node *node);
38 static char *s_chtml40_start_meta_tag     (void *pdoc, Node *node);
39 static char *s_chtml40_end_meta_tag       (void *pdoc, Node *node);
40 static char *s_chtml40_start_textarea_tag (void *pdoc, Node *node);
41 static char *s_chtml40_end_textarea_tag   (void *pdoc, Node *node);
42 static char *s_chtml40_start_p_tag        (void *pdoc, Node *node);
43 static char *s_chtml40_end_p_tag          (void *pdoc, Node *node);
44 static char *s_chtml40_start_pre_tag      (void *pdoc, Node *node);
45 static char *s_chtml40_end_pre_tag        (void *pdoc, Node *node);
46 static char *s_chtml40_start_h1_tag       (void *pdoc, Node *node);
47 static char *s_chtml40_end_h1_tag         (void *pdoc, Node *node);
48 static char *s_chtml40_start_h2_tag       (void *pdoc, Node *node);
49 static char *s_chtml40_end_h2_tag         (void *pdoc, Node *node);
50 static char *s_chtml40_start_h3_tag       (void *pdoc, Node *node);
51 static char *s_chtml40_end_h3_tag         (void *pdoc, Node *node);
52 static char *s_chtml40_start_h4_tag       (void *pdoc, Node *node);
53 static char *s_chtml40_end_h4_tag         (void *pdoc, Node *node);
54 static char *s_chtml40_start_h5_tag       (void *pdoc, Node *node);
55 static char *s_chtml40_end_h5_tag         (void *pdoc, Node *node);
56 static char *s_chtml40_start_h6_tag       (void *pdoc, Node *node);
57 static char *s_chtml40_end_h6_tag         (void *pdoc, Node *node);
58 static char *s_chtml40_start_ul_tag       (void *pdoc, Node *node);
59 static char *s_chtml40_end_ul_tag         (void *pdoc, Node *node);
60 static char *s_chtml40_start_ol_tag       (void *pdoc, Node *node);
61 static char *s_chtml40_end_ol_tag         (void *pdoc, Node *node);
62 static char *s_chtml40_start_li_tag       (void *pdoc, Node *node);
63 static char *s_chtml40_end_li_tag         (void *pdoc, Node *node);
64 static char *s_chtml40_start_head_tag     (void *pdoc, Node *node);
65 static char *s_chtml40_end_head_tag       (void *pdoc, Node *node);
66 static char *s_chtml40_start_title_tag    (void *pdoc, Node *node);
67 static char *s_chtml40_end_title_tag      (void *pdoc, Node *node);
68 static char *s_chtml40_start_base_tag     (void *pdoc, Node *node);
69 static char *s_chtml40_end_base_tag       (void *pdoc, Node *node);
70 static char *s_chtml40_start_body_tag     (void *pdoc, Node *node);
71 static char *s_chtml40_end_body_tag       (void *pdoc, Node *node);
72 static char *s_chtml40_start_a_tag        (void *pdoc, Node *node);
73 static char *s_chtml40_end_a_tag          (void *pdoc, Node *node);
74 static char *s_chtml40_start_br_tag       (void *pdoc, Node *node);
75 static char *s_chtml40_end_br_tag         (void *pdoc, Node *node);
76 static char *s_chtml40_start_tr_tag       (void *pdoc, Node *node);
77 static char *s_chtml40_end_tr_tag         (void *pdoc, Node *node);
78 static char *s_chtml40_start_font_tag     (void *pdoc, Node *node);
79 static char *s_chtml40_end_font_tag       (void *pdoc, Node *node);
80 static char *s_chtml40_start_form_tag     (void *pdoc, Node *node);
81 static char *s_chtml40_end_form_tag       (void *pdoc, Node *node);
82 static char *s_chtml40_start_input_tag    (void *pdoc, Node *node);
83 static char *s_chtml40_end_input_tag      (void *pdoc, Node *node);
84 static char *s_chtml40_start_center_tag   (void *pdoc, Node *node);
85 static char *s_chtml40_end_center_tag     (void *pdoc, Node *node);
86 static char *s_chtml40_start_hr_tag       (void *pdoc, Node *node);
87 static char *s_chtml40_end_hr_tag         (void *pdoc, Node *node);
88 static char *s_chtml40_start_img_tag      (void *pdoc, Node *node);
89 static char *s_chtml40_end_img_tag        (void *pdoc, Node *node);
90 static char *s_chtml40_start_select_tag   (void *pdoc, Node *node);
91 static char *s_chtml40_end_select_tag     (void *pdoc, Node *node);
92 static char *s_chtml40_start_option_tag   (void *pdoc, Node *node);
93 static char *s_chtml40_end_option_tag     (void *pdoc, Node *node);
94 static char *s_chtml40_start_div_tag      (void *pdoc, Node *node);
95 static char *s_chtml40_end_div_tag        (void *pdoc, Node *node);
96 static char *s_chtml40_chxjif_tag         (void *pdoc, Node *node); 
97 static char *s_chtml40_text_tag           (void *pdoc, Node *node);
98 static char *s_chtml40_start_blockquote_tag(void *pdoc, Node *node);
99 static char *s_chtml40_end_blockquote_tag  (void *pdoc, Node *node);
100 static char *s_chtml40_start_dir_tag      (void *pdoc, Node *node);
101 static char *s_chtml40_end_dir_tag        (void *pdoc, Node *node);
102 static char *s_chtml40_start_dl_tag       (void *pdoc, Node *node);
103 static char *s_chtml40_end_dl_tag         (void *pdoc, Node *node);
104 static char *s_chtml40_start_dt_tag       (void *pdoc, Node *node);
105 static char *s_chtml40_end_dt_tag         (void *pdoc, Node *node);
106 static char *s_chtml40_start_dd_tag       (void *pdoc, Node *node);
107 static char *s_chtml40_end_dd_tag         (void *pdoc, Node *node);
108 static char *s_chtml40_start_marquee_tag  (void *pdoc, Node *node);
109 static char *s_chtml40_end_marquee_tag    (void *pdoc, Node *node);
110 static char *s_chtml40_start_blink_tag    (void *pdoc, Node *node);
111 static char *s_chtml40_end_blink_tag      (void *pdoc, Node *node);
112 static char *s_chtml40_start_menu_tag     (void *pdoc, Node *node);
113 static char *s_chtml40_end_menu_tag       (void *pdoc, Node *node);
114 static char *s_chtml40_start_plaintext_tag       (void *pdoc, Node *node);
115 static char *s_chtml40_start_plaintext_tag_inner (void *pdoc, Node *node);
116 static char *s_chtml40_end_plaintext_tag         (void *pdoc, Node *node);
117 static char *s_chtml40_newline_mark       (void *pdoc, Node *node);
118
119 static void  s_init_chtml40(chtml40_t *chtml, Doc *doc, request_rec *r, device_table *spec);
120
121 static int   s_chtml40_search_emoji(chtml40_t *chtml, char *txt, char **rslt);
122
123
124 tag_handler chtml40_handler[] = {
125   /* tagHTML */
126   {
127     s_chtml40_start_html_tag,
128     s_chtml40_end_html_tag,
129   },
130   /* tagMETA */
131   {
132     s_chtml40_start_meta_tag,
133     s_chtml40_end_meta_tag,
134   },
135   /* tagTEXTAREA */
136   {
137     s_chtml40_start_textarea_tag,
138     s_chtml40_end_textarea_tag,
139   },
140   /* tagP */
141   {
142     s_chtml40_start_p_tag,
143     s_chtml40_end_p_tag,
144   },
145   /* tagPRE */
146   {
147     s_chtml40_start_pre_tag,
148     s_chtml40_end_pre_tag,
149   },
150   /* tagUL */
151   {
152     s_chtml40_start_ul_tag,
153     s_chtml40_end_ul_tag,
154   },
155   /* tagLI */
156   {
157     s_chtml40_start_li_tag,
158     s_chtml40_end_li_tag,
159   },
160   /* tagOL */
161   {
162     s_chtml40_start_ol_tag,
163     s_chtml40_end_ol_tag,
164   },
165   /* tagH1 */
166   {
167     s_chtml40_start_h1_tag,
168     s_chtml40_end_h1_tag,
169   },
170   /* tagH2 */
171   {
172     s_chtml40_start_h2_tag,
173     s_chtml40_end_h2_tag,
174   },
175   /* tagH3 */
176   {
177     s_chtml40_start_h3_tag,
178     s_chtml40_end_h3_tag,
179   },
180   /* tagH4 */
181   {
182     s_chtml40_start_h4_tag,
183     s_chtml40_end_h4_tag,
184   },
185   /* tagH5 */
186   {
187     s_chtml40_start_h5_tag,
188     s_chtml40_end_h5_tag,
189   },
190   /* tagH6 */
191   {
192     s_chtml40_start_h6_tag,
193     s_chtml40_end_h6_tag,
194   },
195   /* tagHEAD */
196   {
197     s_chtml40_start_head_tag,
198     s_chtml40_end_head_tag,
199   },
200   /* tagTITLE */
201   {
202     s_chtml40_start_title_tag,
203     s_chtml40_end_title_tag,
204   },
205   /* tagBASE */
206   {
207     s_chtml40_start_base_tag,
208     s_chtml40_end_base_tag,
209   },
210   /* tagBODY */
211   {
212     s_chtml40_start_body_tag,
213     s_chtml40_end_body_tag,
214   },
215   /* tagA */
216   {
217     s_chtml40_start_a_tag,
218     s_chtml40_end_a_tag,
219   },
220   /* tagBR */
221   {
222     s_chtml40_start_br_tag,
223     s_chtml40_end_br_tag,
224   },
225   /* tagTABLE */
226   {
227     NULL,
228     NULL,
229   },
230   /* tagTR */
231   {
232     s_chtml40_start_tr_tag,
233     s_chtml40_end_tr_tag,
234   },
235   /* tagTD */
236   {
237     NULL,
238     NULL,
239   },
240   /* tagTBODY */
241   {
242     NULL,
243     NULL,
244   },
245   /* tagFONT */
246   {
247     s_chtml40_start_font_tag,
248     s_chtml40_end_font_tag,
249   },
250   /* tagFORM */
251   {
252     s_chtml40_start_form_tag,
253     s_chtml40_end_form_tag,
254   },
255   /* tagINPUT */
256   {
257     s_chtml40_start_input_tag,
258     s_chtml40_end_input_tag,
259   },
260   /* tagCENTER */
261   {
262     s_chtml40_start_center_tag,
263     s_chtml40_end_center_tag,
264   },
265   /* tagHR */
266   {
267     s_chtml40_start_hr_tag,
268     s_chtml40_end_hr_tag,
269   },
270   /* tagIMG */
271   {
272     s_chtml40_start_img_tag,
273     s_chtml40_end_img_tag,
274   },
275   /* tagSELECT */
276   {
277     s_chtml40_start_select_tag,
278     s_chtml40_end_select_tag,
279   },
280   /* tagOPTION */
281   {
282     s_chtml40_start_option_tag,
283     s_chtml40_end_option_tag,
284   },
285   /* tagDIV */
286   {
287     s_chtml40_start_div_tag,
288     s_chtml40_end_div_tag,
289   },
290   /* tagCHXJIF */
291   {
292     s_chtml40_chxjif_tag,
293     NULL,
294   },
295   /* tagNOBR */
296   {
297     NULL,
298     NULL,
299   },
300   /* tagSMALL */
301   {
302     NULL,
303     NULL,
304   },
305   /* tagSTYLE */
306   {
307     NULL,
308     NULL,
309   },
310   /* tagSPAN */
311   {
312     NULL,
313     NULL,
314   },
315   /* tagTEXT */
316   {
317     s_chtml40_text_tag,
318     NULL,
319   },
320   /* tagTH */
321   {
322     NULL,
323     NULL,
324   },
325   /* tagB */
326   {
327     NULL,
328     NULL,
329   },
330   /* tagFIELDSET */
331   {
332     NULL,
333     NULL,
334   },
335   /* tagDT */
336   {
337     s_chtml40_start_dt_tag,
338     s_chtml40_end_dt_tag,
339   },
340   /* tagLEGEND */
341   {
342     NULL,
343     NULL,
344   },
345   /* tagLABEL */
346   {
347     NULL,
348     NULL,
349   },
350   /* tagBLOCKQUOTE */
351   {
352     s_chtml40_start_blockquote_tag,
353     s_chtml40_end_blockquote_tag,
354   },
355   /* tagDIR */
356   {
357     s_chtml40_start_dir_tag,
358     s_chtml40_end_dir_tag,
359   },
360   /* tagDL */
361   {
362     s_chtml40_start_dl_tag,
363     s_chtml40_end_dl_tag,
364   },
365   /* tagDD */
366   {
367     s_chtml40_start_dd_tag,
368     s_chtml40_end_dd_tag,
369   },
370   /* tagMENU */
371   {
372     s_chtml40_start_menu_tag,
373     s_chtml40_end_menu_tag,
374   },
375   /* tagPLAINTEXT */
376   {
377     s_chtml40_start_plaintext_tag,
378     s_chtml40_end_plaintext_tag,
379   },
380   /* tagBLINK */
381   {
382     s_chtml40_start_blink_tag,
383     s_chtml40_end_blink_tag,
384   },
385   /* tagMARQUEE */
386   {
387     s_chtml40_start_marquee_tag,
388     s_chtml40_end_marquee_tag,
389   },
390   /* tagNLMARK */
391   {
392     s_chtml40_newline_mark,
393     NULL,
394   },
395 };
396
397
398 /**
399  * converts from CHTML5.0 to CHTML3.0.
400  *
401  * @param r     [i]   Requet_rec is appointed.
402  * @param spec  [i]   The result of the device specification processing which 
403  *                    was done in advance is appointed.
404  * @param src   [i]   The character string before the converting is appointed.
405  * @return The character string after the converting is returned.
406  */
407 char*
408 chxj_convert_chtml40(
409   request_rec         *r,
410   device_table        *spec,
411   const char          *src,
412   apr_size_t          srclen,
413   apr_size_t          *dstlen,
414   chxjconvrule_entry  *entryp,
415   cookie_t            *cookie
416 )
417 {
418   char      *dst = NULL;
419   char      *ss;
420   chtml40_t chtml40;
421   Doc       doc;
422
423   DBG(r, "start chxj_convert_chtml40()");
424
425   /*--------------------------------------------------------------------------*/
426   /* If qrcode xml                                                            */
427   /*--------------------------------------------------------------------------*/
428   *dstlen = srclen;
429   dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
430   if (dst) {
431     DBG(r,"i found qrcode xml");
432     DBG(r, "end chxj_convert_chtml40()");
433     return dst;
434   }
435   DBG(r,"not found qrcode xml");
436
437   /*--------------------------------------------------------------------------*/
438   /* The CHTML structure is initialized.                                      */
439   /*--------------------------------------------------------------------------*/
440   s_init_chtml40(&chtml40, &doc, r, spec);
441
442   chtml40.entryp = entryp;
443   chtml40.cookie = cookie;
444
445   chxj_set_content_type(r, chxj_header_inf_set_content_type(r, "text/html; charset=Windows-31J"));
446
447   /*--------------------------------------------------------------------------*/
448   /* The character string of the input is analyzed.                           */
449   /*--------------------------------------------------------------------------*/
450   qs_init_malloc(&doc);
451   qs_init_root_node(&doc);
452
453   ss = apr_pcalloc(r->pool, srclen + 1);
454   memset(ss, 0, srclen + 1);
455   memcpy(ss, src, srclen);
456
457 #ifdef DUMP_LOG
458   chxj_dump_out("[src] CHTML -> CHTML4.0", ss, srclen);
459 #endif
460   chxj_buffered_write_init(r->pool, &doc.buf);
461
462   qs_parse_string(&doc,ss, strlen(ss));
463
464   /*--------------------------------------------------------------------------*/
465   /* It converts it from CHTML to CHTML.                                      */
466   /*--------------------------------------------------------------------------*/
467   chxj_node_convert(spec,r,(void*)&chtml40, &doc, qs_get_root(&doc), 0);
468   chtml40.out = chxj_buffered_write_flush(chtml40.out, &doc.buf);
469   dst = apr_pstrdup(r->pool, chtml40.out);
470   chxj_buffered_write_terminate(&doc.buf);
471
472   qs_all_free(&doc,QX_LOGMARK);
473
474   if (dst == NULL) {
475     dst = apr_pstrdup(r->pool,ss);
476   }
477   if (strlen(dst) == 0) {
478     dst = apr_psprintf(r->pool, "\n");
479   }
480
481   *dstlen = strlen(dst);
482
483 #ifdef DUMP_LOG
484   chxj_dump_out("[src] CHTML -> CHTML4.0", dst, *dstlen);
485 #endif
486
487   DBG(r, "end chxj_convert_chtml40()");
488   return dst;
489 }
490
491
492 /**
493  * The CHTML structure is initialized.
494  *
495  * @param chtml40 [i/o] The pointer to the HDML structure that wants to be
496  *                   initialized is specified.
497  * @param doc   [i]   The Doc structure that should be set to the initialized
498  *                   HDML structure is specified.
499  * @param r     [i]   To use POOL, the pointer to request_rec is specified.
500  * @param spec  [i]   The pointer to the device_table
501  */
502 static void
503 s_init_chtml40(chtml40_t *chtml40, Doc *doc, request_rec *r, device_table *spec)
504 {
505   memset(doc,     0, sizeof(Doc));
506   memset(chtml40, 0, sizeof(chtml40_t));
507
508   doc->r        = r;
509   chtml40->doc  = doc;
510   chtml40->spec = spec;
511   chtml40->out  = qs_alloc_zero_byte_string(r->pool);
512   chtml40->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
513   chtml40->doc->parse_mode = PARSE_MODE_CHTML;
514 }
515
516
517 /**
518  * Corresponding EMOJI to a current character-code is retrieved. 
519  * The substitution character string is stored in the rslt pointer if agreeing.
520  *
521  * @param chtml40   [i]   The pointer to the CHTML structure is specified. 
522  * @param txt     [i]   The character string to want to examine whether it is 
523  *                      EMOJI is specified. 
524  * @param rslt    [o]   The pointer to the pointer that stores the result is 
525  *                      specified. 
526  * @return When corresponding EMOJI exists, it returns it excluding 0. 
527  */
528 static int
529 s_chtml40_search_emoji(chtml40_t *chtml40, char *txt, char **rslt)
530 {
531   emoji_t       *ee;
532   request_rec   *r;
533   device_table  *spec;
534   int           len;
535
536   spec = chtml40->spec;
537
538   len = strlen(txt);
539   r   = chtml40->doc->r;
540
541   if (!spec) {
542     DBG(r,"spec is NULL");
543   }
544
545   for (ee = chtml40->conf->emoji;
546        ee;
547        ee = ee->next) {
548     if (ee->imode == NULL) {
549       DBG(r, "emoji->imode is NULL");
550       continue;
551     }
552
553     if (ee->imode->string != NULL
554     &&  strlen(ee->imode->string) > 0
555     &&  strncasecmp(ee->imode->string, txt, strlen(ee->imode->string)) == 0) {
556
557       if (spec == NULL || spec->emoji_type == NULL) {
558         *rslt = apr_palloc(r->pool, 3);
559         (*rslt)[0] = ee->imode->hex1byte & 0xff;
560         (*rslt)[1] = ee->imode->hex2byte & 0xff;
561         (*rslt)[2] = 0;
562         return strlen(ee->imode->string);
563       }
564
565       return 0;
566     }
567   }
568
569   return 0;
570 }
571
572
573 /**
574  * It is a handler who processes the HTML tag.
575  *
576  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
577  *                     destination is specified.
578  * @param node   [i]   The HTML tag node is specified.
579  * @return The conversion result is returned.
580  */
581 static char *
582 s_chtml40_start_html_tag(void *pdoc, Node *UNUSED(node)) 
583 {
584   chtml40_t *chtml40 = GET_CHTML40(pdoc);
585   Doc       *doc     = chtml40->doc;
586
587   /*--------------------------------------------------------------------------*/
588   /* start HTML tag                                                           */
589   /*--------------------------------------------------------------------------*/
590   W_L("<html>");
591
592   return chtml40->out;
593 }
594
595
596 /**
597  * It is a handler who processes the HTML tag.
598  *
599  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
600  *                     destination is specified.
601  * @param node   [i]   The HTML tag node is specified.
602  * @return The conversion result is returned.
603  */
604 static char *
605 s_chtml40_end_html_tag(void *pdoc, Node *UNUSED(child)) 
606 {
607   chtml40_t   *chtml40 = GET_CHTML40(pdoc);
608   Doc         *doc     = chtml40->doc;
609
610   W_L("</html>");
611   return chtml40->out;
612 }
613
614
615 /**
616  * It is a handler who processes the META tag.
617  *
618  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
619  *                     destination is specified.
620  * @param node   [i]   The META tag node is specified.
621  * @return The conversion result is returned.
622  */
623 static char *
624 s_chtml40_start_meta_tag(void *pdoc, Node *node) 
625 {
626   chtml40_t     *chtml40;
627   Doc           *doc;
628   request_rec   *r;
629   Attr          *attr;
630   int           content_type_flag;
631   int           refresh_flag;
632
633   chtml40 = GET_CHTML40(pdoc);
634   doc     = chtml40->doc;
635   r       = doc->r;
636
637   content_type_flag = 0;
638   refresh_flag      = 0;
639
640   W_L("<meta");
641   /*--------------------------------------------------------------------------*/
642   /* Get Attributes                                                           */
643   /*--------------------------------------------------------------------------*/
644   for (attr = qs_get_attr(doc,node);
645        attr;
646        attr = qs_get_next_attr(doc,attr)) {
647     char *name   = qs_get_attr_name(doc,attr);
648     char *value  = qs_get_attr_value(doc,attr);
649     switch(*name) {
650     case 'h':
651     case 'H':
652       if (strcasecmp(name, "http-equiv") == 0 && value && *value) {
653         /*----------------------------------------------------------------------*/
654         /* CHTML 2.0                                                            */
655         /*----------------------------------------------------------------------*/
656         W_L(" http-equiv=\"");
657         W_V(value);
658         W_L("\"");
659         if (STRCASEEQ('c','C',"content-type", value))
660           content_type_flag = 1;
661   
662         if (STRCASEEQ('r','R',"refresh", value))
663           refresh_flag = 1;
664       }
665       break;
666
667     case 'c':
668     case 'C':
669       if (strcasecmp(name, "content") == 0 && value && *value) {
670         if (content_type_flag) {
671           W_L(" ");
672           W_V(name);
673           W_L("=\"");
674           W_V(chxj_header_inf_set_content_type(r, "text/html; charset=SHIFT_JIS"));
675           W_L("\"");
676         }
677         else
678         if (refresh_flag) {
679           char *buf;
680           char *sec;
681           char *url;
682           buf = apr_pstrdup(r->pool, value);
683           url = strchr(buf, ';');
684           if (url) {
685             sec = apr_pstrdup(r->pool, buf);
686             sec[url-buf] = 0;
687             url++;
688             url = chxj_encoding_parameter(r, url);
689             url = chxj_add_cookie_parameter(r, url, chtml40->cookie);
690             W_L(" ");
691             W_V(name);
692             W_L("=\"");
693             W_V(sec);
694             W_L(";");
695             W_V(url);
696             W_L("\"");
697           }
698         }
699         else {
700           W_L(" ");
701           W_V(name);
702           W_L("=\"");
703           W_V(value);
704           W_L("\"");
705         }
706       }
707       break;
708
709     default:
710       break;
711     }
712   }
713   W_L(">");
714   return chtml40->out;
715 }
716
717
718 /**
719  * It is a handler who processes the META tag.
720  *
721  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
722  *                     destination is specified.
723  * @param node   [i]   The META tag node is specified.
724  * @return The conversion result is returned.
725  */
726 static char*
727 s_chtml40_end_meta_tag(void* pdoc, Node* UNUSED(child)) 
728 {
729   chtml40_t *chtml40 = GET_CHTML40(pdoc);
730
731   return chtml40->out;
732 }
733
734
735 /**
736  * It is a handler who processes the HEAD tag.
737  *
738  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
739  *                     destination is specified.
740  * @param node   [i]   The HEAD tag node is specified.
741  * @return The conversion result is returned.
742  */
743 static char*
744 s_chtml40_start_head_tag(void* pdoc, Node* UNUSED(node)) 
745 {
746   chtml40_t   *chtml40 = GET_CHTML40(pdoc);
747   Doc         *doc     = chtml40->doc;
748
749   W_L("<head>");
750
751   return chtml40->out;
752 }
753
754
755 /**
756  * It is a handler who processes the HEAD tag.
757  *
758  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
759  *                     destination is specified.
760  * @param node   [i]   The HEAD tag node is specified.
761  * @return The conversion result is returned.
762  */
763 static char *
764 s_chtml40_end_head_tag(void *pdoc, Node *UNUSED(node)) 
765 {
766   chtml40_t *chtml40 = GET_CHTML40(pdoc);
767   Doc       *doc     = chtml40->doc;
768
769   W_L("</head>");
770
771   return chtml40->out;
772 }
773
774
775 /**
776  * It is a handler who processes the TITLE tag.
777  *
778  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
779  *                     destination is specified.
780  * @param node   [i]   The TITLE tag node is specified.
781  * @return The conversion result is returned.
782  */
783 static char *
784 s_chtml40_start_title_tag(void *pdoc, Node *UNUSED(node)) 
785 {
786   chtml40_t     *chtml40 = GET_CHTML40(pdoc);
787   Doc           *doc     = chtml40->doc;
788
789   W_L("<title>");
790
791   return chtml40->out;
792 }
793
794
795 /**
796  * It is a handler who processes the TITLE tag.
797  *
798  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
799  *                     destination is specified.
800  * @param node   [i]   The TITLE tag node is specified.
801  * @return The conversion result is returned.
802  */
803 static char *
804 s_chtml40_end_title_tag(void *pdoc, Node *UNUSED(child)) 
805 {
806   chtml40_t    *chtml40 = GET_CHTML40(pdoc);
807   Doc          *doc     = chtml40->doc;
808
809   W_L("</title>");
810
811   return chtml40->out;
812 }
813
814
815 /**
816  * It is a handler who processes the BASE tag.
817  *
818  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
819  *                     destination is specified.
820  * @param node   [i]   The BASE tag node is specified.
821  * @return The conversion result is returned.
822  */
823 static char *
824 s_chtml40_start_base_tag(void *pdoc, Node *node) 
825 {
826   Attr        *attr;
827   chtml40_t   *chtml40;
828   Doc         *doc;
829   request_rec *r;
830
831   chtml40 = GET_CHTML40(pdoc);
832   doc     = chtml40->doc;
833   r       = doc->r;
834
835   W_L("<base");
836   /*--------------------------------------------------------------------------*/
837   /* Get Attributes                                                           */
838   /*--------------------------------------------------------------------------*/
839   for (attr = qs_get_attr(doc,node);
840        attr;
841        attr = qs_get_next_attr(doc,attr)) {
842     char *name = qs_get_attr_name(doc,attr);
843     char *value = qs_get_attr_value(doc,attr);
844     if (STRCASEEQ('h','H',"href", name)) {
845       W_L(" href=\"");
846       W_V(value);
847       W_L("\"");
848     }
849   }
850   W_L(">");
851
852   return chtml40->out;
853 }
854
855
856 /**
857  * It is a handler who processes the BASE tag.
858  *
859  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
860  *                     destination is specified.
861  * @param node   [i]   The BASE tag node is specified.
862  * @return The conversion result is returned.
863  */
864 static char *
865 s_chtml40_end_base_tag(void *pdoc, Node *UNUSED(child)) 
866 {
867   chtml40_t *chtml40 = GET_CHTML40(pdoc);
868
869   return chtml40->out;
870 }
871
872
873 /**
874  * It is a handler who processes the BODY tag.
875  *
876  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
877  *                     destination is specified.
878  * @param node   [i]   The BODY tag node is specified.
879  * @return The conversion result is returned.
880  */
881 static char *
882 s_chtml40_start_body_tag(void *pdoc, Node *node) 
883 {
884   chtml40_t   *chtml40;
885   Doc         *doc;
886   request_rec *r;
887   Attr        *attr;
888
889   chtml40 = GET_CHTML40(pdoc);
890   doc     = chtml40->doc;
891   r       = doc->r;
892
893   W_L("<body");
894   /*--------------------------------------------------------------------------*/
895   /* Get Attributes                                                           */
896   /*--------------------------------------------------------------------------*/
897   for (attr = qs_get_attr(doc,node);
898        attr;
899        attr = qs_get_next_attr(doc,attr)) {
900     char *name   = qs_get_attr_name(doc,attr);
901     char *value  = qs_get_attr_value(doc,attr);
902     if (STRCASEEQ('b','B', "bgcolor", name) && value && *value) {
903       /*----------------------------------------------------------------------*/
904       /* CHTML 2.0                                                            */
905       /*----------------------------------------------------------------------*/
906       W_L(" bgcolor=\"");
907       W_V(value);
908       W_L("\"");
909     }
910     else if (STRCASEEQ('t','T', "text", name) && value && *value) {
911       /*----------------------------------------------------------------------*/
912       /* CHTML 2.0                                                            */
913       /*----------------------------------------------------------------------*/
914       W_L(" text=\"");
915       W_V(value);
916       W_L("\"");
917     }
918     else if (STRCASEEQ('l','L',"link", name) && value && *value) {
919       /*----------------------------------------------------------------------*/
920       /* CHTML 2.0                                                            */
921       /*----------------------------------------------------------------------*/
922       W_L(" link=\"");
923       W_V(value);
924       W_L("\"");
925     }
926     else if (STRCASEEQ('a','A',"alink", name) && value && *value) {
927       /*----------------------------------------------------------------------*/
928       /* CHTML 4.0                                                            */
929       /*----------------------------------------------------------------------*/
930       W_L(" alink=\"");
931       W_V(value);
932       W_L("\"");
933     }
934     else if (STRCASEEQ('v','V',"vlink", name) && value && *value) {
935       /*----------------------------------------------------------------------*/
936       /* CHTML 4.0                                                            */
937       /*----------------------------------------------------------------------*/
938       W_L(" vlink=\"");
939       W_V(value);
940       W_L("\"");
941     }
942   }
943   W_L(">");
944
945   return chtml40->out;
946 }
947
948
949 /**
950  * It is a handler who processes the BODY tag.
951  *
952  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
953  *                     destination is specified.
954  * @param node   [i]   The BODY tag node is specified.
955  * @return The conversion result is returned.
956  */
957 static char *
958 s_chtml40_end_body_tag(void *pdoc, Node *UNUSED(child)) 
959 {
960   chtml40_t   *chtml40;
961   Doc         *doc;
962
963   chtml40 = GET_CHTML40(pdoc);
964   doc     = chtml40->doc;
965
966   W_L("</body>");
967
968   return chtml40->out;
969 }
970
971
972 /**
973  * It is a handler who processes the A tag.
974  *
975  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
976  *                     destination is specified.
977  * @param node   [i]   The A tag node is specified.
978  * @return The conversion result is returned.
979  */
980 static char *
981 s_chtml40_start_a_tag(void *pdoc, Node *node) 
982 {
983   chtml40_t     *chtml40;
984   Doc           *doc;
985   request_rec   *r;
986   Attr          *attr;
987
988   chtml40 = GET_CHTML40(pdoc);
989   doc     = chtml40->doc;
990   r       = doc->r;
991
992   W_L("<a");
993   /*--------------------------------------------------------------------------*/
994   /* Get Attributes                                                           */
995   /*--------------------------------------------------------------------------*/
996   for (attr = qs_get_attr(doc,node);
997        attr; 
998        attr = qs_get_next_attr(doc,attr)) {
999     char *name  = qs_get_attr_name(doc,attr);
1000     char *value = qs_get_attr_value(doc,attr);
1001     if (STRCASEEQ('n','N',"name", name)) {
1002       /*----------------------------------------------------------------------*/
1003       /* CHTML1.0                                                             */
1004       /*----------------------------------------------------------------------*/
1005       W_L(" name=\"");
1006       W_V(value);
1007       W_L("\"");
1008     }
1009     else if (STRCASEEQ('h','H',"href", name)) {
1010       /*----------------------------------------------------------------------*/
1011       /* CHTML1.0                                                             */
1012       /*----------------------------------------------------------------------*/
1013       value = chxj_encoding_parameter(r, value);
1014       if (! chxj_starts_with(value, "mailto:") && ! chxj_starts_with(value, "tel:")) {
1015         value = chxj_add_cookie_parameter(r, value, chtml40->cookie);
1016       }
1017       W_L(" href=\"");
1018       W_V(value);
1019       W_L("\"");
1020     }
1021     else if (STRCASEEQ('a','A',"accesskey", name)) {
1022       /*----------------------------------------------------------------------*/
1023       /* CHTML1.0                                                             */
1024       /*----------------------------------------------------------------------*/
1025       W_L(" accesskey=\"");
1026       W_V(value);
1027       W_L("\"");
1028     }
1029     else if (STRCASEEQ('c','C',"cti", name)) {
1030       /*----------------------------------------------------------------------*/
1031       /* CHTML 2.0                                                            */
1032       /*----------------------------------------------------------------------*/
1033       W_L(" cti=\"");
1034       W_V(value);
1035       W_L("\"");
1036     }
1037     else if (STRCASEEQ('i','I',"ijam", name)) {
1038       /*----------------------------------------------------------------------*/
1039       /* CHTML 3.0                                                            */
1040       /*----------------------------------------------------------------------*/
1041       /* ignore */
1042     }
1043     else if (STRCASEEQ('u','U',"utn", name)) {
1044       /*----------------------------------------------------------------------*/
1045       /* CHTML 3.0                                                            */
1046       /* It is special only for CHTML.                                        */
1047       /*----------------------------------------------------------------------*/
1048       W_L(" utn ");
1049     }
1050     else if (STRCASEEQ('t','T',"telbook", name)) {
1051       /*----------------------------------------------------------------------*/
1052       /* CHTML 3.0                                                            */
1053       /*----------------------------------------------------------------------*/
1054       /* not support */
1055     }
1056     else if (STRCASEEQ('k','K',"kana", name)) {
1057       /*----------------------------------------------------------------------*/
1058       /* CHTML 3.0                                                            */
1059       /*----------------------------------------------------------------------*/
1060       /* not support */
1061     }
1062     else if (STRCASEEQ('e','E',"email", name)) {
1063       /*----------------------------------------------------------------------*/
1064       /* CHTML 3.0                                                            */
1065       /*----------------------------------------------------------------------*/
1066       /* not support */
1067     }
1068     else if (STRCASEEQ('i','I',"ista", name)) {
1069       /*----------------------------------------------------------------------*/
1070       /* CHTML 4.0                                                            */
1071       /*----------------------------------------------------------------------*/
1072       /* ignore */
1073     }
1074     else if (STRCASEEQ('i','I',"ilet", name)) {
1075       /*----------------------------------------------------------------------*/
1076       /* CHTML 5.0                                                            */
1077       /*----------------------------------------------------------------------*/
1078       /* ignore */
1079     }
1080     else if (STRCASEEQ('i','I',"iswf", name)) {
1081       /*----------------------------------------------------------------------*/
1082       /* CHTML 5.0                                                            */
1083       /*----------------------------------------------------------------------*/
1084       /* ignore */
1085     }
1086     else if (STRCASEEQ('i','I',"irst", name)) {
1087       /*----------------------------------------------------------------------*/
1088       /* CHTML 5.0                                                            */
1089       /*----------------------------------------------------------------------*/
1090       /* ignore */
1091     }
1092   }
1093   W_L(">");
1094   return chtml40->out;
1095 }
1096
1097
1098 /**
1099  * It is a handler who processes the A tag.
1100  *
1101  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1102  *                     destination is specified.
1103  * @param node   [i]   The A tag node is specified.
1104  * @return The conversion result is returned.
1105  */
1106 static char *
1107 s_chtml40_end_a_tag(void *pdoc, Node *UNUSED(child)) 
1108 {
1109   chtml40_t   *chtml40;
1110   Doc         *doc;
1111
1112   chtml40 = GET_CHTML40(pdoc);
1113   doc     = chtml40->doc;
1114
1115   W_L("</a>");
1116
1117   return chtml40->out;
1118 }
1119
1120
1121 /**
1122  * It is a handler who processes the BR tag.
1123  *
1124  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1125  *                     destination is specified.
1126  * @param node   [i]   The BR tag node is specified.
1127  * @return The conversion result is returned.
1128  */
1129 static char *
1130 s_chtml40_start_br_tag(void *pdoc, Node *node)
1131 {
1132   chtml40_t   *chtml40;
1133   Doc         *doc;
1134   request_rec *r;
1135   Attr        *attr;
1136
1137   chtml40 = GET_CHTML40(pdoc);
1138   doc     = chtml40->doc;
1139   r       = doc->r;
1140   W_L("<br");
1141   /*--------------------------------------------------------------------------*/
1142   /* Get Attributes                                                           */
1143   /*--------------------------------------------------------------------------*/
1144   for (attr = qs_get_attr(doc,node);
1145        attr;
1146        attr = qs_get_next_attr(doc,attr)) {
1147     char *name  = qs_get_attr_name(doc,attr);
1148     char *value = qs_get_attr_value(doc,attr);
1149     if (STRCASEEQ('c','C',"clear",name)) {
1150       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('a','A',"all",value))) {
1151         W_L(" clear=\"");
1152         W_V(value);
1153         W_L("\"");
1154       }
1155     }
1156   }
1157   W_L(">");
1158
1159   return chtml40->out;
1160 }
1161
1162
1163 /**
1164  * It is a handler who processes the BR tag.
1165  *
1166  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1167  *                     destination is specified.
1168  * @param node   [i]   The BR tag node is specified.
1169  * @return The conversion result is returned.
1170  */
1171 static char *
1172 s_chtml40_end_br_tag(void *pdoc, Node *UNUSED(child)) 
1173 {
1174   chtml40_t *chtml40 = GET_CHTML40(pdoc);
1175
1176   return chtml40->out;
1177 }
1178
1179
1180 /**
1181  * It is a handler who processes the TR tag.
1182  *
1183  * @param chtml40  [i/o] The pointer to the CHTML structure at the output
1184  *                     destination is specified.
1185  * @param node   [i]   The TR tag node is specified.
1186  * @return The conversion result is returned.
1187  */
1188 static char *
1189 s_chtml40_start_tr_tag(void *pdoc, Node *UNUSED(node)) 
1190 {
1191   chtml40_t *chtml40 = GET_CHTML40(pdoc);
1192
1193   return chtml40->out;
1194 }
1195
1196
1197 /**
1198  * It is a handler who processes the TR tag.
1199  *
1200  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1201  *                     destination is specified.
1202  * @param node   [i]   The TR tag node is specified.
1203  * @return The conversion result is returned.
1204  */
1205 static char *
1206 s_chtml40_end_tr_tag(void *pdoc, Node *UNUSED(child)) 
1207 {
1208   chtml40_t   *chtml40;
1209   Doc         *doc;
1210   request_rec *r;
1211
1212   chtml40 = GET_CHTML40(pdoc);
1213   doc     = chtml40->doc;
1214   r       = doc->r;
1215
1216   W_L("<br>");
1217
1218   return chtml40->out;
1219 }
1220
1221
1222 /**
1223  * It is a handler who processes the FONT tag.
1224  *
1225  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1226  *                     destination is specified.
1227  * @param node   [i]   The FONT tag node is specified.
1228  * @return The conversion result is returned.
1229  */
1230 static char *
1231 s_chtml40_start_font_tag(void *pdoc, Node *node) 
1232 {
1233   Attr          *attr;
1234   chtml40_t     *chtml40;
1235   Doc           *doc;
1236   request_rec   *r;
1237   char          *color = NULL;
1238
1239   chtml40 = GET_CHTML40(pdoc);
1240   doc     = chtml40->doc;
1241   r       = doc->r;
1242
1243   /*--------------------------------------------------------------------------*/
1244   /* Get Attributes                                                           */
1245   /*--------------------------------------------------------------------------*/
1246   for (attr = qs_get_attr(doc,node);
1247        attr && color == NULL; 
1248        attr = qs_get_next_attr(doc,attr)) {
1249     char *name  = qs_get_attr_name(doc,attr);
1250     char *value = qs_get_attr_value(doc,attr);
1251     if (STRCASEEQ('c','C',"color", name) && value && *value) {
1252       color = apr_pstrdup(doc->buf.pool, value);
1253       break;
1254     }
1255     else if (STRCASEEQ('s','S',"size", name)) {
1256       /*----------------------------------------------------------------------*/
1257       /* CHTML 5.0                                                            */
1258       /*----------------------------------------------------------------------*/
1259       /* ignore */
1260     }
1261   }
1262   if (color) {
1263     W_L("<font color=\"");
1264     W_V(color);
1265     W_L("\">");
1266     chtml40->font_flag++;
1267   }
1268   return chtml40->out;
1269 }
1270
1271
1272 /**
1273  * It is a handler who processes the FONT tag.
1274  *
1275  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1276  *                     destination is specified.
1277  * @param node   [i]   The FONT tag node is specified.
1278  * @return The conversion result is returned.
1279  */
1280 static char *
1281 s_chtml40_end_font_tag(void *pdoc, Node *UNUSED(child)) 
1282 {
1283   chtml40_t     *chtml40;
1284   Doc           *doc;
1285   request_rec   *r;
1286
1287   chtml40 = GET_CHTML40(pdoc);
1288   doc     = chtml40->doc;
1289   r       = doc->r;
1290
1291   if (chtml40->font_flag) {
1292     W_L("</font>");
1293     chtml40->font_flag--;
1294   }
1295
1296   return chtml40->out;
1297 }
1298
1299
1300 /**
1301  * It is a handler who processes the FORM tag.
1302  *
1303  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1304  *                     destination is specified.
1305  * @param node   [i]   The FORM tag node is specified.
1306  * @return The conversion result is returned.
1307  */
1308 static char *
1309 s_chtml40_start_form_tag(void *pdoc, Node *node) 
1310 {
1311   chtml40_t     *chtml40;
1312   Doc           *doc;
1313   request_rec   *r;
1314   Attr          *attr;
1315   char          *new_hidden_tag = NULL;
1316   char          *attr_method = NULL;
1317   char          *attr_action = NULL;
1318   char          *attr_utn    = NULL;
1319
1320   chtml40 = GET_CHTML40(pdoc);
1321   doc     = chtml40->doc;
1322   r       = doc->r;
1323
1324   /*--------------------------------------------------------------------------*/
1325   /* Get Attributes                                                           */
1326   /*--------------------------------------------------------------------------*/
1327   for (attr = qs_get_attr(doc,node);
1328        attr;
1329        attr = qs_get_next_attr(doc,attr)) {
1330     char *name  = qs_get_attr_name(doc,attr);
1331     char *value = qs_get_attr_value(doc,attr);
1332     if (STRCASEEQ('a','A',"action", name)) {
1333       /*----------------------------------------------------------------------*/
1334       /* CHTML 1.0                                                            */
1335       /*----------------------------------------------------------------------*/
1336       attr_action = chxj_encoding_parameter(r, value);
1337       attr_action = chxj_add_cookie_parameter(r, attr_action, chtml40->cookie);
1338     }
1339     else if (STRCASEEQ('m','M',"method", name)) {
1340       /*----------------------------------------------------------------------*/
1341       /* CHTML 1.0                                                            */
1342       /*----------------------------------------------------------------------*/
1343       attr_method = apr_pstrdup(doc->pool, value);
1344     }
1345     else if (STRCASEEQ('u','U',"utn", name)) {
1346       /*----------------------------------------------------------------------*/
1347       /* CHTML 3.0                                                            */
1348       /* It is special only for CHTML.                                        */
1349       /*----------------------------------------------------------------------*/
1350       attr_utn = value;
1351     }
1352   }
1353
1354   int post_flag = (attr_method && strcasecmp(attr_method, "post") == 0) ? 1 : 0;
1355
1356   W_L("<form");
1357   if (attr_action) {
1358     char *q;
1359     char *new_query_string = NULL;
1360     q = strchr(attr_action, '?');
1361     if (q) {
1362       new_hidden_tag = chxj_form_action_to_hidden_tag(r, doc->pool, attr_action, 0, post_flag, &new_query_string, CHXJ_TRUE, CHXJ_FALSE, chtml40->entryp);
1363       if (new_hidden_tag || new_query_string) {
1364         *q = 0;
1365       }
1366     }
1367     W_L(" action=\"");
1368     W_V(attr_action);
1369     if (new_query_string) {
1370       W_L("?");
1371       W_V(new_query_string);
1372     }
1373     W_L("\"");
1374   }
1375   if (attr_method) {
1376     W_L(" method=\"");
1377     W_V(attr_method);
1378     W_L("\"");
1379   }
1380   if (attr_utn) {
1381     W_L(" utn");
1382   }
1383   W_L(">");
1384   if (new_hidden_tag) {
1385     W_V(new_hidden_tag);
1386   }
1387   return chtml40->out;
1388 }
1389
1390
1391 /**
1392  * It is a handler who processes the FORM tag.
1393  *
1394  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1395  *                     destination is specified.
1396  * @param node   [i]   The FORM tag node is specified.
1397  * @return The conversion result is returned.
1398  */
1399 static char *
1400 s_chtml40_end_form_tag(void *pdoc, Node *UNUSED(child)) 
1401 {
1402   chtml40_t    *chtml40;
1403   Doc          *doc;
1404
1405   chtml40 = GET_CHTML40(pdoc);
1406   doc     = chtml40->doc;
1407
1408   W_L("</form>");
1409
1410   return chtml40->out;
1411 }
1412
1413
1414 /**
1415  * It is a handler who processes the INPUT tag.
1416  *
1417  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1418  *                     destination is specified.
1419  * @param node   [i]   The INPUT tag node is specified.
1420  * @return The conversion result is returned.
1421  */
1422 static char *
1423 s_chtml40_start_input_tag(void *pdoc, Node *node) 
1424 {
1425   chtml40_t   *chtml40;
1426   Doc         *doc;
1427   request_rec *r;
1428   char        *max_length  = NULL;
1429   char        *type        = NULL;
1430   char        *name        = NULL;
1431   char        *value       = NULL;
1432   char        *istyle      = NULL;
1433   char        *size        = NULL;
1434   char        *checked     = NULL;
1435   char        *accesskey   = NULL;
1436
1437   chtml40   = GET_CHTML40(pdoc);
1438   doc       = chtml40->doc;
1439   r         = doc->r;
1440   W_L("<input");
1441   /*--------------------------------------------------------------------------*/
1442   /* Get Attributes                                                           */
1443   /*--------------------------------------------------------------------------*/
1444   type       = qs_get_type_attr(doc, node, doc->buf.pool);
1445   name       = qs_get_name_attr(doc, node, doc->buf.pool);
1446   value      = qs_get_value_attr(doc,node, doc->buf.pool);
1447   istyle     = qs_get_istyle_attr(doc,node,doc->buf.pool);
1448   max_length = qs_get_maxlength_attr(doc,node,doc->buf.pool);
1449   checked    = qs_get_checked_attr(doc,node,doc->buf.pool);
1450   accesskey  = qs_get_accesskey_attr(doc, node, doc->buf.pool);
1451   size       = qs_get_size_attr(doc, node, doc->buf.pool);
1452
1453   if (type) {
1454     type = qs_trim_string(doc->buf.pool, type);
1455     if (type && (STRCASEEQ('t','T',"text",    type) ||
1456                  STRCASEEQ('p','P',"password",type) ||
1457                  STRCASEEQ('c','C',"checkbox",type) ||
1458                  STRCASEEQ('r','R',"radio",   type) ||
1459                  STRCASEEQ('h','H',"hidden",  type) ||
1460                  STRCASEEQ('s','S',"submit",  type) ||
1461                  STRCASEEQ('r','R',"reset",   type))) {
1462       W_L(" type=\"");
1463       W_V(type);
1464       W_L("\"");
1465     }
1466   }
1467   if (size && *size) {
1468     W_L(" size=\"");
1469     W_V(size);
1470     W_L("\"");
1471   }
1472   if (name && *name) {
1473     W_L(" name=\"");
1474     W_V(name);
1475     W_L("\"");
1476   }
1477   if (value && *value) {
1478     W_L(" value=\"");
1479     W_V(chxj_add_slash_to_doublequote(doc->pool, value));
1480     W_L("\"");
1481   }
1482   if (accesskey && *accesskey) {
1483     W_L(" accesskey=\"");
1484     W_V(accesskey);
1485     W_L("\"");
1486   }
1487   if (istyle) {
1488     /*------------------------------------------------------------------------*/
1489     /* CHTML 2.0                                                              */
1490     /*------------------------------------------------------------------------*/
1491     if (*istyle == '1' || *istyle == '2' || *istyle == '3' || *istyle == '4') {
1492       W_L(" istyle=\"");
1493       W_V(istyle);
1494       W_L("\"");
1495     }
1496   }
1497
1498   /*--------------------------------------------------------------------------*/
1499   /* The figure is default for the password.                                  */
1500   /*--------------------------------------------------------------------------*/
1501   if (max_length && *max_length) {
1502     if (chxj_chk_numeric(max_length) != 0) {
1503       max_length = apr_psprintf(r->pool, "0");
1504     }
1505     if (istyle != NULL && *istyle == '1') {
1506       char *vv = apr_psprintf(doc->buf.pool, " maxlength=\"%d\"", chxj_atoi(max_length) * 2);
1507       W_V(vv);
1508     }
1509     else  {
1510       char *vv = apr_psprintf(doc->buf.pool, " maxlength=\"%d\"", chxj_atoi(max_length));
1511       W_V(vv);
1512     }
1513   }
1514   if (checked) {
1515     W_L(" checked");
1516   }
1517   W_L(">");
1518   return chtml40->out;
1519 }
1520
1521
1522 /**
1523  * It is a handler who processes the INPUT tag.
1524  *
1525  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1526  *                     destination is specified.
1527  * @param node   [i]   The INPUT tag node is specified.
1528  * @return The conversion result is returned.
1529  */
1530 static char *
1531 s_chtml40_end_input_tag(void *pdoc, Node *UNUSED(child)) 
1532 {
1533   chtml40_t *chtml40 = GET_CHTML40(pdoc);
1534
1535   return chtml40->out;
1536 }
1537
1538
1539 /**
1540  * It is a handler who processes the CENTER tag.
1541  *
1542  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1543  *                     destination is specified.
1544  * @param node   [i]   The CENTER tag node is specified.
1545  * @return The conversion result is returned.
1546  */
1547 static char *
1548 s_chtml40_start_center_tag(void *pdoc, Node *UNUSED(node)) 
1549 {
1550   chtml40_t     *chtml40;
1551   Doc           *doc;
1552
1553   chtml40 = GET_CHTML40(pdoc);
1554   doc     = chtml40->doc;
1555
1556   W_L("<center>");
1557
1558   return chtml40->out;
1559 }
1560
1561
1562 /**
1563  * It is a handler who processes the CENTER tag.
1564  *
1565  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1566  *                     destination is specified.
1567  * @param node   [i]   The CENTER tag node is specified.
1568  * @return The conversion result is returned.
1569  */
1570 static char *
1571 s_chtml40_end_center_tag(void *pdoc, Node *UNUSED(child)) 
1572 {
1573   chtml40_t     *chtml40;
1574   Doc           *doc;
1575
1576   chtml40 = GET_CHTML40(pdoc);
1577   doc     = chtml40->doc;
1578
1579   W_L("</center>");
1580
1581   return chtml40->out;
1582 }
1583
1584
1585 /**
1586  * It is a handler who processes the HR tag.
1587  *
1588  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1589  *                     destination is specified.
1590  * @param node   [i]   The HR tag node is specified.
1591  * @return The conversion result is returned.
1592  */
1593 static char *
1594 s_chtml40_start_hr_tag(void *pdoc, Node *node) 
1595 {
1596   Attr        *attr;
1597   chtml40_t   *chtml40;
1598   Doc         *doc;
1599   request_rec *r;
1600
1601   chtml40 = GET_CHTML40(pdoc);
1602   doc     = chtml40->doc;
1603   r       = doc->r;
1604
1605   W_L("<hr");
1606  
1607   for (attr = qs_get_attr(doc,node);
1608        attr; 
1609        attr = qs_get_next_attr(doc,attr)) {
1610     char *name = qs_get_attr_name(doc,attr);
1611     char *value = qs_get_attr_value(doc,attr);
1612     if (STRCASEEQ('a','A',"align", name)) {
1613       /*----------------------------------------------------------------------*/
1614       /* CHTML 1.0                                                            */
1615       /*----------------------------------------------------------------------*/
1616       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
1617         W_L(" align=\"");
1618         W_V(value);
1619         W_L("\"");
1620       }
1621     }
1622     else if (STRCASEEQ('s','S',"size", name)) {
1623       /*----------------------------------------------------------------------*/
1624       /* CHTML 1.0                                                            */
1625       /*----------------------------------------------------------------------*/
1626       if (value && *value) {
1627         W_L(" size=\"");
1628         W_V(value);
1629         W_L("\"");
1630       }
1631     }
1632     else if (STRCASEEQ('w','W',"width", name)) {
1633       /*----------------------------------------------------------------------*/
1634       /* CHTML 1.0                                                            */
1635       /*----------------------------------------------------------------------*/
1636       if (value && *value) {
1637         W_L(" width=\"");
1638         W_V(value);
1639         W_L("\"");
1640       }
1641     }
1642     else if (STRCASEEQ('n','N',"noshade", name)) {
1643       /*----------------------------------------------------------------------*/
1644       /* CHTML 1.0                                                            */
1645       /*----------------------------------------------------------------------*/
1646       W_L(" noshade");
1647     }
1648     else if (STRCASEEQ('c','C',"color", name) && value && *value) {
1649       /*----------------------------------------------------------------------*/
1650       /* CHTML 4.0                                                            */
1651       /*----------------------------------------------------------------------*/
1652       W_L(" color=\"");
1653       W_V(value);
1654       W_L("\"");
1655     }
1656   }
1657   W_L(">");
1658   return chtml40->out;
1659 }
1660
1661
1662 /**
1663  * It is a handler who processes the HR tag.
1664  *
1665  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1666  *                     destination is specified.
1667  * @param node   [i]   The HR tag node is specified.
1668  * @return The conversion result is returned.
1669  */
1670 static char *
1671 s_chtml40_end_hr_tag(void *pdoc, Node *UNUSED(child)) 
1672 {
1673   chtml40_t *chtml40 = GET_CHTML40(pdoc);
1674
1675   return chtml40->out;
1676 }
1677
1678
1679 /**
1680  * It is a handler who processes the IMG tag.
1681  *
1682  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1683  *                     destination is specified.
1684  * @param node   [i]   The IMG tag node is specified.
1685  * @return The conversion result is returned.
1686  */
1687 static char *
1688 s_chtml40_start_img_tag(void *pdoc, Node *node) 
1689 {
1690 #ifndef IMG_NOT_CONVERT_FILENAME
1691   device_table *spec;
1692 #endif
1693   chtml40_t    *chtml40;
1694   Doc          *doc;
1695   request_rec  *r;
1696   Attr         *attr;
1697
1698   chtml40 = GET_CHTML40(pdoc);
1699   doc     = chtml40->doc;
1700   r       = doc->r;
1701 #ifndef IMG_NOT_CONVERT_FILENAME
1702   spec    = chtml40->spec;
1703 #endif
1704
1705   W_L("<img");
1706   /*--------------------------------------------------------------------------*/
1707   /* Get Attributes                                                           */
1708   /*--------------------------------------------------------------------------*/
1709   for (attr = qs_get_attr(doc,node);
1710        attr;
1711        attr = qs_get_next_attr(doc,attr)) {
1712     char *name  = qs_get_attr_name(doc,attr);
1713     char *value = qs_get_attr_value(doc,attr);
1714     if (STRCASEEQ('s','S',"src", name)) {
1715       /*----------------------------------------------------------------------*/
1716       /* CHTML 1.0                                                            */
1717       /*----------------------------------------------------------------------*/
1718 #ifdef IMG_NOT_CONVERT_FILENAME
1719       value = chxj_encoding_parameter(r, value);
1720       value = chxj_add_cookie_parameter(r, value, chtml40->cookie);
1721       value = chxj_add_cookie_no_update_parameter(r, value);
1722       W_L(" src=\"");
1723       W_V(value);
1724       W_L("\"");
1725
1726 #else
1727       value = chxj_img_conv(r,spec,value);
1728       value = chxj_encoding_parameter(r, value);
1729       value = chxj_add_cookie_parameter(r, value, chtml40->cookie);
1730       value = chxj_add_cookie_no_update_parameter(r, value);
1731       W_L(" src=\"");
1732       W_V(value);
1733       W_L("\"");
1734 #endif
1735     }
1736     else if (STRCASEEQ('a','A',"align", name)) {
1737       /*----------------------------------------------------------------------*/
1738       /* CHTML 1.0                                                            */
1739       /*----------------------------------------------------------------------*/
1740       if (value && (STRCASEEQ('t','T',"top",    value) ||
1741                     STRCASEEQ('m','M',"middle", value) ||
1742                     STRCASEEQ('b','B',"bottom", value) ||
1743                     STRCASEEQ('l','L',"left",   value) ||
1744                     STRCASEEQ('c','C',"center", value) ||
1745                     STRCASEEQ('r','R',"right",  value))) {
1746         W_L(" align=\"");
1747         W_V(value);
1748         W_L("\"");
1749       }
1750     }
1751     else if (STRCASEEQ('w','W',"width", name) && value && *value) {
1752       /*----------------------------------------------------------------------*/
1753       /* CHTML 1.0                                                            */
1754       /*----------------------------------------------------------------------*/
1755       W_L(" width=\"");
1756       W_V(value);
1757       W_L("\"");
1758     }
1759     else if (STRCASEEQ('h','H', "height", name) && value && *value) {
1760       /*----------------------------------------------------------------------*/
1761       /* CHTML 1.0                                                            */
1762       /*----------------------------------------------------------------------*/
1763       W_L(" height=\"");
1764       W_V(value);
1765       W_L("\"");
1766     }
1767     else if (STRCASEEQ('h','H',"hspace", name) && value && *value) {
1768       /*----------------------------------------------------------------------*/
1769       /* CHTML 1.0                                                            */
1770       /*----------------------------------------------------------------------*/
1771       W_L(" hspace=\"");
1772       W_V(value);
1773       W_L("\"");
1774     }
1775     else if (STRCASEEQ('v','V',"vspace", name) && value && *value) {
1776       /*----------------------------------------------------------------------*/
1777       /* CHTML 1.0                                                            */
1778       /*----------------------------------------------------------------------*/
1779       W_L(" vspace=\"");
1780       W_V(value);
1781       W_L("\"");
1782     }
1783     else if (STRCASEEQ('a','A',"alt",name) && value && *value) {
1784       /*----------------------------------------------------------------------*/
1785       /* CHTML 1.0                                                            */
1786       /*----------------------------------------------------------------------*/
1787       W_L(" alt=\"");
1788       W_V(value);
1789       W_L("\"");
1790     }
1791   }
1792   W_L(">");
1793   return chtml40->out;
1794 }
1795
1796
1797 /**
1798  * It is a handler who processes the IMG tag.
1799  *
1800  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1801  *                     destination is specified.
1802  * @param node   [i]   The IMG tag node is specified.
1803  * @return The conversion result is returned.
1804  */
1805 static char *
1806 s_chtml40_end_img_tag(void *pdoc, Node *UNUSED(child)) 
1807 {
1808   chtml40_t *chtml40 = GET_CHTML40(pdoc);
1809
1810   return chtml40->out;
1811 }
1812
1813
1814 /**
1815  * It is a handler who processes the SELECT tag.
1816  *
1817  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1818  *                     destination is specified.
1819  * @param node   [i]   The SELECT tag node is specified.
1820  * @return The conversion result is returned.
1821  */
1822 static char *
1823 s_chtml40_start_select_tag(void *pdoc, Node *child)
1824 {
1825   chtml40_t   *chtml40  = GET_CHTML40(pdoc);
1826   Doc         *doc      = chtml40->doc;
1827   char        *size     = NULL;
1828   char        *name     = NULL;
1829   char        *multiple = NULL;
1830   Attr        *attr;
1831
1832   W_L("<select");
1833   for (attr = qs_get_attr(doc,child);
1834        attr;
1835        attr = qs_get_next_attr(doc,attr)) {
1836     char *nm  = qs_get_attr_name(doc,attr);
1837     char *val = qs_get_attr_value(doc,attr);
1838     if (STRCASEEQ('s','S',"size", nm)) {
1839       /*----------------------------------------------------------------------*/
1840       /* CHTML 1.0 version 2.0                                                */
1841       /*----------------------------------------------------------------------*/
1842       size = apr_pstrdup(doc->buf.pool, val);
1843     }
1844     else if (STRCASEEQ('n','N',"name", nm)) {
1845       /*----------------------------------------------------------------------*/
1846       /* CHTML 1.0 version 2.0                                                */
1847       /*----------------------------------------------------------------------*/
1848       name = apr_pstrdup(doc->buf.pool, val);
1849     }
1850     else if (STRCASEEQ('m','M',"multiple", nm)) {
1851       /*----------------------------------------------------------------------*/
1852       /* CHTML 1.0 version 2.0                                                */
1853       /*----------------------------------------------------------------------*/
1854       multiple = apr_pstrdup(doc->buf.pool, val);
1855     }
1856   }
1857   if (size && *size) {
1858     W_L(" size=\"");
1859     W_V(size);
1860     W_L("\"");
1861   }
1862   if (name && *name) {
1863     W_L(" name=\"");
1864     W_V(name);
1865     W_L("\"");
1866   }
1867   if (multiple) {
1868     W_L(" multiple");
1869   }
1870   W_L(">");
1871   return chtml40->out;
1872 }
1873
1874
1875 /**
1876  * It is a handler who processes the SELECT tag.
1877  *
1878  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1879  *                     destination is specified.
1880  * @param node   [i]   The SELECT tag node is specified.
1881  * @return The conversion result is returned.
1882  */
1883 static char *
1884 s_chtml40_end_select_tag(void *pdoc, Node *UNUSED(child))
1885 {
1886   chtml40_t    *chtml40 = GET_CHTML40(pdoc);
1887   Doc          *doc   = chtml40->doc;
1888
1889   W_L("</select>");
1890   return chtml40->out;
1891 }
1892
1893
1894 /**
1895  * It is a handler who processes the OPTION tag.
1896  *
1897  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1898  *                     destination is specified.
1899  * @param node   [i]   The OPTION tag node is specified.
1900  * @return The conversion result is returned.
1901  */
1902 static char *
1903 s_chtml40_start_option_tag(void *pdoc, Node *child)
1904 {
1905   Attr        *attr;
1906   chtml40_t   *chtml40;
1907   Doc         *doc;
1908   request_rec *r;
1909   char        *selected;
1910   char        *value;
1911
1912   chtml40    = GET_CHTML40(pdoc);
1913   doc        = chtml40->doc;
1914   r          = doc->r;
1915   selected   = NULL;
1916   value      = NULL;
1917
1918   W_L("<option");
1919   for (attr = qs_get_attr(doc,child);
1920        attr;
1921        attr = qs_get_next_attr(doc,attr)) {
1922     char *nm  = qs_get_attr_name(doc,attr);
1923     char *val = qs_get_attr_value(doc,attr);
1924     if (STRCASEEQ('s','S',"selected", nm)) {
1925       /*----------------------------------------------------------------------*/
1926       /* CHTML 1.0 version 2.0                                                */
1927       /*----------------------------------------------------------------------*/
1928       selected = apr_pstrdup(doc->buf.pool, val);
1929     }
1930     else if (STRCASEEQ('v','V',"value", nm)) {
1931       /*----------------------------------------------------------------------*/
1932       /* CHTML 1.0 version 2.0                                                */
1933       /*----------------------------------------------------------------------*/
1934       value = apr_pstrdup(doc->buf.pool, val);
1935     }
1936   }
1937   if (value) {
1938     W_L(" value=\"");
1939     W_V(value);
1940     W_L("\"");
1941   }
1942   if (selected) {
1943     W_L(" selected");
1944   }
1945   W_L(">");
1946   return chtml40->out;
1947 }
1948
1949
1950 /**
1951  * It is a handler who processes the OPTION tag.
1952  *
1953  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1954  *                     destination is specified.
1955  * @param node   [i]   The OPTION tag node is specified.
1956  * @return The conversion result is returned.
1957  */
1958 static char *
1959 s_chtml40_end_option_tag(void *pdoc, Node *UNUSED(child))
1960 {
1961   chtml40_t *chtml40 = GET_CHTML40(pdoc);
1962
1963   /* Don't close */
1964
1965   return chtml40->out;
1966 }
1967
1968
1969 /**
1970  * It is a handler who processes the DIV tag.
1971  *
1972  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1973  *                     destination is specified.
1974  * @param node   [i]   The DIV tag node is specified.
1975  * @return The conversion result is returned.
1976  */
1977 static char *
1978 s_chtml40_start_div_tag(void *pdoc, Node *child)
1979 {
1980   Attr          *attr;
1981   chtml40_t     *chtml40;
1982   Doc           *doc;
1983   request_rec   *r;
1984   char          *align;
1985
1986   chtml40 = GET_CHTML40(pdoc);
1987   doc     = chtml40->doc;
1988   r       = doc->r;
1989   align   = NULL;
1990
1991   W_L("<div");
1992   for (attr = qs_get_attr(doc,child);
1993        attr;
1994        attr = qs_get_next_attr(doc,attr)) {
1995     char *nm  = qs_get_attr_name(doc,attr);
1996     char *val = qs_get_attr_value(doc,attr);
1997     if (STRCASEEQ('a','A',"align", nm)) {
1998       /*----------------------------------------------------------------------*/
1999       /* CHTML 1.0 (W3C version 3.2)                                          */
2000       /*----------------------------------------------------------------------*/
2001       if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
2002         align = apr_pstrdup(doc->buf.pool, val);
2003       }
2004     }
2005   }
2006   if (align) {
2007     W_L(" align=\"");
2008     W_V(align);
2009     W_L("\"");
2010   }
2011   W_L(">");
2012   return chtml40->out;
2013 }
2014
2015
2016 /**
2017  * It is a handler who processes the DIV tag.
2018  *
2019  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2020  *                     destination is specified.
2021  * @param node   [i]   The DIV tag node is specified.
2022  * @return The conversion result is returned.
2023  */
2024 static char *
2025 s_chtml40_end_div_tag(void *pdoc, Node *UNUSED(node))
2026 {
2027   chtml40_t    *chtml40 = GET_CHTML40(pdoc);
2028   Doc          *doc     = chtml40->doc;
2029
2030   W_L("</div>");
2031
2032   return chtml40->out;
2033 }
2034
2035
2036 /**
2037  * It is a handler who processes the UL tag.
2038  *
2039  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2040  *                     destination is specified.
2041  * @param node   [i]   The UL tag node is specified.
2042  * @return The conversion result is returned.
2043  */
2044 static char *
2045 s_chtml40_start_ul_tag(void *pdoc, Node *node)
2046 {
2047   chtml40_t   *chtml40 = GET_CHTML40(pdoc);
2048   Doc         *doc     = chtml40->doc;
2049   Attr        *attr;
2050   W_L("<ul");
2051   /*--------------------------------------------------------------------------*/
2052   /* Get Attributes                                                           */
2053   /*--------------------------------------------------------------------------*/
2054   for (attr = qs_get_attr(doc,node);
2055        attr;
2056        attr = qs_get_next_attr(doc,attr)) {
2057     char *name   = qs_get_attr_name(doc,attr);
2058     char *value  = qs_get_attr_value(doc,attr);
2059     if (STRCASEEQ('t','T',"type",name)) {
2060       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
2061         W_L(" type=\"");
2062         W_V(value);
2063         W_L("\"");
2064       }
2065     }
2066   }
2067   W_L(">");
2068
2069   return chtml40->out;
2070 }
2071
2072
2073 /**
2074  * It is a handler who processes the UL tag.
2075  *
2076  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2077  *                     destination is specified.
2078  * @param node   [i]   The UL tag node is specified.
2079  * @return The conversion result is returned.
2080  */
2081 static char *
2082 s_chtml40_end_ul_tag(void *pdoc, Node *UNUSED(child)) 
2083 {
2084   chtml40_t     *chtml40 = GET_CHTML40(pdoc);
2085   Doc           *doc     = chtml40->doc;
2086
2087   W_L("</ul>");
2088
2089   return chtml40->out;
2090 }
2091
2092
2093 /**
2094  * It is a handler who processes the PRE tag.
2095  *
2096  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2097  *                     destination is specified.
2098  * @param node   [i]   The PRE tag node is specified.
2099  * @return The conversion result is returned.
2100  */
2101 static char *
2102 s_chtml40_start_pre_tag(void *pdoc, Node *UNUSED(node)) 
2103 {
2104   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2105   Doc       *doc     = chtml40->doc;
2106
2107   chtml40->pre_flag++;
2108   W_L("<pre>");
2109
2110   return chtml40->out;
2111 }
2112
2113
2114 /**
2115  * It is a handler who processes the PRE tag.
2116  *
2117  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2118  *                     destination is specified.
2119  * @param node   [i]   The PRE tag node is specified.
2120  * @return The conversion result is returned.
2121  */
2122 static char *
2123 s_chtml40_end_pre_tag(void *pdoc, Node *UNUSED(child)) 
2124 {
2125   chtml40_t     *chtml40 = GET_CHTML40(pdoc);
2126   Doc           *doc     = chtml40->doc;
2127
2128   W_L("</pre>");
2129   chtml40->pre_flag--;
2130
2131   return chtml40->out;
2132 }
2133
2134
2135 /**
2136  * It is a handler who processes the P tag.
2137  *
2138  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2139  *                     destination is specified.
2140  * @param node   [i]   The P tag node is specified.
2141  * @return The conversion result is returned.
2142  */
2143 static char *
2144 s_chtml40_start_p_tag(void *pdoc, Node *node) 
2145 {
2146   chtml40_t     *chtml40;
2147   Doc           *doc;
2148   request_rec   *r;
2149   Attr          *attr;
2150   char          *align = NULL;
2151
2152   chtml40 = GET_CHTML40(pdoc);
2153   doc     = chtml40->doc;
2154   r       = doc->r;
2155
2156   W_L("<p");
2157   for (attr = qs_get_attr(doc,node);
2158        attr;
2159        attr = qs_get_next_attr(doc,attr)) {
2160     char *nm  = qs_get_attr_name(doc,attr);
2161     char *val = qs_get_attr_value(doc,attr);
2162     if (STRCASEEQ('a','A',"align", nm)) {
2163       /*----------------------------------------------------------------------*/
2164       /* CHTML 1.0 (W3C version 3.2)                                          */
2165       /*----------------------------------------------------------------------*/
2166       if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
2167         align = apr_pstrdup(doc->buf.pool, val);
2168         break;
2169       }
2170     }
2171   }
2172   if (align) {
2173     W_L(" align=\"");
2174     W_V(align);
2175     W_L("\"");
2176   }
2177   W_L(">");
2178   return chtml40->out;
2179 }
2180
2181
2182 /**
2183  * It is a handler who processes the P tag.
2184  *
2185  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2186  *                     destination is specified.
2187  * @param node   [i]   The P tag node is specified.
2188  * @return The conversion result is returned.
2189  */
2190 static char *
2191 s_chtml40_end_p_tag(void *pdoc, Node *UNUSED(child)) 
2192 {
2193   chtml40_t   *chtml40;
2194   Doc         *doc;
2195
2196   chtml40 = GET_CHTML40(pdoc);
2197   doc     = chtml40->doc;
2198
2199   W_L("</p>");
2200
2201   return chtml40->out;
2202 }
2203
2204
2205 /**
2206  * It is a handler who processes the OL tag.
2207  *
2208  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2209  *                     destination is specified.
2210  * @param node   [i]   The OL tag node is specified.
2211  * @return The conversion result is returned.
2212  */
2213 static char *
2214 s_chtml40_start_ol_tag(void *pdoc, Node *node)
2215 {
2216   chtml40_t     *chtml40;
2217   Doc           *doc;
2218   request_rec   *r;
2219   Attr          *attr;
2220
2221   chtml40 = GET_CHTML40(pdoc);
2222   doc     = chtml40->doc;
2223   r       = doc->r;
2224
2225   W_L("<ol");
2226   /*--------------------------------------------------------------------------*/
2227   /* Get Attributes                                                           */
2228   /*--------------------------------------------------------------------------*/
2229   for (attr = qs_get_attr(doc,node);
2230        attr;
2231        attr = qs_get_next_attr(doc,attr)) {
2232     char *name = qs_get_attr_name(doc,attr);
2233     char *value = qs_get_attr_value(doc,attr);
2234     if (STRCASEEQ('t','T',"type",name) && value && (*value == '1' || *value == 'a' || *value == 'A')) {
2235       W_L(" type=\"");
2236       W_V(value);
2237       W_L("\"");
2238     }
2239     else if (STRCASEEQ('s','S',"start",name) && value && *value) {
2240       W_L(" start=\"");
2241       W_V(value);
2242       W_L("\"");
2243     }
2244   }
2245   W_L(">");
2246
2247   return chtml40->out;
2248 }
2249
2250
2251 /**
2252  * It is a handler who processes the OL tag.
2253  *
2254  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2255  *                     destination is specified.
2256  * @param node   [i]   The OL tag node is specified.
2257  * @return The conversion result is returned.
2258  */
2259 static char *
2260 s_chtml40_end_ol_tag(void *pdoc, Node *UNUSED(node)) 
2261 {
2262   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2263   Doc       *doc     = chtml40->doc;
2264
2265   W_L("</ol>");
2266
2267   return chtml40->out;
2268 }
2269
2270
2271 /**
2272  * It is a handler who processes the LI tag.
2273  *
2274  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2275  *                     destination is specified.
2276  * @param node   [i]   The LI tag node is specified.
2277  * @return The conversion result is returned.
2278  */
2279 static char *
2280 s_chtml40_start_li_tag(void *pdoc, Node *node) 
2281 {
2282   chtml40_t   *chtml40 = GET_CHTML40(pdoc);
2283   Doc         *doc     = chtml40->doc;
2284   Attr        *attr;
2285
2286   W_L("<li");
2287   /*--------------------------------------------------------------------------*/
2288   /* Get Attributes                                                           */
2289   /*--------------------------------------------------------------------------*/
2290   for (attr = qs_get_attr(doc,node);
2291        attr;
2292        attr = qs_get_next_attr(doc,attr)) {
2293     char *name = qs_get_attr_name(doc,attr);
2294     char *value = qs_get_attr_value(doc,attr);
2295     if (STRCASEEQ('t','T',"type",name)) {
2296       if (value && (*value == '1' || *value == 'a' || *value == 'A' || STRCASEEQ('d','D',"disc",value) || STRCASEEQ('s','S',"square",value) || STRCASEEQ('c','C',"circle",value))) {
2297         W_L(" type=\"");
2298         W_V(value);
2299         W_L("\"");
2300       }
2301     }
2302     else if (STRCASEEQ('v','V',"value", name) && value && *value) {
2303       W_L(" value=\"");
2304       W_V(value);
2305       W_L("\"");
2306     }
2307   }
2308   W_L(">");
2309   return chtml40->out;
2310 }
2311
2312
2313 /**
2314  * It is a handler who processes the LI tag.
2315  *
2316  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2317  *                     destination is specified.
2318  * @param node   [i]   The LI tag node is specified.
2319  * @return The conversion result is returned.
2320  */
2321 static char *
2322 s_chtml40_end_li_tag(void *pdoc, Node *UNUSED(child)) 
2323 {
2324   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2325
2326   return chtml40->out;
2327 }
2328
2329
2330 /**
2331  * It is a handler who processes the H1 tag.
2332  *
2333  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2334  *                     destination is specified.
2335  * @param node   [i]   The H1 tag node is specified.
2336  * @return The conversion result is returned.
2337  */
2338 static char *
2339 s_chtml40_start_h1_tag(void *pdoc, Node *node)
2340 {
2341   chtml40_t     *chtml40;
2342   Doc           *doc;
2343   request_rec   *r;
2344   Attr          *attr;
2345
2346   chtml40 = GET_CHTML40(pdoc);
2347   doc     = chtml40->doc;
2348   r       = doc->r;
2349
2350   W_L("<h1");
2351   for (attr = qs_get_attr(doc,node);
2352        attr;
2353        attr = qs_get_next_attr(doc,attr)) {
2354     char *name = qs_get_attr_name(doc,attr);
2355     char *value = qs_get_attr_value(doc,attr);
2356     if (STRCASEEQ('a','A',"align", name)) {
2357       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
2358         W_L(" align=\"");
2359         W_V(value);
2360         W_L("\"");
2361         break;
2362       }
2363     }
2364   }
2365   W_L(">");
2366
2367   return chtml40->out;
2368 }
2369
2370
2371 /**
2372  * It is a handler who processes the H1 tag.
2373  *
2374  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2375  *                     destination is specified.
2376  * @param node   [i]   The H1 tag node is specified.
2377  * @return The conversion result is returned.
2378  */
2379 static char *
2380 s_chtml40_end_h1_tag(void *pdoc, Node *UNUSED(child)) 
2381 {
2382   chtml40_t   *chtml40;
2383   Doc         *doc;
2384
2385   chtml40 = GET_CHTML40(pdoc);
2386   doc     = chtml40->doc;
2387
2388   W_L("</h1>");
2389
2390   return chtml40->out;
2391 }
2392
2393
2394 /**
2395  * It is a handler who processes the H2 tag.
2396  *
2397  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2398  *                     destination is specified.
2399  * @param node   [i]   The H2 tag node is specified.
2400  * @return The conversion result is returned.
2401  */
2402 static char *
2403 s_chtml40_start_h2_tag(void *pdoc, Node *node)
2404 {
2405   chtml40_t     *chtml40;
2406   Doc           *doc;
2407   request_rec   *r;
2408   Attr          *attr;
2409
2410   chtml40 = GET_CHTML40(pdoc);
2411   doc     = chtml40->doc;
2412   r       = doc->r;
2413
2414   W_L("<h2");
2415   for (attr = qs_get_attr(doc,node);
2416        attr;
2417        attr = qs_get_next_attr(doc,attr)) {
2418     char *name  = qs_get_attr_name(doc,attr);
2419     char *value = qs_get_attr_value(doc,attr);
2420     if (STRCASEEQ('a','A',"align", name)) {
2421       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
2422         W_L(" align=\"");
2423         W_V(value);
2424         W_L("\"");
2425         break;
2426       }
2427     }
2428   }
2429   W_L(">");
2430   return chtml40->out;
2431 }
2432
2433
2434 /**
2435  * It is a handler who processes the H2 tag.
2436  *
2437  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2438  *                     destination is specified.
2439  * @param node   [i]   The H2 tag node is specified.
2440  * @return The conversion result is returned.
2441  */
2442 static char *
2443 s_chtml40_end_h2_tag(void *pdoc, Node *UNUSED(child)) 
2444 {
2445   chtml40_t   *chtml40 = GET_CHTML40(pdoc);
2446   Doc         *doc     = chtml40->doc;
2447
2448   W_L("</h2>");
2449
2450   return chtml40->out;
2451 }
2452
2453
2454 /**
2455  * It is a handler who processes the H3 tag.
2456  *
2457  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2458  *                     destination is specified.
2459  * @param node   [i]   The H3 tag node is specified.
2460  * @return The conversion result is returned.
2461  */
2462 static char *
2463 s_chtml40_start_h3_tag(void *pdoc, Node *node)
2464 {
2465   chtml40_t   *chtml40;
2466   Doc         *doc;
2467   request_rec *r;
2468   Attr        *attr;
2469
2470   chtml40 = GET_CHTML40(pdoc);
2471   doc     = chtml40->doc;
2472   r       = doc->r;
2473
2474   W_L("<h3");
2475   for (attr = qs_get_attr(doc,node);
2476        attr;
2477        attr = qs_get_next_attr(doc,attr)) {
2478     char *name  = qs_get_attr_name(doc,attr);
2479     char *value = qs_get_attr_value(doc,attr);
2480     if (STRCASEEQ('a','A',"align", name)) {
2481       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
2482         W_L(" align=\"");
2483         W_V(value);
2484         W_L("\"");
2485         break;
2486       }
2487     }
2488   }
2489   W_L(">");
2490
2491   return chtml40->out;
2492 }
2493
2494
2495 /**
2496  * It is a handler who processes the H3 tag.
2497  *
2498  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2499  *                     destination is specified.
2500  * @param node   [i]   The H3 tag node is specified.
2501  * @return The conversion result is returned.
2502  */
2503 static char *
2504 s_chtml40_end_h3_tag(void *pdoc, Node *UNUSED(child))
2505 {
2506   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2507   Doc       *doc   = chtml40->doc;
2508
2509   W_L("</h3>");
2510
2511   return chtml40->out;
2512 }
2513
2514
2515 /**
2516  * It is a handler who processes the H4 tag.
2517  *
2518  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2519  *                     destination is specified.
2520  * @param node   [i]   The H4 tag node is specified.
2521  * @return The conversion result is returned.
2522  */
2523 static char *
2524 s_chtml40_start_h4_tag(void *pdoc, Node *node)
2525 {
2526   chtml40_t   *chtml40;
2527   Doc         *doc;
2528   request_rec *r;
2529   Attr        *attr;
2530
2531   chtml40 = GET_CHTML40(pdoc);
2532   doc     = chtml40->doc;
2533   r       = doc->r;
2534
2535   W_L("<h4");
2536   for (attr = qs_get_attr(doc,node);
2537        attr;
2538        attr = qs_get_next_attr(doc,attr)) {
2539     char *name  = qs_get_attr_name(doc,attr);
2540     char *value = qs_get_attr_value(doc,attr);
2541     if (STRCASEEQ('a','A',"align", name)) {
2542       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
2543         W_L(" align=\"");
2544         W_V(value);
2545         W_L("\"");
2546         break;
2547       }
2548     }
2549   }
2550   W_L(">");
2551   return chtml40->out;
2552 }
2553
2554
2555 /**
2556  * It is a handler who processes the H4 tag.
2557  *
2558  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2559  *                     destination is specified.
2560  * @param node   [i]   The H4 tag node is specified.
2561  * @return The conversion result is returned.
2562  */
2563 static char *
2564 s_chtml40_end_h4_tag(void *pdoc, Node *UNUSED(child)) 
2565 {
2566   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2567   Doc       *doc     = chtml40->doc;
2568
2569   W_L("</h4>");
2570
2571   return chtml40->out;
2572 }
2573
2574
2575 /**
2576  * It is a handler who processes the H5 tag.
2577  *
2578  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2579  *                     destination is specified.
2580  * @param node   [i]   The H5 tag node is specified.
2581  * @return The conversion result is returned.
2582  */
2583 static char *
2584 s_chtml40_start_h5_tag(void *pdoc, Node *node)
2585 {
2586   chtml40_t   *chtml40;
2587   Doc         *doc;
2588   request_rec *r;
2589   Attr        *attr;
2590
2591   chtml40 = GET_CHTML40(pdoc);
2592   doc     = chtml40->doc;
2593   r       = doc->r;
2594
2595   W_L("<h5");
2596   for (attr = qs_get_attr(doc,node);
2597        attr;
2598        attr = qs_get_next_attr(doc,attr)) {
2599     char *name  = qs_get_attr_name(doc,attr);
2600     char *value = qs_get_attr_value(doc,attr);
2601     if (STRCASEEQ('a','A',"align", name)) {
2602       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
2603         W_L(" align=\"");
2604         W_V(value);
2605         W_L("\"");
2606         break;
2607       }
2608     }
2609   }
2610   W_L(">");
2611   return chtml40->out;
2612 }
2613
2614
2615 /**
2616  * It is a handler who processes the H5 tag.
2617  *
2618  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2619  *                     destination is specified.
2620  * @param node   [i]   The H5 tag node is specified.
2621  * @return The conversion result is returned.
2622  */
2623 static char *
2624 s_chtml40_end_h5_tag(void *pdoc, Node *UNUSED(child)) 
2625 {
2626   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2627   Doc       *doc     = chtml40->doc;
2628
2629   W_L("</h5>");
2630
2631   return chtml40->out;
2632 }
2633
2634
2635 /**
2636  * It is a handler who processes the H6 tag.
2637  *
2638  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2639  *                     destination is specified.
2640  * @param node   [i]   The H6 tag node is specified.
2641  * @return The conversion result is returned.
2642  */
2643 static char *
2644 s_chtml40_start_h6_tag(void *pdoc, Node *node)
2645 {
2646   chtml40_t   *chtml40;
2647   Doc         *doc;
2648   request_rec *r;
2649   Attr        *attr;
2650
2651   chtml40 = GET_CHTML40(pdoc);
2652   doc     = chtml40->doc;
2653   r       = doc->r;
2654
2655   W_L("<h6");
2656   for (attr = qs_get_attr(doc,node);
2657        attr;
2658        attr = qs_get_next_attr(doc,attr)) {
2659     char *name  = qs_get_attr_name(doc,attr);
2660     char *value = qs_get_attr_value(doc,attr);
2661     if (STRCASEEQ('a','A',"align", name)) {
2662       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
2663         W_L(" align=\"");
2664         W_V(value);
2665         W_L("\"");
2666         break;
2667       }
2668     }
2669   }
2670   W_L(">");
2671   return chtml40->out;
2672 }
2673
2674
2675 /**
2676  * It is a handler who processes the H6 tag.
2677  *
2678  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2679  *                     destination is specified.
2680  * @param node   [i]   The H6 tag node is specified.
2681  * @return The conversion result is returned.
2682  */
2683 static char *
2684 s_chtml40_end_h6_tag(void *pdoc, Node *UNUSED(child)) 
2685 {
2686   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2687   Doc       *doc     = chtml40->doc;
2688
2689   W_L("</h6>");
2690
2691   return chtml40->out;
2692 }
2693
2694
2695 /**
2696  * It is a handler who processes the TEXTARE tag.
2697  *
2698  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2699  *                     destination is specified.
2700  * @param node   [i]   The TEXTAREA tag node is specified.
2701  * @return The conversion result is returned.
2702  */
2703 static char *
2704 s_chtml40_start_textarea_tag(void *pdoc, Node *node) 
2705 {
2706   chtml40_t     *chtml40;
2707   Doc           *doc;
2708   request_rec   *r;
2709   Attr          *attr;
2710
2711   chtml40 = GET_CHTML40(pdoc);
2712   doc     = chtml40->doc;
2713   r       = doc->r;
2714
2715   chtml40->textarea_flag++;
2716
2717   W_L("<textarea");
2718   for (attr = qs_get_attr(doc,node);
2719        attr;
2720        attr = qs_get_next_attr(doc,attr)) {
2721     char *name  = qs_get_attr_name(doc,attr);
2722     char *value = qs_get_attr_value(doc,attr);
2723     if (STRCASEEQ('a','A',"accesskey",name) && value && *value != 0) {
2724       W_L(" accesskey=\"");
2725       W_V(value);
2726       W_L("\"");
2727     }
2728     else if (STRCASEEQ('i','I',"istyle", name) && value && (*value == '1' || *value == '2' || *value == '3' || *value == '4')) {
2729       W_L(" istyle=\"");
2730       W_V(value);
2731       W_L("\"");
2732     }
2733     else if (STRCASEEQ('n','N',"name", name) && value && *value) {
2734       W_L(" name=\"");
2735       W_V(value);
2736       W_L("\"");
2737     }
2738     else if (STRCASEEQ('r','R',"rows", name) && value && *value) {
2739       W_L(" rows=\"");
2740       W_V(value);
2741       W_L("\"");
2742     }
2743     else if (STRCASEEQ('c','C',"cols", name) && value && *value) {
2744       W_L(" cols=\"");
2745       W_V(value);
2746       W_L("\"");
2747     }
2748   }
2749   W_L(">");
2750   return chtml40->out;
2751 }
2752
2753
2754 /**
2755  * It is a handler who processes the TEXTAREA tag.
2756  *
2757  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2758  *                     destination is specified.
2759  * @param node   [i]   The TEXTAREA tag node is specified.
2760  * @return The conversion result is returned.
2761  */
2762 static char *
2763 s_chtml40_end_textarea_tag(void *pdoc, Node *UNUSED(child)) 
2764 {
2765   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2766   Doc       *doc     = chtml40->doc;
2767
2768   W_L("</textarea>");
2769   chtml40->textarea_flag--;
2770
2771   return chtml40->out;
2772 }
2773
2774
2775 static char *
2776 s_chtml40_chxjif_tag(void *pdoc, Node *node)
2777 {
2778   Node        *child;
2779   chtml40_t   *chtml40;
2780   Doc         *doc;
2781   request_rec *r;
2782
2783   chtml40 = GET_CHTML40(pdoc);
2784   doc     = chtml40->doc;
2785   r       = doc->r;
2786
2787   for (child = qs_get_child_node(doc, node);
2788        child;
2789        child = qs_get_next_node(doc, child)) {
2790     W_V(child->otext);
2791     s_chtml40_chxjif_tag(chtml40, child);
2792   }
2793
2794   return NULL;
2795 }
2796
2797
2798 static char *
2799 s_chtml40_text_tag(void *pdoc, Node *child)
2800 {
2801   chtml40_t   *chtml40;
2802   Doc         *doc;
2803   request_rec *r;
2804
2805   char        *textval;
2806   char        *tmp;
2807   char        *tdst;
2808   char        one_byte[2];
2809   int         ii;
2810   int         tdst_len;
2811
2812   chtml40 = GET_CHTML40(pdoc);
2813   doc     = chtml40->doc;
2814   r       = doc->r;
2815   
2816   textval = qs_get_node_value(doc,child);
2817   if (strlen(textval) == 0) {
2818     return chtml40->out;
2819   }
2820   
2821   tmp = apr_palloc(r->pool, qs_get_node_size(doc,child)+1);
2822   memset(tmp, 0, qs_get_node_size(doc,child)+1);
2823   
2824   tdst     = qs_alloc_zero_byte_string(doc->buf.pool);
2825   memset(one_byte, 0, sizeof(one_byte));
2826   tdst_len = 0;
2827   
2828   for (ii=0; ii<qs_get_node_size(doc,child); ii++) {
2829     char* out;
2830     int rtn = s_chtml40_search_emoji(chtml40, &textval[ii], &out);
2831     if (rtn) {
2832       tdst = qs_out_apr_pstrcat(r, tdst, out, &tdst_len);
2833       ii+=(rtn - 1);
2834       continue;
2835     }
2836   
2837     if (is_sjis_kanji(textval[ii])) {
2838       one_byte[0] = textval[ii+0];
2839       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2840       one_byte[0] = textval[ii+1];
2841       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2842       ii++;
2843     }
2844     else if (chtml40->pre_flag) {
2845       one_byte[0] = textval[ii+0];
2846       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2847     }
2848     else if (chtml40->textarea_flag) {
2849       one_byte[0] = textval[ii+0];
2850       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2851     }
2852     else if (textval[ii] != '\r' && textval[ii] != '\n') {
2853       one_byte[0] = textval[ii+0];
2854       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2855     }
2856   }
2857   W_V(tdst);
2858   return chtml40->out;
2859 }
2860
2861
2862 /**
2863  * It is a handler who processes the BLOCKQUOTE tag.
2864  *
2865  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2866  *                     destination is specified.
2867  * @param node   [i]   The BLOCKQUOTE tag node is specified.
2868  * @return The conversion result is returned.
2869  */
2870 static char *
2871 s_chtml40_start_blockquote_tag(void *pdoc, Node *UNUSED(child))
2872 {
2873   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2874   Doc       *doc     = chtml40->doc;
2875   W_L("<blockquote>");
2876   return chtml40->out;
2877 }
2878
2879
2880 /**
2881  * It is a handler who processes the BLOCKQUOTE tag.
2882  *
2883  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2884  *                     destination is specified.
2885  * @param node   [i]   The BLOCKQUOTE tag node is specified.
2886  * @return The conversion result is returned.
2887  */
2888 static char *
2889 s_chtml40_end_blockquote_tag(void *pdoc, Node *UNUSED(child))
2890 {
2891   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2892   Doc       *doc     = chtml40->doc;
2893   W_L("</blockquote>");
2894   return chtml40->out;
2895 }
2896
2897
2898 /**
2899  * It is a handler who processes the DIR tag.
2900  *
2901  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2902  *                     destination is specified.
2903  * @param node   [i]   The DIR tag node is specified.
2904  * @return The conversion result is returned.
2905  */
2906 static char *
2907 s_chtml40_start_dir_tag(void *pdoc, Node *node)
2908 {
2909   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2910   Doc       *doc     = chtml40->doc;
2911   Attr      *attr;
2912   W_L("<dir");
2913   for (attr = qs_get_attr(doc,node);
2914        attr;
2915        attr = qs_get_next_attr(doc,attr)) {
2916     char *name   = qs_get_attr_name(doc,attr);
2917     char *value  = qs_get_attr_value(doc,attr);
2918     if (STRCASEEQ('t','T',"type",name)) {
2919       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
2920         W_L(" type=\"");
2921         W_V(value);
2922         W_L("\"");
2923       }
2924     }
2925   }
2926   W_L(">");
2927   return chtml40->out;
2928 }
2929
2930
2931 /**
2932  * It is a handler who processes the DIR tag.
2933  *
2934  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2935  *                     destination is specified.
2936  * @param node   [i]   The DIR tag node is specified.
2937  * @return The conversion result is returned.
2938  */
2939 static char *
2940 s_chtml40_end_dir_tag(void *pdoc, Node *UNUSED(child))
2941 {
2942   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2943   Doc       *doc = chtml40->doc;
2944   W_L("</dir>");
2945   return chtml40->out;
2946 }
2947
2948
2949 /**
2950  * It is a handler who processes the DL tag.
2951  *
2952  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2953  *                     destination is specified.
2954  * @param node   [i]   The DL tag node is specified.
2955  * @return The conversion result is returned.
2956  */
2957 static char *
2958 s_chtml40_start_dl_tag(void *pdoc, Node *UNUSED(child))
2959 {
2960   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2961   Doc       *doc     = chtml40->doc;
2962   W_L("<dl>");
2963   return chtml40->out;
2964 }
2965
2966
2967 /**
2968  * It is a handler who processes the DL tag.
2969  *
2970  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2971  *                     destination is specified.
2972  * @param node   [i]   The DL tag node is specified.
2973  * @return The conversion result is returned.
2974  */
2975 static char *
2976 s_chtml40_end_dl_tag(void *pdoc, Node *UNUSED(child))
2977 {
2978   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2979   Doc       *doc     = chtml40->doc;
2980   W_L("</dl>");
2981   return chtml40->out;
2982 }
2983
2984
2985 /**
2986  * It is a handler who processes the DT tag.
2987  *
2988  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2989  *                     destination is specified.
2990  * @param node   [i]   The DT tag node is specified.
2991  * @return The conversion result is returned.
2992  */
2993 static char *
2994 s_chtml40_start_dt_tag(void *pdoc, Node *UNUSED(child))
2995 {
2996   chtml40_t *chtml40 = GET_CHTML40(pdoc);
2997   Doc       *doc     = chtml40->doc;
2998   W_L("<dt>");
2999   return chtml40->out;
3000 }
3001
3002
3003 /**
3004  * It is a handler who processes the DT tag.
3005  *
3006  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3007  *                     destination is specified.
3008  * @param node   [i]   The DT tag node is specified.
3009  * @return The conversion result is returned.
3010  */
3011 static char *
3012 s_chtml40_end_dt_tag(void *pdoc, Node *UNUSED(child))
3013 {
3014   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3015
3016   return chtml40->out;
3017 }
3018
3019
3020 /**
3021  * It is a handler who processes the DD tag.
3022  *
3023  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3024  *                     destination is specified.
3025  * @param node   [i]   The DD tag node is specified.
3026  * @return The conversion result is returned.
3027  */
3028 static char *
3029 s_chtml40_start_dd_tag(void *pdoc, Node *UNUSED(child))
3030 {
3031   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3032   Doc       *doc     = chtml40->doc;
3033
3034   W_L("<dd>");
3035
3036   return chtml40->out;
3037 }
3038
3039
3040 /**
3041  * It is a handler who processes the DD tag.
3042  *
3043  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3044  *                     destination is specified.
3045  * @param node   [i]   The DD tag node is specified.
3046  * @return The conversion result is returned.
3047  */
3048 static char *
3049 s_chtml40_end_dd_tag(void *pdoc, Node *UNUSED(child))
3050 {
3051   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3052
3053   return chtml40->out;
3054 }
3055
3056
3057 /**
3058  * It is a handler who processes the MARQUEE tag.
3059  *
3060  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3061  *                     destination is specified.
3062  * @param node   [i]   The MARQUEE tag node is specified.
3063  * @return The conversion result is returned.
3064  */
3065 static char *
3066 s_chtml40_start_marquee_tag(void *pdoc, Node *node)
3067 {
3068   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3069   Doc       *doc = chtml40->doc;
3070   Attr      *attr;
3071   W_L("<marquee");
3072   /*--------------------------------------------------------------------------*/
3073   /* Get Attributes                                                           */
3074   /*--------------------------------------------------------------------------*/
3075   for (attr = qs_get_attr(doc,node);
3076        attr;
3077        attr = qs_get_next_attr(doc,attr)) {
3078     char *name   = qs_get_attr_name(doc,attr);
3079     char *value  = qs_get_attr_value(doc,attr);
3080     if (STRCASEEQ('d','D',"direction", name)) {
3081       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value))) {
3082         W_L(" direction=\"");
3083         W_V(value);
3084         W_L("\"");
3085       }
3086     }
3087     else if (STRCASEEQ('b','B',"behavior",name)) {
3088       if (value && (STRCASEEQ('s','S',"scroll",value) || STRCASEEQ('s','S',"slide",value) || STRCASEEQ('a','A',"alternate",value))) {
3089         W_L(" behavior=\""); 
3090         W_V(value);
3091         W_L("\"");
3092       }
3093     }
3094     else if (STRCASEEQ('l','L',"loop",name)) {
3095       if (value && *value) {
3096         W_L(" loop=\"");
3097         W_V(value);
3098         W_L("\"");
3099       }
3100     }
3101   }
3102   W_L(">");
3103   return chtml40->out;
3104 }
3105
3106
3107 /**
3108  * It is a handler who processes the MARQUEE tag.
3109  *
3110  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3111  *                     destination is specified.
3112  * @param node   [i]   The MARQUEE tag node is specified.
3113  * @return The conversion result is returned.
3114  */
3115 static char *
3116 s_chtml40_end_marquee_tag(void *pdoc, Node *UNUSED(child))
3117 {
3118   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3119   Doc       *doc = chtml40->doc;
3120   W_L("</marquee>");
3121   return chtml40->out;
3122 }
3123
3124
3125 /**
3126  * It is a handler who processes the BLINK tag.
3127  *
3128  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3129  *                     destination is specified.
3130  * @param node   [i]   The BLINK tag node is specified.
3131  * @return The conversion result is returned.
3132  */
3133 static char *
3134 s_chtml40_start_blink_tag(void *pdoc, Node *UNUSED(child))
3135 {
3136   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3137   Doc       *doc = chtml40->doc;
3138   W_L("<blink>");
3139   return chtml40->out;
3140 }
3141
3142
3143 /**
3144  * It is a handler who processes the BLINK tag.
3145  *
3146  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3147  *                     destination is specified.
3148  * @param node   [i]   The BLINK tag node is specified.
3149  * @return The conversion result is returned.
3150  */
3151 static char *
3152 s_chtml40_end_blink_tag(void *pdoc, Node *UNUSED(child))
3153 {
3154   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3155   Doc       *doc = chtml40->doc;
3156   W_L("</blink>");
3157   return chtml40->out;
3158 }
3159
3160
3161 /**
3162  * It is a handler who processes the MENU tag.
3163  *
3164  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3165  *                     destination is specified.
3166  * @param node   [i]   The MENU tag node is specified.
3167  * @return The conversion result is returned.
3168  */
3169 static char *
3170 s_chtml40_start_menu_tag(void *pdoc, Node *node)
3171 {
3172   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3173   Doc       *doc     = chtml40->doc;
3174   Attr      *attr;
3175   W_L("<menu");
3176   /*--------------------------------------------------------------------------*/
3177   /* Get Attributes                                                           */
3178   /*--------------------------------------------------------------------------*/
3179   for (attr = qs_get_attr(doc,node);
3180        attr;
3181        attr = qs_get_next_attr(doc,attr)) {
3182     char *name   = qs_get_attr_name(doc,attr);
3183     char *value  = qs_get_attr_value(doc,attr);
3184     if (STRCASEEQ('t','T',"type",name)) {
3185       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
3186         W_L(" type=\"");
3187         W_V(value);
3188         W_L("\"");
3189       }
3190     }
3191   }
3192   W_L(">");
3193   return chtml40->out;
3194 }
3195
3196
3197 /**
3198  * It is a handler who processes the MENU tag.
3199  *
3200  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3201  *                     destination is specified.
3202  * @param node   [i]   The MENU tag node is specified.
3203  * @return The conversion result is returned.
3204  */
3205 static char *
3206 s_chtml40_end_menu_tag(void *pdoc, Node *UNUSED(child))
3207 {
3208   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3209   Doc       *doc = chtml40->doc;
3210   W_L("</menu>");
3211   return chtml40->out;
3212 }
3213
3214
3215 /**
3216  * It is a handler who processes the PLAINTEXT tag.
3217  *
3218  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3219  *                     destination is specified.
3220  * @param node   [i]   The PLAINTEXT tag node is specified.
3221  * @return The conversion result is returned.
3222  */
3223 static char *
3224 s_chtml40_start_plaintext_tag(void *pdoc, Node *node)
3225 {
3226   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3227   Doc       *doc     = chtml40->doc;
3228   W_L("<plaintext>");
3229   s_chtml40_start_plaintext_tag_inner(pdoc,node);
3230   return chtml40->out;
3231 }
3232
3233 static char *
3234 s_chtml40_start_plaintext_tag_inner(void *pdoc, Node *node)
3235 {
3236   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3237   Doc       *doc     = chtml40->doc;
3238   Node      *child;
3239   for (child = qs_get_child_node(doc, node);
3240        child;
3241        child = qs_get_next_node(doc, child)) {
3242     W_V(child->otext);
3243     s_chtml40_start_plaintext_tag_inner(pdoc, child);
3244   }
3245   return chtml40->out;
3246 }
3247
3248
3249 /**
3250  * It is a handler who processes the PLAINTEXT tag.
3251  *
3252  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3253  *                     destination is specified.
3254  * @param node   [i]   The PLAINTEXT tag node is specified.
3255  * @return The conversion result is returned.
3256  */
3257 static char *
3258 s_chtml40_end_plaintext_tag(void *pdoc, Node *UNUSED(child))
3259 {
3260   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3261   return chtml40->out;
3262 }
3263
3264
3265 /**
3266  *  * It is handler who processes the New Line Code.
3267  *   */
3268 static char *
3269 s_chtml40_newline_mark(void *pdoc, Node *UNUSED(node))
3270 {
3271   chtml40_t *chtml40 = GET_CHTML40(pdoc);
3272   Doc *doc = chtml40->doc;
3273   W_NLCODE();
3274   return chtml40->out;
3275 }
3276 /*
3277  * vim:ts=2 et
3278  */