OSDN Git Service

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