Subversion Repositories Kolibri OS

Rev

Rev 8439 | Rev 8443 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8439 Rev 8440
Line 1... Line 1...
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
	char params[6000];
-
 
6
	bool opened;
5
	bool opened;
7
	collection attributes;
6
	collection attributes;
8
	collection values;
7
	collection values;
9
	dword value;
8
	dword value;
10
	bool is();
9
	bool is();
11
	bool parse_tag();
10
	bool parse();
12
	void debug_tag();
11
	void debug_tag();
13
	bool get_next_param();
12
	dword get_next_param();
14
	dword get_value_of();
13
	dword get_value_of();
15
} tag=0;
14
} tag=0;
Line 16... Line 15...
16
 
15
 
17
bool _tag::is(dword _text) 
16
bool _tag::is(dword _text) 
Line 22... Line 21...
22
		return false; 
21
		return false; 
23
	}
22
	}
24
}
23
}
25
 
24
 
Line 26... Line 25...
26
bool _tag::parse_tag(dword _bufpos, bufend)
25
bool _tag::parse(dword _bufpos, bufend)
27
{
26
{
28
	bool retok = true;
27
	bool retok = true;
29
	dword bufpos = ESDWORD[_bufpos];
28
	dword bufpos = ESDWORD[_bufpos];
-
 
29
	dword params, paramsend;
Line 30... Line 30...
30
 
30
 
31
	dword closepos;
31
	dword closepos;
Line 32... Line 32...
32
	dword whitepos;
32
	dword whitepos;
33
 
33
 
34
	if (name) strcpy(#prior, #name); else prior = '\0';
-
 
35
	name = '\0';
34
	if (name) strcpy(#prior, #name); else prior = '\0';
36
	params = '\0';
35
	name = '\0';
Line 37... Line 36...
37
	attributes.drop();
36
	attributes.drop();
38
	values.drop();		
37
	values.drop();		
Line 45... Line 44...
45
		{
44
		{
46
			bufpos++;
45
			bufpos++;
47
		}
46
		}
48
		bufpos+=2;
47
		bufpos+=2;
49
		goto _RET;
48
		retok = false;
-
 
49
		goto _RET;
50
	}
50
	}
51
 
51
 
Line 52... Line 52...
52
	if (ESBYTE[bufpos] == '/') {
52
	if (ESBYTE[bufpos] == '/') {
53
		opened = false;
53
		opened = false;
Line 57... Line 57...
57
	}
57
	}
58
 
58
 
Line 59... Line 59...
59
	closepos = strchr(bufpos, '>');
59
	closepos = strchr(bufpos, '>');
60
	whitepos = strchrw(bufpos, bufend-bufpos);
60
	whitepos = strchrw(bufpos, bufend-bufpos);
-
 
61
 
-
 
62
	if (debug_mode) {
-
 
63
		if (!closepos) debugln("null closepos");
-
 
64
		if (!whitepos) debugln("null whitepos");
-
 
65
	}
-
 
66
 
61
	if (whitepos > closepos) {
67
	if (!whitepos) || (whitepos > closepos) {
62
		//no param
68
		//no param
63
		strncpy(#name, bufpos, math.min(closepos - bufpos, sizeof(tag.name)));
69
		strncpy(#name, bufpos, math.min(closepos - bufpos, sizeof(tag.name)));
64
		debug_tag();
70
		debug_tag();
65
		params = '\0';
-
 
66
		bufpos = closepos;
71
		bufpos = closepos;
67
	} else {
72
	} else {
68
		//we have param
73
		//we have param
69
		strncpy(#name, bufpos, math.min(whitepos - bufpos, sizeof(tag.name)));
74
		strncpy(#name, bufpos, math.min(whitepos - bufpos, sizeof(tag.name)));
70
		strncpy(#params, whitepos, math.min(closepos - whitepos, sizeof(tag.params)));
-
 
71
		debug_tag();
75
		debug_tag();
72
		bufpos = closepos;
76
		bufpos = closepos;
73
		while (get_next_param());
-
 
74
	}
-
 
Line 75... Line 77...
75
 
77
 
-
 
78
		params = malloc(closepos - whitepos + 1);
-
 
79
		strncpy(params, whitepos, closepos - whitepos);
76
	if (!name) {
80
		if (debug_mode) { debug("params: "); debugln(params+1); }
-
 
81
		paramsend = params + closepos - whitepos;
77
		retok = false;
82
		while (paramsend = get_next_param(params, paramsend-1));
78
		goto _RET;
83
		free(params);
Line -... Line 84...
-
 
84
	}
79
	}
85
 
80
 
-
 
81
	strlwr(#name);
86
	if (name) {
82
 
87
		strlwr(#name);
83
	// ignore text inside the next tags
88
		// ignore text inside the next tags
84
	if (is("script")) || (is("style")) || (is("binary")) || (is("select")) { 
89
		if (is("script")) || (is("style")) || (is("binary")) || (is("select")) { 
85
		strcpy(#prior, #name);
90
			strcpy(#prior, #name);
86
		sprintf(#name, "", #prior);
91
			sprintf(#name, "", #prior);
87
		if (strstri(bufpos, #name)) bufpos = EAX-1;
92
			if (strstri(bufpos, #name)) bufpos = EAX-1;
88
		retok = false;
-
 
89
		goto _RET;
-
 
90
	}
93
			retok = false;
-
 
94
		} else {
-
 
95
			if (name[strlen(#name)-1]=='/') name[strlen(#name)-1]=NULL; //for 
-
 
96
		}
-
 
97
	} else {
Line 91... Line 98...
91
 
98
		retok = false;
92
	if (name[strlen(#name)-1]=='/') name[strlen(#name)-1]=NULL; //for 
99
	}
93
 
100
 
94
_RET:
101
_RET:
Line 102... Line 109...
102
		debugch('<'); 
109
		debugch('<'); 
103
		if (!opened) debugch('/');
110
		if (!opened) debugch('/');
104
		debug(#name);
111
		debug(#name);
105
		debugln(">");
112
		debugln(">");
106
		if (params) {
113
	}
107
			debug("params: "); 
-
 
108
			debugln(#params+1);
-
 
109
		}
-
 
110
	}
-
 
111
}
114
}
112
 
115
 
Line 113... Line 116...
113
bool _tag::get_next_param()
116
dword _tag::get_next_param(dword ps, pe)
114
{
117
{
-
 
118
	// "ps" - param start
-
 
119
	// "pe" - param end
-
 
120
	// "q"  - quote char
115
	byte  quotes = NULL;
121
	char q = NULL;
116
	int   i;
122
	dword fixeq;
117
	unsigned char  val[6000];
123
	unsigned char  val[6000];
118
	unsigned char attr[6000];
124
	unsigned char attr[6000];
Line 119... Line 125...
119
 
125
	
-
 
126
	if (ESBYTE[pe] == '/') pe--;
Line 120... Line -...
120
	if (!params) return false;
-
 
121
	
-
 
122
	i = strlen(#params) - 1;
-
 
123
	if (params[i] == '/') i--;
-
 
124
	while (i>0) && (__isWhite(params[i])) i--;
127
	while (pe>ps) && (__isWhite(ESBYTE[pe])) pe--;
125
 
128
 
126
	if (params[i] == '"') || (params[i] == '\'')
129
	if (ESBYTE[pe] == '"') || (ESBYTE[pe] == '\'')
127
	{
130
	{
128
		//remove quotes
131
		//remove quote
129
		quotes = params[i];
132
		q = ESBYTE[pe];
Line 130... Line 133...
130
		params[i] = '\0';
133
		ESBYTE[pe] = '\0';
131
		i--;
134
		pe--;
132
 
135
 
133
		//find VAL start and copy
136
		//find VAL start and copy
134
		i = strrchr(#params, quotes);
137
		pe = strrchr(ps, q) + ps;
Line 135... Line 138...
135
		strlcpy(#val, #params + i, sizeof(val)-1);
138
		strlcpy(#val, pe, sizeof(val)-1);
136
		params[i] = '\0'; 
139
		ESBYTE[pe] = '\0'; 
137
		i--;
140
		pe--;
138
 
141
 
139
		//find ATTR end
142
		//find ATTR end
140
		while (i > 0) && (params[i] != '=') i--;
143
		while (pe > ps) && (ESBYTE[pe] != '=') pe--;
141
		params[i+1] = '\0';
144
		ESBYTE[pe+1] = '\0';
142
	}
145
	}
143
	else
146
	else
144
	{
147
	{
145
		//find VAL start and copy
-
 
146
		while (i > 0) && (params[i] != '=') i--;
148
		//find VAL start and copy
147
		i++;
149
		while (pe > ps) && (ESBYTE[pe] != '=') pe--;
Line 148... Line 150...
148
		strlcpy(#val, #params + i, sizeof(val)-1);
150
		pe++;
149
 
151
		strlcpy(#val, pe, sizeof(val)-1);
150
		//already have ATTR end
152
		//already have ATTR end
151
	}
153
	}
Line 152... Line 154...
152
 
154
 
153
	//find ATTR start and copy
155
	//find ATTR start and copy
154
	while (i>0) && (!__isWhite(params[i])) i--;
156
	while (pe>ps) && (!__isWhite(ESBYTE[pe])) pe--;
155
	strlcpy(#attr, #params + i + 1, sizeof(attr)-1);
157
	strlcpy(#attr, pe + 1, sizeof(attr)-1);
156
	params[i] = '\0';
158
	ESBYTE[pe] = '\0';
157
 
159
 
158
	//fix case: src=./images/KolibriOS_logo2.jpg?sid=e8ece8b38b
160
	//fix case: src=./images/KolibriOS_logo2.jpg?sid=e8ece8b38b
159
	i = strchr(#attr,'=');
161
	fixeq = strchr(#attr,'=');
Line 160... Line 162...
160
	if (!quotes) && (i) {
162
	if (!q) && (fixeq) {
Line 172... Line 174...
172
		debug("val: "); debugln(#val);
174
		debug("val: "); debugln(#val);
173
		debugch('\n');
175
		debugch('\n');
174
	}
176
	}
175
 
177
 
Line -... Line 178...
-
 
178
	if (pe==ps) return NULL;
176
	return true;
179
	return pe;
177
}
180
}
Line 178... Line 181...
178
 
181
 
179
dword _tag::get_value_of(dword _attr_name)
182
dword _tag::get_value_of(dword _attr_name)
180
{
183
{