/* fun getInfo ([[S r1] r1], S) S */ fun getInfo(l,s)=hd switchstr l s;; /* fun getInfos ([[S r1] r1] S) [S r1] */ fun getInfos(l,s)=switchstr l s;; fun IsEmptyString (s) = (strextr s) == nil ;; /* fun strFindNb (S, S, I) I - return the number of time we find the string str2 in the string str1 - return nil if str2 is empty - posinit is the initial position in the string str1 where we start to search for str2 */ fun strFindNb (str1, str2, posinit) = if (str2 == nil) || (!strcmp str2 "") then nil else if (str1 == nil) || (!strcmp str1 "") then 0 else let strfind str1 str2 posinit -> pos in if pos == nil then 0 else let strlen str1 -> sizeStr1 in 1 + strFindNb str1 str2 (pos + sizeStr1);; /**************************************************************************************** * * fun realGETstringSize (ObjFont font1, S str1) [I I] * * - return size in pixels of string str1 using font font1 * - take the caracter "\n" into account returning the * sum of the lines height and the max of the lines witdth. * ****************************************************************************************/ fun realGETstringSize2 (font, txtList, w, h) = if txtList == nil then [w+1 h] else let txtList -> [first next] in let _GETstringSize font first -> [nw nh] in realGETstringSize2 font next (if nw>w then nw else w) (nh+h) ;; fun realGETstringSize (font1, str1) = realGETstringSize2 font1 (lineextr str1) 0 0;; fun realGETstringW (font1, str1) = let (realGETstringSize2 font1 (lineextr str1) 0 0) -> [w _] in w ;; /**************************************************************************************** * * fun maxGETstringSize (ObjFont font1, S str1) [I I] * * - return size in pixels of string str1 using font font1 * - take the caracter "\n" into account returning the * sum of the lines height and the max of the lines witdth. * ****************************************************************************************/ fun maxGETstringSize2 (font, txtList, w, h) = let txtList -> [first next] in if first == nil then [w h] else let realGETstringSize font first -> [nw nh] in maxGETstringSize2 font next (if nw>w then nw else w) (if nh>h then nh else h) ;; fun maxGETstringSize (font, txtList) = maxGETstringSize2 font txtList 0 0;; /**************************************************************************************** Functions on lists ****************************************************************************************/ fun f_replace_in_list (list, searchFun, searchParam, new)= if list==nil then new::nil else let list -> [first next] in if (exec searchFun with [first searchParam]) then new::next else first::(f_replace_in_list next searchFun searchParam new) ;; fun removef_all_in_list (l, f, x)= if l==nil then nil else let l -> [a nxt] in if exec f with [a x] then removef_all_in_list nxt f x else a::(removef_all_in_list nxt f x);; /* return 1 if the name is in the list (casse insensitive) */ fun str_and_list_cmpi (name, list) = if list == nil then 0 else if !strcmpi name (hd list) then 1 else str_and_list_cmpi name (tl list) ;; /* return 1 if the name is in the list (casse sensitive) */ fun str_and_list_cmp (name, list) = if list == nil then 0 else if !strcmp name (hd list) then 1 else str_and_list_cmpi name (tl list) ;; /* Compare two [S r1] Return value: 1 (success) or 0 (failure) */ fun strlist_cmpi (l1, l2) = if (l1 == nil) && (l2 == nil) then 1 else if !strcmpi (hd l1) (hd l2) then strlist_cmpi (tl l1) (tl l2) else 0 ;; /**************************************************************************************** * * return the first missing (non existing) file name in the list, nil all the files in * in the list exist. * ****************************************************************************************/ fun _missing_file (fileNameList) = let fileNameList -> [first next] in if first == nil then nil else if (_checkpack first)==nil then first else _missing_file next ;; /**************************************************************************************** Convert a string list in an integer list. According to the atoi behaviour, the bad string elements are translated in integers with null value. example: "9"::"0"::"43"::"toto"::"098"::nil becomes 9::0::43::0::98::nil ****************************************************************************************/ fun _slist_to_ilist (l) = let l -> [first next] in if first == nil then nil else (atoi first)::_slist_to_ilist next ;; /* inverse of the previous function */ fun _ilist_to_slist (l) = let l -> [first next] in if first == nil then nil else (itoa first)::_ilist_to_slist next ;; /* temporary log error function : fonction : S : name of the fonction where the log message is activated data : [S r1] : name and value for specified relevant data message : S return : U0 : return value specified by function call */ fun logScsError (fonction, data, message, return) = _fooS "-------------------------------------------"; if data == nil then ( _fooS strcatn "SCS error in function "::fonction::nil; _fooS message ) else _fooS strcatn "SCS error in function "::fonction::", using data : "::(strbuild (data::nil))::message::nil; _fooS "-------------------------------------------"; return ;; fun simpleSearch (elt1, elt2) = elt1 == elt2 ;; fun strCompare (str1, str2) = !strcmpi str1 str2 ;; fun stringCompare (str1, str2) = strcmpi str1 str2 ;; /*************************************************************************************** Generic search function for any set of element. The function return the element or nil if not found. Parameters for the function are : - set of element - search function to access the next part of the set of element - element data to search for - access element function - comparison function ***************************************************************************************/ fun searchTemplateFunction (eltSet, searchfun, eltparam, accessfun, compfun)= if eltSet == nil then nil /* not found */ else let (exec compfun with [(exec accessfun with [eltSet]) eltparam]) -> eltfound in if eltfound == nil then searchTemplateFunction (exec searchfun with [eltSet]) searchfun eltparam accessfun compfun else eltfound ;; /*************************************************************************************** return all the string in list "listFile" which contains the string "fileContain" ***************************************************************************************/ fun findFileContaining (listFile, fileContain) = if listFile == nil then nil else let findFileContaining (tl listFile) fileContain -> nextFiles in if (strfindi fileContain (hd listFile) 1) == nil then nextFiles else (hd listFile)::nextFiles ;; /*************************************************************************************** return all the file name containing the string "fileContain" from directory list "dirList" and all sub directories validate by Macfly 05/06/2000 ***************************************************************************************/ fun getAllFileContaining (dirList, fileContain) = if dirList == nil then nil else listcat listcat (findFileContaining (_listoffiles (hd dirList)) fileContain) (getAllFileContaining (_listofsubdir (hd dirList)) fileContain) (getAllFileContaining (tl dirList) fileContain) ;; /*************************************************************************************** return all the string in list "listFile" which end with the string "fileType" ***************************************************************************************/ fun compareEndString (str1, ext) = let strlen str1 -> curFileLen in let strlen ext -> lenFileType in if curFileLen <= lenFileType then 0 else ! strcmpi ext substr str1 curFileLen - lenFileType lenFileType ;; fun compareEndStringList (str1, extList) = if extList == nil then 0 else let compareEndString str1 hd extList -> result in if result then result else compareEndStringList str1 tl extList ;; fun findFileType (listFile, fileTypeList) = if listFile == nil then nil else let findFileType (tl listFile) fileTypeList -> nextFiles in if compareEndStringList (hd listFile) fileTypeList then (hd listFile)::nextFiles else nextFiles ;; /*************************************************************************************** return all the file name which end with the string "fileType" from directory list "dirList" and all sub directories validate by Macfly 05/06/2000 ***************************************************************************************/ fun getAllFileType (dirList, fileType) = if dirList == nil then nil else listcat listcat (findFileType (_listoffiles (hd dirList)) fileType::nil) (getAllFileType (_listofsubdir (hd dirList)) fileType) (getAllFileType (tl dirList) fileType) ;; fun filesCompare( str1, str2 )= strcmp str1 str2;; fun getAllFiles (dirList, fileType)= quicksort getAllFileType dirList fileType @filesCompare ;; fun splitString (str, carac) = if IsEmptyString str then nil else let strfindi carac str 0 -> pos in if pos == nil then str::nil else let strlen str -> long in let strlen carac -> longSep in let (substr str 0 pos) -> sub in let (splitString (substr str (pos + longSep) (long - (pos + longSep - 1))) carac) -> suite in if IsEmptyString sub then suite else sub::suite ;; fun splitFilePath (filename) = splitString filename "/" ;; fun insert_everywhere_in_list (list, insert) = if list == nil then nil else if (tl list) == nil then (hd list)::nil else (hd list)::insert::(insert_everywhere_in_list tl list insert) ;; fun replace_in_string (cible, toreplace, replace) = if IsEmptyString cible then nil else let strfindi toreplace cible 0 -> pos in if pos == nil then cible else let strlen cible -> long in let strlen toreplace -> longSep in let substr cible 0 pos -> sub in strcatn sub::replace::(replace_in_string (substr cible (pos + longSep) (long - (pos + longSep - 1))) toreplace replace)::nil ;; fun get_second_element_in_list (list) = if list == nil then nil else (hd tl hd list)::(get_second_element_in_list (tl list)) ;; fun list_without_last_element (list) = if (list == nil) || ((tl list) == nil) then nil else (hd list)::(list_without_last_element tl list) ;; fun list_last_element (list) = if (list == nil) || ((tl list) == nil) then hd list else list_last_element tl list ;; fun listList_to_list (list) = if list == nil then nil else listcat (hd list) (listList_to_list (tl list)) ;; fun search_all_in_and_not_in_list (list1, list2) = if list1 == nil then [nil nil] else let hd list1 -> elt in let search_all_in_and_not_in_list (tl list1) list2 -> [inList notInList] in if is_in_list list2 elt then [elt::inList notInList] else [inList elt::notInList] ;; fun fit_list (list, nb) = if list == nil || nb <= 0 then nil else (hd list)::(fit_list tl list (nb-1)) ;; /* MAT ICI : ajouter une inversion si sizeof list1 > sizeof list2 ??? */ fun intersection_list (list1, list2) = if list1 == nil then nil else let list1 -> [first next] in if is_in_list first list2 then first::intersection_list next list2 else intersection_list next list2 ;; fun intersection_lists (lists) = let lists -> [list1 [list2 next]] in if list2 == nil then list1 else intersection_lists (intersection_list list1 list2)::next ;; fun lineBuildSeparator (Slist, separator) = if (tl Slist) == nil then (hd Slist) else strcatn (hd Slist)::separator::(lineBuildSeparator tl Slist separator)::nil ;; fun getPathFile (longfile, file)= if (longfile==nil) || (strlen longfile)==0 || (nth_char longfile ((strlen longfile)-1)) == '/ then [longfile file] else getPathFile substr longfile 0 (strlen longfile)-1 strcat substr longfile ((strlen longfile)-1) 1 file;; /* manage relativ paths (relativ files should start with ./ */ fun _RelativePathList(path,l)= if l==nil then nil else let l->[n nxt] in (if !strcmp substr n 0 2 "./" then strcat path substr n 2 strlen n else n)::_RelativePathList path nxt;; /* manage relativ paths (relativ files should start with ./ */ fun _RelativePath (path, str) = if !strcmp substr str 0 2 "./" then strcat path substr str 2 strlen str else str;; fun apply_on_list_with_return (list, func, param) = if list == nil then nil else let exec func with [(hd list) param] -> result in if result == nil then apply_on_list_with_return (tl list) func param else result::(apply_on_list_with_return (tl list) func param) ;; fun insert_in_list (list, func, dat) = if list == nil then dat::nil else let list -> [cur next] in let exec func with [cur dat] -> result in if result == 0 then /* same data -> replacing */ dat::next else if result < 0 then cur::(insert_in_list next func dat) else dat::list ;; /*********** QUICKSORT *************/ fun dividelist_doublon(x,p,r1,r2,f)= if p==nil then [r1 r2] else let p->[a n] in let exec f with [a x] -> r in if r==0 then dividelist_doublon x n r1 a::r2 f else if r<0 then dividelist_doublon x n a::r1 r2 f else dividelist_doublon x n r1 a::r2 f ;; fun quicksort_doublon(l,f)= if l==nil then nil else let l->[vl nl] in let dividelist_doublon vl nl nil nil f -> [va na] in conc quicksort_doublon va f vl::quicksort_doublon na f ;; fun get_doublon_from_sorted_list (l, f, previous) = if l == nil then nil else let l -> [cur next] in if previous == nil then get_doublon_from_sorted_list next f cur else if (exec f with [previous cur]) == 0 then cur::(get_doublon_from_sorted_list next f cur) else get_doublon_from_sorted_list next f cur ;;