123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475(*
* BatFilename - Extended Filename module
* Copyright (C) 1996 Xavier Leroy
* 2008 David Teller, LIFO, Universite d'Orleans
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version,
* with the special exception on linking described in file LICENSE.
*
* This library 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)includeFilename##V<4.4##letis_dir_sepnamei=##V<4.4##try##V<4.4##forj=0toString.lengthdir_sep-1do##V<4.4##ifi+j>=String.lengthname||##V<4.4##name.[i+j]!=dir_sep.[j]thenraiseExit##V<4.4##done;##V<4.4##true##V<4.4##withExit->##V<4.4##false##V<4.4####V<4.4##letextension_lenname=##V<4.4##letrecchecki0i=##V<4.4##ifi<0||is_dir_sepnameithen0##V<4.4##elseifname.[i]='.'thenchecki0(i-1)##V<4.4##elseString.lengthname-i0##V<4.4##in##V<4.4##letrecsearch_doti=##V<4.4##ifi<0||is_dir_sepnameithen0##V<4.4##elseifname.[i]='.'thenchecki(i-1)##V<4.4##elsesearch_dot(i-1)##V<4.4##in##V<4.4##search_dot(String.lengthname-1)##V<4.4####V<4.4##letremove_extensionname=##V<4.4##letl=extension_lennamein##V<4.4##ifl=0thennameelseString.subname0(String.lengthname-l)##V<4.4####V<4.4##letextensionname=##V<4.4##letl=extension_lennamein##V<4.4##ifl=0then""elseString.subname(String.lengthname-l)lletsplit_extensions=remove_extensions,extensions(*$= split_extension & ~printer:(IO.to_string (Tuple2.print String.print String.print))
("/foo/bar", ".baz") (split_extension "/foo/bar.baz")
("/foo/bar", "") (split_extension "/foo/bar")
("/foo/bar", ".") (split_extension "/foo/bar.")
("/foo/.rc", "") (split_extension "/foo/.rc")
("", "") (split_extension "")
*)letwith_temp_file?temp_dirprfxsfxf=lettmp_fn=Filename.temp_file?temp_dirprfxsfxinBatPervasives.finally(fun()->Sys.removetmp_fn)ftmp_fn(* the temp file is expected to exist during f's lifetime, but not after *)(*$T with_temp_file
let fn = with_temp_file "batFilename_with_temp_file" ".tmp" \
(fun fn -> assert(Sys.file_exists fn); fn) in \
not (Sys.file_exists fn)
*)