HTMLv: fixed memory leaks, fixed - show error page if page not found, some code refactoring

git-svn-id: svn://kolibrios.org@4650 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2014-03-15 15:16:08 +00:00
parent 4a31e76907
commit 8dc139d234
5 changed files with 66 additions and 55 deletions

View File

@ -16,10 +16,10 @@ struct TWebBrowser {
void GetNewUrl(); void GetNewUrl();
void Prepare(); void Prepare();
void Parse(); void Parse();
void WhatTextStyle(); void SetTextStyle();
void DrawPage(); void DrawPage();
void DrawScroller(); void DrawScroller();
void TextGoDown(); void NewLine();
}; };
TWebBrowser WB1; TWebBrowser WB1;
@ -302,11 +302,11 @@ void TWebBrowser::Parse(){
if (stroka-1 > list.visible) && (list.first <>0) break 1; //óõîäèì... if (stroka-1 > list.visible) && (list.first <>0) break 1; //óõîäèì...
DrawPage(); DrawPage();
strcpy(#line, #temp); strcpy(#line, #temp);
TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó NewLine(list.x + 5, stroka * 10 + list.y + 5); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
} }
DrawPage(); DrawPage();
line=NULL; line=NULL;
if (tag) WhatTextStyle(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //îáðàáîòêà òåãîâ if (tag) SetTextStyle(list.x + 5, stroka * 10 + list.y + 5); //îáðàáîòêà òåãîâ
tag = parametr = tagparam = ignor_param = NULL; tag = parametr = tagparam = ignor_param = NULL;
break; break;
default: default:
@ -329,13 +329,13 @@ void TWebBrowser::Parse(){
if (stroka-1 > list.visible) && (list.first <>0) break 1; //óõîäèì... if (stroka-1 > list.visible) && (list.first <>0) break 1; //óõîäèì...
DrawPage(); DrawPage();
strcpy(#line, #temp); strcpy(#line, #temp);
TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó NewLine(list.x + 5, stroka * 10 + list.y + 5); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
} }
} }
} }
DrawPage(); //ðèñóåò ïîñëåäíþþ ñòðîêó, ïîòîì ýòî íàäî óáðàòü, îïòèìèçèðîâàâ êîä DrawPage(); //ðèñóåò ïîñëåäíþþ ñòðîêó, ïîòîì ýòî íàäî óáðàòü, îïòèìèçèðîâàâ êîä
TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó NewLine(list.x + 5, stroka * 10 + list.y + 5); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
if (list.visible * 10 + 25 <= list.h) if (list.visible * 10 + 25 <= list.h)
DrawBar(list.x, list.visible * 10 + list.y + 25, list.w, -list.visible * 10 + list.h - 25, bg_color); DrawBar(list.x, list.visible * 10 + list.y + 25, list.w, -list.visible * 10 + list.h - 25, bg_color);
@ -354,7 +354,7 @@ void TWebBrowser::Parse(){
char oldtag[100]; char oldtag[100];
void TWebBrowser::WhatTextStyle(int left1, top1, width1) { void TWebBrowser::SetTextStyle(int left1, top1) {
dword hr_color; dword hr_color;
byte opened; byte opened;
byte meta_encoding; byte meta_encoding;
@ -388,13 +388,13 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
{ {
if (opened) if (opened)
{ {
TextGoDown(left1, top1, width1); NewLine(left1, top1);
strcat(#line, ' \"'); strcat(#line, ' \"');
} }
if (!opened) if (!opened)
{ {
chrcat(#line, '\"'); chrcat(#line, '\"');
TextGoDown(left1, top1, width1); NewLine(left1, top1);
} }
} }
@ -478,63 +478,70 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
return; return;
} }
if (isTag("br")) { if (isTag("br")) {
TextGoDown(left1, top1, width1); NewLine(left1, top1);
return; return;
} }
if (isTag("div")) || (isTag("header")) || (isTag("footer")) { if (isTag("div")) || (isTag("header")) || (isTag("footer")) {
IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1); IF(oldtag[0] <>'h') NewLine(left1, top1);
return; return;
} }
if (isTag("p")) { if (isTag("p")) {
IF(oldtag[0] == 'h') return; IF(oldtag[0] == 'h') return;
TextGoDown(left1, top1, width1); NewLine(left1, top1);
IF(opened) TextGoDown(left1, top1 + 10, width1); IF(opened) NewLine(left1, top1 + 10);
return; return;
} }
if(isTag("table")) { if(isTag("table")) {
if (opened) table.active = opened;
{ NewLine(left1, top1);
table.active = true; if (opened) table.NewTable();
TextGoDown(left1, top1, width1);
table.NewTable();
}
else
{
table.active = false;
TextGoDown(left1, top1, width1);
}
} }
if(isTag("td")) { if(isTag("td")) {
if (opened) if (opened)
{ {
// table.cur_col++;
table.row_h = 0;
do {
if (!strcmp(#parametr, "width="))
{
table.col_w[table.cur_col] = atoi(#options);
// NewLine(left1, top1);
// strcpy(#line, #options);
// NewLine(left1, top1);
}
} while(GetNextParam());
} }
else else
{ {
// if (table.row_h > table.row_max_h) table.row_max_h = table.row_h;
} }
} }
if(isTag("tr")) { if(isTag("tr")) {
if (opened) if (opened)
{ {
// table.cur_col = 0;
table.row_max_h = 0;
table.row_start = stroka;
} }
else else
{ {
TextGoDown(left1, top1, width1); NewLine(left1, top1);
if (table.cur_row == 0) table.max_cols = table.cur_col; if (table.cur_row == 0) table.max_cols = table.cur_col;
table.cur_row++; table.cur_row++;
table.max_cols = table.cur_col;
} }
} }
/* /*
if (isTag("center")) if (isTag("center"))
{ {
if (opened) text_align = ALIGN_CENTER; if (opened) text_align = ALIGN_CENTER;
if (!opened) if (!opened)
{ {
TextGoDown(left1, top1, width1); NewLine(left1, top1);
text_align = ALIGN_LEFT; text_align = ALIGN_LEFT;
} }
return; return;
@ -544,15 +551,15 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (opened) text_align = ALIGN_RIGHT; if (opened) text_align = ALIGN_RIGHT;
if (!opened) if (!opened)
{ {
TextGoDown(left1, top1, width1); NewLine(left1, top1);
text_align = ALIGN_LEFT; text_align = ALIGN_LEFT;
} }
return; return;
} }
*/ */
if (isTag("h1")) || (isTag("h2")) || (isTag("h3")) || (isTag("h4")) { if (isTag("h1")) || (isTag("h2")) || (isTag("h3")) || (isTag("h4")) {
TextGoDown(left1, top1, width1); NewLine(left1, top1);
if (opened) && (stroka>1) TextGoDown(left1, top1 + 10, width1); if (opened) && (stroka>1) NewLine(left1, top1 + 10);
strcpy(#oldtag, #tag); strcpy(#oldtag, #tag);
if (opened) if (opened)
{ {
@ -582,7 +589,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
{ {
li_text = opened; li_text = opened;
IF(opened == 0) return; IF(opened == 0) return;
TextGoDown(left1, top1, width1); NewLine(left1, top1);
return; return;
} }
if (isTag("condition")) if (isTag("condition"))
@ -596,7 +603,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
li_text = opened; li_text = opened;
if (opened) if (opened)
{ {
TextGoDown(left1, top1, width1); NewLine(left1, top1);
if (stroka > -1) && (stroka - 2 < list.visible) DrawBuf.DrawBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555); if (stroka > -1) && (stroka - 2 < list.visible) DrawBuf.DrawBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555);
} }
return; return;
@ -607,7 +614,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
{ {
li_text = opened; li_text = opened;
li_tab--; li_tab--;
TextGoDown(left1, top1, width1); NewLine(left1, top1);
} ELSE li_tab++; } ELSE li_tab++;
if (isTag("dd")) stolbec += 5; if (isTag("dd")) stolbec += 5;
if (isTag("blockquote")) blq_text = opened; if (isTag("blockquote")) blq_text = opened;
@ -620,13 +627,13 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
return; return;
} }
if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999; if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999;
TextGoDown(left1, top1, width1); NewLine(left1, top1);
DrawBuf.DrawBar(5, list.line_h/2, list.w-10, 1, hr_color); DrawBuf.DrawBar(5, list.line_h/2, list.w-10, 1, hr_color);
TextGoDown(left1, top1+list.line_h, width1); NewLine(left1, top1+list.line_h);
} }
if (isTag("img")) if (isTag("img"))
{ {
ImgCache.Images( left1, top1, width1); ImgCache.Images( left1, top1);
return; return;
} }
if (isTag("meta")) || (isTag("?xml")) if (isTag("meta")) || (isTag("?xml"))
@ -664,7 +671,7 @@ void TWebBrowser::DrawScroller() //
} }
void TWebBrowser::TextGoDown(int left1, top1, width1) void TWebBrowser::NewLine(int left1, top1)
{ {
if (!stroka) DrawBar(list.x, list.y, list.w, 5, bg_color); //çàêðàøèâàåì ôîí íàä ïåðâîé ñòðîêîé if (!stroka) DrawBar(list.x, list.y, list.w, 5, bg_color); //çàêðàøèâàåì ôîí íàä ïåðâîé ñòðîêîé
if (t_html) && (!t_body) return; if (t_html) && (!t_body) return;

View File

@ -5,8 +5,8 @@ struct Table
byte max_rows; byte max_rows;
byte cur_col; byte cur_col;
byte cur_row; byte cur_row;
int col_w[255]; int col_w[32];
int col_h[255]; int row_start, row_h, row_max_h;
void NewTable(); void NewTable();
} table; } table;

View File

@ -30,14 +30,14 @@
#include "img\URLgoto.txt"; #include "img\URLgoto.txt";
#ifdef LANG_RUS #ifdef LANG_RUS
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.73"; char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.74";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­" ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤" ?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
char loading[] = "‡ £à㧪  áâà ­¨æë...<br>"; char loading[] = "‡ £à㧪  áâà ­¨æë...<br>";
unsigned char page_not_found[] = FROM "html\page_not_found_ru.htm"; unsigned char page_not_found[] = FROM "html\page_not_found_ru.htm";
char accept_language[]= "Accept-Language: ru\n"; char accept_language[]= "Accept-Language: ru\n";
#else #else
char version[]=" Text-based Browser 0.99.73"; char version[]=" Text-based Browser 0.99.74";
?define IMAGES_CACHE_CLEARED "Images cache cleared" ?define IMAGES_CACHE_CLEARED "Images cache cleared"
?define T_LAST_SLIDE "This slide is the last" ?define T_LAST_SLIDE "This slide is the last"
char loading[] = "Loading...<br>"; char loading[] = "Loading...<br>";
@ -469,6 +469,7 @@ void StopLoading()
mem_Free(EAX); // free data mem_Free(EAX); // free data
http_transfer=0; http_transfer=0;
bufsize = 0; bufsize = 0;
bufpointer = mem_Free(bufpointer);
} }
PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
} }
@ -499,6 +500,7 @@ void OpenPage()
{ {
StopLoading(); StopLoading();
bufsize = 0; bufsize = 0;
bufpointer = mem_Free(bufpointer);
ShowPage(); ShowPage();
return; return;
} }
@ -507,11 +509,13 @@ void OpenPage()
{ {
file_size stdcall (#URL); file_size stdcall (#URL);
bufsize = EBX; bufsize = EBX;
if (!bufsize) return; if (bufsize)
mem_Free(bufpointer); {
bufpointer = mem_Alloc(bufsize); bufpointer = mem_Free(bufpointer);
SetPageDefaults(); bufpointer = mem_Alloc(bufsize);
ReadFile(0, bufsize, bufpointer, #URL); SetPageDefaults();
ReadFile(0, bufsize, bufpointer, #URL);
}
ShowPage(); ShowPage();
} }
} }

View File

@ -3,15 +3,15 @@
<title>Page not found</title> <title>Page not found</title>
</head> </head>
<body> <body>
<h1>Webpage Not Available</h1> <h1>&nbsp;Webpage Not Available</h1>
<h2>What could be done:</h2> <h2>&nbsp;What could be done:</h2>
<ul> <ul>
<li> <li>
Make sure that evetything fine with Internet connection.<br> Make sure that evetything fine with Internet connection.<br>
Open /sys/network/netcfg network diagnostic tool.<br> Open /sys/network/netcfg network diagnostic tool.<br>
</li> </li>
<li> <li>
Check page address, there may have been made a typo<br> Check page address, there may have been made a typo.<br>
</li> </li>
<li> <li>
Server is temporarily unavailable.<br> Server is temporarily unavailable.<br>

View File

@ -4,15 +4,15 @@
<title>‘âà ­¨æ  ­¥ ­ ©¤¥­ </title> <title>‘âà ­¨æ  ­¥ ­ ©¤¥­ </title>
</head> </head>
<body> <body>
<h1>‚¥¡-áâà ­¨æ  ­¥¤®áâ㯭 </h1> <h1>&nbsp;‚¥¡-áâà ­¨æ  ­¥¤®áâ㯭 </h1>
<h2>—â® ¬®¦­® ᤥ« âì:</h2> <h2>&nbsp;—â® ¬®¦­® ᤥ« âì:</h2>
<ul> <ul>
<li> <li>
“¡¥¤¨â¥áì, çâ® ¥áâì ¯®¤ª«î祭¨¥ ª á¥â¨ ˆ­â¥à­¥â.<br> “¡¥¤¨â¥áì, çâ® ¥áâì ¯®¤ª«î祭¨¥ ª á¥â¨ ˆ­â¥à­¥â.<br>
Žâªà®©â¥ /sys/network/netcfg ¤«ï ¤¨ £­®á⨪¨ á¥â¨.<br> Žâªà®©â¥ /sys/network/netcfg ¤«ï ¤¨ £­®á⨪¨ á¥â¨.<br>
</li> </li>
<li> <li>
<09>஢¥àì⥠ ¤à¥áá áâà ­¨æë, ¢®§¬®¦­®, ¡ë«  ᤥ« ­  ®¯¥ç âª <br> <09>஢¥àì⥠ ¤à¥áá áâà ­¨æë, ¢®§¬®¦­®, ¡ë«  ᤥ« ­  ®¯¥ç âª .<br>
</li> </li>
<li> <li>
‘¥à¢¥à ¢à¥¬¥­­® ­¥¤®áâ㯥­. <br> ‘¥à¢¥à ¢à¥¬¥­­® ­¥¤®áâ㯥­. <br>