Rev 8445 | Rev 8500 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8445 | Rev 8490 | ||
---|---|---|---|
1 | struct _tag |
1 | struct _tag |
2 | { |
2 | { |
3 | char name[32]; |
3 | char name[32]; |
4 | char prior[32]; |
4 | char prior[32]; |
5 | bool opened; |
5 | bool opened; |
6 | collection attributes; |
6 | collection attributes; |
7 | collection values; |
7 | collection values; |
8 | dword value; |
8 | dword value; |
9 | bool is(); |
9 | bool is(); |
10 | bool parse(); |
10 | bool parse(); |
11 | void debug_tag(); |
11 | void debug_tag(); |
12 | dword get_next_param(); |
12 | dword get_next_param(); |
13 | dword get_value_of(); |
13 | dword get_value_of(); |
14 | } tag=0; |
14 | } tag=0; |
15 | 15 | ||
16 | bool _tag::is(dword _text) |
16 | bool _tag::is(dword _text) |
17 | { |
17 | { |
18 | if ( !strcmp(#name, _text) ) { |
18 | if ( !strcmp(#name, _text) ) { |
19 | return true; |
19 | return true; |
20 | } else { |
20 | } else { |
21 | return false; |
21 | return false; |
22 | } |
22 | } |
23 | } |
23 | } |
24 | 24 | ||
25 | bool _tag::parse(dword _bufpos, bufend) |
25 | bool _tag::parse(dword _bufpos, bufend) |
26 | { |
26 | { |
27 | bool retok = true; |
27 | bool retok = true; |
28 | dword bufpos = ESDWORD[_bufpos]; |
28 | dword bufpos = ESDWORD[_bufpos]; |
29 | dword params, paramsend; |
29 | dword params, paramsend; |
30 | 30 | ||
31 | dword closepos; |
31 | dword closepos; |
32 | dword whitepos; |
32 | dword whitepos; |
33 | 33 | dword openpos; |
|
- | 34 | ||
34 | if (name) strcpy(#prior, #name); else prior = '\0'; |
35 | if (name) strcpy(#prior, #name); else prior = '\0'; |
35 | name = '\0'; |
36 | name = '\0'; |
36 | attributes.drop(); |
37 | attributes.drop(); |
37 | values.drop(); |
38 | values.drop(); |
38 | 39 | ||
39 | if (!strncmp(bufpos,"!--",3)) |
40 | if (!strncmp(bufpos,"!--",3)) |
40 | { |
41 | { |
41 | bufpos+=3; |
42 | bufpos+=3; |
42 | //STRSTR |
43 | //STRSTR |
43 | while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufend) |
44 | while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufend) |
44 | { |
45 | { |
45 | bufpos++; |
46 | bufpos++; |
46 | } |
47 | } |
47 | bufpos+=2; |
48 | bufpos+=2; |
48 | retok = false; |
49 | retok = false; |
49 | goto _RET; |
50 | goto _RET; |
50 | } |
51 | } |
51 | 52 | ||
52 | if (ESBYTE[bufpos] == '/') { |
53 | if (ESBYTE[bufpos] == '/') { |
53 | opened = false; |
54 | opened = false; |
54 | bufpos++; |
55 | bufpos++; |
55 | } else { |
56 | } else { |
56 | opened = true; |
57 | opened = true; |
57 | } |
58 | } |
58 | 59 | ||
59 | closepos = strchr(bufpos, '>'); |
60 | closepos = strchr(bufpos, '>'); |
60 | whitepos = strchrw(bufpos, bufend-bufpos); |
61 | whitepos = strchrw(bufpos, bufend-bufpos); |
61 | 62 | ||
62 | if (debug_mode) { |
63 | if (debug_mode) { |
63 | if (!closepos) debugln("null closepos"); |
64 | if (!closepos) debugln("null closepos"); |
64 | if (!whitepos) debugln("null whitepos"); |
65 | if (!whitepos) debugln("null whitepos"); |
65 | } |
66 | } |
66 | 67 | ||
67 | if (!whitepos) || (whitepos > closepos) { |
68 | if (!whitepos) || (whitepos > closepos) { |
68 | //no param |
69 | //no param |
69 | strncpy(#name, bufpos, math.min(closepos - bufpos, sizeof(tag.name))); |
70 | strncpy(#name, bufpos, math.min(closepos - bufpos, sizeof(tag.name))); |
70 | debug_tag(); |
71 | debug_tag(); |
71 | bufpos = closepos; |
72 | bufpos = closepos; |
72 | } else { |
73 | } else { |
73 | //we have param |
74 | //we have param |
74 | strncpy(#name, bufpos, math.min(whitepos - bufpos, sizeof(tag.name))); |
75 | while (chrlnum(whitepos, '\"', closepos - whitepos)%2) { //alt="Next>>" |
- | 76 | /* |
|
- | 77 | openpos = strchr(closepos+1, '<'); |
|
- | 78 | closepos = strchr(closepos+1, '>'); |
|
- | 79 | if (openpos) && (openpos < closepos) { |
|
- | 80 | closepos = openpos - 1; |
|
- | 81 | break; |
|
- | 82 | } |
|
- | 83 | */ |
|
- | 84 | if (!openpos = strchr(closepos+1, '<')) break; |
|
- | 85 | if (openpos < strchr(closepos+1, '>')) break; |
|
- | 86 | if (!closepos = EAX) {closepos = bufend;break;} |
|
- | 87 | } |
|
- | 88 | strncpy(#name, bufpos, math.min(whitepos - bufpos, sizeof(tag.name))); |
|
75 | debug_tag(); |
89 | debug_tag(); |
76 | bufpos = closepos; |
90 | bufpos = closepos; |
77 | 91 | ||
78 | params = malloc(closepos - whitepos + 1); |
92 | params = malloc(closepos - whitepos + 1); |
79 | strncpy(params, whitepos, closepos - whitepos); |
93 | strncpy(params, whitepos, closepos - whitepos); |
80 | if (debug_mode) { debug("params: "); debugln(params+1); } |
94 | if (debug_mode) { debug("params: "); debugln(params+1); } |
81 | paramsend = params + closepos - whitepos; |
95 | paramsend = params + closepos - whitepos; |
82 | while (paramsend = get_next_param(params, paramsend-1)); |
96 | while (paramsend = get_next_param(params, paramsend-1)); |
83 | free(params); |
97 | free(params); |
84 | } |
98 | } |
85 | 99 | ||
86 | if (name) { |
100 | if (name) { |
87 | strlwr(#name); |
101 | strlwr(#name); |
88 | // ignore text inside the next tags |
102 | // ignore text inside the next tags |
89 | if (is("script")) || (is("style")) || (is("binary")) || (is("select")) { |
103 | if (is("script")) || (is("style")) || (is("binary")) || (is("select")) { |
90 | strcpy(#prior, #name); |
104 | strcpy(#prior, #name); |
91 | sprintf(#name, "%s>", #prior); |
105 | sprintf(#name, "%s>", #prior); |
92 | if (strstri(bufpos, #name)) bufpos = EAX-1; |
106 | if (strstri(bufpos, #name)) bufpos = EAX-1; |
93 | retok = false; |
107 | retok = false; |
94 | } else { |
108 | } else { |
95 | if (name[strlen(#name)-1]=='/') name[strlen(#name)-1]=NULL; //for |
109 | if (name[strlen(#name)-1]=='/') name[strlen(#name)-1]=NULL; //for |
96 | } |
110 | } |
97 | } else { |
111 | } else { |
98 | retok = false; |
112 | retok = false; |
99 | } |
113 | } |
100 | 114 | ||
101 | _RET: |
115 | _RET: |
102 | ESDWORD[_bufpos] = bufpos; |
116 | ESDWORD[_bufpos] = bufpos; |
103 | return retok; |
117 | return retok; |
104 | } |
118 | } |
105 | 119 | ||
106 | void _tag::debug_tag() |
120 | void _tag::debug_tag() |
107 | { |
121 | { |
108 | if (debug_mode) { |
122 | if (debug_mode) { |
109 | debugch('<'); |
123 | debugch('<'); |
110 | if (!opened) debugch('/'); |
124 | if (!opened) debugch('/'); |
111 | debug(#name); |
125 | debug(#name); |
112 | debugln(">"); |
126 | debugln(">"); |
113 | } |
127 | } |
114 | } |
128 | } |
115 | 129 | ||
116 | dword _tag::get_next_param(dword ps, pe) |
130 | dword _tag::get_next_param(dword ps, pe) |
117 | { |
131 | { |
118 | // "ps" - param start |
132 | // "ps" - param start |
119 | // "pe" - param end |
133 | // "pe" - param end |
120 | // "q" - quote char |
134 | // "q" - quote char |
121 | char q = NULL; |
135 | char q = NULL; |
122 | dword fixeq; |
136 | dword fixeq; |
123 | dword val; |
137 | dword val; |
124 | dword attr; |
138 | dword attr; |
125 | 139 | ||
126 | if (ESBYTE[pe] == '/') pe--; |
140 | if (ESBYTE[pe] == '/') pe--; |
127 | while (pe>ps) && (__isWhite(ESBYTE[pe])) pe--; |
141 | while (pe>ps) && (__isWhite(ESBYTE[pe])) pe--; |
128 | 142 | ||
129 | if (ESBYTE[pe] == '"') || (ESBYTE[pe] == '\'') |
143 | if (ESBYTE[pe] == '"') || (ESBYTE[pe] == '\'') |
130 | { |
144 | { |
131 | //remove quote |
145 | //remove quote |
132 | q = ESBYTE[pe]; |
146 | q = ESBYTE[pe]; |
133 | ESBYTE[pe] = '\0'; |
147 | ESBYTE[pe] = '\0'; |
134 | pe--; |
148 | pe--; |
135 | 149 | ||
136 | //find VAL start and copy |
150 | //find VAL start and copy |
137 | pe = strrchr(ps, q) + ps; |
151 | pe = strrchr(ps, q) + ps; |
138 | val = pe; |
152 | val = pe; |
139 | pe--; |
153 | pe--; |
140 | ESBYTE[pe] = '\0'; |
154 | ESBYTE[pe] = '\0'; |
141 | 155 | ||
142 | //find ATTR end |
156 | //find ATTR end |
143 | while (pe > ps) && (ESBYTE[pe] != '=') pe--; |
157 | while (pe > ps) && (ESBYTE[pe] != '=') pe--; |
144 | ESBYTE[pe] = '\0'; |
158 | ESBYTE[pe] = '\0'; |
145 | } |
159 | } |
146 | else |
160 | else |
147 | { |
161 | { |
148 | //find VAL start and copy |
162 | //find VAL start and copy |
149 | while (pe > ps) && (ESBYTE[pe] != '=') pe--; |
163 | while (pe > ps) && (ESBYTE[pe] != '=') pe--; |
150 | val = pe+1; |
164 | val = pe+1; |
151 | ESBYTE[pe] = '\0'; |
165 | ESBYTE[pe] = '\0'; |
152 | //already have ATTR end |
166 | //already have ATTR end |
153 | } |
167 | } |
154 | 168 | ||
155 | //find ATTR start and copy |
169 | //find ATTR start and copy |
156 | while (pe>ps) && (!__isWhite(ESBYTE[pe])) pe--; |
170 | while (pe>ps) && (!__isWhite(ESBYTE[pe])) pe--; |
157 | attr = pe + 1; |
171 | attr = pe + 1; |
158 | ESBYTE[pe] = '\0'; |
172 | ESBYTE[pe] = '\0'; |
159 | 173 | ||
160 | // Fix case: src=./images/logo?sid=e8ece8b38b |
174 | // Fix case: src=./images/logo?sid=e8ece8b38b |
161 | // Exchange '=' and '\0' position. |
175 | // Exchange '=' and '\0' position. |
162 | // attr: src=./images/logo?sid => src |
176 | // attr: src=./images/logo?sid => src |
163 | // val: e8ece8b38b => ./images/logo?sid=e8ece8b38b |
177 | // val: e8ece8b38b => ./images/logo?sid=e8ece8b38b |
164 | fixeq = strchr(attr,'='); |
178 | fixeq = strchr(attr,'='); |
165 | if (!q) && (fixeq) { |
179 | if (!q) && (fixeq) { |
166 | ESBYTE[val-1] >< ESBYTE[fixeq]; |
180 | ESBYTE[val-1] >< ESBYTE[fixeq]; |
167 | val = fixeq+1; |
181 | val = fixeq+1; |
168 | } |
182 | } |
169 | strlwr(attr); |
183 | strlwr(attr); |
170 | strrtrim(val); |
184 | strrtrim(val); |
171 | 185 | ||
172 | attributes.add(attr); |
186 | attributes.add(attr); |
173 | values.add(val); |
187 | values.add(val); |
174 | 188 | ||
175 | if (debug_mode) { |
189 | if (debug_mode) { |
176 | debug("atr: "); debugln(attr); |
190 | debug("atr: "); debugln(attr); |
177 | debug("val: "); debugln(val); |
191 | debug("val: "); debugln(val); |
178 | debugch('\n'); |
192 | debugch('\n'); |
179 | } |
193 | } |
180 | 194 | ||
181 | if (pe==ps) return NULL; |
195 | if (pe==ps) return NULL; |
182 | return pe; |
196 | return pe; |
183 | } |
197 | } |
184 | 198 | ||
185 | dword _tag::get_value_of(dword _attr_name) |
199 | dword _tag::get_value_of(dword _attr_name) |
186 | { |
200 | { |
187 | int pos = attributes.get_pos_by_name(_attr_name); |
201 | int pos = attributes.get_pos_by_name(_attr_name); |
188 | if (pos == -1) { |
202 | if (pos == -1) { |
189 | value = 0; |
203 | value = 0; |
190 | } else { |
204 | } else { |
191 | value = values.get(pos); |
205 | value = values.get(pos); |
192 | } |
206 | } |
193 | return value; |
207 | return value; |
194 | }>');>> |
208 | }>');>>'))>>'); |
- | 209 | >> |