OSDN Git Service

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