OSDN Git Service

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