OSDN Git Service

* Writing is changed.
[modchxj/mod_chxj.git] / src / chxj_xhtml_mobile_1_0.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 "mod_chxj.h"
18 #include "chxj_xhtml_mobile_1_0.h"
19 #include "chxj_hdml.h"
20 #include "chxj_dump.h"
21 #include "chxj_img_conv.h"
22 #include "chxj_qr_code.h"
23
24
25 static char* s_xhtml_1_0_node_exchange    (xhtml_t* xhtml, Node* node, int indent);
26 static char* s_xhtml_1_0_start_html_tag   (xhtml_t* xhtml, Node* node);
27 static char* s_xhtml_1_0_end_html_tag     (xhtml_t* xhtml, Node* node);
28 static char* s_xhtml_1_0_start_p_tag      (xhtml_t* xhtml, Node* node);
29 static char* s_xhtml_1_0_end_p_tag        (xhtml_t* xhtml, Node* node);
30 static char* s_xhtml_1_0_start_pre_tag    (xhtml_t* xhtml, Node* node);
31 static char* s_xhtml_1_0_end_pre_tag      (xhtml_t* xhtml, Node* node);
32 static char* s_xhtml_1_0_start_ul_tag     (xhtml_t* xhtml, Node* node);
33 static char* s_xhtml_1_0_end_ul_tag       (xhtml_t* xhtml, Node* node);
34 static char* s_xhtml_1_0_start_h1_tag     (xhtml_t* xhtml, Node* node);
35 static char* s_xhtml_1_0_end_h1_tag       (xhtml_t* xhtml, Node* node);
36 static char* s_xhtml_1_0_start_h2_tag     (xhtml_t* xhtml, Node* node);
37 static char* s_xhtml_1_0_end_h2_tag       (xhtml_t* xhtml, Node* node);
38 static char* s_xhtml_1_0_start_h3_tag     (xhtml_t* xhtml, Node* node);
39 static char* s_xhtml_1_0_end_h3_tag       (xhtml_t* xhtml, Node* node);
40 static char* s_xhtml_1_0_start_h4_tag     (xhtml_t* xhtml, Node* node);
41 static char* s_xhtml_1_0_end_h4_tag       (xhtml_t* xhtml, Node* node);
42 static char* s_xhtml_1_0_start_h5_tag     (xhtml_t* xhtml, Node* node);
43 static char* s_xhtml_1_0_end_h5_tag       (xhtml_t* xhtml, Node* node);
44 static char* s_xhtml_1_0_start_h6_tag     (xhtml_t* xhtml, Node* node);
45 static char* s_xhtml_1_0_end_h6_tag       (xhtml_t* xhtml, Node* node);
46 static char* s_xhtml_1_0_start_ol_tag     (xhtml_t* xhtml, Node* node);
47 static char* s_xhtml_1_0_start_ol_tag     (xhtml_t* xhtml, Node* node);
48 static char* s_xhtml_1_0_end_ol_tag       (xhtml_t* xhtml, Node* node);
49 static char* s_xhtml_1_0_start_li_tag     (xhtml_t* xhtml, Node* node);
50 static char* s_xhtml_1_0_end_li_tag       (xhtml_t* xhtml, Node* node);
51 static char* s_xhtml_1_0_start_meta_tag   (xhtml_t* xhtml, Node* node);
52 static char* s_xhtml_1_0_end_meta_tag     (xhtml_t* xhtml, Node* node);
53 static char* s_xhtml_1_0_start_head_tag   (xhtml_t* xhtml, Node* node);
54 static char* s_xhtml_1_0_end_head_tag     (xhtml_t* xhtml, Node* node);
55 static char* s_xhtml_1_0_start_title_tag  (xhtml_t* xhtml, Node* node);
56 static char* s_xhtml_1_0_end_title_tag    (xhtml_t* xhtml, Node* node);
57 static char* s_xhtml_1_0_start_base_tag   (xhtml_t* xhtml, Node* node);
58 static char* s_xhtml_1_0_end_base_tag     (xhtml_t* xhtml, Node* node);
59 static char* s_xhtml_1_0_start_body_tag   (xhtml_t* xhtml, Node* node);
60 static char* s_xhtml_1_0_end_body_tag     (xhtml_t* xhtml, Node* node);
61 static char* s_xhtml_1_0_start_a_tag      (xhtml_t* xhtml, Node* node);
62 static char* s_xhtml_1_0_end_a_tag        (xhtml_t* xhtml, Node* node);
63 static char* s_xhtml_1_0_start_br_tag     (xhtml_t* xhtml, Node* node);
64 static char* s_xhtml_1_0_end_br_tag       (xhtml_t* xhtml, Node* node);
65 static char* s_xhtml_1_0_start_tr_tag     (xhtml_t* xhtml, Node* node);
66 static char* s_xhtml_1_0_end_tr_tag       (xhtml_t* xhtml, Node* node);
67 static char* s_xhtml_1_0_start_font_tag   (xhtml_t* xhtml, Node* node);
68 static char* s_xhtml_1_0_end_font_tag     (xhtml_t* xhtml, Node* node);
69 static char* s_xhtml_1_0_start_form_tag   (xhtml_t* xhtml, Node* node);
70 static char* s_xhtml_1_0_end_form_tag     (xhtml_t* xhtml, Node* node);
71 static char* s_xhtml_1_0_start_input_tag  (xhtml_t* xhtml, Node* node);
72 static char* s_xhtml_1_0_end_input_tag    (xhtml_t* xhtml, Node* node);
73 static char* s_xhtml_1_0_start_center_tag (xhtml_t* xhtml, Node* node);
74 static char* s_xhtml_1_0_end_center_tag   (xhtml_t* xhtml, Node* node);
75 static char* s_xhtml_1_0_start_hr_tag     (xhtml_t* xhtml, Node* node);
76 static char* s_xhtml_1_0_end_hr_tag       (xhtml_t* xhtml, Node* node);
77 static char* s_xhtml_1_0_start_img_tag    (xhtml_t* xhtml, Node* node);
78 static char* s_xhtml_1_0_end_img_tag      (xhtml_t* xhtml, Node* node);
79 static char* s_xhtml_1_0_start_select_tag (xhtml_t* xhtml, Node* node);
80 static char* s_xhtml_1_0_end_select_tag   (xhtml_t* xhtml, Node* node);
81 static char* s_xhtml_1_0_start_option_tag (xhtml_t* xhtml, Node* node);
82 static char* s_xhtml_1_0_end_option_tag   (xhtml_t* xhtml, Node* node);
83 static char* s_xhtml_1_0_start_div_tag    (xhtml_t* xhtml, Node* node);
84 static char* s_xhtml_1_0_end_div_tag      (xhtml_t* xhtml, Node* node);
85 static void  s_init_xhtml(xhtml_t* xhtml, Doc* doc, request_rec* r, device_table* spec);
86 static int   s_xhtml_search_emoji(xhtml_t* xhtml, char* txt, char** rslt);
87 static void  s_xhtml_1_0_chxjif_tag(xhtml_t* xhtml, Node* node);
88  
89 /**
90  * converts from CHTML to XHTML.
91  *
92  * @param r     [i]   Requet_rec is appointed.
93  * @param spec  [i]   The result of the device specification processing which 
94  *                    was done in advance is appointed.
95  * @param src   [i]   The character string before the converting is appointed.
96  * @return The character string after the converting is returned.
97  */
98 char*
99 chxj_exchange_xhtml_mobile_1_0(
100   request_rec*    r,
101   device_table*   spec,
102   const char*     src,
103   apr_size_t      srclen,
104   apr_size_t*     dstlen)
105 {
106   char*     dst = NULL;
107   char*     ss;
108   xhtml_t   xhtml;
109   Doc       doc;
110
111   DBG(r,"start chxj_exchange_xhtml_mobile_1_0()");
112
113   /*--------------------------------------------------------------------------*/
114   /* If qrcode xml                                                            */
115   /*--------------------------------------------------------------------------*/
116   *dstlen = srclen;
117   dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
118   if (dst != NULL) {
119     DBG(r,"i found qrcode xml");
120     return dst;
121   }
122   DBG(r,"not found qrcode xml");
123
124   /*--------------------------------------------------------------------------*/
125   /* The XHTML structure is initialized.                                      */
126   /*--------------------------------------------------------------------------*/
127   s_init_xhtml(&xhtml, &doc, r, spec);
128   ap_set_content_type(r, "text/html; charset=Windows-31J");
129
130   /*--------------------------------------------------------------------------*/
131   /* The character string of the input is analyzed.                           */
132   /*--------------------------------------------------------------------------*/
133   qs_init_malloc(&doc);
134   qs_init_root_node(&doc);
135
136   ss = apr_pcalloc(r->pool, srclen + 1);
137   memset(ss,   0, srclen + 1);
138   memcpy(ss, src, srclen);
139
140 #ifdef DUMP_LOG
141   chxj_dump_out("[src] CHTML->XHTML", ss, srclen);
142 #endif
143   DBG(r,"start parse");
144   qs_parse_string(&doc,ss, strlen(ss));
145   DBG(r,"end parse");
146
147   /*--------------------------------------------------------------------------*/
148   /* It converts it from CHTML to XHTML.                                      */
149   /*--------------------------------------------------------------------------*/
150   dst = s_xhtml_1_0_node_exchange(&xhtml, qs_get_root(&doc), 0);
151   qs_all_free(&doc,QX_LOGMARK);
152
153   if (! dst) 
154     return apr_pstrdup(r->pool,ss);
155
156   if (! strlen(dst))
157     dst = apr_psprintf(r->pool, "\n");
158
159   *dstlen = strlen(dst);
160
161 #ifdef DUMP_LOG
162   chxj_dump_out("[dst] CHTML->XHTML", dst, *dstlen);
163 #endif
164
165   DBG(r,"end chxj_exchange_xhtml_mobile_1_0()");
166
167   return dst;
168 }
169
170 /**
171  * The XHTML structure is initialized.
172  *
173  * @param xhtml [i/o] The pointer to the HDML structure that wants to be
174  *                   initialized is specified.
175  * @param doc   [i]   The Doc structure that should be set to the initialized
176  *                   HDML structure is specified.
177  * @param r     [i]   To use POOL, the pointer to request_rec is specified.
178  * @param spec  [i]   The pointer to the device_table
179  */
180 static void
181 s_init_xhtml(xhtml_t* xhtml, Doc* doc, request_rec* r, device_table* spec)
182 {
183   memset(doc,   0, sizeof(Doc));
184   memset(xhtml, 0, sizeof(xhtml_t));
185
186   doc->r      = r;
187   xhtml->doc  = doc;
188   xhtml->spec = spec;
189   xhtml->out  = qs_alloc_zero_byte_string(r);
190   xhtml->conf = ap_get_module_config(r->per_dir_config, &chxj_module);
191   xhtml->doc->parse_mode = PARSE_MODE_CHTML;
192 }
193
194 /**
195  * It is main processing of conversion from CHTML to XHTML. 
196  *
197  * @param xhtml   [i/o] The pointer to the XHTML structure is specified. 
198  * @param node    [i]   The pointer to a current node is specified. 
199  * @param indent  [i]   The depth of the node processing it now is specified. 
200  *
201  * @return The character string after it converts it is returned. 
202  */
203 static char*
204 s_xhtml_1_0_node_exchange(xhtml_t* xhtml, Node* node, int indent) 
205 {
206   Node*         child;
207   Doc*          doc   = xhtml->doc;
208   request_rec*  r     = doc->r;
209
210   /*--------------------------------------------------------------------------*/
211   /* It is the main loop of the conversion processing.                        */
212   /*--------------------------------------------------------------------------*/
213   for (child = qs_get_child_node(doc,node);
214        child ;
215        child = qs_get_next_node(doc,child)) {
216     char* name = qs_get_node_name(doc,child);
217
218     /*------------------------------------------------------------------------*/
219     /* <P> (for TEST)                                                         */
220     /*------------------------------------------------------------------------*/
221     if ((*name == 'p' || *name == 'P') && strcasecmp(name, "p") == 0) {
222       s_xhtml_1_0_start_p_tag   (xhtml, child);
223       s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
224       s_xhtml_1_0_end_p_tag     (xhtml, child);
225     }
226     else
227     /*------------------------------------------------------------------------*/
228     /* <PRE> (for TEST)                                                       */
229     /*------------------------------------------------------------------------*/
230     if ((*name == 'p' || *name == 'P') && strcasecmp(name, "pre") == 0) {
231       s_xhtml_1_0_start_pre_tag (xhtml, child);
232       s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
233       s_xhtml_1_0_end_pre_tag   (xhtml, child);
234     }
235     else
236     /*------------------------------------------------------------------------*/
237     /* <UL> (for TEST)                                                        */
238     /*------------------------------------------------------------------------*/
239     if ((*name == 'u' || *name == 'U') && strcasecmp(name, "ul") == 0) {
240       s_xhtml_1_0_start_ul_tag  (xhtml, child);
241       s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
242       s_xhtml_1_0_end_ul_tag    (xhtml, child);
243     }
244     /*------------------------------------------------------------------------*/
245     /* <OL> (for TEST)                                                        */
246     /*------------------------------------------------------------------------*/
247     else
248     if ((*name == 'o' || *name == 'O') && strcasecmp(name, "ol") == 0) {
249       s_xhtml_1_0_start_ol_tag  (xhtml, child);
250       s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
251       s_xhtml_1_0_end_ol_tag    (xhtml, child);
252     }
253     /*------------------------------------------------------------------------*/
254     /* <LI> (for TEST)                                                        */
255     /*------------------------------------------------------------------------*/
256     else
257     if ((*name == 'l' || *name == 'L') && strcasecmp(name, "li") == 0) {
258       s_xhtml_1_0_start_li_tag  (xhtml, child);
259       s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
260       s_xhtml_1_0_end_li_tag    (xhtml, child);
261     }
262     /*------------------------------------------------------------------------*/
263     /* <NOBR> (for TEST)                                                      */
264     /*------------------------------------------------------------------------*/
265     else
266     if ((*name == 'n' || *name == 'N') && strcasecmp(name, "nobr") == 0) {
267       s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
268     }
269     else
270     if (*name == 'h' || *name == 'H') {
271       /*----------------------------------------------------------------------*/
272       /* <HTML>                                                               */
273       /*----------------------------------------------------------------------*/
274       if (strcasecmp(name, "html") == 0) {
275         s_xhtml_1_0_start_html_tag(xhtml, child);
276         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
277         s_xhtml_1_0_end_html_tag  (xhtml, child);
278       }
279       /*----------------------------------------------------------------------*/
280       /* <HEAD>                                                               */
281       /*----------------------------------------------------------------------*/
282       else
283       if (strcasecmp(name, "head") == 0) {
284         s_xhtml_1_0_start_head_tag(xhtml, child);
285         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
286         s_xhtml_1_0_end_head_tag  (xhtml, child);
287       }
288       /*----------------------------------------------------------------------*/
289       /* <HR>                                                                 */
290       /*----------------------------------------------------------------------*/
291       else
292       if (strcasecmp(name, "hr") == 0) {
293         s_xhtml_1_0_start_hr_tag  (xhtml, child);
294         s_xhtml_1_0_end_hr_tag    (xhtml, child);
295       }
296       /*----------------------------------------------------------------------*/
297       /* <H1>                                                                 */
298       /*----------------------------------------------------------------------*/
299       else
300       if (strcasecmp(name, "h1") == 0) {
301         s_xhtml_1_0_start_h1_tag  (xhtml, child);
302         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
303         s_xhtml_1_0_end_h1_tag    (xhtml, child);
304       }
305       /*----------------------------------------------------------------------*/
306       /* <H2>                                                                 */
307       /*----------------------------------------------------------------------*/
308       else
309       if (strcasecmp(name, "h2") == 0) {
310         s_xhtml_1_0_start_h2_tag  (xhtml, child);
311         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
312         s_xhtml_1_0_end_h2_tag    (xhtml, child);
313       }
314       /*----------------------------------------------------------------------*/
315       /* <H3>                                                                 */
316       /*----------------------------------------------------------------------*/
317       else
318       if (strcasecmp(name, "h3") == 0) {
319         s_xhtml_1_0_start_h3_tag  (xhtml, child);
320         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
321         s_xhtml_1_0_end_h3_tag    (xhtml, child);
322       }
323       /*----------------------------------------------------------------------*/
324       /* <H4>                                                                 */
325       /*----------------------------------------------------------------------*/
326       else
327       if (strcasecmp(name, "h4") == 0) {
328         s_xhtml_1_0_start_h4_tag  (xhtml, child);
329         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
330         s_xhtml_1_0_end_h4_tag    (xhtml, child);
331       }
332       /*----------------------------------------------------------------------*/
333       /* <H5>                                                                 */
334       /*----------------------------------------------------------------------*/
335       else
336       if (strcasecmp(name, "h5") == 0) {
337         s_xhtml_1_0_start_h5_tag  (xhtml, child);
338         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
339         s_xhtml_1_0_end_h5_tag    (xhtml, child);
340       }
341       /*----------------------------------------------------------------------*/
342       /* <H6>                                                                 */
343       /*----------------------------------------------------------------------*/
344       else
345       if (strcasecmp(name, "h6") == 0) {
346         s_xhtml_1_0_start_h6_tag  (xhtml, child);
347         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
348         s_xhtml_1_0_end_h6_tag    (xhtml, child);
349       }
350     }
351     /*------------------------------------------------------------------------*/
352     /* <META>                                                                 */
353     /*------------------------------------------------------------------------*/
354     else
355     if ((*name == 'm' || *name == 'M') && strcasecmp(name, "meta") == 0) {
356       s_xhtml_1_0_start_meta_tag(xhtml, child);
357       s_xhtml_1_0_end_meta_tag  (xhtml, child);
358     }
359     else 
360     if (*name == 'b' || *name == 'B') {
361       /*----------------------------------------------------------------------*/
362       /* <BASE>                                                               */
363       /*----------------------------------------------------------------------*/
364       if (strcasecmp(name, "base") == 0) {
365         s_xhtml_1_0_start_base_tag(xhtml, child);
366         s_xhtml_1_0_end_base_tag  (xhtml, child);
367       }
368       else
369       /*----------------------------------------------------------------------*/
370       /* <BODY>                                                               */
371       /*----------------------------------------------------------------------*/
372       if (strcasecmp(name, "body") == 0) {
373         s_xhtml_1_0_start_body_tag(xhtml, child);
374         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
375         s_xhtml_1_0_end_body_tag  (xhtml, child);
376       }
377       else
378       /*----------------------------------------------------------------------*/
379       /* <BR>                                                                 */
380       /*----------------------------------------------------------------------*/
381       if (strcasecmp(name, "br") == 0) {
382         s_xhtml_1_0_start_br_tag  (xhtml, child);
383         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
384         s_xhtml_1_0_end_br_tag    (xhtml, child);
385       }
386     }
387     /*------------------------------------------------------------------------*/
388     /* <A>                                                                    */
389     /*------------------------------------------------------------------------*/
390     else
391     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "a") == 0) {
392       s_xhtml_1_0_start_a_tag   (xhtml, child);
393       s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
394       s_xhtml_1_0_end_a_tag     (xhtml, child);
395     }
396     else
397     if (*name == 'f' || *name == 'F') {
398       /*----------------------------------------------------------------------*/
399       /* <FONT>                                                               */
400       /*----------------------------------------------------------------------*/
401       if (strcasecmp(name, "font") == 0) {
402         s_xhtml_1_0_start_font_tag(xhtml, child);
403         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
404         s_xhtml_1_0_end_font_tag  (xhtml, child);
405       }
406       /*----------------------------------------------------------------------*/
407       /* <FORM>                                                               */
408       /*----------------------------------------------------------------------*/
409       else
410       if (strcasecmp(name, "form") == 0) {
411         s_xhtml_1_0_start_form_tag(xhtml, child);
412         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
413         s_xhtml_1_0_end_form_tag  (xhtml, child);
414       }
415     }
416     else 
417     if (*name == 'i' || *name == 'I') {
418       /*----------------------------------------------------------------------*/
419       /* <INPUT>                                                              */
420       /*----------------------------------------------------------------------*/
421       if (strcasecmp(name, "input") == 0) {
422         s_xhtml_1_0_start_input_tag (xhtml, child);
423         s_xhtml_1_0_node_exchange   (xhtml, child,indent+1);
424         s_xhtml_1_0_end_input_tag   (xhtml, child);
425       }
426       /*----------------------------------------------------------------------*/
427       /* <IMG>                                                                */
428       /*----------------------------------------------------------------------*/
429       else
430       if (strcasecmp(name, "img") == 0) {
431         s_xhtml_1_0_start_img_tag (xhtml, child);
432         s_xhtml_1_0_end_img_tag   (xhtml, child);
433       }
434     }
435     else
436     if (*name == 's' || *name == 'S') {
437       /*----------------------------------------------------------------------*/
438       /* <SELECT>                                                             */
439       /*----------------------------------------------------------------------*/
440       if (strcasecmp(name, "select") == 0) {
441         s_xhtml_1_0_start_select_tag(xhtml, child);
442         s_xhtml_1_0_node_exchange   (xhtml, child, indent+1);
443         s_xhtml_1_0_end_select_tag  (xhtml, child);
444       }
445       /*----------------------------------------------------------------------*/
446       /* <STYLE> (for TEST)                                                   */
447       /*----------------------------------------------------------------------*/
448       else
449       if (strcasecmp(name, "style") == 0) {
450         s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
451       }
452       /*----------------------------------------------------------------------*/
453       /* <SPAN> (for TEST)                                                    */
454       /*----------------------------------------------------------------------*/
455       else
456       if (strcasecmp(name, "span") == 0) {
457         s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
458       }
459     }
460     /*------------------------------------------------------------------------*/
461     /* <OPTION>                                                               */
462     /*------------------------------------------------------------------------*/
463     else
464     if ((*name == 'o' || *name == 'O') && strcasecmp(name, "option") == 0) {
465       s_xhtml_1_0_start_option_tag(xhtml, child);
466       s_xhtml_1_0_node_exchange   (xhtml, child, indent+1);
467       s_xhtml_1_0_end_option_tag  (xhtml, child);
468     }
469     /*------------------------------------------------------------------------*/
470     /* <DIV>                                                                  */
471     /*------------------------------------------------------------------------*/
472     else
473     if ((*name == 'd' || *name == 'D') && strcasecmp(name, "div") == 0) {
474       s_xhtml_1_0_start_div_tag (xhtml, child);
475       s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
476       s_xhtml_1_0_end_div_tag   (xhtml, child);
477     }
478     else
479     if (*name == 'c' || *name == 'C') {
480       /*----------------------------------------------------------------------*/
481       /* <CHXJ:IF>                                                            */
482       /*----------------------------------------------------------------------*/
483       if (strcasecmp(name, "chxj:if") == 0) {
484         ap_log_rerror(APLOG_MARK, APLOG_DEBUG,0,r, "chxj:if tag found");
485         if (chxj_chxjif_is_mine(xhtml->spec, doc, child)) {
486           char* destlang = qs_get_destlang_attr(doc, child, r);
487           if (destlang != NULL && strcasecmp(destlang, "hdml") == 0) {
488             ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
489           }
490           ap_log_rerror(APLOG_MARK, APLOG_DEBUG,0,r, "chxj:if tag is mine");
491   
492           char* parse_attr = NULL;
493           parse_attr = qs_get_parse_attr(doc, child, r);
494           if (parse_attr != NULL && strcasecmp(parse_attr, "true") == 0) {
495             s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
496           }
497           else {
498             s_xhtml_1_0_chxjif_tag(xhtml, child);
499           }
500         }
501       }
502       /*----------------------------------------------------------------------*/
503       /* <CENTER>                                                             */
504       /*----------------------------------------------------------------------*/
505       else
506       if (strcasecmp(name, "center") == 0) {
507         s_xhtml_1_0_start_center_tag(xhtml, child);
508         s_xhtml_1_0_node_exchange   (xhtml, child,indent+1);
509         s_xhtml_1_0_end_center_tag  (xhtml, child);
510       }
511     }
512     else
513     if (*name == 't' || *name == 'T') {
514       /*----------------------------------------------------------------------*/
515       /* <TITLE>                                                              */
516       /*----------------------------------------------------------------------*/
517       if (strcasecmp(name, "title") == 0) {
518         s_xhtml_1_0_start_title_tag (xhtml, child);
519         s_xhtml_1_0_node_exchange   (xhtml, child,indent+1);
520         s_xhtml_1_0_end_title_tag   (xhtml, child);
521       }
522       /*----------------------------------------------------------------------*/
523       /* <TABLE> (for TEST)                                                   */
524       /*----------------------------------------------------------------------*/
525       else
526       if (strcasecmp(name, "table") == 0) {
527         s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
528       }
529       /*----------------------------------------------------------------------*/
530       /* <TBODY> (for TEST)                                                   */
531       /*----------------------------------------------------------------------*/
532       else
533       if (strcasecmp(name, "tbody") == 0) {
534         s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
535       }
536       /*----------------------------------------------------------------------*/
537       /* <TH> (for TEST)                                                      */
538       /*----------------------------------------------------------------------*/
539       else
540       if (strcasecmp(name, "th") == 0) {
541         s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
542       }
543       /*----------------------------------------------------------------------*/
544       /* <TR> (for TEST)                                                      */
545       /*----------------------------------------------------------------------*/
546       else
547       if (strcasecmp(name, "tr") == 0) {
548         s_xhtml_1_0_start_tr_tag  (xhtml, child);
549         s_xhtml_1_0_node_exchange (xhtml, child,indent+1);
550         s_xhtml_1_0_end_tr_tag    (xhtml, child);
551       }
552       /*----------------------------------------------------------------------*/
553       /* <TD> (for TEST)                                                      */
554       /*----------------------------------------------------------------------*/
555       else
556       if (strcasecmp(name, "td") == 0) {
557         s_xhtml_1_0_node_exchange (xhtml, child, indent+1);
558       }
559       /*----------------------------------------------------------------------*/
560       /* NORMAL TEXT                                                          */
561       /*----------------------------------------------------------------------*/
562       else
563       if (strcasecmp(name, "text") == 0) {
564         char*   textval;
565         char*   tmp;
566         char*   tdst;
567         char    one_byte[2];
568         int     ii;
569         int     tdst_len;
570   
571         textval = qs_get_node_value(doc,child);
572         textval = qs_trim_string(xhtml->doc->r, textval);
573         if (strlen(textval) == 0)
574           continue;
575   
576         tmp = apr_palloc(r->pool, qs_get_node_size(doc,child)+1);
577         memset(tmp, 0, qs_get_node_size(doc,child)+1);
578   
579         tdst     = qs_alloc_zero_byte_string(r);
580         memset(one_byte, 0, sizeof(one_byte));
581         tdst_len = 0;
582   
583         for (ii=0; ii<qs_get_node_size(doc,child); ii++) {
584           char* out;
585           int rtn = s_xhtml_search_emoji(xhtml, &textval[ii], &out);
586           if (rtn != 0) {
587             ap_log_rerror(APLOG_MARK, APLOG_DEBUG,0, r,
588                             "[%s][%d]", out, rtn);
589             tdst = qs_out_apr_pstrcat(r, tdst, out, &tdst_len);
590             ii+=(rtn - 1);
591             continue;
592           }
593           if (is_sjis_kanji(textval[ii])) {
594             one_byte[0] = textval[ii+0];
595             tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
596             one_byte[0] = textval[ii+1];
597             tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
598             ii++;
599           }
600           else if (xhtml->pre_flag) {
601             one_byte[0] = textval[ii+0];
602             tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
603           }
604           else if (textval[ii] != '\r' && textval[ii] != '\n') {
605             one_byte[0] = textval[ii+0];
606             tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
607           }
608         }
609         xhtml->out = apr_pstrcat(r->pool, xhtml->out, tdst, NULL);
610       }
611     }
612   }
613
614   return xhtml->out;
615 }
616
617 /**
618  * Corresponding EMOJI to a current character-code is retrieved. 
619  * The substitution character string is stored in the rslt pointer if agreeing.
620  *
621  * @param xhtml   [i]   The pointer to the XHTML structure is specified. 
622  * @param txt     [i]   The character string to want to examine whether it is 
623  *                      EMOJI is specified. 
624  * @param rslt    [o]   The pointer to the pointer that stores the result is 
625  *                      specified. 
626  * @return When corresponding EMOJI exists, it returns it excluding 0. 
627  */
628 static int
629 s_xhtml_search_emoji(xhtml_t* xhtml, char* txt, char** rslt)
630 {
631   emoji_t*      ee;
632   request_rec*  r;
633   device_table* spec;
634   int           len;
635
636   spec = xhtml->spec;
637
638   len = strlen(txt);
639   r = xhtml->doc->r;
640
641   if (spec == NULL)
642     ap_log_rerror(APLOG_MARK, APLOG_DEBUG,0,r, "spec is NULL");
643
644   for (ee = xhtml->conf->emoji;
645        ee;
646        ee = ee->next) {
647     unsigned char hex1byte;
648     unsigned char hex2byte;
649     if (!ee->imode) {
650       ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
651                       "emoji->imode is NULL");
652       continue;
653     }
654
655     if (ee->imode->string != NULL
656     &&  strlen(ee->imode->string) > 0
657     &&  strncasecmp(ee->imode->string, txt, strlen(ee->imode->string)) == 0) {
658       if (spec == NULL || spec->emoji_type == NULL) {
659         *rslt = apr_psprintf(r->pool,
660                         "<img localsrc=%s>",
661                         ee->ezweb->typeA);
662         return strlen(ee->imode->string);
663       }
664
665       if (strcasecmp(xhtml->spec->emoji_type, "a") == 0) {
666         *rslt = apr_psprintf(r->pool,
667                         "<img localsrc=%s>",
668                         ee->ezweb->typeA);
669         return strlen(ee->imode->string);
670       } 
671       else
672       if (strcasecmp(xhtml->spec->emoji_type, "b") == 0) {
673         *rslt = apr_psprintf(r->pool,
674                         "<img localsrc=%s>",
675                         ee->ezweb->typeB);
676         return strlen(ee->imode->string);
677       }
678       else
679       if (strcasecmp(xhtml->spec->emoji_type, "c") == 0) {
680         *rslt = apr_psprintf(r->pool,
681                         "<img localsrc=%s>",
682                         ee->ezweb->typeC);
683         return strlen(ee->imode->string);
684       }
685       else
686       if (strcasecmp(xhtml->spec->emoji_type, "d") == 0) {
687         *rslt = apr_psprintf(r->pool,
688                         "<img localsrc=%s>",
689                         ee->ezweb->typeD);
690         return strlen(ee->imode->string);
691       }
692       else {
693         *rslt = apr_psprintf(r->pool,
694                         "<img localsrc=%s>",
695                         ee->ezweb->typeA);
696         return strlen(ee->imode->string);
697       }
698       return 0;
699     }
700     hex1byte = ee->imode->hex1byte & 0xff;
701     hex2byte = ee->imode->hex2byte & 0xff;
702     if (len >= 2
703     && ((unsigned char)txt[0] & 0xff) == ((unsigned char)hex1byte)
704     && ((unsigned char)txt[1] & 0xff) == ((unsigned char)hex2byte)) {
705       if (spec == NULL || spec->emoji_type == NULL) {
706         *rslt = apr_psprintf(r->pool,
707                         "<img localsrc=\"%s\">",
708                         ee->ezweb->typeA);
709         return 2;
710       }
711
712       if (strcasecmp(xhtml->spec->emoji_type, "a") == 0) {
713         *rslt = apr_psprintf(r->pool,
714                         "<img localsrc=\"%s\">",
715                         ee->ezweb->typeA);
716         return 2;
717       } 
718       else
719       if (strcasecmp(xhtml->spec->emoji_type, "b") == 0) {
720         *rslt = apr_psprintf(r->pool,
721                         "<img localsrc=\"%s\">",
722                         ee->ezweb->typeB);
723         return 2;
724       }
725       else
726       if (strcasecmp(xhtml->spec->emoji_type, "c") == 0) {
727         *rslt = apr_psprintf(r->pool,
728                         "<img localsrc=\"%s\">",
729                         ee->ezweb->typeC);
730         return 2;
731       }
732       else
733       if (strcasecmp(xhtml->spec->emoji_type, "d") == 0) {
734         *rslt = apr_psprintf(r->pool,
735                         "<img localsrc=\"%s\">",
736                         ee->ezweb->typeD);
737         return 2;
738       }
739       else {
740         *rslt = apr_psprintf(r->pool,
741                         "<img localsrc=\"%s\">",
742                         ee->ezweb->typeD);
743         return 2;
744       }
745       return 0;
746     }
747   }
748   return 0;
749 }
750
751 /**
752  * It is a handler who processes the HTML tag.
753  *
754  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
755  *                     destination is specified.
756  * @param node   [i]   The HTML tag node is specified.
757  * @return The conversion result is returned.
758  */
759 static char*
760 s_xhtml_1_0_start_html_tag(xhtml_t* xhtml, Node* node) 
761 {
762   Attr*         attr;
763   Doc*          doc   = xhtml->doc;
764   request_rec*  r     = doc->r;
765
766   /*--------------------------------------------------------------------------*/
767   /* Add XML Declare                                                          */
768   /*--------------------------------------------------------------------------*/
769   xhtml->out = apr_pstrcat(r->pool, 
770     xhtml->out, 
771     "<?xml version=\"1.0\" encoding=\"Windows-31J\"?>\r\n", 
772     NULL);
773
774   /*--------------------------------------------------------------------------*/
775   /* Add DocType                                                              */
776   /*--------------------------------------------------------------------------*/
777   xhtml->out = apr_pstrcat(r->pool, 
778           xhtml->out, 
779           "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML Basic 1.0//EN\"\r\n",NULL);
780   xhtml->out = apr_pstrcat(r->pool, 
781           xhtml->out, 
782           " \"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd\">\r\n",NULL);
783
784   /*--------------------------------------------------------------------------*/
785   /* start HTML tag                                                           */
786   /*--------------------------------------------------------------------------*/
787   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<html", NULL);
788   xhtml->out = apr_pstrcat(r->pool, xhtml->out, 
789           " xmlns=\"http://www.w3.org/1999/xhtml\"", NULL);
790
791   /*--------------------------------------------------------------------------*/
792   /* Get Attributes                                                           */
793   /*--------------------------------------------------------------------------*/
794   for (attr = qs_get_attr(doc,node);
795        attr; 
796        attr = qs_get_next_attr(doc,attr)) {
797     char* name  = qs_get_attr_name(doc,attr);
798     char* value = qs_get_attr_value(doc,attr);
799     if (strcasecmp(name, "lang") == 0) {
800       xhtml->out = apr_pstrcat(r->pool, 
801                       xhtml->out, 
802                       " xml:lang=\"", 
803                       value, 
804                       "\"", 
805                       NULL);
806     }
807     else
808     if (strcasecmp(name, "version") == 0) {
809       xhtml->out = apr_pstrcat(r->pool, 
810                       xhtml->out, 
811                       " version=\"-//OPENWAVE//DTD XHTML Mobile 1.0//EN\"", 
812                       NULL);
813     }
814   }
815
816   xhtml->out = apr_pstrcat(r->pool, xhtml->out, ">\r\n", NULL);
817   return xhtml->out;
818 }
819
820 /**
821  * It is a handler who processes the HTML tag.
822  *
823  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
824  *                     destination is specified.
825  * @param node   [i]   The HTML tag node is specified.
826  * @return The conversion result is returned.
827  */
828 static char*
829 s_xhtml_1_0_end_html_tag(xhtml_t* xhtml, Node* child) 
830 {
831   Doc*          doc = xhtml->doc;
832   request_rec*  r   = doc->r;
833
834   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</html>\r\n", NULL);
835
836   return xhtml->out;
837 }
838
839 /**
840  * It is a handler who processes the META tag.
841  *
842  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
843  *                     destination is specified.
844  * @param node   [i]   The META tag node is specified.
845  * @return The conversion result is returned.
846  */
847 static char*
848 s_xhtml_1_0_start_meta_tag(xhtml_t* xhtml, Node* node) 
849 {
850   Attr*         attr;
851   Doc*          doc   = xhtml->doc;
852   request_rec*  r     = doc->r;
853   int           content_type_flag = 0;
854
855   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<meta", NULL);
856
857   /*--------------------------------------------------------------------------*/
858   /* Get Attributes                                                           */
859   /*--------------------------------------------------------------------------*/
860   for (attr = qs_get_attr(doc,node);
861        attr; 
862        attr = qs_get_next_attr(doc,attr)) {
863     char* name  = qs_get_attr_name(doc,attr);
864     char* value = qs_get_attr_value(doc,attr);
865     if (strcasecmp(name, "name") == 0) {
866       xhtml->out = apr_pstrcat(r->pool,
867                       xhtml->out,
868                       " ", 
869                       name, 
870                       "=\"", 
871                       value, 
872                       "\"", 
873                       NULL);
874     }
875     else
876     if (strcasecmp(name, "http-equiv") == 0) {
877       xhtml->out = apr_pstrcat(r->pool,
878                       xhtml->out,
879                       " ", 
880                       name,
881                       "=\"",
882                       value,
883                       "\"", 
884                       NULL);
885       if ((*value == 'c' || *value == 'C') && strcasecmp(value, "content-type") == 0) {
886         content_type_flag = 1;
887       }
888     }
889     else
890     if (strcasecmp(name, "content") == 0) {
891       if (content_type_flag) {
892         xhtml->out = apr_pstrcat(r->pool,
893                         xhtml->out, 
894                         " ", 
895                         name, 
896                         "=\"", 
897                         "text/html; charset=Windows-31J", 
898                         "\"", 
899                         NULL);
900       }
901       else {
902         xhtml->out = apr_pstrcat(r->pool,
903                         xhtml->out, 
904                         " ", 
905                         name, 
906                         "=\"", 
907                         value, 
908                         "\"", 
909                         NULL);
910       }
911     }
912   }
913
914   xhtml->out = apr_pstrcat(r->pool, 
915                   xhtml->out, 
916                   " />\r\n", 
917                   NULL);
918
919   return xhtml->out;
920 }
921
922 /**
923  * It is a handler who processes the META tag.
924  *
925  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
926  *                     destination is specified.
927  * @param node   [i]   The META tag node is specified.
928  * @return The conversion result is returned.
929  */
930 static char*
931 s_xhtml_1_0_end_meta_tag(xhtml_t* xhtml, Node* child) 
932 {
933   return xhtml->out;
934 }
935
936 /**
937  * It is a handler who processes the HEAD tag.
938  *
939  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
940  *                     destination is specified.
941  * @param node   [i]   The HEAD tag node is specified.
942  * @return The conversion result is returned.
943  */
944 static char*
945 s_xhtml_1_0_start_head_tag(xhtml_t* xhtml, Node* node) 
946 {
947   Doc*          doc = xhtml->doc;
948   request_rec*  r   = doc->r;
949   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<head>\r\n", NULL);
950
951   return xhtml->out;
952 }
953
954 /**
955  * It is a handler who processes the HEAD tag.
956  *
957  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
958  *                     destination is specified.
959  * @param node   [i]   The HEAD tag node is specified.
960  * @return The conversion result is returned.
961  */
962 static char*
963 s_xhtml_1_0_end_head_tag(xhtml_t* xhtml, Node* child) 
964 {
965   Doc*          doc = xhtml->doc;
966   request_rec*  r   = doc->r;
967
968   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</head>\r\n", NULL);
969   return xhtml->out;
970 }
971
972 /**
973  * It is a handler who processes the TITLE tag.
974  *
975  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
976  *                     destination is specified.
977  * @param node   [i]   The TITLE tag node is specified.
978  * @return The conversion result is returned.
979  */
980 static char*
981 s_xhtml_1_0_start_title_tag(xhtml_t* xhtml, Node* node) 
982 {
983   Doc* doc = xhtml->doc;
984   request_rec* r = doc->r;
985
986   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<title>", NULL);
987   return xhtml->out;
988 }
989
990 /**
991  * It is a handler who processes the TITLE tag.
992  *
993  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
994  *                     destination is specified.
995  * @param node   [i]   The TITLE tag node is specified.
996  * @return The conversion result is returned.
997  */
998 static char*
999 s_xhtml_1_0_end_title_tag(xhtml_t* xhtml, Node* child) 
1000 {
1001   Doc*          doc = xhtml->doc;
1002   request_rec*  r   = doc->r;
1003
1004   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</title>\r\n", NULL);
1005
1006   return xhtml->out;
1007 }
1008
1009 /**
1010  * It is a handler who processes the BASE tag.
1011  *
1012  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1013  *                     destination is specified.
1014  * @param node   [i]   The BASE tag node is specified.
1015  * @return The conversion result is returned.
1016  */
1017 static char*
1018 s_xhtml_1_0_start_base_tag(xhtml_t* xhtml, Node* node) 
1019 {
1020   Attr*         attr;
1021   Doc*          doc   = xhtml->doc;
1022   request_rec*  r     = doc->r;
1023
1024   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<base", NULL);
1025
1026   /*--------------------------------------------------------------------------*/
1027   /* Get Attributes                                                           */
1028   /*--------------------------------------------------------------------------*/
1029   for (attr = qs_get_attr(doc,node);
1030        attr;
1031        attr = qs_get_next_attr(doc,attr)) {
1032     char* name = qs_get_attr_name(doc,attr);
1033     char* value = qs_get_attr_value(doc,attr);
1034     if (strcasecmp(name, "href") == 0) {
1035       xhtml->out = apr_pstrcat(r->pool, 
1036                       xhtml->out, 
1037                       " href=\"", 
1038                       value, 
1039                       "\"", 
1040                       NULL);
1041     }
1042   }
1043   xhtml->out = apr_pstrcat(r->pool, xhtml->out, " />\r\n", NULL);
1044   return xhtml->out;
1045 }
1046
1047 /**
1048  * It is a handler who processes the BASE tag.
1049  *
1050  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1051  *                     destination is specified.
1052  * @param node   [i]   The BASE tag node is specified.
1053  * @return The conversion result is returned.
1054  */
1055 static char*
1056 s_xhtml_1_0_end_base_tag(xhtml_t* xhtml, Node* child) 
1057 {
1058   return xhtml->out;
1059 }
1060
1061 /**
1062  * It is a handler who processes the BODY tag.
1063  *
1064  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1065  *                     destination is specified.
1066  * @param node   [i]   The BODY tag node is specified.
1067  * @return The conversion result is returned.
1068  */
1069 static char*
1070 s_xhtml_1_0_start_body_tag(xhtml_t* xhtml, Node* node) 
1071 {
1072   Doc* doc = xhtml->doc;
1073   request_rec* r = doc->r;
1074   Attr* attr;
1075
1076   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<body", NULL);
1077
1078   /*--------------------------------------------------------------------------*/
1079   /* Get Attributes                                                           */
1080   /*--------------------------------------------------------------------------*/
1081   for (attr = qs_get_attr(doc,node);
1082        attr;
1083        attr = qs_get_next_attr(doc,attr)) {
1084     char* name  = qs_get_attr_name(doc,attr);
1085     char* value = qs_get_attr_value(doc,attr);
1086     if ((*name == 'b' || *name == 'B') && strcasecmp(name, "bgcolor") == 0) {
1087       xhtml->out = apr_pstrcat(r->pool, 
1088                       xhtml->out, 
1089                       " bgcolor=\"", 
1090                       value, 
1091                       "\"", 
1092                       NULL);
1093     }
1094     else
1095     if ((*name == 't' || *name == 'T') && strcasecmp(name, "text") == 0) {
1096       xhtml->out = apr_pstrcat(r->pool, 
1097                       xhtml->out, 
1098                       " text=\"", 
1099                       value, 
1100                       "\"", 
1101                       NULL);
1102     }
1103     else
1104     if ((*name == 'l' || *name == 'L') && strcasecmp(name, "link") == 0) {
1105       xhtml->out = apr_pstrcat(r->pool, 
1106                       xhtml->out, 
1107                       " link=\"", 
1108                       value, 
1109                       "\"", 
1110                       NULL);
1111     }
1112     else
1113     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "alink") == 0) {
1114       /* ignore */
1115     }
1116     else
1117     if ((*name == 'v' || *name == 'V') && strcasecmp(name, "vlink") == 0) {
1118       /* ignore */
1119     }
1120   }
1121   xhtml->out = apr_pstrcat(r->pool, xhtml->out, ">\r\n", NULL);
1122   return xhtml->out;
1123 }
1124
1125 /**
1126  * It is a handler who processes the BODY tag.
1127  *
1128  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1129  *                     destination is specified.
1130  * @param node   [i]   The BODY tag node is specified.
1131  * @return The conversion result is returned.
1132  */
1133 static char*
1134 s_xhtml_1_0_end_body_tag(xhtml_t* xhtml, Node* child) 
1135 {
1136   Doc*          doc = xhtml->doc;
1137   request_rec*  r = doc->r;
1138
1139   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</body>\r\n", NULL);
1140
1141   return xhtml->out;
1142 }
1143
1144 /**
1145  * It is a handler who processes the A tag.
1146  *
1147  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1148  *                     destination is specified.
1149  * @param node   [i]   The A tag node is specified.
1150  * @return The conversion result is returned.
1151  */
1152 static char*
1153 s_xhtml_1_0_start_a_tag(xhtml_t* xhtml, Node* node) 
1154 {
1155   Doc*          doc   = xhtml->doc;
1156   request_rec*  r     = doc->r;
1157   Attr*         attr;
1158
1159   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<a", NULL);
1160
1161   /*--------------------------------------------------------------------------*/
1162   /* Get Attributes                                                           */
1163   /*--------------------------------------------------------------------------*/
1164   for (attr = qs_get_attr(doc,node);
1165        attr; 
1166        attr = qs_get_next_attr(doc,attr)) {
1167     char* name  = qs_get_attr_name(doc,attr);
1168     char* value = qs_get_attr_value(doc,attr);
1169
1170     if ((*name == 'n' || *name == 'N') && strcasecmp(name, "name") == 0) {
1171       xhtml->out = apr_pstrcat(r->pool, 
1172                       xhtml->out, 
1173                       " id=\"", 
1174                       value, 
1175                       "\"", 
1176                       NULL);
1177     }
1178     else
1179     if ((*name == 'h' || *name == 'H') && strcasecmp(name, "href") == 0) {
1180       xhtml->out = apr_pstrcat(r->pool, 
1181                       xhtml->out, 
1182                       " href=\"", 
1183                       value, 
1184                       "\"", 
1185                       NULL);
1186     }
1187     else
1188     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "accesskey") == 0) {
1189       xhtml->out = apr_pstrcat(r->pool, 
1190                       xhtml->out, 
1191                       " accesskey=\"", 
1192                       value, 
1193                       "\"", 
1194                       NULL);
1195     }
1196     else
1197     if (strcasecmp(name, "cti") == 0) {
1198       /* ignore */
1199     }
1200     else
1201     if (strcasecmp(name, "ijam") == 0) {
1202       /* ignore */
1203     }
1204     else
1205     if (strcasecmp(name, "utn") == 0) {
1206       /* ignore */
1207     }
1208     else
1209     if (strcasecmp(name, "telbook") == 0) {
1210       /* ignore */
1211     }
1212     else
1213     if (strcasecmp(name, "kana") == 0) {
1214       /* ignore */
1215     }
1216     else
1217     if (strcasecmp(name, "email") == 0) {
1218       /* ignore */
1219     }
1220     else
1221     if (strcasecmp(name, "ista") == 0) {
1222       /* ignore */
1223     }
1224     else
1225     if (strcasecmp(name, "ilet") == 0) {
1226       /* ignore */
1227     }
1228     else
1229     if (strcasecmp(name, "iswf") == 0) {
1230       /* ignore */
1231     }
1232     else
1233     if (strcasecmp(name, "irst") == 0) {
1234       /* ignore */
1235     }
1236   }
1237   xhtml->out = apr_pstrcat(r->pool, xhtml->out, ">", NULL);
1238   return xhtml->out;
1239 }
1240
1241 /**
1242  * It is a handler who processes the A tag.
1243  *
1244  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1245  *                     destination is specified.
1246  * @param node   [i]   The A tag node is specified.
1247  * @return The conversion result is returned.
1248  */
1249 static char*
1250 s_xhtml_1_0_end_a_tag(xhtml_t* xhtml, Node* child) 
1251 {
1252   Doc* doc = xhtml->doc;
1253   request_rec* r = doc->r;
1254
1255   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</a>", NULL);
1256   return xhtml->out;
1257 }
1258
1259 /**
1260  * It is a handler who processes the BR tag.
1261  *
1262  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1263  *                     destination is specified.
1264  * @param node   [i]   The BR tag node is specified.
1265  * @return The conversion result is returned.
1266  */
1267 static char*
1268 s_xhtml_1_0_start_br_tag(xhtml_t* xhtml, Node* node) 
1269 {
1270   Doc* doc = xhtml->doc;
1271   request_rec* r = doc->r;
1272   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<br />\r\n", NULL);
1273   return xhtml->out;
1274 }
1275
1276 /**
1277  * It is a handler who processes the BR tag.
1278  *
1279  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1280  *                     destination is specified.
1281  * @param node   [i]   The BR tag node is specified.
1282  * @return The conversion result is returned.
1283  */
1284 static char*
1285 s_xhtml_1_0_end_br_tag(xhtml_t* xhtml, Node* child) 
1286 {
1287   return xhtml->out;
1288 }
1289
1290 /**
1291  * It is a handler who processes the TR tag.
1292  *
1293  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1294  *                     destination is specified.
1295  * @param node   [i]   The TR tag node is specified.
1296  * @return The conversion result is returned.
1297  */
1298 static char*
1299 s_xhtml_1_0_start_tr_tag(xhtml_t* xhtml, Node* node) 
1300 {
1301   Doc* doc = xhtml->doc;
1302   request_rec* r = doc->r;
1303   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<br />\r\n", NULL);
1304   return xhtml->out;
1305 }
1306
1307 /**
1308  * It is a handler who processes the TR tag.
1309  *
1310  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1311  *                     destination is specified.
1312  * @param node   [i]   The TR tag node is specified.
1313  * @return The conversion result is returned.
1314  */
1315 static char*
1316 s_xhtml_1_0_end_tr_tag(xhtml_t* xhtml, Node* child) 
1317 {
1318   return xhtml->out;
1319 }
1320
1321 /**
1322  * It is a handler who processes the FONT tag.
1323  *
1324  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1325  *                     destination is specified.
1326  * @param node   [i]   The FONT tag node is specified.
1327  * @return The conversion result is returned.
1328  */
1329 static char*
1330 s_xhtml_1_0_start_font_tag(xhtml_t* xhtml, Node* node) 
1331 {
1332   Doc* doc = xhtml->doc;
1333   request_rec* r = doc->r;
1334   Attr* attr;
1335
1336   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<font", NULL);
1337   /* Get Attributes */
1338   for (attr = qs_get_attr(doc,node);
1339        attr; attr = qs_get_next_attr(doc,attr)) {
1340     char* name = qs_get_attr_name(doc,attr);
1341     char* value = qs_get_attr_value(doc,attr);
1342     if ((*name == 'c' || *name == 'C') && strcasecmp(name, "color") == 0) {
1343       xhtml->out = apr_pstrcat(r->pool, xhtml->out, " color=\"",value,"\"", NULL);
1344     }
1345     else
1346     if ((*name == 's' || *name == 'S') && strcasecmp(name, "size") == 0) {
1347       xhtml->out = apr_pstrcat(r->pool, xhtml->out, " size=\"",value,"\"", NULL);
1348     }
1349   }
1350   xhtml->out = apr_pstrcat(r->pool, xhtml->out, ">", NULL);
1351   return xhtml->out;
1352 }
1353
1354 /**
1355  * It is a handler who processes the FONT tag.
1356  *
1357  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1358  *                     destination is specified.
1359  * @param node   [i]   The FONT tag node is specified.
1360  * @return The conversion result is returned.
1361  */
1362 static char*
1363 s_xhtml_1_0_end_font_tag(xhtml_t* xhtml, Node* child) 
1364 {
1365   Doc* doc = xhtml->doc;
1366   request_rec* r = doc->r;
1367   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</font>", NULL);
1368   return xhtml->out;
1369 }
1370
1371 /**
1372  * It is a handler who processes the FORM tag.
1373  *
1374  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1375  *                     destination is specified.
1376  * @param node   [i]   The FORM tag node is specified.
1377  * @return The conversion result is returned.
1378  */
1379 static char*
1380 s_xhtml_1_0_start_form_tag(xhtml_t* xhtml, Node* node) 
1381 {
1382   Doc* doc = xhtml->doc;
1383   request_rec* r = doc->r;
1384   Attr* attr;
1385
1386   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<form", NULL);
1387
1388   /*--------------------------------------------------------------------------*/
1389   /* Get Attributes                                                           */
1390   /*--------------------------------------------------------------------------*/
1391   for (attr = qs_get_attr(doc,node);
1392        attr;
1393        attr = qs_get_next_attr(doc,attr)) {
1394     char* name = qs_get_attr_name(doc,attr);
1395     char* value = qs_get_attr_value(doc,attr);
1396     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "action") == 0) {
1397       xhtml->out = apr_pstrcat(r->pool, 
1398                       xhtml->out, 
1399                       " action=\"",
1400                       value,
1401                       "\"", 
1402                       NULL);
1403     }
1404     else
1405     if ((*name == 'm' || *name == 'M') && strcasecmp(name, "method") == 0) {
1406       xhtml->out = apr_pstrcat(r->pool, 
1407                       xhtml->out, 
1408                       " method=\"",
1409                       value,
1410                       "\"", 
1411                       NULL);
1412     }
1413     else
1414     if ((*name == 'u' || *name == 'U') && strcasecmp(name, "utn") == 0) {
1415       /* ignore */
1416     }
1417   }
1418   xhtml->out = apr_pstrcat(r->pool, xhtml->out, ">", NULL);
1419   return xhtml->out;
1420 }
1421
1422 /**
1423  * It is a handler who processes the FORM tag.
1424  *
1425  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1426  *                     destination is specified.
1427  * @param node   [i]   The FORM tag node is specified.
1428  * @return The conversion result is returned.
1429  */
1430 static char*
1431 s_xhtml_1_0_end_form_tag(xhtml_t* xhtml, Node* child) 
1432 {
1433   Doc* doc = xhtml->doc;
1434   request_rec* r = doc->r;
1435
1436   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</form>", NULL);
1437   return xhtml->out;
1438 }
1439
1440 /**
1441  * It is a handler who processes the INPUT tag.
1442  *
1443  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1444  *                     destination is specified.
1445  * @param node   [i]   The INPUT tag node is specified.
1446  * @return The conversion result is returned.
1447  */
1448 static char*
1449 s_xhtml_1_0_start_input_tag(xhtml_t* xhtml, Node* node) 
1450 {
1451   Doc*          doc         = xhtml->doc;
1452   request_rec*  r           = doc->r;
1453   char*         max_length  = NULL;
1454   char*         type        = NULL;
1455   char*         name        = NULL;
1456   char*         value       = NULL;
1457   char*         istyle      = NULL;
1458   char*         size        = NULL;
1459   char*         checked     = NULL;
1460   char*         accesskey   = NULL;
1461
1462   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<input", NULL);
1463
1464   /*--------------------------------------------------------------------------*/
1465   /* Get Attributes                                                           */
1466   /*--------------------------------------------------------------------------*/
1467
1468   type       = qs_get_type_attr(doc, node, r);
1469   name       = qs_get_name_attr(doc, node, r);
1470   value      = qs_get_value_attr(doc,node,r);
1471   istyle     = qs_get_istyle_attr(doc,node,r);
1472   max_length = qs_get_maxlength_attr(doc,node,r);
1473   checked    = qs_get_checked_attr(doc,node,r);
1474   accesskey  = qs_get_accesskey_attr(doc, node, r);
1475   size       = qs_get_size_attr(doc, node, r);
1476
1477   if (type) {
1478     xhtml->out = apr_pstrcat(r->pool,
1479                     xhtml->out, 
1480                     " type=\"", 
1481                     type, 
1482                     "\" ", 
1483                     NULL);
1484   }
1485   if (size) {
1486     xhtml->out = apr_pstrcat(r->pool, 
1487                     xhtml->out, 
1488                     " size=\"", 
1489                     size, 
1490                     "\" ", 
1491                     NULL);
1492   }
1493   if (name) {
1494     xhtml->out = apr_pstrcat(r->pool, 
1495                     xhtml->out, 
1496                     " name=\"", 
1497                     name, 
1498                     "\" ", 
1499                     NULL);
1500   }
1501   if (value) {
1502     xhtml->out = apr_pstrcat(r->pool, 
1503                     xhtml->out, 
1504                     " value=\"", 
1505                     value, 
1506                     "\" ", 
1507                     NULL);
1508   }
1509   if (accesskey) {
1510     xhtml->out = apr_pstrcat(r->pool, 
1511                     xhtml->out, 
1512                     " accesskey=\"", 
1513                     accesskey, "\" ", 
1514                     NULL);
1515   }
1516   if (istyle) {
1517     char* fmt = qs_conv_istyle_to_format(r,istyle);
1518     if (max_length) {
1519       int ii;
1520       for (ii=0; ii<strlen(max_length); ii++) {
1521         if (max_length[ii] < '0' || max_length[ii] > '9') {
1522           max_length = apr_psprintf(r->pool, "0");
1523           break;
1524         }
1525       }
1526
1527       xhtml->out = apr_pstrcat(r->pool, 
1528                       xhtml->out, 
1529                       apr_psprintf(r->pool, " FORMAT=\"%d%s\"", 
1530                       atoi(max_length), 
1531                       fmt), 
1532                       NULL);
1533     }
1534     else {
1535       xhtml->out = apr_pstrcat(r->pool, 
1536                       xhtml->out, 
1537                       " FORMAT=\"", 
1538                       "*", 
1539                       fmt, 
1540                       "\"", 
1541                       NULL);
1542     }
1543   }
1544   /*--------------------------------------------------------------------------*/
1545   /* The figure is default for the password.                                  */
1546   /*--------------------------------------------------------------------------*/
1547   if (type && istyle == NULL 
1548   && (*type == 'p' || *type == 'P') 
1549   && strcasecmp(type, "password") == 0) {
1550     if (max_length) {
1551       xhtml->out = apr_pstrcat(r->pool, 
1552                       xhtml->out, 
1553                       " FORMAT=\"", 
1554                       max_length, 
1555                       "N", 
1556                       "\"", 
1557                       NULL);
1558     }
1559     else {
1560       xhtml->out = apr_pstrcat(r->pool, 
1561                       xhtml->out, 
1562                       " FORMAT=\"", "*", "N", "\"", NULL);
1563     }
1564   }
1565   if (checked) {
1566     xhtml->out = apr_pstrcat(r->pool, 
1567                     xhtml->out, " checked=\"checked\"", NULL);
1568   }
1569
1570   xhtml->out = apr_pstrcat(r->pool, xhtml->out, " />", NULL);
1571   return xhtml->out;
1572 }
1573
1574 /**
1575  * It is a handler who processes the INPUT tag.
1576  *
1577  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1578  *                     destination is specified.
1579  * @param node   [i]   The INPUT tag node is specified.
1580  * @return The conversion result is returned.
1581  */
1582 static char*
1583 s_xhtml_1_0_end_input_tag(xhtml_t* xhtml, Node* child) 
1584 {
1585   return xhtml->out;
1586 }
1587
1588 /**
1589  * It is a handler who processes the CENTER tag.
1590  *
1591  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1592  *                     destination is specified.
1593  * @param node   [i]   The CENTER tag node is specified.
1594  * @return The conversion result is returned.
1595  */
1596 static char*
1597 s_xhtml_1_0_start_center_tag(xhtml_t* xhtml, Node* node) 
1598 {
1599   Doc*          doc = xhtml->doc;
1600   request_rec*  r   = doc->r;
1601
1602   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<center>", NULL);
1603
1604   return xhtml->out;
1605 }
1606
1607 /**
1608  * It is a handler who processes the CENTER tag.
1609  *
1610  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1611  *                     destination is specified.
1612  * @param node   [i]   The CENTER tag node is specified.
1613  * @return The conversion result is returned.
1614  */
1615 static char*
1616 s_xhtml_1_0_end_center_tag(xhtml_t* xhtml, Node* child) 
1617 {
1618   Doc*          doc = xhtml->doc;
1619   request_rec*  r   = doc->r;
1620
1621   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</center>", NULL);
1622
1623   return xhtml->out;
1624 }
1625
1626 /**
1627  * It is a handler who processes the HR tag.
1628  *
1629  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1630  *                     destination is specified.
1631  * @param node   [i]   The HR tag node is specified.
1632  * @return The conversion result is returned.
1633  */
1634 static char*
1635 s_xhtml_1_0_start_hr_tag(xhtml_t* xhtml, Node* node) 
1636 {
1637   Doc*          doc = xhtml->doc;
1638   request_rec*  r   = doc->r;
1639
1640   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<hr />", NULL);
1641
1642   return xhtml->out;
1643 }
1644
1645 /**
1646  * It is a handler who processes the HR tag.
1647  *
1648  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1649  *                     destination is specified.
1650  * @param node   [i]   The HR tag node is specified.
1651  * @return The conversion result is returned.
1652  */
1653 static char*
1654 s_xhtml_1_0_end_hr_tag(xhtml_t* xhtml, Node* child) 
1655 {
1656   return xhtml->out;
1657 }
1658
1659 /**
1660  * It is a handler who processes the PRE tag.
1661  *
1662  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1663  *                     destination is specified.
1664  * @param node   [i]   The PRE tag node is specified.
1665  * @return The conversion result is returned.
1666  */
1667 static char*
1668 s_xhtml_1_0_start_pre_tag(xhtml_t* xhtml, Node* node) 
1669 {
1670   Doc*          doc = xhtml->doc;
1671   request_rec*  r   = doc->r;
1672
1673   xhtml->pre_flag++;
1674   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<pre>", NULL);
1675
1676   return xhtml->out;
1677 }
1678
1679 /**
1680  * It is a handler who processes the PRE tag.
1681  *
1682  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1683  *                     destination is specified.
1684  * @param node   [i]   The PRE tag node is specified.
1685  * @return The conversion result is returned.
1686  */
1687 static char*
1688 s_xhtml_1_0_end_pre_tag(xhtml_t* xhtml, Node* child) 
1689 {
1690   Doc*          doc = xhtml->doc;
1691   request_rec*  r   = doc->r;
1692
1693   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</pre>", NULL);
1694   xhtml->pre_flag--;
1695
1696   return xhtml->out;
1697 }
1698
1699 /**
1700  * It is a handler who processes the P tag.
1701  *
1702  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1703  *                     destination is specified.
1704  * @param node   [i]   The P tag node is specified.
1705  * @return The conversion result is returned.
1706  */
1707 static char*
1708 s_xhtml_1_0_start_p_tag(xhtml_t* xhtml, Node* node) 
1709 {
1710   Doc*          doc = xhtml->doc;
1711   request_rec*  r   = doc->r;
1712
1713   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<p>", NULL);
1714
1715   return xhtml->out;
1716 }
1717
1718 /**
1719  * It is a handler who processes the P tag.
1720  *
1721  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1722  *                     destination is specified.
1723  * @param node   [i]   The P tag node is specified.
1724  * @return The conversion result is returned.
1725  */
1726 static char*
1727 s_xhtml_1_0_end_p_tag(xhtml_t* xhtml, Node* child) 
1728 {
1729   Doc*          doc = xhtml->doc;
1730   request_rec*  r   = doc->r;
1731
1732   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</p>", NULL);
1733
1734   return xhtml->out;
1735 }
1736
1737 /**
1738  * It is a handler who processes the UL tag.
1739  *
1740  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1741  *                     destination is specified.
1742  * @param node   [i]   The UL tag node is specified.
1743  * @return The conversion result is returned.
1744  */
1745 static char*
1746 s_xhtml_1_0_start_ul_tag(xhtml_t* xhtml, Node* node) 
1747 {
1748   Doc*          doc = xhtml->doc;
1749   request_rec*  r   = doc->r;
1750
1751   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<ul>", NULL);
1752
1753   return xhtml->out;
1754 }
1755
1756 /**
1757  * It is a handler who processes the UL tag.
1758  *
1759  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1760  *                     destination is specified.
1761  * @param node   [i]   The UL tag node is specified.
1762  * @return The conversion result is returned.
1763  */
1764 static char*
1765 s_xhtml_1_0_end_ul_tag(xhtml_t* xhtml, Node* child) 
1766 {
1767   Doc*          doc = xhtml->doc;
1768   request_rec*  r   = doc->r;
1769
1770   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</ul>", NULL);
1771
1772   return xhtml->out;
1773 }
1774
1775 /**
1776  * It is a handler who processes the H1 tag.
1777  *
1778  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1779  *                     destination is specified.
1780  * @param node   [i]   The H1 tag node is specified.
1781  * @return The conversion result is returned.
1782  */
1783 static char*
1784 s_xhtml_1_0_start_h1_tag(xhtml_t* xhtml, Node* node) 
1785 {
1786   Doc*          doc = xhtml->doc;
1787   request_rec*  r   = doc->r;
1788
1789   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<h1>", NULL);
1790
1791   return xhtml->out;
1792 }
1793
1794 /**
1795  * It is a handler who processes the H1 tag.
1796  *
1797  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1798  *                     destination is specified.
1799  * @param node   [i]   The H1 tag node is specified.
1800  * @return The conversion result is returned.
1801  */
1802 static char*
1803 s_xhtml_1_0_end_h1_tag(xhtml_t* xhtml, Node* child) 
1804 {
1805   Doc*          doc = xhtml->doc;
1806   request_rec*  r   = doc->r;
1807
1808   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</h1>", NULL);
1809
1810   return xhtml->out;
1811 }
1812
1813 /**
1814  * It is a handler who processes the H2 tag.
1815  *
1816  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1817  *                     destination is specified.
1818  * @param node   [i]   The H2 tag node is specified.
1819  * @return The conversion result is returned.
1820  */
1821 static char*
1822 s_xhtml_1_0_start_h2_tag(xhtml_t* xhtml, Node* node) 
1823 {
1824   Doc*          doc = xhtml->doc;
1825   request_rec*  r   = doc->r;
1826
1827   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<h2>", NULL);
1828
1829   return xhtml->out;
1830 }
1831
1832 /**
1833  * It is a handler who processes the H2 tag.
1834  *
1835  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1836  *                     destination is specified.
1837  * @param node   [i]   The H2 tag node is specified.
1838  * @return The conversion result is returned.
1839  */
1840 static char*
1841 s_xhtml_1_0_end_h2_tag(xhtml_t* xhtml, Node* child) 
1842 {
1843   Doc*          doc = xhtml->doc;
1844   request_rec*  r   = doc->r;
1845
1846   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</h2>", NULL);
1847
1848   return xhtml->out;
1849 }
1850
1851 /**
1852  * It is a handler who processes the H3 tag.
1853  *
1854  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1855  *                     destination is specified.
1856  * @param node   [i]   The H3 tag node is specified.
1857  * @return The conversion result is returned.
1858  */
1859 static char*
1860 s_xhtml_1_0_start_h3_tag(xhtml_t* xhtml, Node* node) 
1861 {
1862   Doc*          doc = xhtml->doc;
1863   request_rec*  r   = doc->r;
1864
1865   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<h3>", NULL);
1866
1867   return xhtml->out;
1868 }
1869
1870 /**
1871  * It is a handler who processes the H3 tag.
1872  *
1873  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1874  *                     destination is specified.
1875  * @param node   [i]   The H3 tag node is specified.
1876  * @return The conversion result is returned.
1877  */
1878 static char*
1879 s_xhtml_1_0_end_h3_tag(xhtml_t* xhtml, Node* child) 
1880 {
1881   Doc*          doc = xhtml->doc;
1882   request_rec*  r   = doc->r;
1883
1884   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</h3>", NULL);
1885
1886   return xhtml->out;
1887 }
1888
1889 /**
1890  * It is a handler who processes the H4 tag.
1891  *
1892  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1893  *                     destination is specified.
1894  * @param node   [i]   The H4 tag node is specified.
1895  * @return The conversion result is returned.
1896  */
1897 static char*
1898 s_xhtml_1_0_start_h4_tag(xhtml_t* xhtml, Node* node) 
1899 {
1900   Doc*          doc = xhtml->doc;
1901   request_rec*  r   = doc->r;
1902
1903   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<h4>", NULL);
1904
1905   return xhtml->out;
1906 }
1907
1908 /**
1909  * It is a handler who processes the H4 tag.
1910  *
1911  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1912  *                     destination is specified.
1913  * @param node   [i]   The H4 tag node is specified.
1914  * @return The conversion result is returned.
1915  */
1916 static char*
1917 s_xhtml_1_0_end_h4_tag(xhtml_t* xhtml, Node* child) 
1918 {
1919   Doc*          doc = xhtml->doc;
1920   request_rec*  r   = doc->r;
1921
1922   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</h4>", NULL);
1923
1924   return xhtml->out;
1925 }
1926
1927 /**
1928  * It is a handler who processes the H5 tag.
1929  *
1930  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1931  *                     destination is specified.
1932  * @param node   [i]   The H5 tag node is specified.
1933  * @return The conversion result is returned.
1934  */
1935 static char*
1936 s_xhtml_1_0_start_h5_tag(xhtml_t* xhtml, Node* node) 
1937 {
1938   Doc*          doc = xhtml->doc;
1939   request_rec*  r   = doc->r;
1940
1941   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<h5>", NULL);
1942
1943   return xhtml->out;
1944 }
1945
1946 /**
1947  * It is a handler who processes the H5 tag.
1948  *
1949  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1950  *                     destination is specified.
1951  * @param node   [i]   The H5 tag node is specified.
1952  * @return The conversion result is returned.
1953  */
1954 static char*
1955 s_xhtml_1_0_end_h5_tag(xhtml_t* xhtml, Node* child) 
1956 {
1957   Doc*          doc = xhtml->doc;
1958   request_rec*  r   = doc->r;
1959
1960   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</h5>", NULL);
1961
1962   return xhtml->out;
1963 }
1964
1965 /**
1966  * It is a handler who processes the H6 tag.
1967  *
1968  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1969  *                     destination is specified.
1970  * @param node   [i]   The H6 tag node is specified.
1971  * @return The conversion result is returned.
1972  */
1973 static char*
1974 s_xhtml_1_0_start_h6_tag(xhtml_t* xhtml, Node* node) 
1975 {
1976   Doc*          doc = xhtml->doc;
1977   request_rec*  r   = doc->r;
1978
1979   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<h6>", NULL);
1980
1981   return xhtml->out;
1982 }
1983
1984 /**
1985  * It is a handler who processes the H6 tag.
1986  *
1987  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
1988  *                     destination is specified.
1989  * @param node   [i]   The H6 tag node is specified.
1990  * @return The conversion result is returned.
1991  */
1992 static char*
1993 s_xhtml_1_0_end_h6_tag(xhtml_t* xhtml, Node* child) 
1994 {
1995   Doc*          doc = xhtml->doc;
1996   request_rec*  r   = doc->r;
1997
1998   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</h6>", NULL);
1999
2000   return xhtml->out;
2001 }
2002
2003 /**
2004  * It is a handler who processes the OL tag.
2005  *
2006  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2007  *                     destination is specified.
2008  * @param node   [i]   The OL tag node is specified.
2009  * @return The conversion result is returned.
2010  */
2011 static char*
2012 s_xhtml_1_0_start_ol_tag(xhtml_t* xhtml, Node* node) 
2013 {
2014   Doc*          doc = xhtml->doc;
2015   request_rec*  r   = doc->r;
2016
2017   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<ol>", NULL);
2018
2019   return xhtml->out;
2020 }
2021
2022 /**
2023  * It is a handler who processes the OL tag.
2024  *
2025  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2026  *                     destination is specified.
2027  * @param node   [i]   The OL tag node is specified.
2028  * @return The conversion result is returned.
2029  */
2030 static char*
2031 s_xhtml_1_0_end_ol_tag(xhtml_t* xhtml, Node* child) 
2032 {
2033   Doc*          doc = xhtml->doc;
2034   request_rec*  r   = doc->r;
2035
2036   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</ol>", NULL);
2037
2038   return xhtml->out;
2039 }
2040
2041 /**
2042  * It is a handler who processes the LI tag.
2043  *
2044  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2045  *                     destination is specified.
2046  * @param node   [i]   The LI tag node is specified.
2047  * @return The conversion result is returned.
2048  */
2049 static char*
2050 s_xhtml_1_0_start_li_tag(xhtml_t* xhtml, Node* node) 
2051 {
2052   Doc*          doc = xhtml->doc;
2053   request_rec*  r   = doc->r;
2054
2055   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<li>", NULL);
2056
2057   return xhtml->out;
2058 }
2059
2060 /**
2061  ** It is a handler who processes the LI tag.
2062  *
2063  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2064  *                     destination is specified.
2065  * @param node   [i]   The LI tag node is specified.
2066  * @return The conversion result is returned.
2067  */
2068 static char*
2069 s_xhtml_1_0_end_li_tag(xhtml_t* xhtml, Node* child) 
2070 {
2071   Doc*          doc = xhtml->doc;
2072   request_rec*  r   = doc->r;
2073
2074   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</li>", NULL);
2075
2076   return xhtml->out;
2077 }
2078
2079 /**
2080  * It is a handler who processes the IMG tag.
2081  *
2082  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2083  *                     destination is specified.
2084  * @param node   [i]   The IMG tag node is specified.
2085  * @return The conversion result is returned.
2086  */
2087 static char*
2088 s_xhtml_1_0_start_img_tag(xhtml_t* xhtml, Node* node) 
2089 {
2090   Doc*          doc = xhtml->doc;
2091   request_rec*  r   = doc->r;
2092   Attr* attr;
2093
2094 #ifndef IMG_NOT_CONVERT_FILENAME
2095   device_table_t* spec = xhtml->spec;
2096 #endif
2097
2098   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<img", NULL);
2099
2100   /*--------------------------------------------------------------------------*/
2101   /* Get Attributes                                                           */
2102   /*--------------------------------------------------------------------------*/
2103   for (attr = qs_get_attr(doc,node);
2104        attr;
2105        attr = qs_get_next_attr(doc,attr)) {
2106     char* name  = qs_get_attr_name(doc,attr);
2107     char* value = qs_get_attr_value(doc,attr);
2108
2109     if ((*name == 's' || *name == 'S') && strcasecmp(name, "src") == 0) {
2110 #ifdef IMG_NOT_CONVERT_FILENAME
2111       xhtml->out = apr_pstrcat(r->pool, 
2112                       xhtml->out, " src=\"",value,"\"", NULL);
2113 #else
2114       xhtml->out = apr_pstrcat(r->pool, xhtml->out,
2115                       " src=\"", chxj_img_conv(r,spec,value) , NULL);
2116       xhtml->out = apr_pstrcat(r->pool, xhtml->out, "\"", NULL);
2117 #endif
2118     }
2119     else
2120     if (*name == 'a' || *name == 'A') {
2121       if (strcasecmp(name, "align" ) == 0) {
2122         xhtml->out = apr_pstrcat(r->pool, 
2123                         xhtml->out, " align=\"",value,"\"", NULL);
2124       }
2125       else
2126       if (strcasecmp(name, "alt"   ) == 0) {
2127         xhtml->out = apr_pstrcat(r->pool, 
2128                         xhtml->out, " alt=\"",value,"\"", NULL);
2129       }
2130     }
2131     else
2132     if ((*name == 'w' || *name == 'W') && strcasecmp(name, "width" ) == 0) {
2133       xhtml->out = apr_pstrcat(r->pool, 
2134                       xhtml->out, " width=\"",value,"\"", NULL);
2135     }
2136     else
2137     if (*name == 'h' || *name == 'H') {
2138       if (strcasecmp(name, "height") == 0) {
2139         xhtml->out = apr_pstrcat(r->pool, 
2140                         xhtml->out, " height=\"",value,"\"", NULL);
2141       }
2142       else
2143       if (strcasecmp(name, "hspace") == 0) {
2144         xhtml->out = apr_pstrcat(r->pool, 
2145                         xhtml->out, " hspace=\"",value,"\"", NULL);
2146       }
2147     }
2148     else
2149     if ((*name == 'v' || *name == 'V') && strcasecmp(name, "vspace") == 0) {
2150       xhtml->out = apr_pstrcat(r->pool, 
2151                       xhtml->out, " vspace=\"",value,"\"", NULL);
2152     }
2153   }
2154
2155   xhtml->out = apr_pstrcat(r->pool, xhtml->out, ">", NULL);
2156
2157   return xhtml->out;
2158 }
2159
2160 /**
2161  * It is a handler who processes the IMG tag.
2162  *
2163  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2164  *                     destination is specified.
2165  * @param node   [i]   The IMG tag node is specified.
2166  * @return The conversion result is returned.
2167  */
2168 static char*
2169 s_xhtml_1_0_end_img_tag(xhtml_t* xhtml, Node* child) 
2170 {
2171   return xhtml->out;
2172 }
2173
2174 /**
2175  * It is a handler who processes the SELECT tag.
2176  *
2177  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2178  *                     destination is specified.
2179  * @param node   [i]   The SELECT tag node is specified.
2180  * @return The conversion result is returned.
2181  */
2182 static char*
2183 s_xhtml_1_0_start_select_tag(xhtml_t* xhtml, Node* child)
2184 {
2185   Doc* doc = xhtml->doc;
2186   request_rec* r = doc->r;
2187   Attr* attr;
2188
2189   char* size      = NULL;
2190   char* name      = NULL;
2191
2192   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<select", NULL);
2193   for (attr = qs_get_attr(doc,child);
2194        attr;
2195        attr = qs_get_next_attr(doc,attr)) {
2196     char* nm  = qs_get_attr_name(doc,attr);
2197     char* val = qs_get_attr_value(doc,attr);
2198
2199     if ((*nm == 's' || *nm == 'S') && strcasecmp(nm, "size") == 0) {
2200       /* CHTML version 2.0 */
2201       size = apr_pstrdup(r->pool, val);
2202     }
2203     else
2204     if ((*nm == 'n' || *nm == 'N') && strcasecmp(nm, "name") == 0) {
2205       /* CHTML version 2.0 */
2206       name = apr_pstrdup(r->pool, val);
2207     }
2208     else
2209     if ((*nm == 'm' || *nm == 'M') && strcasecmp(nm, "multiple") == 0) {
2210       /* CHTML version 2.0 */
2211       /* Ignore */
2212     }
2213   }
2214
2215   if (size)
2216     xhtml->out = apr_pstrcat(r->pool, xhtml->out, " size=\"",size,"\"", NULL);
2217
2218   if (name)
2219     xhtml->out = apr_pstrcat(r->pool, xhtml->out, " name=\"",name,"\"", NULL);
2220
2221   xhtml->out = apr_pstrcat(r->pool, xhtml->out, ">\n", NULL);
2222
2223   return xhtml->out;
2224 }
2225
2226 /**
2227  * It is a handler who processes the SELECT tag.
2228  *
2229  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2230  *                     destination is specified.
2231  * @param node   [i]   The SELECT tag node is specified.
2232  * @return The conversion result is returned.
2233  */
2234 static char*
2235 s_xhtml_1_0_end_select_tag(xhtml_t* xhtml, Node* child)
2236 {
2237   Doc* doc = xhtml->doc;
2238   request_rec* r = doc->r;
2239
2240   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</select>\n", NULL);
2241   return xhtml->out;
2242 }
2243
2244 /**
2245  * It is a handler who processes the OPTION tag.
2246  *
2247  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2248  *                     destination is specified.
2249  * @param node   [i]   The OPTION tag node is specified.
2250  * @return The conversion result is returned.
2251  */
2252 static char*
2253 s_xhtml_1_0_start_option_tag(xhtml_t* xhtml, Node* child)
2254 {
2255   Doc* doc = xhtml->doc;
2256   request_rec* r = doc->r;
2257   Attr* attr;
2258
2259   char* selected   = NULL;
2260   char* value      = NULL;
2261
2262   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<option", NULL);
2263   for (attr = qs_get_attr(doc,child);
2264        attr;
2265        attr = qs_get_next_attr(doc,attr)) {
2266     char* nm  = qs_get_attr_name(doc,attr);
2267     char* val = qs_get_attr_value(doc,attr);
2268
2269     if ((*nm == 's' || *nm == 'S') && strcasecmp(nm, "selected") == 0) {
2270       /* CHTML version 2.0 */
2271       selected = apr_pstrdup(r->pool, val);
2272     }
2273     else
2274     if ((*nm == 'v' || *nm == 'V') && strcasecmp(nm, "value") == 0) {
2275       /* CHTML version 2.0 */
2276       value = apr_pstrdup(r->pool, val);
2277     }
2278   }
2279
2280   if (value)
2281     xhtml->out = apr_pstrcat(r->pool, xhtml->out, " value=\"",value,"\"", NULL);
2282   else
2283     xhtml->out = apr_pstrcat(r->pool, xhtml->out, " value=\"\"", NULL);
2284
2285   if (selected)
2286     xhtml->out = apr_pstrcat(r->pool, xhtml->out, " selected=\"selected\"", NULL);
2287
2288   xhtml->out = apr_pstrcat(r->pool, xhtml->out, ">", NULL);
2289
2290   return xhtml->out;
2291 }
2292
2293 /**
2294  * It is a handler who processes the OPTION tag.
2295  *
2296  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2297  *                     destination is specified.
2298  * @param node   [i]   The OPTION tag node is specified.
2299  * @return The conversion result is returned.
2300  */
2301 static char*
2302 s_xhtml_1_0_end_option_tag(xhtml_t* xhtml, Node* child)
2303 {
2304   Doc* doc = xhtml->doc;
2305   request_rec* r = doc->r;
2306
2307   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</option>\n", NULL);
2308
2309   return xhtml->out;
2310 }
2311
2312 /**
2313  * It is a handler who processes the DIV tag.
2314  *
2315  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2316  *                     destination is specified.
2317  * @param node   [i]   The DIV tag node is specified.
2318  * @return The conversion result is returned.
2319  */
2320 static char*
2321 s_xhtml_1_0_start_div_tag(xhtml_t* xhtml, Node* child)
2322 {
2323   Doc* doc = xhtml->doc;
2324   request_rec* r = doc->r;
2325   Attr* attr;
2326
2327   char* align   = NULL;
2328
2329   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "<div", NULL);
2330   for (attr = qs_get_attr(doc,child);
2331        attr;
2332        attr = qs_get_next_attr(doc,attr)) {
2333     char* nm  = qs_get_attr_name(doc,attr);
2334     char* val = qs_get_attr_value(doc,attr);
2335
2336     if ((*nm == 'a' || *nm == 'A') && strcasecmp(nm, "align") == 0) {
2337       /* CHTML version 3.2 */
2338       align = apr_pstrdup(r->pool, val);
2339     }
2340   }
2341
2342   if (align)
2343     xhtml->out = apr_pstrcat(r->pool, 
2344                     xhtml->out, " align=\"", align, "\"", NULL);
2345
2346   xhtml->out = apr_pstrcat(r->pool, xhtml->out, ">", NULL);
2347
2348   return xhtml->out;
2349 }
2350
2351 /**
2352  * It is a handler who processes the DIV tag.
2353  *
2354  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2355  *                     destination is specified.
2356  * @param node   [i]   The DIV tag node is specified.
2357  * @return The conversion result is returned.
2358  */
2359 static char*
2360 s_xhtml_1_0_end_div_tag(xhtml_t* xhtml, Node* child)
2361 {
2362   Doc* doc = xhtml->doc;
2363   request_rec* r = doc->r;
2364
2365   xhtml->out = apr_pstrcat(r->pool, xhtml->out, "</div>\n", NULL);
2366
2367   return xhtml->out;
2368 }
2369
2370 /**
2371  * It is a handler who processes the CHXJ:IF tag.
2372  *
2373  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2374  *                     destination is specified.
2375  * @param node   [i]   The CHXJ:IF tag node is specified.
2376  */
2377 static void
2378 s_xhtml_1_0_chxjif_tag(xhtml_t* xhtml, Node* node)
2379 {
2380   Doc*         doc   = xhtml->doc;
2381   Node*        child;
2382   request_rec* r = xhtml->doc->r;
2383
2384   for (child = qs_get_child_node(doc, node);
2385        child;
2386        child = qs_get_next_node(doc, child)) {
2387     xhtml->out = apr_pstrcat(r->pool, xhtml->out, child->otext, NULL);
2388     s_xhtml_1_0_chxjif_tag(xhtml, child);
2389   }
2390 }
2391 /*
2392  * vim:ts=2 et
2393  */