Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file indexMisc.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187(**************************************************************************)(* *)(* Copyright 2013 OCamlPro *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the Lesser GNU Public License version 3.0. *)(* *)(* This software is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* Lesser GNU General Public License for more details. *)(* *)(**************************************************************************)letdebug_enabled=trymatchSys.getenv"OCP_DEBUG"with""|"0"->false|_->truewithNot_found->falseletdebug=ifdebug_enabledthenfunfmt->Printf.eprintf("\027[36m"^^fmt^^"\027[m%!")elsefunfmt->Printf.ifprintfstderrfmtlettimer()=ifdebug_enabledthenlett=Sys.time()infun()->Sys.time()-.telsefun()->0.letrecfoldl_nextfacc=function|[]->acc|[x]->faccxNone|x1::(x2::_astl)->foldl_nextf(faccx1(Somex2))tltypekey=charlist(* Used as path separator in keys *)letdot=char_of_int0letdots=String.make1dotletstring_to_keys=letrecauxacci=ifi>=0thenletc=matchs.[i]with|'.'|'#'ascwheni>0->(matchs.[i-1]with'a'..'z'|'A'..'Z'|'0'..'9'->dot|_->c)|c->cinaux(c::acc)(i-1)elseaccinaux[](String.lengths-1)letkey_to_stringl=letrecauxn=function|[]->Bytes.createn|c::r->lets=aux(n+1)rinBytes.setsn(ifc=dotthen'.'elsec);sinlets=aux0linBytes.to_stringsletmodpath_to_key?(enddot=true)path=List.fold_right(funpacc->letacc=ifacc<>[]||enddotthendot::accelseaccinstring_to_keyp@acc)path[]letkey_to_modpathl=letrecauxacc1acc2=function|'\000'::r->aux[](acc1::acc2)r|c::r->aux(c::acc1)acc2r|[]->ifacc1=[]thenacc2elseacc1::acc2inList.rev_map(funl->key_to_string(List.revl))(aux[][]l)letmodpath_to_stringpath=String.concat"."pathletparent_typeid=matchid.IndexTypes.kindwith|Fieldparent|Variantparent|Methodparent->Someparent|Type|Value|Exception|Module|ModuleType|Class|OpenType|ClassType|Keyword->Noneletunique_subdirs?(skip=fun_->false)dir_list=letrecsubdirsaccpath=Array.fold_left(funaccp->ifskippthenaccelseletpath=Filename.concatpathpiniftrySys.is_directorypathwithSys_error_->falsethensubdirsaccpathelseacc)(path::acc)(Sys.readdirpath)inletremove_dupsl=letrecaux=function|a::(b::_asr)whena=b->auxr|a::r->a::auxr|[]->[]inaux(List.sortcomparel)inremove_dups(List.fold_leftsubdirs[]dir_list)(* - Project root finding - *)letbuild_roots=(* by increasing order of priority *)["_darcs";".hg";".git";"jengaroot.ml";"omakeroot";"_build";"_obuild"]letfind_build_dirpath=let(/)=Filename.concatinletfiles=Sys.readdirpathinlet_,root=letrecmemsuffixx=function|a::r->ifx=athenSomerelsememsuffixxr|[]->NoneinArray.fold_left(fun(roots,found)f->matchmemsuffixfrootswith|None->roots,found|Someroots->roots,Somef)(build_roots,None)filesinmatchrootwith|None->None|Some("_obuild"|"_build"asdir)->Some(path/dir)|Some_->Somepathletstring_splitcharstr=letrecauxpos=tryleti=String.index_fromstrposcharinString.substrpos(i-pos)::aux(succi)withNot_found|Invalid_argument_->letl=String.lengthstrin[String.substrpos(l-pos)]inaux0letmake_relative?(path=Sys.getcwd())file=ifFilename.is_relativefilethenfileelseletrecauxcwdfile=matchcwd,filewith|d1::cwd,d2::filewhend1=d2->auxcwdfile|cwd,file->List.fold_left(funfile_->Filename.parent_dir_name::file)filecwdinletsep=Filename.dir_sep.[0]inletd=aux(string_splitseppath)(string_splitsepfile)inifd=[]thenFilename.current_dir_nameelseString.concatFilename.dir_sepdletproject_root?(path=Sys.getcwd())()=let(/)=Filename.concatinlethome=trySys.getenv"HOME"withNot_found->""inletpath=ifFilename.is_relativepaththenSys.getcwd()/pathelsepathinletrecfindpath=ifpath=homethenNoneelsematchfind_build_dirpathwith|None->letparent=Filename.dirnamepathinifpath=parentthenNoneelsefindparent|Somebuild->Some(path,build)inmatchfindpathwith|None->None,None|Some(root,build)->Someroot,Somebuild