OSDN Git Service

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