OSDN Git Service

*** empty log message ***
[modchxj/mod_chxj.git] / include / qs_parse_string.h
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 #ifndef __QS_PARSE_STRING_H__
18 #define __QS_PARSE_STRING_H__
19 #include <httpd.h>
20
21 /*
22 #define DEBUG
23 #define USE_LOG
24 */
25
26 /**
27  * Max of memory allocation times.
28  */
29 #define QX_ALLOC_MAX   (100*1024)
30
31 /**
32  * It is judged whether it is the first byte of Japanese Shift_JIS 
33  * "ZENKAKU KANJI". 
34  */
35 #define is_sjis_kanji(c)  ((0x81 <= (unsigned char)(c&0xff) && \
36                            (unsigned char)(c&0xff) <= 0x9f)  \
37                           || (0xe0 <= (unsigned char)(c&0xff) && \
38                            (unsigned char)(c&0xff) <= 0xfc))
39 /**
40  * It is judged whether it is a byte of Japanese Shift_JIS "HANKAKU KANA". 
41  */
42 #define is_sjis_kana(c)   ((0xa1 <= (unsigned char)(c&0xff) && (unsigned char)(c&0xff) <= 0xdf))
43
44 /**
45  * It is judged whether it is a Japanese code part of EUC. 
46  */
47 #define is_euc_kanji(c)   (0xa1 <= (unsigned char)(c&0xff) && (unsigned char)(c&0xff) <= 0xfe)
48
49 /**
50  * It is judged whether it is a Japanese code part of EUC "KANA". 
51  */
52 #define is_euc_kana(c)    (0x8e == (unsigned char)(c&0xff))
53
54 /**
55  * True is returned for whitespace. 
56  */
57 #define is_white_space(c)     (' ' == (unsigned char)(c&0xff)  \
58                            || '\t' == (unsigned char)(c&0xff) \
59                            || '\n' == (unsigned char)(c&0xff) \
60                            || '\r' == (unsigned char)(c&0xff))
61
62 /**
63  * True is returned for the quotation mark. 
64  */
65 #define is_quote(c)       ('\'' == (unsigned char)(c&0xff) \
66                          ||'"'  == (unsigned char)(c&0xff))
67
68 /**
69  * It is judged whether the tag of the object has the child element. 
70  * The "<option>" tag has the child. Please write </ option >. 
71  */
72 #define has_child(c)       ((strcasecmp(c, "base"     ) != 0) \
73                         &&  (strcasecmp(c, "meta"     ) != 0) \
74                         &&  (strcasecmp(c, "br"       ) != 0) \
75                         &&  (strcasecmp(c, "dt"       ) != 0) \
76                         &&  (strcasecmp(c, "dd"       ) != 0) \
77                         &&  (strcasecmp(c, "hr"       ) != 0) \
78                         &&  (strcasecmp(c, "img"      ) != 0) \
79                         &&  (strcasecmp(c, "input"    ) != 0) \
80                         &&  (strcasecmp(c, "p"        ) != 0) \
81                         &&  (strcasecmp(c, "plaintext") != 0) \
82                         &&  (strcasecmp(c, "?xml"     ) != 0) \
83                         &&  (strcasecmp(c, "!doctype" ) != 0) \
84                         &&  (strcasecmp(c, "link"     ) != 0) \
85                         &&  (strcasecmp(c, "!--"      ) != 0) \
86                         &&  (strncasecmp(c, "![CDATA[",8) != 0))
87
88 /**
89  * It is judged whether the tag of the object has the child element. 
90  * The "<option>" tag has the child. Please write </ option >. 
91  */
92 #define has_child_hdml(c)  ((strcasecmp(c, "center"     ) != 0) \
93                         &&  (strcasecmp(c, "br"         ) != 0) \
94                         &&  (strcasecmp(c, "action"     ) != 0) \
95                         &&  (strcasecmp(c, "!--"      ) != 0))
96
97 /**
98  * The structure of the attribute is defined.
99  */
100 typedef struct Attr Attr;
101
102 struct Attr {
103   struct Attr* next;
104   struct Node* parent;
105   char *name;
106   char *value;
107 };
108
109 /**
110  * The structure of the element is defined. 
111  */
112 typedef struct Node Node;
113
114 struct Node {
115   struct Node* next;
116   struct Node* parent;
117   struct Node* child;
118   struct Node* child_tail;
119   struct Attr* attr;
120   struct Attr* attr_tail;
121   char* name;
122   char* value;
123   int   size;
124   char* otext;
125 };
126
127 typedef struct pointer_table_t {
128   unsigned int address;
129   unsigned long size;
130   struct pointer_table_t* next;
131   struct pointer_table_t* prev;
132 } Pointer_Table;
133
134
135 typedef enum chxj_parse_mode_t {
136   PARSE_MODE_CHTML=0,
137   PARSE_MODE_NO_PARSE,
138 } ParseMode_t;
139
140 typedef struct _doc {
141   Node*         now_parent_node;
142   Node*         root_node;
143
144   int           do_init_flag;
145   unsigned long alloc_size;
146
147   Pointer_Table* pointer_table;
148   Pointer_Table* free_list_head;
149   Pointer_Table* free_list_tail;
150   Pointer_Table* allocated_list_head;
151   Pointer_Table* allocated_list_tail;
152
153   ParseMode_t    parse_mode;
154
155   apr_allocator_t* allocator;
156   apr_pool_t*      pool;
157
158 #ifndef __NON_MOD_CHXJ__
159   request_rec* r;
160 #endif
161 } Doc;
162
163 /*
164  * Prototype Declare
165  */
166 extern Node* qs_init_root_node(
167   Doc* doc);
168
169 extern void qs_add_child_node(
170   Doc* doc, 
171   Node*);
172
173 extern void qs_free_node(
174   Doc* doc,
175   Node*);
176
177 Node* qs_get_root(Doc* doc) ;
178 Node* qs_parse_string(Doc* doc, const char* ss, int len);
179 char* qs_get_node_value(Doc* doc,Node* node);
180 char* qs_get_node_name(Doc* doc, Node* node) ;
181 int qs_get_node_size(Doc* doc, Node* node) ;
182 Node* qs_get_child_node(Doc* doc, Node* node) ;
183 Node* qs_get_next_node(Doc* doc, Node* node) ;
184 Attr* qs_get_attr(Doc* doc, Node* node) ;
185 Attr* qs_get_next_attr(Doc* doc, Attr* attr) ;
186 char* qs_get_attr_name(Doc* doc, Attr* attr) ;
187 char* qs_get_attr_value(Doc* doc, Attr* attr) ;
188 #endif