OSDN Git Service

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