HTMLv: code optimizations

git-svn-id: svn://kolibrios.org@3061 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2012-11-19 15:30:03 +00:00
parent d994c2a92d
commit bac1b76c41
5 changed files with 95 additions and 119 deletions

View File

@ -281,7 +281,7 @@ void TWebBrowser::OpenPage()
{
KillProcess(downloader_id); //óáèâàåì ñòàðûé ïðîöåññ
DeleteFile(#download_path);
IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]='';
IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]=NULL;
downloader_id = RunProgram("/sys/network/downloader", #URL);
//Browser Hack v2.0
Pause(60);
@ -344,7 +344,7 @@ void TWebBrowser::ParseHTML(dword bword){
li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 0; //îáíóëÿåì òåãè
link_color = 0x0000FF;
bg_color = 0xFFFFFF;
line = '';
line = NULL;
strcpy(#page_links,"|");
strcpy(#header, #version);
@ -364,7 +364,7 @@ void TWebBrowser::ParseHTML(dword bword){
case 0x0a:
if (pre_text)
{
bukva = temp = '';
bukva = temp = NULL;
goto NEXT_MARK;
}
case '\9':
@ -402,25 +402,8 @@ void TWebBrowser::ParseHTML(dword bword){
strcat(#tag, #bukva);
}
for (j=0; unicode_tags[j]!=0; j+=2;)
{
if (!strcmp(#tag, unicode_tags[j]))
{
strcat(#line, unicode_tags[j+1]);
break 1;
}
}
rez = atoi(#tag + 1) - 1040;
if (tag[1] == '1') && (rez>=0) && (rez<=72) && (strlen(#tag) == 5)
{
bukva = unicode_chars[rez];
//GOTO DEFAULT_MARK; //îáðàáàòûâàåì áóêâó ëó÷øå íàâåðíî strcat(#line, unicode_tags[j+1]); è break 1;
strcat(#line, #bukva);
break;
}
strcat(#line,#tag); //âûâîäèì íà ýêðàí íåîáðàáîòàííûé òåã, òàê áðàóçåðû çà÷åì-òî äåëàþò
bukva = GetUnicodeSymbol();
if (bukva) goto DEFAULT_MARK;
break;
case '<':
bword++; //ïðîìîòàåì ñèìâîë <
@ -516,7 +499,7 @@ void TWebBrowser::ParseHTML(dword bword){
if (anchor)
{
//åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
anchor='';
anchor=NULL;
lines.first=anchor_line_num;
ParseHTML(buf);
}
@ -597,10 +580,10 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
rez = 0;
strcpy(#tag, #tag+1);
}
else
rez = 1;
else rez = 1;
if (!chTag("html")) {
if (!chTag("html"))
{
IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0;
return;
}
@ -609,14 +592,8 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if(!chTag("title"))
{
if (rez)
{
header=0;
}
else //òåã çàêðûëñÿ - âûâåëè ñòðîêó
{
if (stroka==0) DrawTitle(#header);
}
if (rez) header=NULL;
else if (!stroka) DrawTitle(#header); //òåã çàêðûëñÿ - âûâåëè ñòðîêó
return;
}
@ -630,30 +607,16 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
{
if (!strcmp(#anchor, #options))
{
anchor_line_num=lines.first+stroka;
}
if (!strcmp(#anchor, #options)) anchor_line_num=lines.first+stroka;
}
if (!chTag("body"))
{
BODY_MARK:
if (!strcmp(#parametr, "link="))
link_color = GetColor(#options);
if (!strcmp(#parametr, "text="))
text_colors[0]=GetColor(#options);
if (!strcmp(#parametr, "bgcolor="))
bg_color=GetColor(#options);
IF(tagparam)
{
GetNextParam();
GOTO BODY_MARK;
}
do{
if (!strcmp(#parametr, "link=")) link_color = GetColor(#options);
if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options);
if (!strcmp(#parametr, "bgcolor=")) bg_color=GetColor(#options);
} while(GetNextParam());
return;
}
@ -662,10 +625,9 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
{
if (rez)
{
if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
_A_MARK:
do{
if (!strcmp(#parametr, "href="))
{
if (stroka - 1 > lines.visible) || (stroka < -2) return;
@ -686,11 +648,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
anchor_line_num=lines.first+stroka;
}
}
if (tagparam)
{
GetNextParam();
GOTO _A_MARK;
}
} while(GetNextParam());
}
else {
link = 0;
@ -707,15 +665,12 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
text_color_index++;
text_colors[text_color_index] = text_colors[text_color_index-1];
COL_MARK:
do{
if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
{
text_colors[text_color_index] = GetColor(#options);
}
IF(tagparam) {
GetNextParam();
GOTO COL_MARK;
}
} while(GetNextParam());
}
else
if (text_color_index > 0) text_color_index--;
@ -745,7 +700,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
return;
}
else
oldtag='';
oldtag=NULL;
if (!chTag("b")) || (!chTag("strong")) || (!chTag("big")) {
b_text = rez;
@ -795,7 +750,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (!chTag("img"))
{
if (GetFileInfo(libimg)<>0) return; //åñëè áèáëèîòåêè íåò
IMG_TAG:
do{
if (!strcmp(#parametr,"src=")) //íàäî îáúåäèíèòü ñ GetNewUrl()
{
if (downloader_id) strcpy(#temp, #history_list[history_current-1].Item);
@ -816,11 +771,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
strcat(#alt, "]");
}
IF(tagparam)
{
GetNextParam();
GOTO IMG_TAG;
}
} while(GetNextParam());
if (!image)
{
@ -855,7 +806,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (!chTag("meta")) || (!chTag("?xml"))
{
META:
do{
if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
{
strcpy(#options, #options[strrchr(#options, '=')]); //ïîèñê â content=
@ -864,11 +815,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u")) ReadHtml(_KOI);
if (!strcmp(#options, "dos")) || (!strcmp(#options, "cp-866")) ReadHtml(_DOS);
}
if (tagparam)
{
GetNextParam();
goto META;
}
} while(GetNextParam());
return;
}
}

View File

@ -24,7 +24,7 @@ dword UrlsHistory::CurrentUrl()
void UrlsHistory::AddUrl() //òóò íóæåí ââîäèìûé ýëåìåíò - äëÿ óíèâåðñàëüíîñòè
{
int i;
if (history_num>0) && (strcmp(#URL,#history_list[history_current].Item)==0) return;
if (history_num>0) && (!strcmp(#URL,#history_list[history_current].Item)) return;
if (history_current>=MAX_HISTORY_NUM-1)
{

View File

@ -1,8 +1,10 @@
void GetNextParam()
unsigned int GetNextParam()
{
byte kavichki = false;
int i = strlen(#tagparam) - 1;
if (!tagparam) return 0;
WHILE((i > 0) && ((tagparam[i] == '"') || (tagparam[i] == ' ') || (tagparam[i] == '\'') || (tagparam[i] == '/')))
{
IF (tagparam[i] == '"') || (tagparam[i] == '\'') kavichki=tagparam[i];
@ -43,4 +45,6 @@ void GetNextParam()
strcpy(#parametr, #tagparam + i + 1);
tagparam[i] = 0x00;
return 1;
}

View File

@ -30,11 +30,15 @@ void GetURLfromPageLinks(int id)
int i, j = 0;
for (i = 0; i <= id - 401; i++)
{
do j++;
do
{
j++;
if (j>=strlen(#page_links)) return; //íå ñàìîå óäà÷íîå ðåøåíèå
}
while (page_links[j] <>'|');
}
page_links[j] = 0x00;
strcpy(#URL, #page_links[strrchr(#page_links, '|')]);
strcpy(#URL, #page_links+strrchr(#page_links, '|'));
}

View File

@ -1,8 +1,3 @@
byte unicode_chars[] = "€亗儎厗噲墛媽崕彁憭摂晼棙櫄洔潪煚、¥ウЖ┆<EFBFBD><EFBFBD><EFBFBD>徕沅彐玷殛腱眍镳駂<EFBFBD>243i\105\244\0";
char *unicode_tags[]={
"nbsp", " ",
"#38", " ",
@ -66,3 +61,29 @@ char *unicode_tags[]={
"percnt","%",
0};
byte unicode_chars[] = "<EFBFBD>ƒ„…†‡ˆ‰ŠŒ<EFBFBD>Ž<EFBFBD><EFBFBD>“”•˜™šœ<EFBFBD>žŸ ¡¢£¤¥¦§¨©ª«¬­®¯àáâãäåæçèéêëìíîïðñh£\243i\105\244\0";
unsigned char GetUnicodeSymbol()
{
int j;
for (j=0; unicode_tags[j]!=0; j+=2;)
{
if (!strcmp(#tag, unicode_tags[j]))
{
strcat(#line, unicode_tags[j+1]);
return NULL;
}
}
rez = atoi(#tag + 1) - 1040;
if (tag[1] == '1') && (rez>=0) && (rez<=72) && (strlen(#tag) == 5)
{
return unicode_chars[rez];
}
strcat(#line,#tag); //âûâîäèì íà ýêðàí íåîáðàáîòàííûé òåã, òàê áðàóçåðû çà÷åì-òî äåëàþò
return NULL;
}