Subversion Repositories Kolibri OS

Rev

Rev 2818 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2818 Rev 2823
Line 7... Line 7...
7
int i;
7
int i;
8
 
8
 
Line 9... Line 9...
9
char download_path[]="/rd/1/.download";
9
char download_path[]="/rd/1/.download";
10
char search_path[]="http://nigma.ru/index.php?s=";
10
char search_path[]="http://nigma.ru/index.php?s=";
11
char version[]=" Text-based Browser 0.94c";
11
char version[]=" Text-based Browser 0.94d";
Line 12... Line 12...
12
 
12
 
13
 
13
 
14
struct TWebBrowser {
14
struct TWebBrowser {
-
 
15
	int left, top, width, height;
15
	int left, top, width, height;
16
	void Scan(int);
16
	void Scan(int);
17
	void GetNewUrl();
17
	void OpenPage();
18
	void OpenPage();
18
	void ReadHtml(byte);
19
	void ReadHtml(byte);
19
	void ShowPage();
20
	void ShowPage();
20
	void ParseHTML(dword, dword);
21
	void ParseHTML(dword);
21
	void WhatTextStyle(int left1, top1, width1);
22
	void WhatTextStyle(int left1, top1, width1);
Line 22... Line 23...
22
	void DrawScroller();
23
	void DrawScroller();
Line 50... Line 51...
50
#include "include\history.h"
51
#include "include\history.h"
51
#include "include\colors.h"
52
#include "include\colors.h"
52
#include "include\unicode_tags.h"
53
#include "include\unicode_tags.h"
53
#include "include\some_code.h"
54
#include "include\some_code.h"
-
 
55
#include "include\parce_tag.h"
Line 54... Line 56...
54
 
56
 
55
 
57
 
56
void TWebBrowser::Scan(int id)
58
void TWebBrowser::Scan(int id)
Line 178... Line 180...
178
			BREAK; 
180
			BREAK; 
179
		default:
181
		default:
180
			RETURN;
182
			RETURN;
181
	}
183
	}
182
	ParseHTML(buf, filesize);
184
	ParseHTML(buf);
183
}
185
}
184
 
186
 
Line 185... Line 187...
185
 
187
 
186
 
188
 
