HTMLv 0.94d STABLE

git-svn-id: svn://kolibrios.org@2823 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2012-06-23 22:30:59 +00:00
parent 8cee52c51b
commit c208ff6147
3 changed files with 80 additions and 110 deletions

View File

@ -58,6 +58,7 @@ void main()
else strcpy(#URL, "/sys/index.htm");
strcpy(#editURL, #URL);
lines.column_max = 101;
WB1.OpenPage();
SetEventMask(0x27);
@ -114,7 +115,7 @@ void main()
btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height;
IF (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
IF (btn<>lines.first) WB1.ParseHTML(buf, filesize); //чтоб лишний раз не перерисовывать
IF (btn<>lines.first) WB1.ParseHTML(buf); //чтоб лишний раз не перерисовывать
m.get();
}

View File

@ -9,16 +9,17 @@ int i;
char download_path[]="/rd/1/.download";
char search_path[]="http://nigma.ru/index.php?s=";
char version[]=" Text-based Browser 0.94c";
char version[]=" Text-based Browser 0.94d";
struct TWebBrowser {
int left, top, width, height;
void Scan(int);
void GetNewUrl();
void OpenPage();
void ReadHtml(byte);
void ShowPage();
void ParseHTML(dword, dword);
void ParseHTML(dword);
void WhatTextStyle(int left1, top1, width1);
void DrawScroller();
};
@ -52,6 +53,7 @@ int anchor_line_num;
#include "include\colors.h"
#include "include\unicode_tags.h"
#include "include\some_code.h"
#include "include\parce_tag.h"
void TWebBrowser::Scan(int id)
@ -180,12 +182,12 @@ void TWebBrowser::Scan(int id)
default:
RETURN;
}
ParseHTML(buf, filesize);
ParseHTML(buf);
}
void GetNewUrl(){
void TWebBrowser::GetNewUrl(){
IF (!strcmp(get_URL_part(2),"./")) strcpy(#URL, #URL+2); //èãíîðèì :)
if (URL[0] <> '/')
@ -215,7 +217,7 @@ void GetNewUrl(){
void TWebBrowser::ReadHtml(byte dest)
void TWebBrowser::ReadHtml(byte encoding)
{
if (!strcmp(get_URL_part(5),"http:")))
file_size stdcall (#download_path);
@ -232,9 +234,9 @@ void TWebBrowser::ReadHtml(byte dest)
else
ReadFile(0, filesize, buf, #URL);
if (dest==_WIN) wintodos(buf);
if (dest==_UTF) utf8rutodos(buf);
if (dest==_KOI) koitodos(buf);
if (encoding==_WIN) wintodos(buf);
if (encoding==_UTF) utf8rutodos(buf);
if (encoding==_KOI) koitodos(buf);
}
@ -287,13 +289,13 @@ void TWebBrowser::ShowPage()
return;
}
ParseHTML(buf, filesize);
ParseHTML(buf);
IF (!strcmp(#version, #header)) DrawTitle(#header);
}
void TWebBrowser::ParseHTML(dword bword, fsize){
void TWebBrowser::ParseHTML(dword bword){
word bukva[1];
int j, perenos_num;
byte ignor_param = 0;
@ -318,7 +320,7 @@ void TWebBrowser::ParseHTML(dword bword, fsize){
debug("Start parsing");
for ( ; buf+fsize > bword; bword++;) {//ESBYTE[bword]
for ( ; buf+filesize > bword; bword++;) {//ESBYTE[bword]
bukva = ESBYTE[bword];
switch (bukva) {
case 0x0a:
@ -350,7 +352,7 @@ void TWebBrowser::ParseHTML(dword bword, fsize){
do
{
bword++;
if (bword >= buf + fsize) break 1;
if (bword >= buf + filesize) break 1;
}
while (ESBYTE[bword] <>'-');
@ -358,7 +360,7 @@ void TWebBrowser::ParseHTML(dword bword, fsize){
if (ESBYTE[bword] <>'-') goto HH_;
}
}
while (ESBYTE[bword] <>'>') && (bword < buf + fsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
while (ESBYTE[bword] <>'>') && (bword < buf + filesize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
{
bukva = ESBYTE[bword];
if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
@ -375,7 +377,11 @@ void TWebBrowser::ParseHTML(dword bword, fsize){
if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=''; //íåáîëüøîé ôèêñ äëÿ ðàáîòû ñ XHTML-òåãàìè òèïà br/
if (strlen(#tagparam) > 0) && (strlen(#tagparam) < 4000) GetNextParam();
WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //îáðàáîòêà òåãîâ
//while (tagparam)
//{
// GetNextParam();
WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //îáðàáîòêà òåãîâ
//}
line = tag = parametr = tagparam = ignor_param = 0; //âñ¸ îáíóëÿåì
@ -386,7 +392,6 @@ void TWebBrowser::ParseHTML(dword bword, fsize){
bword++;
bukva=ESBYTE[bword];
strcpy(#temp,#bukva);
bword++;
bukva=ESBYTE[bword];
strcat(#temp,#bukva);
@ -455,7 +460,7 @@ void TWebBrowser::ParseHTML(dword bword, fsize){
{
anchor='';
lines.first=anchor_line_num;
ParseHTML(buf, filesize);
ParseHTML(buf);
}
debug("End parsing");
@ -463,48 +468,6 @@ void TWebBrowser::ParseHTML(dword bword, fsize){
}
void GetNextParam()
{
byte kavichki = false;
int i = strlen(#tagparam) - 1;
WHILE((i > 0) && ((tagparam[i] == '"') || (tagparam[i] == ' ') || (tagparam[i] == '\'') || (tagparam[i] == '/')))
{
IF (tagparam[i] == '"') || (tagparam[i] == '\'') kavichki=tagparam[i];
tagparam[i] = 0x00;
i--;
}
IF (kavichki)
{
i=find_symbol(#tagparam, kavichki);
strcpy(#options, #tagparam + i);
}
ELSE
{
WHILE((i > 0) && (tagparam[i] <>'=')) i--; //i=find_symbol(#tagparam, '=')+1;
i++;
strcpy(#options, #tagparam + i); //êîïèðóåì îïöèþ
WHILE (options[0] == ' ') strcpy(#options, #options+1);
}
tagparam[i] = 0x00;
FOR ( ; ((tagparam[i] <>' ') && (i > 0); i--)
{
IF (tagparam[i] == '=') //äåðçêàÿ çàãëóøêà
{
//copystr(#tagparam+i+2,#options);
tagparam[i + 1] = 0x00;
}
}
strcpy(#parametr, #tagparam + i + 1); //êîïèðóåì ïàðàìåòð
tagparam[i] = 0x00;
}
char oldtag[100];
void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
dword hr_color;
@ -539,9 +502,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
}
IF (ignor_text == 1) return;
//
//
IF(!chTag("q")) strcat(#line, "\"");
//âûâîä íà ýêðàí
@ -563,7 +524,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
DrawBar(stolbec * 6 + left1, top1 + 8, strlen(#line) * 6, 1, text_colors[text_color_index]);
}
}
//
IF(!tag) return;
stolbec += strlen(#line);
@ -579,20 +540,17 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
{
BODY_MARK:
if (strcmp(#parametr, "link=") == 0)
if (!strcmp(#parametr, "link="))
link_color = GetColor(#options);
if (strcmp(#parametr, "text=") == 0)
{
if (!strcmp(#parametr, "text="))
text_colors[0]=GetColor(#options);
}
if (strcmp(#parametr, "bgcolor=") == 0)
{
if (!strcmp(#parametr, "bgcolor="))
bg_color=GetColor(#options);
}
IF(tagparam) {
IF(tagparam)
{
GetNextParam();
GOTO BODY_MARK;
}
@ -696,7 +654,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
return;
}
/////////////////////////////
if(!chTag("li")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
if(!chTag("li")) || (!chTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
{
li_text = rez;
IF(rez == 0) return;
@ -725,58 +683,67 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (!chTag("img"))
{
//IF (GetFileInfo(#libimg)<>0) return; //åñëè áèáëèîòåêè íåò
//if (GetFileInfo(#libimg)<>0) return; //åñëè áèáëèîòåêè íåò
IMG_TAG:
IF (strcmp(#parametr,"src=")==0) //íàäî îáúåäèíèòü ñ GetNewUrl()
{
if (!strcmp(#parametr,"src=")) //íàäî îáúåäèíèòü ñ GetNewUrl()
{
strcpy(#temp, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
temp[find_symbol(#temp, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
strcat(#temp, #options);
image=load_image(#temp);
w=DSWORD[image+4];
h=DSWORD[image+8];
}
IF(tagparam) {
w=DSWORD[image+4];
h=DSWORD[image+8];
}
if (!strcmp(#parametr,"alt="))
{
strcpy(#tag, "[Image: ");
strcat(#tag, #options);
strcat(#tag, "]");
}
IF(tagparam)
{
GetNextParam();
GOTO IMG_TAG;
}
if (!image)
{
//debug(#tag);
return;
}
if (w>width1) w=width1;
if (stroka==0) DrawBar(left, top, width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
if (image)
{
stroka+=h/10;
if (top1+h<WB1.top) || (top1>WB1.top+WB1.height-10) //åñëè ÂѨ èçîáðàæåíèå óøëî ÂÅÐÕ èëè ÂÍÈÇ
return;
stroka+=h/10;
if (top1+h<WB1.top) || (top1>WB1.top+WB1.height-10) //åñëè ÂѨ èçîáðàæåíèå óøëî ÂÅÐÕ èëè ÂÍÈÇ
return;
if (top1<WB1.top) //åñëè ÷àñòü èçîáðàæåíèÿ ñâåðõó
{
img_lines_first=WB1.top-top1;
h=h-img_lines_first;
top1=WB1.top;
}
if (top1>WB1.top+WB1.height-h-15) //åñëè ÷àñòü èçîáðàæåíèÿ ñíèçó IF (stroka - 2 < lines.visible)
{
h=WB1.top+WB1.height-top1-15;
}
IF (h<=0) return;
img_draw stdcall (image,left1-5,top1+10,w, h,0,img_lines_first);
DrawBar(left1+w - 5, top1 + 10, width1-w + 5, h, bg_color);
IF (link)
{
DefineButton(left1 - 5, top1+10, w, h, blink + BT_HIDE, 0xB5BFC9);
}
}
/*else
if (top1<WB1.top) //åñëè ÷àñòü èçîáðàæåíèÿ ñâåðõó
{
IF (strcmp(#parametr,"alt=")==0) copystr(#options,#line+strlen(#line));
}*/
DrawBar(left, top, width-15, 10, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
img_lines_first=WB1.top-top1;
h=h-img_lines_first;
top1=WB1.top;
}
if (top1>WB1.top+WB1.height-h-15) //åñëè ÷àñòü èçîáðàæåíèÿ ñíèçó IF (stroka - 2 < lines.visible)
{
h=WB1.top+WB1.height-top1-15;
}
IF (h<=0) return;
img_draw stdcall (image,left1-5,top1+10,w, h,0,img_lines_first);
DrawBar(left1+w - 5, top1 + 10, width1-w + 5, h, bg_color);
IF (link)
{
DefineButton(left1 - 5, top1+10, w, h, blink + BT_HIDE, 0xB5BFC9);
}
return;
}

View File

@ -7,6 +7,8 @@
<body bgcolor="#000000" link="#0066FF" text="#FFFFFF">
<img src="background.gif" alt="background">
<b>Это тестовая страница для проверки HTML Viewer</b><br />
<br />
Эта программа поддерживает все популярные кодировки: cp1251, koi-8, cp866, Unicode.<br><br>