OSDN Git Service

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