text
stringlengths
12
786k
let compare_binary_files bytes_to_ignore file1 file2 = Sys . with_input_file ~ bin : true file1 @@ fun ic1 -> Sys . with_input_file ~ bin : true file2 @@ fun ic2 -> seek_in ic1 bytes_to_ignore ; seek_in ic2 bytes_to_ignore ; let rec compare ( ) = let block1 = really_input_up_to ic1 in let block2 ...
let compare_files ( ? tool = default_comparison_tool ) files = match tool with | External { tool_name ; tool_flags ; result_of_exitcode } -> let commandline = String . concat " " [ tool_name ; tool_flags ; files . reference_filename ; files . output_filename ] in let settings = Ru...
let check_file ( ? tool = default_comparison_tool ) files = if Sys . file_exists files . reference_filename then compare_files ~ tool : tool files else begin if Sys . file_is_empty files . output_filename then Same else Unexpected_output end
let diff files = let temporary_file = Filename . temp_file " ocamltest " " diff " in let diff_commandline = Filename . quote_command " diff " ~ stdout : temporary_file [ " -- strip - trailing - cr " ; " - u " ; files . reference_filename ; files . output_filename ] in let ...
let promote { filetype ; reference_filename ; output_filename } ignore_conf = match filetype , ignore_conf with | Text , { lines = skip_lines ; _ } -> Sys . with_output_file reference_filename @@ fun reference -> Sys . with_input_file output_filename @@ fun output -> for _ = 1 to skip_...
= " camltk_add_file_input " = " camltk_rem_file_input " = " camltk_add_file_output " = " camltk_rem_file_output "
let fd_table = Hashtbl . create 37
let add_fileinput ~ fd ~ callback : f = let id = new_function_id ( ) in Hashtbl . add callback_naming_table id ( fun _ -> f ( ) ) ; Hashtbl . add fd_table ( fd , ' r ' ) id ; if ! Protocol . debug then begin Protocol . prerr_cbid id ; prerr_endline " for fileinput " end ;...
let remove_fileinput ~ fd = try let id = Hashtbl . find fd_table ( fd , ' r ' ) in clear_callback id ; Hashtbl . remove fd_table ( fd , ' r ' ) ; if ! Protocol . debug then begin prerr_string " clear " ; Protocol . prerr_cbid id ; prerr_endline " for fileinput " end ; r...
let add_fileoutput ~ fd ~ callback : f = let id = new_function_id ( ) in Hashtbl . add callback_naming_table id ( fun _ -> f ( ) ) ; Hashtbl . add fd_table ( fd , ' w ' ) id ; if ! Protocol . debug then begin Protocol . prerr_cbid id ; prerr_endline " for fileoutput " end...
let remove_fileoutput ~ fd = try let id = Hashtbl . find fd_table ( fd , ' w ' ) in clear_callback id ; Hashtbl . remove fd_table ( fd , ' w ' ) ; if ! Protocol . debug then begin prerr_string " clear " ; Protocol . prerr_cbid id ; prerr_endline " for fileoutput " end ; ...
type descr = { interface_only : string list ; interface : string list ; internal : string list }
let server = { interface_only = [ " eliom_content_sigs " ; " eliom_form_sigs " ; " eliom_parameter_sigs " ; " eliom_registration_sigs " ; " eliom_service_sigs " ; " eliom_shared_sigs " ] ; interface = [ " eliom_bus " ; " eliom_client_value " ; " eliom_syntax ...
let client = { interface_only = [ " eliom_content_sigs " ; " eliom_form_sigs " ; " eliom_parameter_sigs " ; " eliom_registration_sigs " ; " eliom_service_sigs " ; " eliom_shared_sigs " ] ; interface = [ " eliom_bus " ; " eliom_client_value " ; " eliom_client_...
let server_ext = { interface_only = [ ] ; interface = [ " atom_feed " ; " eliom_atom " ; " eliom_openid " ; " eliom_s2s " ] ; internal = [ ] }
let ocamlbuild = { interface_only = [ ] ; interface = [ " ocamlbuild_eliom " ] ; internal = [ ] }
let ppx = { interface_only = [ ] ; interface = [ " ppx_eliom " ; " ppx_eliom_client " ; " ppx_eliom_type " ; " ppx_eliom_server " ] ; internal = [ " ppx_eliom_utils " ] }
let ( . -- ) name ext = name ^ " . " ^ ext
let exts el sl = List . flatten ( List . map ( fun ext -> List . map ( fun name -> name . -- ext ) sl ) el )
let list_to_file filename list = let oc = open_out filename in List . iter ( fun s -> output_string oc s ; output_char oc ' \ n ' ) list ; close_out oc
let client_mllib = client . interface @ client . internal
let client_extra = exts [ " cmi " ] ( client . interface_only @ client . interface )
let client_api = client . interface_only @ client . interface
let server_mllib = server . interface @ server . internal
let server_extra = exts [ " cmi " ] ( server . interface_only @ server . interface ) @ exts [ " cmx " ] ( server . interface @ server . internal )
let server_api = server . interface_only @ server . interface
let server_ext_mllib = server_ext . interface @ server_ext . internal
let server_ext_extra = exts [ " cmi " ] ( server_ext . interface_only @ server_ext . interface ) @ exts [ " cmx " ] ( server_ext . interface @ server_ext . internal )
let ocamlbuild_mllib = ocamlbuild . interface @ ocamlbuild . internal
let ocamlbuild_extra = exts [ " cmi " ] ( ocamlbuild . interface_only @ ocamlbuild . interface ) @ exts [ " cmx " ] ( ocamlbuild . interface @ ocamlbuild . internal )
let ocamlbuild_api = ocamlbuild . interface_only @ ocamlbuild . interface
let ppx_mllib = ppx . interface @ ppx . internal
let ppx_extra = exts [ " cmi " ] ppx . interface @ exts [ " cmx " ] ( ppx . interface @ ppx . internal )
let templates = Array . to_list ( Sys . readdir templates_dir )
let templates_files = List . map ( fun name -> name , Array . to_list ( Sys . readdir ( templates_dir ^ " " / ^ name ) ) ) templates
let map_file path = let fd = Unix . openfile path [ Unix . O_RDONLY ] 0o444 in let stat = Unix . fstat fd in let size = stat . Unix . st_size in let m = Array1 . map_file fd char c_layout false size in Unix . close fd ; m , size
let map_writable path = let fd = Unix . openfile path [ Unix . O_RDWR ] 0o666 in let stat = Unix . fstat fd in let size = stat . Unix . st_size in let m = Array1 . map_file fd char c_layout true size in m , size , fd
let get_char map pos = Bigarray . Array1 . get map pos
let set_char map pos value = Bigarray . Array1 . set map pos value
let generic_quote quotequote s = let l = String . length s in let b = Buffer . create ( l + 20 ) in Buffer . add_char b ' ' ' ; \ for i = 0 to l - 1 do if s . [ i ] = ' ' ' \ then Buffer . add_string b quotequote else Buffer . add_char b s . [ i ] done ; Buffer . ...
let generic_basename is_dir_sep current_dir_name name = let rec find_end n = if n < 0 then String . sub name 0 1 else if is_dir_sep name n then find_end ( n - 1 ) else find_beg n ( n + 1 ) and find_beg n p = if n < 0 then String . sub name 0 p else if is_dir_sep name n then String . sub name...
let generic_dirname is_dir_sep current_dir_name name = let rec trailing_sep n = if n < 0 then String . sub name 0 1 else if is_dir_sep name n then trailing_sep ( n - 1 ) else base n and base n = if n < 0 then current_dir_name else if is_dir_sep name n then intermediate_sep n else base ( n - 1 ) a...
module type SYSDEPS = sig val null : string val current_dir_name : string val parent_dir_name : string val dir_sep : string val is_dir_sep : string -> int -> bool val is_relative : string -> bool val is_implicit : string -> bool val check_suffix : string -> string -> bool val chop_suffix_opt : suffix :...
module Unix : SYSDEPS = struct let null = " / dev / null " let current_dir_name = " . " let parent_dir_name = " . . " let dir_sep = " " / let is_dir_sep s i = s . [ i ] = ' ' / let is_relative n = String . length n < 1 || n . [ 0 ] <> ' ' / let is_implicit ...
module Win32 : SYSDEPS = struct let null = " NUL " let current_dir_name = " . " let parent_dir_name = " . . " let dir_sep = " " \\ let is_dir_sep s i = let c = s . [ i ] in c = ' ' / || c = ' ' \\ || c = ' ' : let is_relative n = ( String . length n < 1 |...
module Cygwin : SYSDEPS = struct let null = " / dev / null " let current_dir_name = " . " let parent_dir_name = " . . " let dir_sep = " " / let is_dir_sep = Win32 . is_dir_sep let is_relative = Win32 . is_relative let is_implicit = Win32 . is_implicit let check_suffix = Win32 . ...
module Sysdeps = ( val ( match Sys . os_type with | " Win32 " -> ( module Win32 : SYSDEPS ) | " Cygwin " -> ( module Cygwin : SYSDEPS ) | _ -> ( module Unix : SYSDEPS ) ) )
let concat dirname filename = let l = String . length dirname in if l = 0 || is_dir_sep dirname ( l - 1 ) then dirname ^ filename else dirname ^ dir_sep ^ filename
let chop_suffix name suff = let n = String . length name - String . length suff in if n < 0 then invalid_arg " Filename . chop_suffix " else String . sub name 0 n
let extension_len name = let rec check i0 i = if i < 0 || is_dir_sep name i then 0 else if name . [ i ] = ' . ' then check i0 ( i - 1 ) else String . length name - i0 in let rec search_dot i = if i < 0 || is_dir_sep name i then 0 else if name . [ i ] = ' . ' then check i ( ...
let extension name = let l = extension_len name in if l = 0 then " " else String . sub name ( String . length name - l ) l
let chop_extension name = let l = extension_len name in if l = 0 then invalid_arg " Filename . chop_extension " else String . sub name 0 ( String . length name - l )
let remove_extension name = let l = extension_len name in if l = 0 then name else String . sub name 0 ( String . length name - l )
let prng = lazy ( Random . State . make_self_init ( ) )
let temp_file_name temp_dir prefix suffix = let rnd = ( Random . State . bits ( Lazy . force prng ) ) land 0xFFFFFF in concat temp_dir ( Printf . sprintf " % s % 06x % s " prefix rnd suffix )
let current_temp_dir_name = ref temp_dir_name
let set_temp_dir_name s = current_temp_dir_name := s
let get_temp_dir_name ( ) = ! current_temp_dir_name
let temp_file ( ? temp_dir = ! current_temp_dir_name ) prefix suffix = let rec try_name counter = let name = temp_file_name temp_dir prefix suffix in try close_desc ( open_desc name [ Open_wronly ; Open_creat ; Open_excl ] 0o600 ) ; name with Sys_error _ as e -> if counter >= 1000 then rais...
let open_temp_file ( ? mode = [ Open_text ] ) ( ? perms = 0o600 ) ( ? temp_dir = ! current_temp_dir_name ) prefix suffix = let rec try_name counter = let name = temp_file_name temp_dir prefix suffix in try ( name , open_out_gen ( Open_wronly :: Open_creat :: Open_excl :: mode ) per...
let cvs = Canvas . create win [ ] ; ;
let t = Label . create cvs [ Text " File name " ] ; ;
let b = Button . create cvs [ Text " Save " ; Command ( function _ -> let s = getSaveFile [ Title " SAVE FILE TEST " ; DefaultExtension " . foo " ; FileTypes [ { typename = " just test " ; extensions = [ " . foo " ; " . test " ] ; mactypes = [ " FOOO ...
let bb = Button . create cvs [ Text " Open " ; Command ( function _ -> let s = getOpenFile [ ] in Label . configure t [ Text s ] ) ] ; ;
let q = Button . create cvs [ Text " Quit " ; Command ( function _ -> closeTk ( ) ; exit 0 ) ] ; ;
type filepath = { absolute : bool ; filepath : string list }
type filename = { filename : string }
let is_absolute fp = fp . absolute
let emptyFn = { filename = " " }
let currentDir = { absolute = false ; filepath = [ ] }
let fp_to_string x = match x . filepath , x . absolute with | ( [ ] , true ) -> " " / | ( [ ] , false ) -> " . " / | ( l , true ) -> " " / ^ String . concat Filename . dir_sep l | ( l , false ) -> String . concat Filename . dir_sep l
let fn_to_string x = x . filename
let got_dirsep x = let gotDirsep = ref false in let dirsepLen = String . length ( Filename . dir_sep ) in for i = 0 to String . length x - dirsepLen - 1 do if String . sub x i dirsepLen = Filename . dir_sep then gotDirsep := true done ; ! gotDirsep
let fp x = match string_split Filename . dir_sep . [ 0 ] x with | " " :: p -> { absolute = true ; filepath = List . filter ( fun x -> x <> " . " && x <> " " ) p } | p -> { absolute = false ; filepath = List . filter ( fun x -> x <> " . " && x <> " " ...
let fn = function | " " | " . " | " . . " -> raise EmptyFilename | filename when got_dirsep filename -> raise ( InvalidFilename filename ) | filename -> { filename }
let valid_fn x = try let _ = fn x in true with _ -> false
let ( ) <//> ( afp : filepath ) ( bfp : filepath ) = match ( afp . absolute , bfp . absolute ) with | _ , true -> failwith " the second argument cannot be an absolute path " | _ -> { absolute = afp . absolute ; filepath = afp . filepath @ bfp . filepath }
let ( ) </> ( afp : filepath ) ( bfp : filename ) = { absolute = afp . absolute ; filepath = afp . filepath @ [ bfp . filename ] }
let ( . ) <> ( afp : filename ) ext = fn ( afp . filename ^ " . " ^ ext )
let with_optpath mdir ( filename : filename ) = let path = match mdir with | None -> currentDir | Some dir -> dir in path </> filename
let path_length path = List . length path . filepath
let path_dirname path = { path with filepath = list_init path . filepath }
let path_basename path = fn ( list_last path . filepath )
let path_parent path = path_dirname ( path_dirname path )
let in_current_dir ( x : filename ) = fp x . filename
let chop_extension ( x : filename ) = fn ( Filename . chop_extension ( fn_to_string x ) )
let global_dir = ref ( getcwd ( ) )
let scroll_link sb lb = Listbox . configure lb ~ yscrollcommand : ( Scrollbar . set sb ) ; Scrollbar . configure sb ~ command : ( Listbox . yview lb )
let bind_enter_focus w = bind w ~ events [ ` : Enter ] ~ action ( : fun _ -> Focus . set w ) ; ;
let myentry_create p ~ variable = let w = Entry . create p ~ relief : ` Sunken ~ textvariable : variable in bind_enter_focus w ; w
let subshell cmd = let r , w = pipe ( ) in match fork ( ) with 0 -> close r ; dup2 ~ src : w ~ dst : stdout ; execv ~ prog " :/ bin / sh " ~ args [ :| " / bin / sh " ; " - c " ; cmd ] | | id -> close w ; let rc = in_channel_of_descr r in let rec it l = match try ...
let dirget = regexp " ( [ [ ] ) ( . ) " ^\\^\\*?*/\\\\*\\
let parse_filter src = let s = global_replace ( regexp " " ) /+ " " / src in let s = global_replace ( regexp " . " ) /\\/ " " / s in let s = global_replace ( regexp " ( [ ] [ . ] [ ] [ ] [ . ] [ ] [ ] ) . . " ) \\^/\\|^\\/^/\\|^/^\\/\\|^...
let ls dir pattern = subshell ( " cd " ^ dir ^ " ; / bin / ls - ad " ^ pattern " ^ 2 >/ dev / null " )
let get_files_in_directory dir = let dirh = opendir dir in let rec get_them l = match try Some ( Unix . readdir dirh ) with _ -> None with | None -> Unix . closedir dirh ; l | Some x -> get_them ( x :: l ) in List . sort ~ cmp : compare ( get_them [ ] )
let rec get_directories_in_files path = List . filter ~ f ( : fun x -> try ( stat ( path ^ x ) ) . st_kind = S_DIR with _ -> false )
let remove_directories path = List . filter ~ f ( : fun x -> try ( stat ( path ^ x ) ) . st_kind <> S_DIR with _ -> false )
let add_completion lb action = let prefx = ref " " and maxi = ref 0 and current = ref 0 and lastevent = ref 0 in let rec move_forward ( ) = if Listbox . get lb ~ index ( ` : Num ! current ) < ! prefx then if ! current < ! maxi then begin incr current ; move_forward ( ) end and rec...
let f ~ title ~ action : proc ~ filter : deffilter ~ file : deffile ~ multi ~ sync = let current_pattern = ref " " and current_dir = ref " " in let filter_init_completion = ref ( fun _ -> ( ) ) and directory_init_completion = ref ( fun _ -> ( ) ) in let tl = Toplevel . creat...
let removeDirContent wpath = let path = fp_to_string wpath in let rec rmdir_recursive f path = let dirhandle = Unix . opendir path in ( try while true do let ent = Unix . readdir dirhandle in if String . length ent > 0 && ent . [ 0 ] <> ' . ' then let fent = path ^ Filename . dir_sep ...