text stringlengths 12 786k |
|---|
let time2ml str = assert ( String . length str = 8 ) ; let hour = sub 0 2 str in let minute = sub 3 2 str in let second = sub 6 2 str in ( hour , minute , second ) |
let year2ml str = assert ( String . length str = 4 ) ; sub 0 4 str |
let timestamp2ml str = assert ( String . length str = 14 ) ; let year = sub 0 4 str in let month = sub 4 2 str in let day = sub 6 2 str in let hour = sub 8 2 str in let minute = sub 10 2 str in let second = sub 12 2 str in ( year , month , day , hour , minute , second ) |
let opt f arg = match arg with | None -> None | Some x -> Some ( f x ) |
let not_null f arg = match arg with | None -> fail " not_null was applied to None " | Some x -> f x |
let names result = Array . init ( fields result ) ~ f ( : function offset -> match fetch_field_dir result offset with | Some field -> field . name | None -> " " ) |
let types result = Array . init ( fields result ) ~ f ( : function offset -> match fetch_field_dir result offset with | Some field -> field . ty | None -> ( fail " Unknown type in field " ) ) |
let column result = let names = names result in let map = match Array . length names with | 0 -> StrMap . empty | n -> let rec loop i map = if i = n then map else loop ( i + 1 ) ( StrMap . add ~ key : names . ( i ) ~ data : i map ) in loop 0 StrMap . empty in let col ~ key ~ row... |
let ml2str str = " ' " ^ escape str ^ " ' " |
let ml2rstr conn str = " ' " ^ real_escape conn str ^ " ' " |
let ml2int x = string_of_int x |
let ml2decimal x = x |
let ml322int x = Int32 . to_string x |
let ml642int x = Int64 . to_string x |
let mlnative2int x = Nativeint . to_string x |
let ml2float x = string_of_float x |
let ml2enum x = escape x |
let ml2renum x = real_escape x |
let ml2set_filter f x = let rec loop f = function | [ ] -> " " | [ x ] -> f x | x :: y :: ys -> f x ^ " , " ^ loop f ( y :: ys ) in loop f x |
let ml2set x = ml2set_filter escape x |
let ml2rset conn x = ml2set_filter ( real_escape conn ) x |
let ml2datetimel ~ year ~ month ~ day ~ hour ~ min ~ sec = Printf . sprintf " ' % 04d -% 02d -% 02d % 02d :% 02d :% 02d ' " year month day hour min sec |
let ml2datetime ( year , month , day , hour , min , sec ) = ml2datetimel ~ year ~ month ~ day ~ hour ~ min ~ sec |
let ml2datel ~ year ~ month ~ day = Printf . sprintf " % 04d -% 02d -% 02d " year month day |
let ml2date ( year , month , day ) = ml2datel ~ year ~ month ~ day |
let ml2timel ~ hour ~ min ~ sec = Printf . sprintf " % 02d :% 02d % 02d " hour min sec |
let ml2time ( hour , min , sec ) = ml2timel ~ hour ~ min ~ sec |
let ml2year yyyy = Printf . sprintf " % 04d " yyyy |
let ml2timestampl ~ year ~ month ~ day ~ hour ~ min ~ sec = Printf . sprintf " % 04d % 02d % 02d % 02d % 02d % 02d " year month day hour min sec |
let ml2timestamp ( year , month , day , hour , min , sec ) = ml2timestampl ~ year ~ month ~ day ~ hour ~ min ~ sec |
let values vs = let rec loop arg = match arg with | [ ] -> " " | [ x ] -> x | x :: y :: ys -> x ^ " , " ^ loop ( y :: ys ) in " ( " ^ loop vs ^ " ) " |
let iter res ~ f = if size res > Int64 . zero then let rec loop ( ) = match fetch res with | Some row -> f row ; loop ( ) | None -> ( ) in to_row res Int64 . zero ; loop ( ) |
let iter_col res ~ key ~ f = let col = column res ~ key in iter res ~ f ( : function row -> f ( col ~ row ) ) |
let iter_cols res ~ key ~ f = let col = column res in iter res ~ f ( : function row -> f ( Array . map key ~ f ( : function key -> col ~ key ~ row ) ) ) |
let map res ~ f = if size res > Int64 . zero then let rec loop lst = match fetch res with | Some row -> loop ( f row :: lst ) | None -> lst in to_row res Int64 . zero ; List . rev ( loop [ ] ) else [ ] |
let map_col res ~ key ~ f = let col = column res ~ key in map res ~ f ( : function row -> f ( col ~ row ) ) |
let map_cols res ~ key ~ f = let col = column res in map res ~ f ( : function row -> f ( Array . map key ~ f ( : function key -> col ~ key ~ row ) ) ) |
let top = opentk ( ) |
let scroll_link sb tx = Text . configure tx [ YScrollCommand ( Scrollbar . set sb ) ] ; Scrollbar . configure sb [ ScrollCommand ( Text . yview tx ) ] |
let f = Frame . create top [ ] |
let text = Text . create f [ ] |
let scrollbar = Scrollbar . create f [ ] |
let buffer = ref " " |
let insertMark = TextIndex ( Mark " insert " , [ ] ) |
let eol_insertMark = TextIndex ( Mark " insert " , [ LineEnd ] ) |
let kill ( ) = buffer := Text . get text insertMark eol_insertMark ; prerr_endline ( " Killed : " ^ ! buffer ) ; Text . delete text insertMark eol_insertMark ; ; |
let yank ( ) = Text . insert text insertMark ! buffer [ ] ; prerr_endline ( " Yanked : " ^ ! buffer ) ; ; |
let _ = scroll_link scrollbar text ; pack [ text ; scrollbar ] [ Side Side_Left ; Fill Fill_Y ] ; pack [ f ] [ ] ; bind text [ [ Control ] , KeyPressDetail " y " ] ( BindSet ( [ ] , fun _ -> yank ( ) ) ) ; bind text [ [ Control ] , KeyPressDetail "... |
module Outcome = struct type ( ' a , ' b ) t = | Good of ' a | Bad of ' b let ignore_good = function | Good _ -> ( ) | Bad e -> raise e let good = function | Good x -> x | Bad exn -> raise exn let wrap f x = try Good ( f x ) with e -> Bad e end |
let opt_print elt ppf = function | Some x -> fprintf ppf " [ @< 2 > Some @ % a ] " @ elt x | None -> pp_print_string ppf " None " |
let ksbprintf g fmt = let buff = Buffer . create 42 in let f = formatter_of_buffer buff in kfprintf ( fun f -> ( pp_print_flush f ( ) ; g ( Buffer . contents buff ) ) ) f fmt |
let sbprintf fmt = ksbprintf ( fun x -> x ) fmt |
module Set = struct module type OrderedTypePrintable = sig include Set . OrderedType val print : formatter -> t -> unit end module type S = sig include Set . S val find : ( elt -> bool ) -> t -> elt val map : ( elt -> elt ) -> t -> t val of_list : elt list -> t val print : formatter -> t ... |
module List = struct include List let print pp_elt f ls = fprintf f " [ @< 2 [ >@ " ; let _ = fold_left begin fun first elt -> if not first then fprintf f " ; @ " ; pp_elt f elt ; false end true ls in fprintf f " @ ] ] " @ let filter_opt f xs = List . fold_right begin fun x acc... |
module String = struct include String let print f s = fprintf f " % S " s let chomp s = let is_nl_char = function ' \ n ' | ' \ r ' -> true | _ -> false in let rec cut n = if n = 0 then 0 else if is_nl_char s . [ n - 1 ] then cut ( n - 1 ) else n in let ls = length s in let n ... |
let sys_readdir , reset_readdir_cache , reset_readdir_cache_for = let cache = Hashtbl . create 103 in let sys_readdir dir = try Hashtbl . find cache dir with Not_found -> let res = Outcome . wrap Sys . readdir dir in ( Hashtbl . add cache dir res ; res ) and reset_readdir_cache ( ) = Hash... |
let sys_file_exists x = let dirname = Filename . dirname x in let basename = Filename . basename x in match sys_readdir dirname with | Outcome . Bad _ -> false | Outcome . Good a -> if basename = Filename . current_dir_name then true else try Array . iter ( fun x -> if x = basename then raise E... |
let sys_command = match Sys . os_type with | " Win32 " -> fun cmd -> if cmd = " " then 0 else let cmd = " bash - c " ^ Filename . quote cmd in let cmd = String . subst " " " " " " \&\\&\ " " && cmd in Sys . command cmd | _ -> fun cmd -> if cmd = " " then 0 else ... |
let filename_concat x y = if x = Filename . current_dir_name || x = " " then y else if x . [ String . length x - 1 ] = ' ' / then if y = " " then x else x ^ y else x ^ " " / ^ y |
let invalid_arg ' fmt = ksbprintf invalid_arg fmt |
let the = function Some x -> x | None -> invalid_arg " the : expect Some not None " |
let getenv ? default var = try Sys . getenv var with Not_found -> match default with | Some x -> x | None -> failwith ( sprintf " This command must have % S in his environment " var ) ; ; |
let with_input_file ( ? bin = false ) x f = let ic = ( if bin then open_in_bin else open_in ) x in try let res = f ic in close_in ic ; res with e -> ( close_in ic ; raise e ) |
let with_output_file ( ? bin = false ) x f = reset_readdir_cache_for ( Filename . dirname x ) ; let oc = ( if bin then open_out_bin else open_out ) x in try let res = f oc in close_out oc ; res with e -> ( close_out oc ; raise e ) |
let read_file x = with_input_file ~ bin : true x begin fun ic -> let len = in_channel_length ic in let buf = String . create len in let ( ) = really_input ic buf 0 len in buf end |
let copy_chan ic oc = let m = in_channel_length ic in let m = ( m lsr 12 ) lsl 12 in let m = max 16384 ( min Sys . max_string_length m ) in let buf = String . create m in let rec loop ( ) = let len = input ic buf 0 m in if len > 0 then begin output oc buf 0 len ; loop ( ) end in loop... |
let copy_file src dest = reset_readdir_cache_for ( Filename . dirname dest ) ; with_input_file ~ bin : true src begin fun ic -> with_output_file ~ bin : true dest begin fun oc -> copy_chan ic oc end end |
let ( !* ) = Lazy . force |
let ( @:= ) ref list = ref := ! ref @ list |
let ( & ) f x = f x |
let ( |> ) x f = f x |
let print_string_list = List . print String . print |
module Digest = struct include Digest let digest_cache = Hashtbl . create 103 let reset_digest_cache ( ) = Hashtbl . clear digest_cache let reset_digest_cache_for file = Hashtbl . remove digest_cache file let file f = try Hashtbl . find digest_cache f with Not_found -> let res = file f in ( Hashtb... |
let reset_filesys_cache ( ) = Digest . reset_digest_cache ( ) ; reset_readdir_cache ( ) |
let reset_filesys_cache_for_file file = Digest . reset_digest_cache_for file ; reset_readdir_cache_for ( Filename . dirname file ) |
let sys_remove x = reset_filesys_cache_for_file x ; Sys . remove x |
let with_temp_file pre suf fct = let tmp = Filename . temp_file pre suf in try let res = fct tmp in Sys . remove tmp ; res with e -> ( Sys . remove tmp ; raise e ) |
let memo f = let cache = Hashtbl . create 103 in fun x -> try Hashtbl . find cache x with Not_found -> let res = f x in ( Hashtbl . add cache x res ; res ) |
type stats = { stat_file_kind : file_kind ; stat_key : string } |
type implem = { mutable is_degraded : bool ; mutable is_link : string -> bool ; mutable run_and_open : ' a . string -> ( in_channel -> ' a ) -> ' a ; mutable readlink : string -> string ; mutable execute_many : ? max_jobs : int -> ? ticker ( : unit -> unit ) -> ? period : f... |
let stat f = { stat_key = f ; stat_file_kind = if sys_file_exists f then if Sys . is_directory f then FK_dir else FK_file else let _ = with_input_file f input_char in assert false } |
let run_and_open s kont = with_temp_file " ocamlbuild " " out " begin fun tmp -> let s = Printf . sprintf " % s > ' % s ' " s tmp in let st = sys_command s in if st <> 0 then failwith ( Printf . sprintf " Error while running : % s " s ) ; with_input_file tmp kont end |
let readlinkcmd = let cache = Hashtbl . create 32 in fun x -> try Hashtbl . find cache x with Not_found -> run_and_open ( Printf . sprintf " readlink % s " ( Filename . quote x ) ) begin fun ic -> let y = String . chomp ( input_line ic ) in Hashtbl . replace cache x y ; y end |
let rec readlink x = if sys_file_exists x then try let y = readlinkcmd x in if ( lstat y ) . stat_file_kind = FK_dir then raise Link_to_directories_not_supported else y with Failure ( _ ) -> raise Not_a_link else raise No_such_file try ignore ( readlink x ) ; true with | No_such_file | Not_a_link... |
let implem = { is_degraded = true ; stat = stat ; lstat = lstat ; readlink = readlink ; is_link = is_link ; run_and_open = run_and_open ; at_exit_once = at_exit ; report_error = ( fun _ -> raise ) ; gettimeofday = ( fun ( ) -> assert false ) ; stdout_isatty = ( fun ( ) ... |
let is_degraded = lazy implem . is_degraded |
let stat x = implem . stat x |
let lstat x = implem . lstat x |
let readlink x = implem . readlink x |
let is_link x = implem . is_link x |
let run_and_open x = implem . run_and_open x |
let at_exit_once x = implem . at_exit_once x |
let report_error x = implem . report_error x |
let gettimeofday x = implem . gettimeofday x |
let stdout_isatty x = implem . stdout_isatty x |
let execute_many ? max_jobs = implem . execute_many ? max_jobs |
let run_and_read cmd = let bufsiz = 2048 in let buf = String . create bufsiz in let totalbuf = Buffer . create 4096 in implem . run_and_open cmd begin fun ic -> let rec loop pos = let len = input ic buf 0 bufsiz in if len > 0 then begin Buffer . add_substring totalbuf buf 0 len ; loop ( pos + ... |
let is_var t = pattern_match t ~ var ( : fun _ -> true ) ~ symbol ( : fun _ -> false ) |
let is_symbol t = pattern_match t ~ var ( : fun _ -> false ) ~ symbol ( : fun _ -> true ) |
let to_var t = pattern_match t ~ var ( : fun var -> Some var ) ~ symbol ( : fun _ -> None ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.