HTMLv: code clear and structuring

git-svn-id: svn://kolibrios.org@4488 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2014-01-19 20:06:42 +00:00
parent cfffb7f087
commit de218dc14a
4 changed files with 88 additions and 73 deletions

View File

@ -1,4 +1,6 @@
#include "..\lib\draw_buf.h" #include "..\lib\draw_buf.h"
#include "..\lib\list_box.h"
int downloader_id; int downloader_id;
@ -13,7 +15,6 @@ edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(U
scroll_bar scroll_wv = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; scroll_bar scroll_wv = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
char editURL[sizeof(URL)]; char editURL[sizeof(URL)];
char page_links[12000];
char header[2048]; char header[2048];
@ -38,6 +39,7 @@ byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text, li_tab,
link, ignor_text, cur_encoding, text_align; link, ignor_text, cur_encoding, text_align;
byte condition_text_active, condition_text_val, condition_href, condition_max; byte condition_text_active, condition_text_val, condition_href, condition_max;
enum { _WIN, _DOS, _KOI, _UTF };
enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT}; enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT};
@ -62,8 +64,8 @@ char anchor[256];
#include "..\TWB\colors.h" #include "..\TWB\colors.h"
#include "..\TWB\unicode_tags.h" #include "..\TWB\unicode_tags.h"
#include "..\TWB\img_cache.h" #include "..\TWB\img_cache.h"
#include "..\TWB\some_code.h"
#include "..\TWB\parce_tag.h" #include "..\TWB\parce_tag.h"
#include "..\TWB\links.h"
@ -133,7 +135,7 @@ void TWebBrowser::GetNewUrl(){
editURL[strrchr(#editURL, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî / editURL[strrchr(#editURL, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
} }
IF (!strcmp(get_URL_part(3),"../")) //íà óðîâåíü ââåðõ IF (!strncmp(#URL,"../",3)) //íŕ óđîâĺíü ââĺđő
{ {
strcpy(#URL,#URL+3); strcpy(#URL,#URL+3);
editURL[strrchr(#editURL, '/')-1] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî / editURL[strrchr(#editURL, '/')-1] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
@ -150,7 +152,7 @@ void TWebBrowser::GetNewUrl(){
void TWebBrowser::ReadHtml(byte encoding) void TWebBrowser::ReadHtml(byte encoding)
{ {
if (!strcmp(get_URL_part(5),"http:"))) if (!strncmp(#URL,"http:",5))
file_size stdcall (#download_path); file_size stdcall (#download_path);
else else
file_size stdcall (#URL); file_size stdcall (#URL);
@ -160,7 +162,7 @@ void TWebBrowser::ReadHtml(byte encoding)
mem_Free(buf); mem_Free(buf);
buf = mem_Alloc(filesize); buf = mem_Alloc(filesize);
if (!strcmp(get_URL_part(5),"http:"))) if (!strncmp(#URL,"http:",5))
ReadFile(0, filesize, buf, #download_path); ReadFile(0, filesize, buf, #download_path);
else else
ReadFile(0, filesize, buf, #URL); ReadFile(0, filesize, buf, #URL);
@ -185,7 +187,7 @@ void TWebBrowser::ShowPage()
else else
{ {
WriteText(list.x + 10, list.y + 18, 0x80, 0, "Page not found. May be, URL contains some errors."); WriteText(list.x + 10, list.y + 18, 0x80, 0, "Page not found. May be, URL contains some errors.");
if (!strcmp(get_URL_part(5),"http:"))) WriteText(list.x + 10, list.y + 32, 0x80, 0, "Or Internet unavilable for your configuration."); if (!strncmp(#URL,"http:",5)) WriteText(list.x + 10, list.y + 32, 0x80, 0, "Or Internet unavilable for your configuration.");
} }
//return; //return;
} }
@ -213,7 +215,7 @@ void TWebBrowser::ParseHTML(dword bword){
link_color = 0x0000FF; link_color = 0x0000FF;
bg_color = 0xFFFFFF; bg_color = 0xFFFFFF;
DrawBuf.Fill(bg_color); DrawBuf.Fill(bg_color);
strcpy(#page_links,"|"); PageLinks.Clear();
strcpy(#header, #version); strcpy(#header, #version);
stroka = -list.first; stroka = -list.first;
stolbec = 0; stolbec = 0;
@ -391,15 +393,15 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
} }
else rez = 1; else rez = 1;
if (!chTag("html")) if (isTag("html"))
{ {
IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0; IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0;
return; return;
} }
if (!chTag("script")) || (!chTag("style")) || (!chTag("binary")) ignor_text = rez; if (isTag("script")) || (isTag("style")) || (isTag("binary")) ignor_text = rez;
if(!chTag("title")) if(isTag("title"))
{ {
if (rez) header=NULL; if (rez) header=NULL;
else if (!stroka) DrawTitle(#header); //òåã çàêðûëñÿ - âûâåëè ñòðîêó else if (!stroka) DrawTitle(#header); //òåã çàêðûëñÿ - âûâåëè ñòðîêó
@ -410,14 +412,14 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
IF(!chTag("q")) chrcat(#line, '\"'); IF(isTag("q")) chrcat(#line, '\"');
if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
{ {
if (!strcmp(#anchor, #options)) anchor_line_num=list.first+stroka; if (!strcmp(#anchor, #options)) anchor_line_num=list.first+stroka;
} }
if (!chTag("body")) if (isTag("body"))
{ {
do{ do{
if (!strcmp(#parametr, "condition_max=")) { condition_max = atoi(#options); debugi(condition_max); } if (!strcmp(#parametr, "condition_max=")) { condition_max = atoi(#options); debugi(condition_max); }
@ -432,7 +434,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
return; return;
} }
if (!chTag("a")) if (isTag("a"))
{ {
if (rez) if (rez)
{ {
@ -449,8 +451,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
link = 1; link = 1;
blink++; blink++;
text_colors[text_color_index] = link_color; text_colors[text_color_index] = link_color;
strcat(#page_links, #options); PageLinks.Add(#options);
strcat(#page_links, "|");
} }
if (anchor) && (!strcmp(#parametr, "name=")) if (anchor) && (!strcmp(#parametr, "name="))
{ {
@ -468,7 +469,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
return; return;
} }
if (!chTag("font")) if (isTag("font"))
{ {
if (rez) if (rez)
{ {
@ -486,22 +487,22 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (text_color_index > 0) text_color_index--; if (text_color_index > 0) text_color_index--;
return; return;
} }
if(!chTag("tr")) || (!chTag("br")) { if(isTag("tr")) || (isTag("br")) {
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
return; return;
} }
if (!chTag("div")) { if (isTag("div")) {
IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1); IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1);
return; return;
} }
if (!chTag("p")) { if (isTag("p")) {
IF(oldtag[0] == 'h') return; IF(oldtag[0] == 'h') return;
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
IF(rez) TextGoDown(left1, top1 + 10, width1); IF(rez) TextGoDown(left1, top1 + 10, width1);
return; return;
} }
/* /*
if (!chTag("center")) if (isTag("center"))
{ {
if (rez) text_align = ALIGN_CENTER; if (rez) text_align = ALIGN_CENTER;
if (!rez) if (!rez)
@ -511,7 +512,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
} }
return; return;
} }
if (!chTag("right")) if (isTag("right"))
{ {
if (rez) text_align = ALIGN_RIGHT; if (rez) text_align = ALIGN_RIGHT;
if (!rez) if (!rez)
@ -522,7 +523,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
return; return;
} }
*/ */
if (!chTag("h1")) || (!chTag("h2")) || (!chTag("h3")) || (!chTag("h4")) { if (isTag("h1")) || (isTag("h2")) || (isTag("h3")) || (isTag("h4")) {
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
if (rez) && (stroka>1) TextGoDown(left1, top1 + 10, width1); if (rez) && (stroka>1) TextGoDown(left1, top1 + 10, width1);
strcpy(#oldtag, #tag); strcpy(#oldtag, #tag);
@ -542,28 +543,28 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
else else
oldtag=NULL; oldtag=NULL;
if (!chTag("b")) || (!chTag("strong")) || (!chTag("big")) { if (isTag("b")) || (isTag("strong")) || (isTag("big")) {
b_text = rez; b_text = rez;
return; return;
} }
if(!chTag("i")) || (!chTag("em")) || (!chTag("subtitle")) { if(isTag("i")) || (isTag("em")) || (isTag("subtitle")) {
i_text = rez; i_text = rez;
return; return;
} }
if (!chTag("dt")) if (isTag("dt"))
{ {
li_text = rez; li_text = rez;
IF(rez == 0) return; IF(rez == 0) return;
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
return; return;
} }
if (!chTag("condition")) if (isTag("condition"))
{ {
condition_text_active = rez; condition_text_active = rez;
if (rez) && (!strcmp(#parametr, "show_if=")) condition_text_val = atoi(#options); if (rez) && (!strcmp(#parametr, "show_if=")) condition_text_val = atoi(#options);
return; return;
} }
if(!chTag("li")) || (!chTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè if (isTag("li")) || (isTag("dt")) //íŕäî ńäĺëŕňü âëîćĺííűĺ ńďčńęč
{ {
li_text = rez; li_text = rez;
if (rez) if (rez)
@ -573,18 +574,18 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
} }
return; return;
} }
if (!chTag("u")) || (!chTag("ins")) u_text = rez; if (isTag("u")) || (isTag("ins")) u_text = rez;
if (!chTag("s")) || (!chTag("strike")) || (!chTag("del")) s_text = rez; if (isTag("s")) || (isTag("strike")) || (isTag("del")) s_text = rez;
if (!chTag("ul")) || (!chTag("ol")) IF(!rez) if (isTag("ul")) || (isTag("ol")) IF(!rez)
{ {
li_text = rez; li_text = rez;
li_tab--; li_tab--;
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
} ELSE li_tab++; } ELSE li_tab++;
if (!chTag("dd")) stolbec += 5; if (isTag("dd")) stolbec += 5;
if (!chTag("blockquote")) blq_text = rez; if (isTag("blockquote")) blq_text = rez;
if (!chTag("pre")) pre_text = rez; if (isTag("pre")) pre_text = rez;
if (!chTag("hr")) if (isTag("hr"))
{ {
if (anchor) || (stroka < -1) if (anchor) || (stroka < -1)
{ {
@ -596,12 +597,12 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
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); TextGoDown(left1, top1+list.line_h, width1);
} }
if (!chTag("img")) if (isTag("img"))
{ {
ImgCache1.Images( left1, top1, width1); ImgCache1.Images( left1, top1, width1);
return; return;
} }
if (!chTag("meta")) || (!chTag("?xml")) if (isTag("meta")) || (isTag("?xml"))
{ {
do{ do{
if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding=")) if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
@ -645,3 +646,10 @@ void TWebBrowser::TextGoDown(int left1, top1, width1)
if (blq_text) stolbec = 8; else stolbec = 0; if (blq_text) stolbec = 8; else stolbec = 0;
if (li_text) stolbec = li_tab * 5; if (li_text) stolbec = li_tab * 5;
} }
int isTag(dword text)
{
if (!strcmp(#tag,text)) return 1; else return 0;
}

36
programs/cmm/TWB/links.h Normal file
View File

@ -0,0 +1,36 @@
struct LinksArray
{
char page_links[12000];
void Add();
dword GetURL();
void Clear();
} PageLinks;
void LinksArray::Add(dword new_link)
{
strcat(#page_links, new_link);
strcat(#page_links, "|");
}
dword LinksArray::GetURL(int id)
{
int i, j = 0;
for (i = 0; i <= id - 401; i++)
{
do
{
j++;
if (j>=strlen(#page_links)) return;
}
while (page_links[j] <>'|');
}
page_links[j] = 0x00;
strcpy(#URL, #page_links+strrchr(#page_links, '|'));
return #URL;
}
void LinksArray::Clear()
{
strcpy(#page_links,"|");
}

View File

@ -1,30 +0,0 @@
enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
enum { _WIN, _DOS, _KOI, _UTF };
dword get_URL_part(int len) {
char temp1[sizeof(URL)];
strcpy(#temp1, #URL);
temp1[len] = 0x00;
return #temp1;
}
inline byte chTag(dword text) {return strcmp(#tag,text);}
void GetURLfromPageLinks(int id)
{
int i, j = 0;
for (i = 0; i <= id - 401; i++)
{
do
{
j++;
if (j>=strlen(#page_links)) return;
}
while (page_links[j] <>'|');
}
page_links[j] = 0x00;
strcpy(#URL, #page_links+strrchr(#page_links, '|'));
}

View File

@ -16,7 +16,6 @@
#include "..\lib\file_system.h" #include "..\lib\file_system.h"
#include "..\lib\mem.h" #include "..\lib\mem.h"
#include "..\lib\dll.h" #include "..\lib\dll.h"
#include "..\lib\list_box.h"
//*.obj libraries //*.obj libraries
#include "..\lib\lib.obj\box_lib.h" #include "..\lib\lib.obj\box_lib.h"
#include "..\lib\lib.obj\libio_lib.h" #include "..\lib\lib.obj\libio_lib.h"
@ -26,11 +25,11 @@
#include "img\URLgoto.txt"; #include "img\URLgoto.txt";
#ifdef LANG_RUS #ifdef LANG_RUS
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.6"; char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.61";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­" ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤" ?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
#else #else
char version[]=" Text-based Browser 0.99.6"; char version[]=" Text-based Browser 0.99.61";
?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"
#endif #endif
@ -48,6 +47,8 @@ int action_buf;
#include "..\TWB\TWB.c" #include "..\TWB\TWB.c"
#include "menu_rmb.h" #include "menu_rmb.h"
enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
void main() void main()
{ {
@ -251,7 +252,7 @@ void Scan(int id)
OpenPage(); OpenPage();
return; return;
case 052: //F3 case 052: //F3
if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); if (strncmp(#URL,"http:",5)<>0) RunProgram("/rd/1/tinypad", #URL);
else RunProgram("/rd/1/tinypad", #download_path); else RunProgram("/rd/1/tinypad", #download_path);
return; return;
case 054: //F5 case 054: //F5
@ -336,7 +337,7 @@ void Scan(int id)
void ProcessLinks(int id) void ProcessLinks(int id)
{ {
GetURLfromPageLinks(id); strcpy(#URL, PageLinks.GetURL(id));
//$1 - Condition Script //$1 - Condition Script
if (URL[0] == '$') if (URL[0] == '$')
@ -397,7 +398,7 @@ void OpenPage()
BrowserHistory.AddUrl(); BrowserHistory.AddUrl();
strcpy(#header, #version); strcpy(#header, #version);
pre_text =0; pre_text =0;
if (!strcmp(get_URL_part(5),"http:"))) if (!strncmp(#URL,"http:",5))
{ {
KillProcess(downloader_id); KillProcess(downloader_id);
DeleteFile(#download_path); DeleteFile(#download_path);