1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)(** Minisys regroups some code that used to be in System.
Unlike System, this module has no dependency and could
be used for initial compilation target such as coqdep_boot.
The functions here are still available in System thanks to
an include. For the signature, look at the top of system.mli
*)(** Dealing with directories *)typeunix_path=string(* path in unix-style, with '/' separator *)typefile_kind=|FileDirofunix_path*(* basename of path: *)string|FileRegularofstring(* basename of file *)(* Copy of Filename.concat but assuming paths to always be POSIX *)let(//)dirnamefilename=letl=String.lengthdirnameinifl=0||dirname.[l-1]='/'thendirname^filenameelsedirname^"/"^filename(* Excluding directories; We avoid directories starting with . as well
as CVS and _darcs and any subdirs given via -exclude-dir *)letskipped_dirnames=ref["CVS";"_darcs"]letexclude_directoryf=skipped_dirnames:=f::!skipped_dirnames(* Note: this test is possibly used for Coq module/file names but also for
OCaml filenames, whose syntax as of today is more restrictive for
module names (only initial letter then letter, digits, _ or quote),
but more permissive (though disadvised) for file names *)letok_dirnamef=not(f="")&&f.[0]!='.'&¬(List.memf!skipped_dirnames)&&matchUnicode.ident_refutationfwithNone->true|_->false(* Check directory can be opened *)letexists_dirdir=(* See BZ#5391 on windows failing on a trailing (back)slash *)letrecstrip_trailing_slashdir=letlen=String.lengthdiriniflen>0&&(dir.[len-1]='/'||dir.[len-1]='\\')thenstrip_trailing_slash(String.subdir0(len-1))elsedirinletdir=ifSys.os_type="Win32"thenstrip_trailing_slashdirelsedirintrySys.is_directorydirwithSys_error_->falseletapply_subdirfpathname=(* we avoid all files and subdirs starting by '.' (e.g. .svn) *)(* as well as skipped files like CVS, ... *)letbase=tryFilename.chop_extensionnamewithInvalid_argument_->nameinifok_dirnamebasethenletpath=ifpath="."thennameelsepath//nameinmatchtry(Unix.statpath).Unix.st_kindwithUnix.Unix_error_->Unix.S_BLKwith|Unix.S_DIRwhenname=base->f(FileDir(path,name))|Unix.S_REG->f(FileRegularname)|_->()letreaddirdir=trySys.readdirdirwithany->[||]letprocess_directoryfpath=Array.iter(apply_subdirfpath)(readdirpath)letprocess_subdirectoriesfpath=letf=functionFileDir(path,base)->fpathbase|FileRegular_->()inprocess_directoryfpath