OSDN Git Service

* Fixed Bug.
[modchxj/mod_chxj.git] / src / chxj_node_convert.c
1 /*
2  * Copyright (C) 2005-2009 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
19 tag_handlers chxj_tag_handlers[] = {
20   {
21     .type    = CHXJ_SPEC_UNKNOWN,
22     .handler = NULL,
23   },
24   {
25     .type    = CHXJ_SPEC_Chtml_1_0,
26     .handler = chtml10_handler,
27   },
28   {
29     .type    = CHXJ_SPEC_Chtml_2_0,
30     .handler = chtml20_handler,
31   },
32   {
33     .type    = CHXJ_SPEC_Chtml_3_0,
34     .handler = chtml30_handler,
35   },
36   {
37     .type    = CHXJ_SPEC_Chtml_4_0,
38     .handler = chtml40_handler,
39   },
40   {
41     .type    = CHXJ_SPEC_Chtml_5_0,
42     .handler = chtml50_handler,
43   },
44   {
45     .type    = CHXJ_SPEC_Chtml_6_0,
46     .handler = chtml50_handler,
47   },
48   {
49     .type    = CHXJ_SPEC_Chtml_7_0,
50     .handler = chtml50_handler,
51   },
52   {
53     .type    = CHXJ_SPEC_XHtml_Mobile_1_0,
54     .handler = xhtml_handler,
55   },
56   {
57     .type    = CHXJ_SPEC_Hdml,
58     .handler = hdml_handler,
59   },
60   {
61     .type    = CHXJ_SPEC_Jhtml,
62     .handler = jhtml_handler,
63   },
64   {
65     .type    = CHXJ_SPEC_Jxhtml,
66     .handler = jxhtml_handler,
67   },
68   {
69     .type    = CHXJ_SPEC_HTML,
70     .handler = NULL,
71   },
72 };
73
74
75 /**
76  * It is main processing of conversion from CHTML to XXML. 
77  *
78  * @param spec    [i]   
79  * @param r       [i]   
80  * @param pdoc    [i/o] The pointer to the XXML structure is specified. 
81  * @param doc     [i/o] The pointer to the XXML structure is specified. 
82  * @param node    [i]   The pointer to a current node is specified. 
83  * @param indent  [i]   The depth of the node processing it now is specified. 
84  *
85  * @return The character string after it converts it is returned. 
86  */
87 char *
88 chxj_node_convert(
89   device_table *spec,
90   request_rec  *r,
91   void         *pdoc, 
92   Doc          *doc, 
93   Node         *node, 
94   int          indent
95 )
96 {
97   Node         *child;
98   tag_handler  *handlers;
99
100
101   handlers = chxj_tag_handlers[spec->html_spec_type].handler;
102
103   /*--------------------------------------------------------------------------*/
104   /* It is the main loop of the conversion processing.                        */
105   /*--------------------------------------------------------------------------*/
106   for (child = qs_get_child_node(doc,node);
107        child;
108        child = qs_get_next_node(doc,child)) {
109     char *name = qs_get_node_name(doc,child);
110     switch(*name) {
111     case 'h':
112     case 'H':
113       /*----------------------------------------------------------------------*/
114       /* <HTML>                                                               */
115       /*----------------------------------------------------------------------*/
116       if (strcasecmp(name, "html") == 0) {
117         if (handlers[tagHTML].start_tag_handler) 
118           handlers[tagHTML].start_tag_handler(pdoc, child);
119
120         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
121
122         if (handlers[tagHTML].end_tag_handler)
123           handlers[tagHTML].end_tag_handler(pdoc, child);
124       }
125       /*----------------------------------------------------------------------*/
126       /* <HEAD>                                                               */
127       /*----------------------------------------------------------------------*/
128       else 
129       if (strcasecmp(name, "head") == 0) {
130         if (handlers[tagHEAD].start_tag_handler) 
131           handlers[tagHEAD].start_tag_handler(pdoc, child);
132
133         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
134
135         if (handlers[tagHEAD].end_tag_handler)
136           handlers[tagHEAD].end_tag_handler(pdoc, child);
137       }
138       /*----------------------------------------------------------------------*/
139       /* <HR>                                                                 */
140       /*----------------------------------------------------------------------*/
141       else 
142       if (strcasecmp(name, "hr") == 0) {
143         if (handlers[tagHR].start_tag_handler) 
144           handlers[tagHR].start_tag_handler(pdoc, child);
145
146         if (handlers[tagHR].end_tag_handler)
147           handlers[tagHR].end_tag_handler(pdoc, child);
148       }
149       /*----------------------------------------------------------------------*/
150       /* <H1>                                                                 */
151       /*----------------------------------------------------------------------*/
152       else
153       if (strcasecmp(name, "h1") == 0) {
154         if (handlers[tagH1].start_tag_handler) 
155           handlers[tagH1].start_tag_handler(pdoc, child);
156
157         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
158
159         if (handlers[tagH1].end_tag_handler)
160           handlers[tagH1].end_tag_handler(pdoc, child);
161       }
162       /*----------------------------------------------------------------------*/
163       /* <H2>                                                                 */
164       /*----------------------------------------------------------------------*/
165       else
166       if (strcasecmp(name, "h2") == 0) {
167         if (handlers[tagH2].start_tag_handler) 
168           handlers[tagH2].start_tag_handler(pdoc, child);
169
170         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
171
172         if (handlers[tagH2].end_tag_handler)
173           handlers[tagH2].end_tag_handler(pdoc, child);
174       }
175       /*----------------------------------------------------------------------*/
176       /* <H3>                                                                 */
177       /*----------------------------------------------------------------------*/
178       else
179       if (strcasecmp(name, "h3") == 0) {
180         if (handlers[tagH3].start_tag_handler) 
181           handlers[tagH3].start_tag_handler(pdoc, child);
182
183         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
184
185         if (handlers[tagH3].end_tag_handler)
186           handlers[tagH3].end_tag_handler(pdoc, child);
187       }
188       /*----------------------------------------------------------------------*/
189       /* <H4>                                                                 */
190       /*----------------------------------------------------------------------*/
191       else
192       if (strcasecmp(name, "h4") == 0) {
193         if (handlers[tagH4].start_tag_handler) 
194           handlers[tagH4].start_tag_handler(pdoc, child);
195
196         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
197
198         if (handlers[tagH4].end_tag_handler)
199           handlers[tagH4].end_tag_handler(pdoc, child);
200       }
201       /*----------------------------------------------------------------------*/
202       /* <H5>                                                                 */
203       /*----------------------------------------------------------------------*/
204       else
205       if (strcasecmp(name, "h5") == 0) {
206         if (handlers[tagH5].start_tag_handler) 
207           handlers[tagH5].start_tag_handler(pdoc, child);
208
209         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
210
211         if (handlers[tagH5].end_tag_handler)
212           handlers[tagH5].end_tag_handler(pdoc, child);
213       }
214       /*----------------------------------------------------------------------*/
215       /* <H6>                                                                 */
216       /*----------------------------------------------------------------------*/
217       else
218       if (strcasecmp(name, "h6") == 0) {
219         if (handlers[tagH6].start_tag_handler) 
220           handlers[tagH6].start_tag_handler(pdoc, child);
221
222         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
223
224         if (handlers[tagH6].end_tag_handler)
225           handlers[tagH6].end_tag_handler(pdoc, child);
226       }
227       else {
228         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
229       }
230       break;
231
232
233     case 'p':
234     case 'P':
235       /*----------------------------------------------------------------------*/
236       /* <P>                                                                  */
237       /*----------------------------------------------------------------------*/
238       if (strcasecmp(name, "p") == 0) {
239         if (handlers[tagP].start_tag_handler) 
240           handlers[tagP].start_tag_handler(pdoc, child);
241
242         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
243
244         if (handlers[tagP].end_tag_handler)
245           handlers[tagP].end_tag_handler(pdoc, child);
246       }
247       /*----------------------------------------------------------------------*/
248       /* <PRE>                                                                */
249       /*----------------------------------------------------------------------*/
250       else if (strcasecmp(name, "pre") == 0) {
251         if (handlers[tagPRE].start_tag_handler) 
252           handlers[tagPRE].start_tag_handler(pdoc, child);
253
254         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
255
256         if (handlers[tagPRE].end_tag_handler)
257           handlers[tagPRE].end_tag_handler(pdoc, child);
258       }
259       /*----------------------------------------------------------------------*/
260       /* <PLAINTEXT>                                                          */
261       /*----------------------------------------------------------------------*/
262       else if (strcasecmp(name, "plaintext") == 0) {
263         if (handlers[tagPLAINTEXT].start_tag_handler) 
264           handlers[tagPLAINTEXT].start_tag_handler(pdoc, child);
265
266         if (handlers[tagPLAINTEXT].end_tag_handler)
267           handlers[tagPLAINTEXT].end_tag_handler(pdoc, child);
268       }
269       /*----------------------------------------------------------------------*/
270       /* <PARAM>                                                              */
271       /*----------------------------------------------------------------------*/
272       else if (strcasecmp(name, "param") == 0) {
273         /* ignore param tag block. */
274       }
275       else {
276         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
277       }
278       break;
279
280     case 'n':
281     case 'N':
282       /*----------------------------------------------------------------------*/
283       /* <NOBR>                                                               */
284       /*----------------------------------------------------------------------*/
285       if (strcasecmp(name, "nobr") == 0) {
286         if (handlers[tagNOBR].start_tag_handler) 
287           handlers[tagNOBR].start_tag_handler(pdoc, child);
288
289         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
290
291         if (handlers[tagNOBR].end_tag_handler)
292           handlers[tagNOBR].end_tag_handler(pdoc, child);
293       }
294       else {
295         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
296       }
297       break;
298
299     case 'u':
300     case 'U':
301       /*----------------------------------------------------------------------*/
302       /* <UL>                                                                 */
303       /*----------------------------------------------------------------------*/
304       if (strcasecmp(name, "ul") == 0) {
305         if (handlers[tagUL].start_tag_handler) 
306           handlers[tagUL].start_tag_handler(pdoc, child);
307
308         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
309
310         if (handlers[tagUL].end_tag_handler)
311           handlers[tagUL].end_tag_handler(pdoc, child);
312       }
313       else {
314         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
315       }
316       break;
317
318     case 'l':
319     case 'L':
320       /*----------------------------------------------------------------------*/
321       /* <LI>                                                                 */
322       /*----------------------------------------------------------------------*/
323       if (strcasecmp(name, "li") == 0) {
324         if (handlers[tagLI].start_tag_handler) 
325           handlers[tagLI].start_tag_handler(pdoc, child);
326
327         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
328
329         if (handlers[tagLI].end_tag_handler)
330           handlers[tagLI].end_tag_handler(pdoc, child);
331       }
332       else
333       /*----------------------------------------------------------------------*/
334       /* <LEGEND>                                                             */
335       /*----------------------------------------------------------------------*/
336       if (strcasecmp(name, "legend") == 0) {
337         if (handlers[tagLEGEND].start_tag_handler) 
338           handlers[tagLEGEND].start_tag_handler(pdoc, child);
339
340         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
341
342         if (handlers[tagLEGEND].end_tag_handler)
343           handlers[tagLEGEND].end_tag_handler(pdoc, child);
344       }
345       else
346       /*----------------------------------------------------------------------*/
347       /* <LABEL>                                                              */
348       /*----------------------------------------------------------------------*/
349       if (strcasecmp(name, "label") == 0) {
350         if (handlers[tagLABEL].start_tag_handler) 
351           handlers[tagLABEL].start_tag_handler(pdoc, child);
352
353         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
354
355         if (handlers[tagLABEL].end_tag_handler)
356           handlers[tagLABEL].end_tag_handler(pdoc, child);
357       }
358       else {
359         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
360       }
361       
362       break;
363
364     case 'o':
365     case 'O':
366       /*----------------------------------------------------------------------*/
367       /* <OL>                                                                 */
368       /*----------------------------------------------------------------------*/
369       if (strcasecmp(name, "ol") == 0) {
370         if (handlers[tagOL].start_tag_handler) 
371           handlers[tagOL].start_tag_handler(pdoc, child);
372
373         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
374
375         if (handlers[tagOL].end_tag_handler)
376           handlers[tagOL].end_tag_handler(pdoc, child);
377       }
378       else
379       /*----------------------------------------------------------------------*/
380       /* <OPTION>                                                             */
381       /*----------------------------------------------------------------------*/
382       if (strcasecmp(name, "option") == 0) {
383         if (handlers[tagOPTION].start_tag_handler) 
384           handlers[tagOPTION].start_tag_handler(pdoc, child);
385
386         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
387
388         if (handlers[tagOPTION].end_tag_handler)
389           handlers[tagOPTION].end_tag_handler(pdoc, child);
390       }
391       else
392       /*----------------------------------------------------------------------*/
393       /* <OBJECT>                                                             */
394       /*----------------------------------------------------------------------*/
395       if (strcasecmp(name, "object") == 0) {
396         /* ignore object block */
397       }
398       else {
399         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
400       }
401
402       break;
403
404     case 'm':
405     case 'M':
406       /*----------------------------------------------------------------------*/
407       /* <META>                                                               */
408       /*----------------------------------------------------------------------*/
409       if (strcasecmp(name, "meta") == 0) {
410         if (handlers[tagMETA].start_tag_handler) 
411           handlers[tagMETA].start_tag_handler(pdoc, child);
412
413         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
414
415         if (handlers[tagMETA].end_tag_handler)
416           handlers[tagMETA].end_tag_handler(pdoc, child);
417       }
418       /*----------------------------------------------------------------------*/
419       /* <MENU>                                                               */
420       /*----------------------------------------------------------------------*/
421       else if (strcasecmp(name, "menu") == 0) {
422         if (handlers[tagMENU].start_tag_handler) 
423           handlers[tagMENU].start_tag_handler(pdoc, child);
424
425         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
426
427         if (handlers[tagMENU].end_tag_handler)
428           handlers[tagMENU].end_tag_handler(pdoc, child);
429       }
430       /*----------------------------------------------------------------------*/
431       /* <MARQUEE>                                                            */
432       /*----------------------------------------------------------------------*/
433       else if (strcasecmp(name, "marquee") == 0) {
434         if (handlers[tagMARQUEE].start_tag_handler) 
435           handlers[tagMARQUEE].start_tag_handler(pdoc, child);
436
437         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
438
439         if (handlers[tagMARQUEE].end_tag_handler)
440           handlers[tagMARQUEE].end_tag_handler(pdoc, child);
441       }
442       else {
443         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
444       }
445       break;
446
447     case 'b':
448     case 'B':
449       /*----------------------------------------------------------------------*/
450       /* <B>                                                                  */
451       /*----------------------------------------------------------------------*/
452       if (strlen(name) == 1) {
453         if (handlers[tagB].start_tag_handler) 
454           handlers[tagB].start_tag_handler(pdoc, child);
455
456         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
457
458         if (handlers[tagB].end_tag_handler)
459           handlers[tagB].end_tag_handler(pdoc, child);
460       }
461       else
462       /*----------------------------------------------------------------------*/
463       /* <BASE>                                                               */
464       /*----------------------------------------------------------------------*/
465       if (strcasecmp(name, "base") == 0) {
466         if (handlers[tagBASE].start_tag_handler) 
467           handlers[tagBASE].start_tag_handler(pdoc, child);
468
469         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
470
471         if (handlers[tagBASE].end_tag_handler)
472           handlers[tagBASE].end_tag_handler(pdoc, child);
473       }
474       /*----------------------------------------------------------------------*/
475       /* <BODY>                                                               */
476       /*----------------------------------------------------------------------*/
477       else
478       if (strcasecmp(name, "body") == 0) {
479         if (handlers[tagBODY].start_tag_handler) 
480           handlers[tagBODY].start_tag_handler(pdoc, child);
481
482         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
483
484         if (handlers[tagBODY].end_tag_handler)
485           handlers[tagBODY].end_tag_handler(pdoc, child);
486       }
487       /*----------------------------------------------------------------------*/
488       /* <BR>                                                                 */
489       /*----------------------------------------------------------------------*/
490       else if (strcasecmp(name, "br") == 0) {
491         if (handlers[tagBR].start_tag_handler) 
492           handlers[tagBR].start_tag_handler(pdoc, child);
493
494         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
495
496         if (handlers[tagBR].end_tag_handler)
497           handlers[tagBR].end_tag_handler(pdoc, child);
498       }
499       /*----------------------------------------------------------------------*/
500       /* <BLOCKQUOTE>                                                         */
501       /*----------------------------------------------------------------------*/
502       else if (strcasecmp(name, "blockquote") == 0) {
503         if (handlers[tagBLOCKQUOTE].start_tag_handler) 
504           handlers[tagBLOCKQUOTE].start_tag_handler(pdoc, child);
505
506         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
507
508         if (handlers[tagBLOCKQUOTE].end_tag_handler)
509           handlers[tagBLOCKQUOTE].end_tag_handler(pdoc, child);
510       }
511       /*----------------------------------------------------------------------*/
512       /* <BLINK>                                                              */
513       /*----------------------------------------------------------------------*/
514       else if (strcasecmp(name, "blink") == 0) {
515         if (handlers[tagBLINK].start_tag_handler) 
516           handlers[tagBLINK].start_tag_handler(pdoc, child);
517
518         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
519
520         if (handlers[tagBLINK].end_tag_handler)
521           handlers[tagBLINK].end_tag_handler(pdoc, child);
522       }
523       else {
524         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
525       }
526       break;
527
528     case 'a':
529     case 'A':
530       /*----------------------------------------------------------------------*/
531       /* <A>                                                                  */
532       /*----------------------------------------------------------------------*/
533       if (strcasecmp(name, "a") == 0) {
534         if (handlers[tagA].start_tag_handler) 
535           handlers[tagA].start_tag_handler(pdoc, child);
536
537         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
538
539         if (handlers[tagA].end_tag_handler)
540           handlers[tagA].end_tag_handler(pdoc, child);
541       }
542       else {
543         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
544       }
545       break;
546
547     case 'f':
548     case 'F':
549       /*----------------------------------------------------------------------*/
550       /* <FONT>                                                               */
551       /*----------------------------------------------------------------------*/
552       if (strcasecmp(name, "font") == 0) {
553         if (handlers[tagFONT].start_tag_handler) 
554           handlers[tagFONT].start_tag_handler(pdoc, child);
555
556         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
557
558         if (handlers[tagFONT].end_tag_handler)
559           handlers[tagFONT].end_tag_handler(pdoc, child);
560       }
561       /*----------------------------------------------------------------------*/
562       /* <FORM>                                                               */
563       /*----------------------------------------------------------------------*/
564       else
565       if (strcasecmp(name, "form") == 0) {
566         if (handlers[tagFORM].start_tag_handler) 
567           handlers[tagFORM].start_tag_handler(pdoc, child);
568
569         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
570
571         if (handlers[tagFORM].end_tag_handler)
572           handlers[tagFORM].end_tag_handler(pdoc, child);
573       }
574       /*----------------------------------------------------------------------*/
575       /* <FIELDSET>                                                           */
576       /*----------------------------------------------------------------------*/
577       else
578       if (strcasecmp(name, "fieldset") == 0) {
579         if (handlers[tagFIELDSET].start_tag_handler) 
580           handlers[tagFIELDSET].start_tag_handler(pdoc, child);
581
582         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
583
584         if (handlers[tagFIELDSET].end_tag_handler)
585           handlers[tagFIELDSET].end_tag_handler(pdoc, child);
586       }
587       else {
588         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
589       }
590       break;
591
592     case 'i':
593     case 'I':
594       /*----------------------------------------------------------------------*/
595       /* <INPUT>                                                              */
596       /*----------------------------------------------------------------------*/
597       if (strcasecmp(name, "input") == 0) {
598         if (handlers[tagINPUT].start_tag_handler) 
599           handlers[tagINPUT].start_tag_handler(pdoc, child);
600
601         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
602
603         if (handlers[tagINPUT].end_tag_handler)
604           handlers[tagINPUT].end_tag_handler(pdoc, child);
605       }
606       /*----------------------------------------------------------------------*/
607       /* <IMG>                                                                */
608       /*----------------------------------------------------------------------*/
609       else
610       if (strcasecmp(name, "img") == 0) {
611         if (handlers[tagIMG].start_tag_handler) 
612           handlers[tagIMG].start_tag_handler(pdoc, child);
613
614         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
615
616         if (handlers[tagIMG].end_tag_handler)
617           handlers[tagIMG].end_tag_handler(pdoc, child);
618       }
619       else {
620         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
621       }
622       break;
623
624     case 's':
625     case 'S':
626       /*----------------------------------------------------------------------*/
627       /* <SELECT>                                                             */
628       /*----------------------------------------------------------------------*/
629       if (strcasecmp(name, "select") == 0) {
630         if (handlers[tagSELECT].start_tag_handler) 
631           handlers[tagSELECT].start_tag_handler(pdoc, child);
632
633         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
634
635         if (handlers[tagSELECT].end_tag_handler)
636           handlers[tagSELECT].end_tag_handler(pdoc, child);
637       }
638       /*----------------------------------------------------------------------*/
639       /* <STYLE>                                                              */
640       /*----------------------------------------------------------------------*/
641       else
642       if (strcasecmp(name, "style") == 0) {
643         if (handlers[tagSTYLE].start_tag_handler) 
644           handlers[tagSTYLE].start_tag_handler(pdoc, child);
645 #if 0
646         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
647 #endif
648
649         if (handlers[tagSTYLE].end_tag_handler)
650           handlers[tagSTYLE].end_tag_handler(pdoc, child);
651       }
652       /*----------------------------------------------------------------------*/
653       /* <SPAN>                                                               */
654       /*----------------------------------------------------------------------*/
655       else
656       if (strcasecmp(name, "span") == 0) {
657         if (handlers[tagSPAN].start_tag_handler) 
658           handlers[tagSPAN].start_tag_handler(pdoc, child);
659
660         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
661
662         if (handlers[tagSPAN].end_tag_handler)
663           handlers[tagSPAN].end_tag_handler(pdoc, child);
664       }
665       /*----------------------------------------------------------------------*/
666       /* <SMALL>                                                              */
667       /*----------------------------------------------------------------------*/
668       else
669       if (strcasecmp(name, "small") == 0) {
670         if (handlers[tagSMALL].start_tag_handler) 
671           handlers[tagSMALL].start_tag_handler(pdoc, child);
672
673         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
674
675         if (handlers[tagSMALL].end_tag_handler)
676           handlers[tagSMALL].end_tag_handler(pdoc, child);
677       }
678       /*----------------------------------------------------------------------*/
679       /* <SCRIPT>                                                             */
680       /*----------------------------------------------------------------------*/
681       else 
682       if (strcasecmp(name, "script") == 0) {
683         /* ignore script block */
684       }
685       else {
686         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
687       }
688       break;
689   
690     case 'd':
691     case 'D':
692       /*----------------------------------------------------------------------*/
693       /* <DIV>                                                                */
694       /*----------------------------------------------------------------------*/
695       if (strcasecmp(name, "div") == 0) {
696         if (handlers[tagDIV].start_tag_handler) 
697           handlers[tagDIV].start_tag_handler(pdoc, child);
698
699         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
700
701         if (handlers[tagDIV].end_tag_handler)
702           handlers[tagDIV].end_tag_handler(pdoc, child);
703       }
704       /*----------------------------------------------------------------------*/
705       /* <DIR>                                                                */
706       /*----------------------------------------------------------------------*/
707       else if (strcasecmp(name, "dir") == 0) {
708         if (handlers[tagDIR].start_tag_handler) 
709           handlers[tagDIR].start_tag_handler(pdoc, child);
710
711         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
712
713         if (handlers[tagDIR].end_tag_handler)
714           handlers[tagDIR].end_tag_handler(pdoc, child);
715       }
716       /*----------------------------------------------------------------------*/
717       /* <DL>                                                                 */
718       /*----------------------------------------------------------------------*/
719       else if (strcasecmp(name, "dl") == 0) {
720         if (handlers[tagDL].start_tag_handler) 
721           handlers[tagDL].start_tag_handler(pdoc, child);
722
723         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
724
725         if (handlers[tagDL].end_tag_handler)
726           handlers[tagDL].end_tag_handler(pdoc, child);
727       }
728       /*----------------------------------------------------------------------*/
729       /* <DT>                                                                 */
730       /*----------------------------------------------------------------------*/
731       else if (strcasecmp(name, "dt") == 0) {
732         if (handlers[tagDT].start_tag_handler) 
733           handlers[tagDT].start_tag_handler(pdoc, child);
734
735         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
736
737         if (handlers[tagDT].end_tag_handler)
738           handlers[tagDT].end_tag_handler(pdoc, child);
739       }
740       /*----------------------------------------------------------------------*/
741       /* <DD>                                                                 */
742       /*----------------------------------------------------------------------*/
743       else if (strcasecmp(name, "dd") == 0) {
744         if (handlers[tagDD].start_tag_handler) 
745           handlers[tagDD].start_tag_handler(pdoc, child);
746
747         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
748
749         if (handlers[tagDD].end_tag_handler)
750           handlers[tagDD].end_tag_handler(pdoc, child);
751       }
752       else {
753         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
754       }
755       break;
756
757     case 'c':
758     case 'C':
759       /*----------------------------------------------------------------------*/
760       /* NL (CrLf)                                                            */
761       /*----------------------------------------------------------------------*/
762       if (strcasecmp(name, QS_PARSE_NL_MARK) == 0) {
763         if (handlers[tagNLMARK].start_tag_handler) 
764           handlers[tagNLMARK].start_tag_handler(pdoc, child);
765       }
766       else
767       /*----------------------------------------------------------------------*/
768       /* <CENTER>                                                             */
769       /*----------------------------------------------------------------------*/
770       if (strcasecmp(name, "center") == 0) {
771         if (handlers[tagCENTER].start_tag_handler) 
772           handlers[tagCENTER].start_tag_handler(pdoc, child);
773
774         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
775
776         if (handlers[tagCENTER].end_tag_handler)
777           handlers[tagCENTER].end_tag_handler(pdoc, child);
778       }
779       /*----------------------------------------------------------------------*/
780       /* <CHXJ:IF>                                                            */
781       /*----------------------------------------------------------------------*/
782       else
783       if (strcasecmp(name, "chxj:if") == 0) {
784         if (chxj_chxjif_is_mine(spec, doc, child)) {
785           char* parse_attr;
786
787           parse_attr = qs_get_parse_attr(doc, child, r->pool);
788
789           if (parse_attr && strcasecmp(parse_attr, "true") == 0) {
790             chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
791           }
792           else {
793             if (handlers[tagCHXJIF].start_tag_handler)
794               handlers[tagCHXJIF].start_tag_handler(pdoc, child);
795           }
796         }
797       }
798       else {
799         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
800       }
801       break;
802
803     case 't':
804     case 'T':
805       /*----------------------------------------------------------------------*/
806       /* <TEXTAREA>                                                           */
807       /*----------------------------------------------------------------------*/
808       if (strcasecmp(name, "textarea") == 0) {
809         if (handlers[tagTEXTAREA].start_tag_handler) 
810           handlers[tagTEXTAREA].start_tag_handler(pdoc, child);
811
812         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
813
814         if (handlers[tagTEXTAREA].end_tag_handler)
815           handlers[tagTEXTAREA].end_tag_handler(pdoc, child);
816       }
817       else
818       /*----------------------------------------------------------------------*/
819       /* <TITLE>                                                              */
820       /*----------------------------------------------------------------------*/
821       if (strcasecmp(name, "title") == 0) {
822         if (handlers[tagTITLE].start_tag_handler) 
823           handlers[tagTITLE].start_tag_handler(pdoc, child);
824
825         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
826
827         if (handlers[tagTITLE].end_tag_handler)
828           handlers[tagTITLE].end_tag_handler(pdoc, child);
829       }
830       /*----------------------------------------------------------------------*/
831       /* <TABLE>                                                              */
832       /*----------------------------------------------------------------------*/
833       else
834       if (strcasecmp(name, "table") == 0) {
835         if (handlers[tagTABLE].start_tag_handler) 
836           handlers[tagTABLE].start_tag_handler(pdoc, child);
837
838         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
839
840         if (handlers[tagTABLE].end_tag_handler)
841           handlers[tagTABLE].end_tag_handler(pdoc, child);
842       }
843       /*----------------------------------------------------------------------*/
844       /* <TBODY>                                                              */
845       /*----------------------------------------------------------------------*/
846       else
847       if (strcasecmp(name, "tbody") == 0) {
848         if (handlers[tagTBODY].start_tag_handler) 
849           handlers[tagTBODY].start_tag_handler(pdoc, child);
850
851         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
852
853         if (handlers[tagTBODY].end_tag_handler)
854           handlers[tagTBODY].end_tag_handler(pdoc, child);
855       }
856       /*----------------------------------------------------------------------*/
857       /* <TH>                                                                 */
858       /*----------------------------------------------------------------------*/
859       else
860       if (strcasecmp(name, "th") == 0) {
861         if (handlers[tagTH].start_tag_handler) 
862           handlers[tagTH].start_tag_handler(pdoc, child);
863
864         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
865
866         if (handlers[tagTH].end_tag_handler)
867           handlers[tagTH].end_tag_handler(pdoc, child);
868       }
869       /*----------------------------------------------------------------------*/
870       /* <TR>                                                                 */
871       /*----------------------------------------------------------------------*/
872       else
873       if (strcasecmp(name, "tr") == 0) {
874         if (handlers[tagTR].start_tag_handler) 
875           handlers[tagTR].start_tag_handler(pdoc, child);
876
877         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
878
879         if (handlers[tagTR].end_tag_handler)
880           handlers[tagTR].end_tag_handler(pdoc, child);
881       }
882       /*----------------------------------------------------------------------*/
883       /* <TD>                                                                 */
884       /*----------------------------------------------------------------------*/
885       else
886       if (strcasecmp(name, "td") == 0) {
887         if (handlers[tagTD].start_tag_handler) 
888           handlers[tagTD].start_tag_handler(pdoc, child);
889
890         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
891
892         if (handlers[tagTD].end_tag_handler)
893           handlers[tagTD].end_tag_handler(pdoc, child);
894       }
895       /*----------------------------------------------------------------------*/
896       /* NORMAL TEXT                                                          */
897       /*----------------------------------------------------------------------*/
898       else
899       if (strcasecmp(name, "text") == 0) {
900         if (handlers[tagTEXT].start_tag_handler)
901           handlers[tagTEXT].start_tag_handler(pdoc, child);
902       }
903       else {
904         chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
905       }
906       break;
907
908     default:
909       chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
910     }
911   }
912
913   return NULL;
914 }
915
916
917 char *
918 chxj_node_convert_chxjif_only(
919   request_rec  *r,
920   device_table *spec,
921   const char   *src,
922   apr_size_t   *len  
923 )
924 {
925   Doc  doc;
926   char *dst;
927   int  pass = 0;
928   apr_size_t dst_pos = 0;
929   apr_size_t ii;
930
931   memset(&doc, 0, sizeof(Doc));
932
933   apr_pool_create(&doc.pool, r->pool);
934   doc.r = r;
935
936   dst = apr_palloc(doc.pool, *len + 1);
937   memset(dst, 0, *len + 1);
938
939   for (ii =0; ii<*len; ii++) {
940     if (src[ii + 0] == '<') {
941       apr_size_t endpoint = chxj_cut_tag(&src[ii + 0], *len - ii);
942       Node *node   = qs_parse_tag(&doc, &src[ii], endpoint);
943       char *name   = qs_get_node_name(&doc,node);
944       if (STRCASEEQ('c','C',"chxj:if", name)) {
945         if (! chxj_chxjif_is_mine(spec, &doc, node)) {
946           pass = 1;
947         }
948         ii += endpoint;
949       }
950       else if (STRCASEEQ('/','/', "/chxj:if", name)) {
951         pass = 0;
952         ii += endpoint;
953       }
954       else {
955         if (! pass) {
956 #if 0
957           memcpy(&dst[dst_pos], &src[ii], endpoint + 1);
958           dst_pos += (endpoint + 1);
959 #else
960           dst[dst_pos++] = src[ii];
961 #endif
962         }
963 #if 0
964         ii += endpoint;
965 #endif
966       }
967     }
968     else {
969       if (! pass) {
970         if (is_sjis_kanji(src[ii])) {
971           dst[dst_pos++] = src[ii++];
972           dst[dst_pos++] = src[ii];
973         }
974         else  {
975           dst[dst_pos++] = src[ii];
976         }
977       }
978     }
979   }
980   *len = strlen(dst);
981   return dst;
982 }
983 /*
984  * vim:ts=2 et
985  */