From ae17b4e1657388266a8238539ffca9ac50e4d3b3 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Thu, 14 Jan 2016 23:05:51 +0000 Subject: [PATCH] Aelia 0.3: Sandwich menu, handle redirects, add links.h + lib/debug.h git-svn-id: svn://kolibrios.org@6058 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/aelia/aelia.c | 56 +++++-- programs/cmm/aelia/buidin_pages/about.htm | Bin 538 -> 554 bytes programs/cmm/aelia/link.h | 55 +++++++ programs/cmm/aelia/parse_address.h | 74 --------- programs/cmm/aelia/prepare_page.h | 38 ++++- programs/cmm/aelia/toolbar.png | Bin 1778 -> 2216 bytes programs/cmm/browser/WebView.c | 2 +- programs/cmm/examples/compile.bat | 3 - programs/cmm/lib/debug.h | 68 ++++++++ programs/cmm/lib/kolibri.h | 69 ++------- programs/cmm/lib/obj/iconv.h | 4 - programs/cmm/lib/patterns/http_downloader.h | 163 ++++++++++++++++++++ programs/cmm/lib/strings.h | 24 +-- 13 files changed, 371 insertions(+), 185 deletions(-) create mode 100644 programs/cmm/aelia/link.h delete mode 100644 programs/cmm/aelia/parse_address.h create mode 100644 programs/cmm/lib/debug.h create mode 100644 programs/cmm/lib/patterns/http_downloader.h diff --git a/programs/cmm/aelia/aelia.c b/programs/cmm/aelia/aelia.c index 5268a2d569..672c101c16 100644 --- a/programs/cmm/aelia/aelia.c +++ b/programs/cmm/aelia/aelia.c @@ -1,4 +1,4 @@ -#define MEMSIZE 4096*30 +#define MEMSIZE 4096*60 #include "../lib/font.h" #include "../lib/io.h" @@ -13,9 +13,7 @@ #include "../lib/patterns/libimg_load_skin.h" #include "../lib/patterns/simple_open_dialog.h" #include "../lib/patterns/history.h" - -#include "../browser/http_downloader.h" -#include "parse_address.h" +#include "../lib/patterns/http_downloader.h" char default_dir[] = "/rd/1"; od_filter filter2 = {0,0}; @@ -48,9 +46,9 @@ enum { MAGNIFY_PLUS, CHANGE_ENCODING, RUN_EDIT, - SHOW_INFO, GO_BACK, GO_FORWARD, + SANDWICH }; char address[UML]="http://"; @@ -60,7 +58,11 @@ edit_box address_box = {250,56,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,UML,#add #include "ini.h" #include "gui.h" #include "label.h" +#include "link.h" #include "prepare_page.h" +//#include "special_symbols.h" + +#define SANDWICH_MENU "Refresh page\nEdit page\nHistory\nAbout" void InitDlls() { @@ -75,7 +77,7 @@ void InitDlls() void main() -{ +{ InitDlls(); OpenDialog_init stdcall (#o_dialog); label.init(DEFAULT_FONT); @@ -98,12 +100,19 @@ void main() break; case evReDraw: draw_window(); - if (menu.list.cur_y) { + if (menu.list.cur_y>=10) && (menu.list.cur_y<20) { encoding = menu.list.cur_y - 10; - debugln("evReDraw: charset changed"); - EventOpenAddress(history.current()); + EventPageRefresh(); menu.list.cur_y = 0; } + if (menu.list.cur_y>=20) { + menu.list.cur_y-=20; + if (menu.list.cur_y==0) EventPageRefresh(); + if (menu.list.cur_y==1) EventRunEdit(); + if (menu.list.cur_y==2) EventShowHistory(); + if (menu.list.cur_y==3) EventShowInfo(); + menu.list.cur_y = 0; + } } } } @@ -139,8 +148,8 @@ void HandleButtonEvent() case RUN_EDIT: EventRunEdit(); break; - case SHOW_INFO: - EventShowInfo(); + case SANDWICH: + EventShowSandwichMenu(); break; } } @@ -205,6 +214,7 @@ void HandleMouseEvent() edit_box_mouse stdcall (#address_box); mouse.get(); list.wheel_size = 7; + link.hover(); if (list.MouseScroll(mouse.vert)) { DrawPage(); return; @@ -279,6 +289,8 @@ char temp[UML]; else DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE/2); } + strcpy(#address,downloader.url); + DrawAddressBox(); io.buffer_data = downloader.bufpointer; } } @@ -356,6 +368,17 @@ void EventGoForward() if (history.forward()) EventOpenAddress(history.current()); } +void EventShowSandwichMenu() +{ + menu.selected = 0; + menu.show(Form.left+Form.cwidth-130,Form.top+TOOLBAR_H+skin_height-10, 130, SANDWICH_MENU, 20); +} + +void EventPageRefresh() +{ + EventOpenAddress(history.current()); +} + /* ------------------------------------------- */ @@ -375,11 +398,10 @@ void draw_window() DrawToolbarButton(GO_BACK, 8); DrawToolbarButton(GO_FORWARD, 33); DrawToolbarButton(OPEN_FILE, 68); - DrawToolbarButton(MAGNIFY_PLUS, Form.cwidth - 161); - DrawToolbarButton(MAGNIFY_MINUS, Form.cwidth - 136); - DrawToolbarButton(CHANGE_ENCODING, Form.cwidth - 102); - DrawToolbarButton(RUN_EDIT, Form.cwidth - 68); - DrawToolbarButton(SHOW_INFO, Form.cwidth - 34); + DrawToolbarButton(MAGNIFY_PLUS, Form.cwidth - 125); + DrawToolbarButton(MAGNIFY_MINUS, Form.cwidth - 100); + DrawToolbarButton(CHANGE_ENCODING, Form.cwidth - 64); + DrawToolbarButton(SANDWICH, Form.cwidth - 31); DrawAddressBox(); @@ -413,7 +435,7 @@ void DrawAddressBox() { address_box.left = 97; address_box.top = 11; - address_box.width = Form.cwidth - address_box.left - 172; + address_box.width = Form.cwidth - address_box.left - 138; DrawRectangle(address_box.left-4, address_box.top-5, address_box.width+6, 23, 0x8C8C8C); DrawWideRectangle(address_box.left-3, address_box.top-3, address_box.width+5, 21, 4, address_box.color); address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#address); diff --git a/programs/cmm/aelia/buidin_pages/about.htm b/programs/cmm/aelia/buidin_pages/about.htm index 7fdb0ffef0d1d84211ef6982a3e7cfef6013c25a..0d53678a211180316c64155206daa495d68ca3af 100644 GIT binary patch delta 31 ncmbQmvWjIwBBSxfq`8cIZiWiF3MCnt#R>(9>8X?dGRgt~o{b7P delta 16 XcmZ3*GK*zGBBRm9q`8cf`I)2vF2n@k diff --git a/programs/cmm/aelia/link.h b/programs/cmm/aelia/link.h new file mode 100644 index 0000000000..831c848226 --- /dev/null +++ b/programs/cmm/aelia/link.h @@ -0,0 +1,55 @@ +struct _link +{ + int count; + int x[4096], y[4096], w[4096], h[4096]; + collection text; + collection url; + void clear(); + void add(); + int hover(); + int active; +} link; + +void _link::clear() +{ + text.drop(); + url.drop(); + count = 0; +} + +void _link::add(int _xx, _yy, _ww, _hh, dword _textt, _urll ) +{ + if (count==4095) return; + x[count] = _xx; + y[count] = _yy; + w[count] = _ww; + h[count] = _hh; + text.add(_textt); + url.add(_urll); + count++; +} + +int _link::hover() +{ + //char tempp[4096]; + dword color; + int i; + active = 0; + mouse.x = mouse.x - list.x; + mouse.y = mouse.y - list.y; + for (i=0; ilist.first*list.item_h) && (link.y[i]link.x[i]) + && (-list.first*list.item_h+link.y[i]mouse.y) + color = 0xFF0000; + else + color = 0xCCCccc; + DrawRectangle(link.x[i]+list.x+1, -list.first*list.item_h+link.y[i]+list.y, link.w[i], link.h[i], color); + } + } + return false; +} \ No newline at end of file diff --git a/programs/cmm/aelia/parse_address.h b/programs/cmm/aelia/parse_address.h deleted file mode 100644 index 946f84d22b..0000000000 --- a/programs/cmm/aelia/parse_address.h +++ /dev/null @@ -1,74 +0,0 @@ - -int check_is_the_adress_local(dword _in) -{ - if(!strncmp(_in,"/sys/",5)) return true; - if(!strncmp(_in,"/hd/",4)) return true; - if(!strncmp(_in,"/fd/",4)) return true; - if(!strncmp(_in,"/rd/",4)) return true; - if(!strncmp(_in,"/tmp/",5)) return true; - if(!strncmp(_in,"/cd/",4)) return true; - if(!strncmp(_in,"/bd/",4)) return true; - if(!strncmp(_in,"/usbhd/",7)) return true; - if(!strncmp(_in,"/kolibrios/",11)) return true; - return false; -} - -/* -int check_is_the_url_absolute(dword in) -{ - if(!strncmp(_in,"http:",5)) return true; - if(!strncmp(_in,"https:",6)) return true; - if(!strncmp(_in,"ftp:",4)) return true; -} - -void GetAbsoluteURL(dword in_URL) -{ - int i; - dword orig_URL = in_URL; - char newurl[UML]; - - while (i=strstr(in_URL, "&")) - { - strcpy(i+1, i+5); - } - - if (UrlIsAbsolute(in_URL)) return; - - IF (!strcmpn(in_URL,"./", 2)) in_URL+=2; - if (!http_transfer) - { - strcpy(#newurl, History.current()); - } - else - { - strcpy(#newurl, History.items.get(History.active-2)); - } - - if (ESBYTE[in_URL] == '/') //remove everything after site domain name - { - i = strchr(#newurl+8, '/'); - if (i) ESBYTE[i]=0; - in_URL+=1; - } - - _CUT_ST_LEVEL_MARK: - - if (newurl[strrchr(#newurl, '/')-2]<>'/') - { - newurl[strrchr(#newurl, '/')] = 0x00; - } - - IF (!strncmp(in_URL,"../",3)) - { - in_URL+=3; - newurl[strrchr(#newurl, '/')-1] = 0x00; - goto _CUT_ST_LEVEL_MARK; - } - - if (newurl[strlen(#newurl)-1]<>'/') strcat(#newurl, "/"); - - strcat(#newurl, in_URL); - strcpy(orig_URL, #newurl); -} - -*/ \ No newline at end of file diff --git a/programs/cmm/aelia/prepare_page.h b/programs/cmm/aelia/prepare_page.h index 62e8b60f48..77f9c4d66f 100644 --- a/programs/cmm/aelia/prepare_page.h +++ b/programs/cmm/aelia/prepare_page.h @@ -6,6 +6,7 @@ void PreparePage() //get font chars width, need to increase performance get_label_symbols_size(); ChangeCharset(charsets[encoding], "CP866", io.buffer_data); + link.clear(); if (strstri(io.buffer_data, " found"); DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceTxt(false); //get page height to calculate buffer size @@ -82,8 +83,19 @@ struct _style { bool pre; bool ignore; dword color; + void clear(); } style; +void _style::clear() +{ + b=u=i=s=0; + h1=h2=h3=h4=h5=h6=0; + a=0; + pre=0; + ignore=0; + color=0; +} + struct _text { dword start; int x, y; @@ -96,6 +108,7 @@ struct _tag { dword value[10]; void parce(); int nameis(); + void clear(); }; void _tag::parce() @@ -108,10 +121,15 @@ void _tag::parce() int _tag::nameis(dword _in_tag_name) { - if (strcmp(_in_tag_name, name)==0) return true; + if (name) && (strcmp(_in_tag_name, name)==0) return true; return false; } +void _tag::clear() +{ + start=name=0; +} + #define HTML_PADDING_X 8; #define HTML_PADDING_Y 5; @@ -127,21 +145,24 @@ _text text; _tag tag; dword DOM_pos; + tag.clear(); + style.clear(); /* Create DOM */ debugln("creating DOM"); DOM.len = strlen(io.buffer_data); DOM.start = malloc(DOM.len); DOM.end = DOM.start + DOM.len; strlcpy(DOM.start, io.buffer_data, DOM.len); + //RemoveSpecialSymbols(DOM.start, DOM.len); + //DOM.len = strlen(DOM.start); /* Parce DOM */ debugln("starting DOM parce..."); - text.start = DOM_pos; + text.start = DOM.start; for (DOM_pos=DOM.start; DOM_pos list.w) { - //debugln("long line cut"); zeroch = 0; for (line_break=tag.start-1; line_break>text.start; line_break--;) { @@ -161,7 +181,10 @@ dword DOM_pos; ESBYTE[line_break] >< zeroch; //restore line } if (draw==true) { - if (style.a) label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color); + if (style.a) { + link.add(stroka_x,stroka_y,get_label_len(text.start),list.item_h,text.start," "); + label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color); + } WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start); } ESBYTE[line_break] >< zeroch; //restore line @@ -170,7 +193,10 @@ dword DOM_pos; stroka_y += list.item_h; } if (draw==true) { - if (style.a) label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color); + if (style.a) { + link.add(stroka_x,stroka_y,get_label_len(text.start),list.item_h,text.start," "); + label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color); + } WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start); } stroka_x += get_label_len(text.start); diff --git a/programs/cmm/aelia/toolbar.png b/programs/cmm/aelia/toolbar.png index 931b6cf93051dbb6dbbbd0df254ee51b2f3086e9..5a0df64907d830e571017a960d3f47f422afd8a9 100644 GIT binary patch delta 2215 zcmV;Y2w3;>4X6>28Gi-<000{AbB6!`2yaP5K~#9!?VD$46ub9owf$-Yg`OUre%sKx#_r~w;-Mdxq-@m7iA3u^etbav|7SyU$EAl&W;zZSe z0RyOU*pEJ(xppv8=HZ-1=6#wUAxlIp+mh7f~{M(P8(EMSm^w5*|KG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rR;2d> z`PdWkoegq|X_K^dux5d#`(wVrd668YOYulQ($*Lpx84r12 z$&Y}|S&z2XXDV)HV)WLvTEwATANeT++e0eF&7cUk)8(l;TacSt41XASuQN*ea0Tkj z)+UGTx(roDZbFE8z)Id%I4aXc#doJeCRuNzXo36MSmUp<7fFQR0IKo?%HXNf+bD6! TlAQVK&!=PxzXW@9!THX=sKD>^ diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index 0d93aaaa33..1afb258663 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -26,6 +26,7 @@ //useful patterns #include "..\lib\patterns\libimg_load_skin.h" #include "..\lib\patterns\history.h" +#include "..\lib\patterns\http_downloader.h" char homepage[] = FROM "html\\homepage.htm"; @@ -101,7 +102,6 @@ enum { #include "..\TWB\TWB.c" #include "history.h" #include "show_src.h" -#include "http_downloader.h" #include "download_manager.h" char editURL[sizeof(URL)]; diff --git a/programs/cmm/examples/compile.bat b/programs/cmm/examples/compile.bat index 28f174e891..2f1a4bd111 100644 --- a/programs/cmm/examples/compile.bat +++ b/programs/cmm/examples/compile.bat @@ -1,18 +1,15 @@ c-- window.c c-- collections.c c-- menu.c -c-- mixcolors.c @echo off @del _window @del _collections @del _menu -@del _mixcolors @rename window.com _window @rename collections.com _collections @rename menu.com _menu -@rename mixcolors.com _mixcolors @del warning.txt @echo on diff --git a/programs/cmm/lib/debug.h b/programs/cmm/lib/debug.h new file mode 100644 index 0000000000..8646c48a73 --- /dev/null +++ b/programs/cmm/lib/debug.h @@ -0,0 +1,68 @@ +#ifndef INCLUDE_DEBUG_H +#define INCLUDE_DEBUG_H +#print "[include ]\n" + +#ifndef INCLUDE_STRING_H +#include "../lib/strings.h" +#endif + +inline fastcall void debugch( ECX) +{ + $push eax + $push ebx + $mov eax,63 + $mov ebx,1 + $int 0x40 + $pop ebx + $pop eax +} + +inline fastcall void debug( EDX) +{ + $push eax + $push ebx + $push ecx + $mov eax, 63 + $mov ebx, 1 +NEXT_CHAR: + $mov ecx, DSDWORD[edx] + $or cl, cl + $jz DONE + $int 0x40 + $inc edx + $jmp NEXT_CHAR +DONE: + $pop ecx + $pop ebx + $pop eax +} + +inline fastcall void debugln( EDX) +{ + debug( EDX); + debugch('\n'); +} + +inline void debugi(dword d_int) +{ + char tmpch[12]; + itoa_(#tmpch, d_int); + debugln(#tmpch); +} + +:void assert(dword _type, _actual, _expected) +{ + char r[4096]; + if (_type=='s') { + if (streq(_actual, _expected)) return; + sprintf(#r, "==========nok{\nactual: %s\nexpected: %s", _actual, _expected); + debugln(#r); + } + if (_type=='i') { + if (_actual == _expected)) return; + sprintf(#r, "==========nok{\nactual: %i\nexpected: %i", _actual, _expected); + debugln(#r); + } +} + +#endif \ No newline at end of file diff --git a/programs/cmm/lib/kolibri.h b/programs/cmm/lib/kolibri.h index 760f9f30b5..9ae2138194 100644 --- a/programs/cmm/lib/kolibri.h +++ b/programs/cmm/lib/kolibri.h @@ -74,7 +74,7 @@ char program_path[4096]; #define SCAN_CODE_DEL 083 #define SCAN_CODE_INS 082 #define SCAN_CODE_SPACE 057 - + #define SCAN_CODE_LEFT 075 #define SCAN_CODE_RIGHT 077 #define SCAN_CODE_DOWN 080 @@ -404,8 +404,8 @@ inline fastcall int GetClientTop() $mov eax, 48 $mov ebx, 5 $int 0x40 - $mov eax, ebx - $shr eax, 16 + $mov eax, ebx + $shr eax, 16 } inline fastcall int GetClientHeight() @@ -413,7 +413,7 @@ inline fastcall int GetClientHeight() $mov eax, 48 $mov ebx, 5 $int 0x40 - $mov eax, ebx + $mov eax, ebx } @@ -437,61 +437,6 @@ inline fastcall int PlaySpeaker( ESI) $int 0x40 } -inline fastcall void debugln( EDX) -{ - $push eax - $push ebx - $push ecx - $mov eax, 63 - $mov ebx, 1 -NEXT_CHAR: - $mov ecx, DSDWORD[edx] - $or cl, cl - $jz DONE - $int 0x40 - $inc edx - $jmp NEXT_CHAR -DONE: - $mov cl, 13 - $int 0x40 - $mov cl, 10 - $int 0x40 - $pop ecx - $pop ebx - $pop eax -} - -inline fastcall void debug( EDX) -{ - $push eax - $push ebx - $push ecx - $mov eax, 63 - $mov ebx, 1 -NEXT_CHAR: - $mov ecx, DSDWORD[edx] - $or cl, cl - $jz DONE - $int 0x40 - $inc edx - $jmp NEXT_CHAR -DONE: - $pop ecx - $pop ebx - $pop eax -} - - -inline fastcall void debugch( ECX) -{ - $push eax - $push ebx - $mov eax,63 - $mov ebx,1 - $int 0x40 - $pop ebx - $pop eax -} //------------------------------------------------------------------------------ void DefineAndDrawWindow(dword x, y, size_w, size_h, byte WindowType,dword WindowAreaColor, EDI, ESI) @@ -606,7 +551,7 @@ void DrawBar(dword x,y,w,h,EDX) EAX = 13; EBX = x<<16+w; ECX = y<<16+h; - $int 0x40 + $int 0x40 } void DefineButton(dword x,y,w,h,EDX,ESI) @@ -812,3 +757,7 @@ ______STOP______: #ifndef INCLUDE_MEM_H #include "../lib/mem.h" #endif + +#ifndef INCLUDE_DEBUG_H +#include "../lib/debug.h" +#endif \ No newline at end of file diff --git a/programs/cmm/lib/obj/iconv.h b/programs/cmm/lib/obj/iconv.h index b77e106b59..30ca826c07 100644 --- a/programs/cmm/lib/obj/iconv.h +++ b/programs/cmm/lib/obj/iconv.h @@ -7,10 +7,6 @@ #include "../lib/kolibri.h" #endif -#ifndef INCLUDE_DLL_H -#include "../lib/dll.h" -#endif - dword iconv_lib = #a_iconv_lib; char a_iconv_lib[19]="/sys/lib/iconv.obj\0"; diff --git a/programs/cmm/lib/patterns/http_downloader.h b/programs/cmm/lib/patterns/http_downloader.h new file mode 100644 index 0000000000..39281a9fe0 --- /dev/null +++ b/programs/cmm/lib/patterns/http_downloader.h @@ -0,0 +1,163 @@ + +enum { + STATE_NOT_STARTED, + STATE_IN_PROGRESS, + STATE_COMPLETED +}; + +struct DOWNLOADER { + unsigned data_downloaded_size, data_full_size; + dword bufpointer, bufsize, url; + byte state; + dword http_transfer; + int http_status_code; + dword Start(); + void Stop(); + void Completed(); + int MonitorProgress(); +} downloader; + +dword DOWNLOADER::Start(dword _url) +{ + url = _url; + state = STATE_IN_PROGRESS; + http_get stdcall (url, 0, 0, #accept_language); + http_transfer = EAX; + return http_transfer; +} + +void DOWNLOADER::Stop() +{ + state = STATE_NOT_STARTED; + if (http_transfer!=0) + { + EAX = http_transfer; + EAX = EAX.http_msg.content_ptr; // get pointer to data + $push EAX // save it on the stack + http_free stdcall (http_transfer); // abort connection + $pop EAX + mem_Free(EAX); // free data + http_transfer=0; + bufsize = 0; + bufpointer = mem_Free(bufpointer); + } + data_downloaded_size = data_full_size = 0; +} + +void DOWNLOADER::Completed() +{ + state = STATE_COMPLETED; + ESI = http_transfer; + bufpointer = ESI.http_msg.content_ptr; + bufsize = ESI.http_msg.content_received; + http_free stdcall (http_transfer); + http_transfer=0; +} + +int DOWNLOADER::MonitorProgress() +{ + dword receive_result; + char redirect_url[4096*3], finaladress[4096*3]; + if (http_transfer <= 0) return false; + http_receive stdcall (http_transfer); + receive_result = EAX; + EDI = http_transfer; + http_status_code = EDI.http_msg.status; + data_full_size = EDI.http_msg.content_length; + data_downloaded_size = EDI.http_msg.content_received; + if (!data_full_size) data_full_size = data_downloaded_size * 6 + 1; + + if (receive_result == 0) { + if (http_status_code >= 300) && (http_status_code < 400) + { + http_find_header_field stdcall (http_transfer, "location\0"); + if (EAX!=0) { + ESI = EAX; + EDI = #redirect_url; + do { + $lodsb; + $stosb; + } while (AL != 0) && (AL != 13) && (AL != 10)); + DSBYTE[EDI-1]='\0'; + } + get_absolute_url(#finaladress, url, #redirect_url); + Stop(); + Start(#finaladress); + url = #finaladress; + return false; + } + Completed(); + } + return true; +} + + +/*===================================== +== == +== CHECK URL TYPE == +== == +=====================================*/ + + +int check_is_the_adress_local(dword _in) +{ + if (ESBYTE[_in]!='/') return false; + _in++; + if(!strncmp(_in,"rd/",3)) return true; + if(!strncmp(_in,"fd/",3)) return true; + if(!strncmp(_in,"hd/",3)) return true; + if(!strncmp(_in,"bd/",3)) return true; + if(!strncmp(_in,"cd/",3)) return true; + if(!strncmp(_in,"sys/",4)) return true; + if(!strncmp(_in,"tmp/",4)) return true; + if(!strncmp(_in,"usbhd",6)) return true; + if(!strncmp(_in,"kolibrios",10)) return true; + return false; +} + +int check_is_the_url_absolute(dword _in) +{ + if(!strncmp(_in,"ftp:",4)) return true; + if(!strncmp(_in,"http:",5)) return true; + if(!strncmp(_in,"https:",6)) return true; + if(!strncmp(_in,"mailto:",7)) return true; + if(check_is_the_adress_local(_in)) return true; + return false; +} + +void get_absolute_url(dword _rez, _base, _new) +{ + int i; + debug("_base:");debugln(_base); + debug("_new:");debugln(_new); + //case: ./valera.html + if (!strncmp(_new,"./", 2)) _new+=2; + //case: http://site.name + if (check_is_the_url_absolute(_new)) { + strcpy(_rez, _new); + goto _GET_ABSOLUTE_URL_END; + } + //case: /valera.html + if (ESBYTE[_new] == '/') //remove everything after site domain name + { + strcpy(_rez, _base); + i = strchr(_rez+8,'/'); + if (i<1) i=strlen(_rez)+_rez; + strcpy(i, _new); + goto _GET_ABSOLUTE_URL_END; + } + //case: ../../valera.html + strcpy(_rez, _base); + ESBYTE[ strrchr(_rez,'/') + _rez -1 ] = '\0'; //remove name + while (!strncmp(_new,"../",3)) + { + _new += 3; + ESBYTE[ strrchr(_rez,'/') + _rez -1 ] = '\0'; + } + //case: valera.html + chrcat(_rez, '/'); + strcat(_rez, _new); + _GET_ABSOLUTE_URL_END: + while (i=strstr(_rez, "&")) strcpy(i+1, i+5); + debug("_rez:");debugln(_rez); +} diff --git a/programs/cmm/lib/strings.h b/programs/cmm/lib/strings.h index ba5e065bb6..2ea1ee5c5c 100644 --- a/programs/cmm/lib/strings.h +++ b/programs/cmm/lib/strings.h @@ -181,6 +181,10 @@ inline signed int strcmp(dword text1, text2) return 0; } +inline signed int streq(dword text1, text2) { + if (!strcmp(text1,text2)) return true; else return false; +} + /* signed int strncmp(dword s1, s2, signed n) unsigned char _s1,_s2; @@ -385,18 +389,6 @@ inline fastcall void chrcat(ESI, BL) ESBYTE[ESI+EDI+1] = 0; } - -inline fastcall signed int old_strchr( ESI,BL) -{ - int jj=0; - do{ - jj++; - $lodsb - IF(AL==BL) return jj; - } while(AL!=0); - return 0; -} - inline dword strchr(dword shb;char s) { char ss; @@ -897,14 +889,6 @@ inline signed strcoll(dword text1,text2) return 0; } -inline void debugi(dword d_int) -{ - char tmpch[12]; - itoa_(#tmpch, d_int); - debugln(#tmpch); -} - - #define strnmov strmovn #define stricmp strcmpi #define strcmpn strncmp