Subversion Repositories Kolibri OS

Rev

Rev 9089 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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