From bac1b76c41dd3d545f0ab2a422a5e498a5608d6d Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Mon, 19 Nov 2012 15:30:03 +0000 Subject: [PATCH] HTMLv: code optimizations git-svn-id: svn://kolibrios.org@3061 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/network/htmlv/browser/TWB.h | 167 ++++++------------ .../network/htmlv/browser/include/history.h | 2 +- .../network/htmlv/browser/include/parce_tag.h | 6 +- .../network/htmlv/browser/include/some_code.h | 8 +- .../htmlv/browser/include/unicode_tags.h | 31 +++- 5 files changed, 95 insertions(+), 119 deletions(-) diff --git a/programs/network/htmlv/browser/TWB.h b/programs/network/htmlv/browser/TWB.h index a69a0b8dad..920499ceb7 100644 --- a/programs/network/htmlv/browser/TWB.h +++ b/programs/network/htmlv/browser/TWB.h @@ -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); } @@ -594,13 +577,13 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) { // if (tag[0] == '/') { - rez = 0; - strcpy(#tag, #tag+1); + 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,35 +625,30 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) { { if (rez) { - if (link) IF(text_color_index > 0) text_color_index--; // - _A_MARK: - if (!strcmp(#parametr, "href=")) - { - if (stroka - 1 > lines.visible) || (stroka < -2) return; - - text_color_index++; - text_colors[text_color_index] = text_colors[text_color_index-1]; - - link = 1; - blink++; - text_colors[text_color_index] = link_color; - strcat(#page_links, #options); - strcat(#page_links, "|"); - } - if (anchor) && (!strcmp(#parametr, "name=")) - { - if (!strcmp(#anchor, #options)) + do{ + if (!strcmp(#parametr, "href=")) { - anchor_line_num=lines.first+stroka; + if (stroka - 1 > lines.visible) || (stroka < -2) return; + + text_color_index++; + text_colors[text_color_index] = text_colors[text_color_index-1]; + + link = 1; + blink++; + text_colors[text_color_index] = link_color; + strcat(#page_links, #options); + strcat(#page_links, "|"); } - } - if (tagparam) - { - GetNextParam(); - GOTO _A_MARK; - } + if (anchor) && (!strcmp(#parametr, "name=")) + { + if (!strcmp(#anchor, #options)) + { + anchor_line_num=lines.first+stroka; + } + } + } 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: - if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#') - { - text_colors[text_color_index] = GetColor(#options); - } - IF(tagparam) { - GetNextParam(); - GOTO COL_MARK; - } + do{ + if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#') + { + text_colors[text_color_index] = GetColor(#options); + } + } 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,20 +806,16 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) { if (!chTag("meta")) || (!chTag("?xml")) { - META: - if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding=")) - { - strcpy(#options, #options[strrchr(#options, '=')]); // content= + do{ + if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding=")) + { + strcpy(#options, #options[strrchr(#options, '=')]); // content= - if (!strcmp(#options,"utf-8")) || (!strcmp(#options,"utf8")) ReadHtml(_UTF); - 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; - } + if (!strcmp(#options,"utf-8")) || (!strcmp(#options,"utf8")) ReadHtml(_UTF); + if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u")) ReadHtml(_KOI); + if (!strcmp(#options, "dos")) || (!strcmp(#options, "cp-866")) ReadHtml(_DOS); + } + } while(GetNextParam()); return; } } diff --git a/programs/network/htmlv/browser/include/history.h b/programs/network/htmlv/browser/include/history.h index de5c59de64..5f77d41f21 100644 --- a/programs/network/htmlv/browser/include/history.h +++ b/programs/network/htmlv/browser/include/history.h @@ -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) { diff --git a/programs/network/htmlv/browser/include/parce_tag.h b/programs/network/htmlv/browser/include/parce_tag.h index 48923ed8c8..15ab1e06f5 100644 --- a/programs/network/htmlv/browser/include/parce_tag.h +++ b/programs/network/htmlv/browser/include/parce_tag.h @@ -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; } \ No newline at end of file diff --git a/programs/network/htmlv/browser/include/some_code.h b/programs/network/htmlv/browser/include/some_code.h index c8c8e6db9a..94112be6e3 100644 --- a/programs/network/htmlv/browser/include/some_code.h +++ b/programs/network/htmlv/browser/include/some_code.h @@ -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, '|')); } diff --git a/programs/network/htmlv/browser/include/unicode_tags.h b/programs/network/htmlv/browser/include/unicode_tags.h index ac1dfd125d..743c827216 100644 --- a/programs/network/htmlv/browser/include/unicode_tags.h +++ b/programs/network/htmlv/browser/include/unicode_tags.h @@ -1,8 +1,3 @@ - - -byte unicode_chars[] = "h\243i\105\244\0"; - - char *unicode_tags[]={ "nbsp", " ", "#38", " ", @@ -66,3 +61,29 @@ char *unicode_tags[]={ "percnt","%", 0}; + + +byte unicode_chars[] = "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; +}