OSDN Git Service

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