OSDN Git Service

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