OSDN Git Service

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