Line 187... Line 189...
187
void GetNewUrl(){
189
void TWebBrowser::GetNewUrl(){
188
	IF (!strcmp(get_URL_part(2),"./")) strcpy(#URL, #URL+2); //èãíîðèì :)
190
	IF (!strcmp(get_URL_part(2),"./")) strcpy(#URL, #URL+2); //èãíîðèì :)
189
	
191
	
Line 213... Line 215...
213
}
215
}
214
 
216
 
Line 215... Line 217...
215
 
217
 
216
	
218
	
217
void TWebBrowser::ReadHtml(byte dest)
219
void TWebBrowser::ReadHtml(byte encoding)
218
{
220
{
219
	if (!strcmp(get_URL_part(5),"http:"))) 
221
	if (!strcmp(get_URL_part(5),"http:"))) 
220
		file_size stdcall (#download_path);
222
		file_size stdcall (#download_path);
Line 230... Line 232...
230
		ReadFile(0, filesize, buf, #download_path);
232
		ReadFile(0, filesize, buf, #download_path);
231
	else
233
	else
232
		ReadFile(0, filesize, buf, #URL);
234
		ReadFile(0, filesize, buf, #URL);
233
		
235
		
Line 234... Line 236...
234
	if (dest==_WIN) wintodos(buf);
236
	if (encoding==_WIN) wintodos(buf);
235
	if (dest==_UTF) utf8rutodos(buf);
237
	if (encoding==_UTF) utf8rutodos(buf);
236
	if (dest==_KOI) koitodos(buf);
238
	if (encoding==_KOI) koitodos(buf);
237
}
239
}
Line 238... Line 240...
238
 
240
 
239
 
241
 
Line 285... Line 287...
285
		DrawTitle(#version); //?
287
		DrawTitle(#version); //?
286
		return;
288
		return;
287
	}
289
	}
288
	
290
	
Line 289... Line 291...
289
	ParseHTML(buf, filesize);
291
	ParseHTML(buf);
290
	IF (!strcmp(#version, #header)) DrawTitle(#header);
292
	IF (!strcmp(#version, #header)) DrawTitle(#header);
291
}
293
}
Line 292... Line 294...
292
 
294
 
293
 
295
 
294
 
296
 
295
void TWebBrowser::ParseHTML(dword bword, fsize){
297
void TWebBrowser::ParseHTML(dword bword){
296
	word bukva[1];
298
	word bukva[1];
Line 316... Line 318...
316
	if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
318
	if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
317
	
319
	
Line 318... Line 320...
318
	debug("Start parsing");
320
	debug("Start parsing");
Line 319... Line 321...
319
	
321
	
320
	for ( ; buf+fsize > bword; bword++;) {//ESBYTE[bword]
322
	for ( ; buf+filesize > bword; bword++;) {//ESBYTE[bword]
321
	  bukva = ESBYTE[bword];
323
	  bukva = ESBYTE[bword];
322
	  switch (bukva) {
324
	  switch (bukva) {
323
		case 0x0a:
325
		case 0x0a:
324
			if (pre_text)
326
			if (pre_text)
Line 348... Line 350...
348
					HH_:
350
					HH_:
349
					do
351
					do
350
					{
352
					{
351
						bword++;
353
						bword++;
352
						if (bword >= buf + fsize) break 1;
354
						if (bword >= buf + filesize) break 1;
353
					}
355
					}
354
					while (ESBYTE[bword] <>'-');
356
					while (ESBYTE[bword] <>'-');
355
					
357
					
Line 356... Line 358...
356
					bword++;
358
					bword++;
357
					if (ESBYTE[bword] <>'-') goto HH_;
359
					if (ESBYTE[bword] <>'-') goto HH_;
358
				}
360
				}
359
			}
361
			}
360
			while (ESBYTE[bword] <>'>') && (bword < buf + fsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
362
			while (ESBYTE[bword] <>'>') && (bword < buf + filesize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
361
			{
363
			{
362
				bukva = ESBYTE[bword];
364
				bukva = ESBYTE[bword];
363
				if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
365
				if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
364
				if (!ignor_param) && (bukva <>' ') strcat(#tag, #bukva);
366
				if (!ignor_param) && (bukva <>' ') strcat(#tag, #bukva);
365
				else
367
				else
Line 373... Line 375...
373
			lowcase(#tagparam);
375
			lowcase(#tagparam);
374
 
376
 
Line 375... Line 377...
375
			if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=''; //íåáîëüøîé ôèêñ äëÿ ðàáîòû ñ XHTML-òåãàìè òèïà br/
377
			if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=''; //íåáîëüøîé ôèêñ äëÿ ðàáîòû ñ XHTML-òåãàìè òèïà br/
376
			if (strlen(#tagparam) > 0) && (strlen(#tagparam) < 4000) GetNextParam();
378
			if (strlen(#tagparam) > 0) && (strlen(#tagparam) < 4000) GetNextParam();
-
 
379
			//while (tagparam)
-
 
380
			//{
-
 
381
			//	GetNextParam();
377
			WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //îáðàáîòêà òåãîâ
382
				WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //îáðàáîòêà òåãîâ
-
 
383
			//}
Line 378... Line 384...
378
 
384
 
Line 379... Line 385...
379
			line = tag = parametr = tagparam = ignor_param = 0; //âñ¸ îáíóëÿåì
385
			line = tag = parametr = tagparam = ignor_param = 0; //âñ¸ îáíóëÿåì
380
			
386
			
381
			break;
387
			break;
Line 382... Line 388...
382
		case '=': //ïîääåðæêà øàéòàíñêîé êîäèðîâêè ñòðàíèö, ñîõðàí¸ííûõ ÷åðåç ÈÅ7
388
		case '=': //ïîääåðæêà øàéòàíñêîé êîäèðîâêè ñòðàíèö, ñîõðàí¸ííûõ ÷åðåç ÈÅ7
383
			if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
389
			if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
384
 
390
 
385
			bword++;
-
 
386
			bukva=ESBYTE[bword];
391
			bword++;
387
			strcpy(#temp,#bukva);
392
			bukva=ESBYTE[bword];
388
 
393
			strcpy(#temp,#bukva);
Line 389... Line 394...
389
			bword++;
394
			bword++;
Line 453... Line 458...
453
	if (anchor)
458
	if (anchor)
454
	{
459
	{
455
		anchor='';
460
		anchor='';
456
		lines.first=anchor_line_num;
461
		lines.first=anchor_line_num;
457
		ParseHTML(buf, filesize);
462
		ParseHTML(buf);
458
	}
463
	}
Line 459... Line 464...
459
	
464
	
460
	debug("End parsing");
465
	debug("End parsing");
461
	DrawScroller(); //ðèñóåì ñêðîëë
466
	DrawScroller(); //ðèñóåì ñêðîëë
Line 462... Line -...
462
}
-
 
463
 
-
 
464
 
-
 
465
void GetNextParam()
-
 
466
{
-
 
467
	byte	kavichki = false;
-
 
468
	int		i = strlen(#tagparam) - 1;
-
 
469
	
-
 
470
	WHILE((i > 0) && ((tagparam[i] == '"') || (tagparam[i] == ' ') || (tagparam[i] == '\'') || (tagparam[i] == '/')))
-
 
471
	{
-
 
472
		IF (tagparam[i] == '"') || (tagparam[i] == '\'') kavichki=tagparam[i];
-
 
473
		tagparam[i] = 0x00;
-
 
474
		i--;
-
 
475
	}
-
 
476
 
-
 
477
	IF (kavichki)
-
 
478
	{
-
 
479
		i=find_symbol(#tagparam, kavichki);
-
 
480
		strcpy(#options, #tagparam + i);
-
 
481
	}
-
 
482
	ELSE
-
 
483
	{
-
 
484
		WHILE((i > 0) && (tagparam[i] <>'=')) i--; //i=find_symbol(#tagparam, '=')+1;
-
 
485
		i++;
-
 
486
		
-
 
487
		strcpy(#options, #tagparam + i); //êîïèðóåì îïöèþ
-
 
488
		WHILE (options[0] == ' ') strcpy(#options, #options+1);
-
 
489
	}
-
 
490
	tagparam[i] = 0x00;
-
 
491
 
-
 
492
	FOR ( ; ((tagparam[i] <>' ') && (i > 0); i--)
-
 
493
	{
-
 
494
		IF (tagparam[i] == '=') //äåðçêàÿ çàãëóøêà
-
 
495
		{
-
 
496
			//copystr(#tagparam+i+2,#options);
-
 
497
			tagparam[i + 1] = 0x00;
-
 
498
		}
-
 
499
	}
-
 
500
 
-
 
501
	strcpy(#parametr, #tagparam + i + 1); //êîïèðóåì ïàðàìåòð
-
 
502
	tagparam[i] = 0x00;
-
 
503
}
-
 
504
 
467
}
505
 
468
 
506
 
469
 
Line 507... Line 470...
507
char oldtag[100];
470
char oldtag[100];
Line 537... Line 500...
537
		return;
500
		return;
538
	}
501
	}
539
	
502
	
Line 540... Line 503...
540
	IF (ignor_text == 1) return;
503
	IF (ignor_text == 1) return;
541
	//
-
 
Line 542... Line -...
542
 
-
 
543
	//
504
 
Line 544... Line 505...
544
	IF(!chTag("q")) strcat(#line, "\"");
505
	IF(!chTag("q")) strcat(#line, "\"");
545
	
506
	
546
	//âûâîä íà ýêðàí
507
	//âûâîä íà ýêðàí
Line 561... Line 522...
561
			DefineButton(stolbec * 6 + left1 - 2, top1, strlen(#line) * 6 + 3, 9, blink + BT_HIDE, 0xB5BFC9); //
522
			DefineButton(stolbec * 6 + left1 - 2, top1, strlen(#line) * 6 + 3, 9, blink + BT_HIDE, 0xB5BFC9); //
562
			DrawBar(stolbec * 6 + left1, top1 + 8, strlen(#line) * 6, 1, text_colors[text_color_index]);
523
			DrawBar(stolbec * 6 + left1, top1 + 8, strlen(#line) * 6, 1, text_colors[text_color_index]);
563
		}
524
		}
564
	}
525
	}
565
	//
526
 
566
	IF(!tag) return;
527
	IF(!tag) return;
567
	stolbec += strlen(#line);
528
	stolbec += strlen(#line);
568
 
529
 
Line 569... Line 530...
569
	if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
530
	if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
570
	{
531
	{
Line 577... Line 538...
577
	if (!chTag("body"))
538
	if (!chTag("body"))
578
	{
539
	{
579
		BODY_MARK:
540
		BODY_MARK:
Line 580... Line 541...
580
		
541
		
581
		if (strcmp(#parametr, "link=") == 0)
542
		if (!strcmp(#parametr, "link="))
Line 582... Line 543...
582
			link_color = GetColor(#options);
543
			link_color = GetColor(#options);
583
		
-
 
584
		if (strcmp(#parametr, "text=") == 0)
544
		
585
		{
-
 
Line 586... Line 545...
586
			text_colors[0]=GetColor(#options);
545
		if (!strcmp(#parametr, "text="))
587
		}
-
 
588
		
546
			text_colors[0]=GetColor(#options);
589
		if (strcmp(#parametr, "bgcolor=") == 0)
-
 
Line 590... Line 547...
590
		{
547
		
-
 
548
		if (!strcmp(#parametr, "bgcolor="))
591
			bg_color=GetColor(#options);
549
			bg_color=GetColor(#options);
592
		}
550
		
593
		
551
		IF(tagparam)
Line 594... Line 552...
594
		IF(tagparam) {
552
		{
Line 694... Line 652...
694
		TextGoDown(left1, top1, width1);
652
		TextGoDown(left1, top1, width1);
695
		return;
653
		return;
696
	}
654
	}
697
	/////////////////////////////
655
	/////////////////////////////
698
	if(!chTag("li")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
656
	if(!chTag("li")) || (!chTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
699
	{
657
	{
700
		li_text = rez;
658
		li_text = rez;
701
		IF(rez == 0) return;
659
		IF(rez == 0) return;
702
		TextGoDown(left1, top1, width1);
660
		TextGoDown(left1, top1, width1);
703
		IF(stroka > -1) && (stroka - 2 < lines.visible) DrawBar(li_tab * 5 * 6 + left1 - 5, top1 + 12, 2, 2, 0);
661
		IF(stroka > -1) && (stroka - 2 < lines.visible) DrawBar(li_tab * 5 * 6 + left1 - 5, top1 + 12, 2, 2, 0);
704
		return;
662
		return;
Line 723... Line 681...
723
	}
681
	}
724
 
682
 
Line 725... Line 683...
725
	if (!chTag("img"))
683
	if (!chTag("img"))
726
	{
684
	{
727
		//IF (GetFileInfo(#libimg)<>0) return;  //åñëè áèáëèîòåêè íåò
685
		//if (GetFileInfo(#libimg)<>0) return;  //åñëè áèáëèîòåêè íåò
728
		IMG_TAG:
686
		IMG_TAG:
729
			IF (strcmp(#parametr,"src=")==0)   //íàäî îáúåäèíèòü ñ GetNewUrl()
687
			if (!strcmp(#parametr,"src="))   //íàäî îáúåäèíèòü ñ GetNewUrl()
730
	          {
688
			{
731
				strcpy(#temp, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
689
				strcpy(#temp, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
732
				temp[find_symbol(#temp, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
690
				temp[find_symbol(#temp, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
733
				strcat(#temp, #options);
691
				strcat(#temp, #options);
734
				image=load_image(#temp);
692
				image=load_image(#temp);
735
	
-
 
736
	                w=DSWORD[image+4];
693
				w=DSWORD[image+4];
737
	                h=DSWORD[image+8]; 
694
				h=DSWORD[image+8];
738
	          }
695
			}
-
 
696
  			if (!strcmp(#parametr,"alt="))
-
 
697
			{
-
 
698
				strcpy(#tag, "[Image: ");
-
 
699
				strcat(#tag, #options);
-
 
700
				strcat(#tag, "]");
-
 
701
			}
-
 
702
 
739
		IF(tagparam) {
703
		IF(tagparam)
-
 
704
		{
740
			GetNextParam();
705
			GetNextParam();
741
			GOTO IMG_TAG;
706
			GOTO IMG_TAG;
742
		}
707
		}
Line -... Line 708...
-
 
708
		
-
 
709
		if (!image)
-
 
710
		{
-
 
711
			//debug(#tag);
-
 
712
			return;
-
 
713
		}
743
 
714
 
Line 744... Line 715...
744
		if (w>width1) w=width1;
715
		if (w>width1) w=width1;
745
		
716
	
746
        if (image)
717
		if (stroka==0) DrawBar(left, top, width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
Line 747... Line 718...
747
        {
718
		
748
			stroka+=h/10;
719
		stroka+=h/10;
Line 749... Line 720...
749
			
720
		
750
			if (top1+hWB1.top+WB1.height-10) //åñëè ÂѨ èçîáðàæåíèå óøëî ÂÅÐÕ èëè ÂÍÈÇ
721
		if (top1+hWB1.top+WB1.height-10) //åñëè ÂѨ èçîáðàæåíèå óøëî ÂÅÐÕ èëè ÂÍÈÇ
-
 
722
			return;
751
				return;
723
 
752
 
724
		if (top1
753
			if (top1
725
		{
754
			{
726
			DrawBar(left, top, width-15, 10, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
Line 770... Line 742...
770
			{
742
		{
771
				DefineButton(left1 - 5, top1+10, w, h, blink + BT_HIDE, 0xB5BFC9);
743
			DefineButton(left1 - 5, top1+10, w, h, blink + BT_HIDE, 0xB5BFC9);
772
			}
744
		}
773
 
745
 
Line 774... Line -...
774
        }
-
 
775
		/*else
-
 
776
		{
-
 
777
			IF (strcmp(#parametr,"alt=")==0) copystr(#options,#line+strlen(#line));
-
 
778
		}*/
-
 
779
		return;
746
		return;
780
	}
747
	}
Line 781... Line 748...
781
 
748
 
782
	if (!chTag("meta")) || (!chTag("?xml"))
749
	if (!chTag("meta")) || (!chTag("?xml"))