OSDN Git Service

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