OSDN Git Service

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