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