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