00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00046 lcat(p, q){
00047 if p==nil then
00048 q
00049 else
00050 (hd p)::lcat (tl p) q;
00051 }
00052
00053
00062 divideList(x,p,r1,r2,f){
00063 if p==nil then [r1 r2]
00064 else let p->[a n] in
00065 let exec f with [a x] -> r in
00066 if r==0 then divideList x n r1 r2 f
00067 else if r<0 then divideList x n a::r1 r2 f
00068 else divideList x n r1 a::r2 f;
00069 }
00070
00071
00080 divideListString(x,p,r1,r2,f){
00081 if p==nil then [r1 r2]
00082 else let p->[a n] in
00083 let exec f with [strcatn a strcatn x] -> r in
00084 if r==0 then divideListString x n r1 r2 f
00085 else if r<0 then divideListString x n a::r1 r2 f
00086 else divideListString x n r1 a::r2 f;
00087 }
00088
00089
00098 divideListPos(x,p,r1,r2,pos,f){
00099 if p==nil then [r1 r2]
00100 else let p->[a n] in
00101 let exec f with [(nth_list a pos) (nth_list x pos)] -> r in
00102 if r==0 then divideListPos x n r1 r2 pos f
00103 else if r<0 then divideListPos x n a::r1 r2 pos f
00104 else divideListPos x n r1 a::r2 pos f;
00105 }
00106
00107
00116 divideList3(x,p,r1,r2,f){
00117 if p==nil then [r1 r2]
00118 else let p->[a n] in
00119 let a->[aa _] in
00120 let x->[xx _] in
00121 let exec f with [aa xx] -> r in
00122 if r==0 then divideList3 x n r1 r2 f
00123 else if r<0 then divideList3 x n a::r1 r2 f
00124 else divideList3 x n r1 a::r2 f;
00125 }
00126
00127
00136 splitList(l, e, f){
00137 if l == nil then [nil nil] else
00138 let l -> [head tail] in
00139 let splitList tail e f -> [left right] in
00140 if exec f with [head e] then
00141 [head::left right]
00142 else
00143 [left head::right];
00144 }
00145
00146
00159 isSmaller(s, t){
00160 ((strcmp s t) < 0);
00161 }
00162
00163
00176 isLarger(s, t){
00177 ((strcmp s t) > 0);
00178 }
00179
00180
00193 suppDoublon(s1,s2){
00194 strcmpi s1 s2;
00195 }
00196
00197
00210 suppDoublon2(s1,s2){
00211 s1!=s2;
00212 }
00213
00214
00225 quicksort(l,f){
00226 if l==nil then nil
00227 else let l->[vl nl] in
00228 let divideList vl nl nil nil f->[va na] in
00229 lcat quicksort va f vl::quicksort na f;
00230 }
00231
00232
00243 quicksortByPos(l,pos,f){
00244 if l==nil then nil
00245 else let l->[vl nl] in
00246 let divideListPos vl nl nil nil pos f->[va na] in
00247 lcat quicksortByPos va pos f vl::quicksortByPos na pos f;
00248 }
00249
00250
00261 quicksortList(l,f){
00262 if l==nil then nil
00263 else let l->[vl nl] in
00264 let divideListString vl nl nil nil f->[va na] in
00265 lcat quicksortList va f vl::quicksortList na f;
00266 }
00267
00268
00279 quicksort3(l,f){
00280 if l==nil then nil
00281 else let l->[vl nl] in
00282 let divideList3 vl nl nil nil f->[va na] in
00283 lcat quicksort3 va f vl::quicksort3 na f;
00284 }
00285
00286
00297 sortlist(l,f){
00298 if l == nil then nil else
00299 let l -> [head tail] in
00300 let splitList tail head f -> [left right] in
00301 lcat (sortlist left f) head::(sortlist right f);
00302 }
00303
00304
00314 revertlist(list){
00315 if list==nil then nil else
00316 let list -> [first next] in
00317 lcat revertlist next first::nil;
00318 }
00319
00320
00331 isStringInList(l, string){
00332 (l!=nil)&&((!strcmp string hd l)||(isStringInList tl l string));
00333 }
00334
00335
00346 isStringInListi(l, string){
00347 (l!=nil)&&((!strcmpi string hd l)||(isStringInListi tl l string));
00348 }
00349
00350
00361 isFirstWordInList(l, string){
00362 (l!=nil)&&((!strcmp (hd hd (strextr string)) (hd l))||(isFirstWordInList tl l string));
00363 }
00364
00365
00376 isFirstWordInListi(l, string){
00377 (l!=nil)&&((!strcmpi (hd hd (strextr string)) (hd l))||(isFirstWordInListi tl l string));
00378 }
00379
00380
00391 isFirstStringInList(l, string){
00392 let hd hd l -> tstr in
00393 (l!=nil)&&((!strcmp string tstr)||(isFirstStringInList tl l string));
00394 }
00395
00396
00397 getPathFile(longfile, file){
00398 if (longfile==nil) || (strlen longfile)==0 || (nth_char longfile ((strlen longfile)-1)) == '/ then
00399 (
00400 if (strfind "." file 0) != nil then
00401 [longfile file]
00402 else if file != nil then
00403 [strcatn longfile::file::"/"::nil nil]
00404 else
00405 [longfile nil];
00406 )
00407 else
00408 getPathFile
00409 substr longfile 0 (strlen longfile)-1
00410 strcat
00411 substr longfile ((strlen longfile)-1) 1
00412 file;
00413 }
00414
00415
00416 getlastPathDir(path){
00417 while ((strfind "/" path 0) != nil) do
00418 set path = substr path ((strfind "/" path 0) + 1) 2048;
00419 path;
00420 }
00421
00422
00423 getFileExt(file){
00424 let getPathFile file "" -> [_ file2] in
00425 let 0 -> pos in
00426 (
00427 while (strfind "." file2 pos + 1) != nil do
00428 (
00429 set pos = strfind "." file2 pos + 1;
00430 );
00431 substr file2 (pos + 1) 1024;
00432 );
00433 }
00434
00435
00436 getFilePathWithoutExt(file){
00437 substr file 0 (strfind "." file 0);
00438 }
00439
00440
00441 // return the fileName without Path and Extension
00442 getFileNameWithoutExt(file){
00443 let getPathFile file "" -> [_ file2] in
00444 substr file2 0 (strfind "." file2 0);
00445 }
00446
00447
00448 /* manage relativ paths (relativ files should start with ./ */
00449 getRelativePath(path, file){
00450 if !strcmp substr file 0 2 "./" then
00451 strcatn path::"/"::(substr file 2 strlen file)::nil
00452 else file;
00453 }
00454
00455
00456 cutDotName(name){
00457 [(substr name 0 (strfind "." name 0)) (substr name ((strfind "." name 0) + 1) 1024)];
00458 }
00459
00460
00461 makeDotName(id, name){
00462 strcatn id::"."::name::nil;
00463 }
00464
00465
00466 getFilesFromDir(dir, mask){
00467 let _listoffiles dir -> files in
00468 let nil -> lfiles in
00469 let sizelist files -> size in
00470 let 0 -> i in
00471 (
00472 while i < size do
00473 (
00474 let nth_list files i -> file in
00475 let getFileExt file -> ext in
00476 if !(isStringInList mask ext) then nil else
00477 set lfiles = lcat lfiles file::nil;
00478
00479 set i = i + 1;
00480 );
00481 lfiles;
00482 );
00483 }
00484
00485
00486 getBooleanFromString(str){
00487 if (!strcmpi strtrim str "enable") || (!strcmpi strtrim str "ON") || (!strcmpi strtrim str "true") || (!strcmpi strtrim str "yes") || ((atoi str) == 1) then 1 else 0;
00488 }
00489
00490
00491 isLastWordfromString(word, string){
00492 !strcmpi word (substr string ((strlen string) - (strlen word)) (strlen word));
00493 }
00494
00495
00496 isFirstWordfromString(word, string){
00497 !strcmpi word (substr string 0 (strlen word));
00498 }
00499
00500
00501 listLowercase(l){
00502 let sizelist l -> size in
00503 let nil -> ndata in
00504 let 0 -> i in
00505 (
00506 while i < size do
00507 (
00508 let nth_list l i -> elem in
00509 set ndata = lcat ndata (strlowercase elem)::nil;
00510
00511 set i = i + 1;
00512 );
00513 ndata;
00514 );
00515 }
00516
00517
00518 getFilesFromDirRecursive(dir){
00519 if (isLastWordfromString ".svn" dir) then nil else
00520 let _listoffiles dir -> lfiles in
00521 let _listofsubdir dir -> lsubdirs in
00522 (
00523 let sizelist lsubdirs -> size in
00524 let 0 -> i in
00525 while i < size do
00526 (
00527 let nth_list lsubdirs i -> elem in
00528 set lfiles = lcat lfiles (getFilesFromDirRecursive elem);
00529 set i = i + 1;
00530 );
00531
00532 lfiles;
00533 );
00534 }
00535
00536
00537 getDirectoryWithoutLastSlash(dir){
00538 if isLastWordfromString "/" dir then
00539 substr dir 0 ((strlen dir) - 1)
00540 else
00541 dir;
00542 }
00543
00544
00545 getDirectoryWithoutFirstSlash(dir){
00546 if isFirstWordfromString "/" dir then
00547 substr dir 1 ((strlen dir) - 1)
00548 else
00549 dir;
00550 }
00551
00552
00553 apply_on_list(l,f,x){
00554 if l==nil then 0
00555 else let l -> [a nxt] in
00556 (exec f with [a x];
00557 apply_on_list nxt f x);
00558 }
00559
00560
00561 rev_apply_on_list(l,f,x){
00562 if l==nil then 0
00563 else let l -> [a nxt] in
00564 (rev_apply_on_list nxt f x;
00565 exec f with [a x];0);
00566 }
00567
00568
00569 search_in_list(l,f,x){
00570 if l==nil then nil
00571 else let l -> [a nxt] in
00572 if exec f with [a x] then a
00573 else search_in_list nxt f x;
00574 }
00575
00576
00577 remove_from_list(l,p){
00578 if l==nil then nil
00579 else let l -> [a nxt] in
00580 if a==p then nxt
00581 else a::remove_from_list nxt p;
00582 }
00583
00584
00585 remove_string_from_list(l, elt){
00586 if l==nil
00587 then
00588 nil
00589 else
00590 let hd l -> elm in
00591 if !strcmpi elm elt then
00592 tl l
00593 else
00594 (hd l)::remove_string_from_list tl l elt;
00595 }
00596
00597
00598 remove_idx_from_list(l, idx){
00599 if l==nil
00600 then
00601 nil
00602 else
00603 let hd l -> [id _] in
00604 if id == idx then
00605 tl l
00606 else
00607 (hd l)::remove_idx_from_list tl l idx;
00608 }
00609
00610
00611 remove_sid_from_list(l, sid){
00612 if l==nil
00613 then
00614 nil
00615 else
00616 let hd l -> [id _] in
00617 if (!strcmp id sid) then
00618 tl l
00619 else
00620 (hd l)::remove_sid_from_list tl l sid;
00621 }
00622
00623
00624 remove_first_string_from_list(l, elt){
00625 if l==nil
00626 then
00627 nil
00628 else
00629 let hd hd l -> elm in
00630 if !strcmpi elm elt then
00631 tl l
00632 else
00633 (hd l)::remove_first_string_from_list tl l elt;
00634 }
00635
00636
00637 remove_all_first_string_from_list(l, elt){
00638 if l==nil
00639 then
00640 nil
00641 else
00642 let hd hd l -> elm in
00643 if !strcmpi elm elt then
00644 remove_all_first_string_from_list tl l elt
00645 else
00646 (hd l)::remove_all_first_string_from_list tl l elt;
00647 }
00648
00649
00650 remove_first_and_second_string_from_list(l, elt1, elt2){
00651 if l==nil
00652 then
00653 nil
00654 else
00655 let hd hd l -> elm1 in
00656 let hd tl hd l -> elm2 in
00657 if (!strcmpi elm1 elt1) && (!strcmpi elm2 elt2) then
00658 tl l
00659 else
00660 (hd l)::remove_first_and_second_string_from_list tl l elt1 elt2;
00661 }
00662
00663
00664 remove_first_string_from_list_start_with(l, elt){
00665 if l==nil
00666 then
00667 nil
00668 else
00669 let hd hd l -> elm in
00670 if !strcmpi (substr elm 0 (strlen elt)) elt then
00671 remove_first_string_from_list_start_with tl l elt
00672 else
00673 (hd l)::remove_first_string_from_list_start_with tl l elt;
00674 }
00675
00676
00677 pos_in_list(l,p,n){
00678 if l==nil then nil
00679 else let l -> [a nxt] in
00680 if a==p then n
00681 else pos_in_list nxt p n+1;
00682 }
00683
00684
00685 create_tab(n,f,x){
00686 let mktab n nil -> t in
00687 (let 0->i in while i<n do
00688 (set t.i=exec f with [i x];
00689 set i=i+1);
00690 t);
00691 }
00692
00693
00694 addFifo(x,f){
00695 let x::nil -> l in
00696 if f==nil then [l l]
00697 else let f->[a b] in
00698 (mutate b<-[_ l]; [a l]);
00699 }
00700
00701
00702 getFifo(f){
00703 if f==nil then [nil nil]
00704 else let f->[a b] in
00705 if a==b then [hd a nil]
00706 else [hd a [tl a b]];
00707 }
00708
00709
00710 sizeFifo(f){
00711 if f==nil then 0
00712 else let f->[a _] in sizelist a;
00713 }
00714
00715
00716 concFifo(f,g){
00717 if f==nil then g
00718 else if g==nil then f
00719 else let f->[a b] in let g->[c d] in
00720 (mutate b<-[_ c]; [a d]);
00721 }
00722
00723
00724 hexListToBignumList(l){
00725 let sizelist l -> size in
00726 let nil -> ndata in
00727 let 0 -> i in
00728 (
00729 while i < size do
00730 (
00731 let nth_list l i -> elt in
00732 set ndata = lcat ndata (BigFromAsc elt)::nil;
00733
00734 set i = i + 1;
00735 );
00736 ndata;
00737 );
00738 }
00739
00740
00741 strcatnSep(l, sep){
00742 let sizelist l -> size in
00743 let nil -> ndata in
00744 let 0 -> i in
00745 (
00746 while i < size do
00747 (
00748 let nth_list l i -> elem in
00749 if i == 0 then
00750 set ndata = elem
00751 else
00752 set ndata = strcatn ndata::sep::elem::nil;
00753
00754 set i = i + 1;
00755 );
00756 ndata;
00757 );
00758 }
00759
00760
00761 strreplace(s, from, to){
00762 let 0 -> pos in
00763 let strlen from -> fsize in
00764 let strlen to -> tsize in
00765 if ((fsize <= 0) || (tsize <= 0)) then s else
00766 while ((set pos = strfind from s pos) != nil) do
00767 set s = strcatn (substr s 0 pos)::to::(substr s (pos + fsize) ((strlen s) - pos))::nil;
00768
00769 s;
00770 }
00771
00772
00773 strreplacei(s, from, to){
00774 let 0 -> pos in
00775 let strlen from -> fsize in
00776 let strlen to -> tsize in
00777 if ((fsize <= 0) || (tsize <= 0)) then s else
00778 while ((set pos = strfindi from s pos) != nil) do
00779 set s = strcatn (substr s 0 pos)::to::(substr s (pos + fsize) ((strlen s) - pos))::nil;
00780
00781 s;
00782 }
00783
00784
00785 addSlashes(s){
00786 let "" -> ret in
00787 let strextr s -> l in
00788 (
00789 let sizelist l -> size in
00790 let 0 -> i in
00791 while (i < size) do
00792 (
00793 let nth_list l i -> line in
00794 set ret = strcatn ret::"\\n"::(strcatnSep line "\ ")::nil;
00795
00796 set i = i + 1;
00797 );
00798 ret;
00799 );
00800 }
00801
00802
00803 strTruncate(s, maxlen, rp){
00804 if (strlen s) > maxlen then
00805 strcat substr s 0 (maxlen - (strlen rp)) rp
00806 else
00807 s;
00808 }
00809
00810
00811 strToList(s){
00812 let nil -> ret in
00813 let strextr s -> l in
00814 (
00815 let sizelist l -> size in
00816 let 0 -> i in
00817 while (i < size) do
00818 (
00819 let nth_list l i -> line in
00820 set ret = lcat ret (strcatnSep line " ")::nil;
00821
00822 set i = i + 1;
00823 );
00824 ret;
00825 );
00826 }
00827
00828
00829 listToString(l){
00830 let nil -> ret in
00831 (
00832 let sizelist l -> size in
00833 let 0 -> i in
00834 while (i < size) do
00835 (
00836 let nth_list l i -> line in
00837 let strextr line -> lp in
00838 set ret = lcat ret (hd lp)::nil;
00839
00840 set i = i + 1;
00841 );
00842 if ret == nil then nil else strbuild ret;
00843 );
00844 }
00845
00846
00847 /* ********************************************************************************************* /
00848 HTTP DOWNLOAD
00849 / ********************************************************************************************* */
00850
00851 cbDownloadFile(req, p, data, code){
00852 let p -> [str url cbfun] in
00853 if (code == 0) then
00854 (
00855 mutate p <- [(strcat str data) _ _];
00856 0;
00857 )
00858 // download finished
00859 else if (code == 1) then
00860 (
00861 exec cbfun with [url (strcat str data)];
00862 )
00863 else
00864 (
00865 _fooS strcat ">>>>>>>>> Http download failed : " url;
00866 exec cbfun with [url nil];
00867 0;
00868 );
00869 0;
00870 }
00871
00872
00873 downloadFile(file, cbfun){
00874 if (!strcmp (substr file 0 8) "https://") || (!strcmp (substr file 0 7) "http://") || (!strcmp (substr file 0 7) "file://") || (!strcmp (substr file 0 6) "ftp://") then
00875 (
00876 INETGetURL _channel file 0 @cbDownloadFile ["" file cbfun];
00877 0;
00878 )
00879 else
00880 (
00881 exec cbfun with [file nil];
00882 );
00883 0;
00884 }
00885
00886
00887 cbGetUrlContent(req, p, data, code){
00888 let p -> [str url cbfun] in
00889 if (code == 0) then
00890 (
00891 mutate p <- [(strcat str data) _ _];
00892 0;
00893 )
00894 // download finished
00895 else if (code == 1) then
00896 (
00897 exec cbfun with [url (strcat str data)];
00898 )
00899 else
00900 (
00901 _fooS strcat ">>>>>>>>> Http download failed : " url;
00902 exec cbfun with [url nil];
00903 0;
00904 );
00905 0;
00906 }
00907
00908
00909 postUrl(url, params, cbfun){
00910 if (!strcmp (substr url 0 8) "https://") || (!strcmp (substr url 0 7) "http://") || (!strcmp (substr url 0 7) "file://") || (!strcmp (substr url 0 6) "ftp://") then
00911 (
00912 INETGetURLex2 _channel "POST" url "content-type: application/x-www-form-urlencoded" params 0 @cbGetUrlContent ["" url cbfun];
00913 0;
00914 )
00915 else
00916 (
00917 exec cbfun with [url nil];
00918 );
00919 0;
00920 }
00921
00922 // -- [/filterPKG] --
00923