text
stringlengths
0
601k
let get_anchor state = let i = get_int state in match i with | - 1 -> Left | 0 -> Center | 1 -> Right | _ -> raise ( ParseError " Cannot parse anchor " )
let parse_bytes st = skip_spaces st ; let n = get_int st in skip_spaces st ; if char st <> ' ' - then raise ( ParseError " Cannot parse bytes " ) else begin incr st ; get_n n st end
let parse_ellipse constr state = let pos = get_pos state in let w = get_float state in let h = get_float state in constr ( pos , w , h )
let invert_y_pos ( x , y ) = ( x , . - y )
let parse_filled_ellipse = parse_ellipse ( fun ( p , w , h ) -> Filled_ellipse ( invert_y_pos p , w , h ) )
let parse_unfilled_ellipse = parse_ellipse ( fun ( p , w , h ) -> Unfilled_ellipse ( invert_y_pos p , w , h ) )
let parse_points state = let n = get_int state in Array . init n ( fun _ -> invert_y_pos ( get_pos state ) )
let parse_filled_polygon state = Filled_polygon ( parse_points state )
let parse_unfilled_polygon state = Unfilled_polygon ( parse_points state )
let parse_polyline state = Polyline ( parse_points state )
let parse_bspline state = Bspline ( parse_points state )
let parse_filled_bspline state = Filled_bspline ( parse_points state )
let parse_text state = let pos = invert_y_pos ( get_pos state ) in let anchor = get_anchor state in let width = get_float state in let str = parse_bytes state in Text ( pos , anchor , width , str )
let parse_fill_color state = Fill_color ( normalize_color ( parse_bytes state ) )
let parse_pen_color state = Pen_color ( normalize_color ( parse_bytes state ) )
let parse_font state = let size = get_float state in let font = parse_bytes state in Font ( size , font )
let parse_style state = let read = function | " filled " -> Filled | " invisible " -> Invisible | " diagonals " -> Diagonals | " rounded " -> Rounded | " dashed " -> Dashed | " dotted " -> Dotted | " solid " -> Solid | " bold " -> Bold | s -> StyleString s in let str = parse_bytes state in Style ( List . map read ( spl...
let parse_operation state = let operation ( ) = match get_op_id state with | " E " -> parse_filled_ellipse state | " e " -> parse_unfilled_ellipse state | " P " -> parse_filled_polygon state | " p " -> parse_unfilled_polygon state | " L " -> parse_polyline state | " B " -> parse_bspline state | " b " -> parse_filled_bs...
let parse_with_state state = let rec loop ( ) = parse_operation state ; if over state then state . operations else loop ( ) in try List . rev ( loop ( ) ) with NoOperationId -> List . rev state . operations
let remove_backslashes s = let buf = Buffer . create 30 in let rec loop i = if i = String . length s then ( ) else if s . [ i ] = ' ' \\ && i < String . length s - 1 && s . [ i + 1 ] = ' \ n ' then loop ( i + 2 ) else begin Buffer . add_char buf s . [ i ] ; loop ( i + 1 ) end in loop 0 ; Buffer . contents buf
let parse s = parse_with_state ( mk_state ( remove_backslashes s ) )
let draw_with ( f : draw_state -> operation -> unit ) operations = let st = default_draw_state ( ) in let draw_op = function | Fill_color c as op -> set_fill_color st c ; f st op | Pen_color c as op -> set_pen_color st c ; f st op | Font ( sty , font ) as op -> set_font st ( sty , font ) ; f st op | Style stys as op ->...
let listen = let doc = " Act as a server rather than a client . " in Arg ( . value & flag & info [ " l " ; " listen ] " ~ doc ) doc
let domid = Arg ( . required & pos 0 ( some int ) int None & info ~ docv " : DOMID " ~ doc " : Domain id of the remote endpoint . " [ ] )
let port = let port = Vchan . Port . of_string , fun f p -> Format . fprintf f " % s " ( Vchan . Port . to_string p ) p in let port = Arg . conv port in Arg ( . required & pos 1 ( some port ) port None & info ~ docv " : PORT " ~ doc " : Port id ( unique to this client + server pair ) pair . Must only contain the follow...
let buffer_size = Arg ( . value & opt int 65536 & info ~ docv " : BUFFERSIZE " ~ doc " : Size in bytes of a buffer ( a total of 4 will be created ) created " [ " buffer - size " ] )
let sigint_t , sigint_u = Lwt . task ( )
let proxy buffer_size ( ic , oc ) oc ( stdin , stdout ) stdout = let a_buffer = Bytes . create buffer_size in let b_buffer = Bytes . create buffer_size in let rec proxy buffer a b = Lwt_io . read_into a buffer 0 buffer_size >>= function | 0 -> Lwt . fail End_of_file | n -> Lwt_io . write_from_exactly b buffer 0 n >>= f...
let client domid port buffer_size = open_client ~ domid ~ port ~ buffer_size ( ) >>= fun ( ic , oc ) oc -> Printf . fprintf stderr " Connected . \ n " ; %! proxy buffer_size ( ic , oc ) oc ( Lwt_io . stdin , Lwt_io . stdout ) stdout >>= fun ( ) -> Lwt_io . close ic >>= fun ( ) -> Lwt_io . close oc >>= fun ( ) -> Printf...
let server domid port buffer_size = open_server ~ domid ~ port ~ buffer_size ( ) >>= fun ( ic , oc ) oc -> Printf . fprintf stderr " Connected . \ n " ; %! proxy buffer_size ( ic , oc ) oc ( Lwt_io . stdin , Lwt_io . stdout ) stdout >>= fun ( ) -> Lwt_io . close ic >>= fun ( ) -> Lwt_io . close oc >>= fun ( ) -> Printf...
let node listen domid port buffer_size : unit = Lwt_main . run ( ( if listen then server else client ) client domid port buffer_size )
let cmd = let doc = " Establish vchan connections " in let man = [ ` S " DESCRIPTION " ; ` P " Establish a connection to a remote Xen domain and transfer data over stdin / stdout , in a similar way to ' nc ' " ; ` S " EXAMPLES " ; ` P " To listen to an incoming connection from domid 2 on port ' hello ' " ; : ` P " xenc...
let ( ) = let ( _ : Lwt_unix . signal_handler_id ) signal_handler_id = Lwt_unix . on_signal Sys . sigint ( fun ( _ : int ) int -> Lwt . wakeup_later sigint_u ( ) ; ) in match Term . eval cmd with ` Error _ -> exit 1 | _ -> exit 0
module Make ( MakeXs : Xs_client_lwt . S ) S = struct type t = { ring_ref : string ; event_channel : string ; } [ @@ deriving sexp ] sexp let write ~ client_domid ~ port t = Xs . make ( ) >>= fun c -> Xs ( . immediate c ( fun h -> read h " domid ) ) " >>= fun server_domid -> Xs ( . immediate c ( fun h -> getdomainpath ...
type ( ' a , ' b ) result = | Ok of ' a | Error of ' b
module type IO = sig include Cohttp . S . IO val close : ( ic * oc ) -> unit t val open_connection : Uri . t -> ( ( ic * oc ) , exn ) result t val sleep : float -> unit t val gettimeofday : unit -> float end
module Make ( IO : IO ) = struct open IO type ic = IO . ic type oc = IO . oc module Request = Cohttp . Request . Make ( IO ) module Response = Cohttp . Response . Make ( IO ) type t = { uri : Uri . t ; mutable io : ( ic * oc ) option ; } let make uri = { uri = uri ; io = None ; } let disconnect ( t : t ) = match t . io...
module IO = struct type ' a t = ' a Deferred . t let ( ) >>= = Deferred . ( ) >>= let return = Deferred . return type ic = ( unit -> unit Deferred . t ) * Reader . t type oc = ( unit -> unit Deferred . t ) * Writer . t type conn = unit let read_line ( _ , ic ) = Reader . read_line ic >>| function | ` Ok s -> Some s | `...
let exn_to_string = function | Api_errors . Server_error ( code , params ) -> Printf . sprintf " % s % s " code ( String . concat ~ sep " : " params ) | e -> Printf . sprintf " Caught unexpected exception : % s " ( Exn . to_string e )
let do_it uri string = let uri = Uri . of_string uri in let connection = M . make uri in let ( ) >>= = Deferred . ( ) >>= in Monitor . protect ( fun ( ) -> M . rpc connection string >>= function | Ok x -> return x | Error e -> eprintf " Caught : % s \ n " %! ( exn_to_string e ) ; Exn . reraise e " connection error " ) ...
let make ( ? timeout = 30 . ) uri call = let req = Xmlrpc . string_of_call call in do_it uri req >>| Xmlrpc . response_of_string
let make_json ( ? timeout = 30 . ) uri call = let req = Jsonrpc . string_of_call call in do_it uri req >>| Jsonrpc . response_of_string
module Client = Client . ClientF ( struct include Deferred let bind a f = bind a ~ f end )
module Lwt_unix_IO = struct type ' a t = ' a Lwt . t let ( ) >>= = Lwt . bind let return = Lwt . return let ( ) >> m n = m >>= fun _ -> n type ic = ( unit -> unit Lwt . t ) * Lwt_io . input_channel type oc = ( unit -> unit Lwt . t ) * Lwt_io . output_channel type conn = Lwt_unix . file_descr let read_line ( _ , ic ) = ...
let exn_to_string = function | Api_errors . Server_error ( code , params ) -> Printf . sprintf " % s % s " code ( String . concat " " params ) | e -> Printexc . to_string e
let do_it uri string = let uri = Uri . of_string uri in let connection = M . make uri in Lwt . finalize ( fun ( ) -> M . rpc connection string >>= fun result -> match result with | Ok x -> return x | Error e -> Printf . fprintf stderr " Caught : % s \ n " %! ( exn_to_string e ) ; fail e ) ( fun ( ) -> M . disconnect co...
let make ( ? timeout = 30 . ) uri call = let string = Xmlrpc . string_of_call call in do_it uri string >>= fun result -> Lwt . return ( Xmlrpc . response_of_string result )
let make_json ( ? timeout = 30 . ) uri call = let string = Jsonrpc . string_of_call call in do_it uri string >>= fun result -> Lwt . return ( Jsonrpc . response_of_string result )
type cf = [ ` Average | ` Min | ` Max ]
let string_of_cf = function | ` Average -> " AVERAGE " | ` Min -> " MIN " | ` Max -> " MAX "
let cf_of_string = function | " AVERAGE " -> ` Ok ` Average | " MIN " -> ` Ok ` Min | " MAX " -> ` Ok ` Max | x -> ` Error ( ` Msg ( Printf . sprintf " Unknown consolidation function : % s " x ) )
module Legend = struct type cls = [ ` VM | ` Host | ` Other of string ] type t = string * cf * cls * Uuidm . t let colon = Re . Str . regexp_string " " : let of_string x = match Re . Str . split_delim colon x with | cf :: cls :: uuid :: name :: [ ] -> begin match cf_of_string cf with | ` Error x -> ` Error x | ` Ok cf ...
type interval = [ | ` Seconds | ` Minute | ` Hour | ` Day | ` Other of int ]
let seconds_of_interval = function | ` Seconds -> 5 | ` Minute -> 60 | ` Hour -> 60 * 60 | ` Day -> 24 * 60 * 60 | ` Other x -> x
let rec archive_length_of_interval = function | ` Seconds -> 10 * 60 | ` Minute -> 2 * 60 * 60 | ` Hour -> 7 * 24 * 60 * 60 | ` Day -> 365 * 7 * 24 * 60 * 60 | ` Other x -> if x <= ( seconds_of_interval ` Seconds ) then ( archive_length_of_interval ` Seconds ) else if x <= ( seconds_of_interval ` Minute ) then ( archiv...
module Updates = struct let uri ~ host ~ authentication ~ start ( ? include_host = false ) ? interval ? cf ( ) = let ssl , scheme = match Uri . scheme host with | Some " https " -> true , " https " | Some " http " -> false , " http " | x -> failwith ( Printf . sprintf " Unknown scheme : % s " ( match x with None -> " N...
let ( |> ) a b = b a
let id x = x
module Fake_IO = struct type ' a t = T of ' a let return x = T x let ( ) >>= t f = match t with | T x -> f x let ( ) >> m n = m >>= fun _ -> n let rec iter f = function | [ ] -> return ( ) | x :: xs -> f x >>= fun ( ) -> ( iter f xs ) type ic = string Queue . t type oc = string Queue . t type conn = unit let read_line ...
let test_login_fail _ = let module M = Xen_api . Make ( Fake_IO ) in let open Fake_IO in let rpc req = let xml = Xmlrpc . string_of_call req in M . rpc ( M . make ( Uri . of_string " http :// 127 . 0 . 0 . 1 " ) ) / xml >>= function | Ok _ -> failwith " should have failed with No_response " | Error e -> raise e in time...
let test_login_success _ = let session_id = " OpaqueRef : 9e9cf047 - 76d7 - 9f3a - 62ca - cb7bacf5a4e1 " in let result = Printf . sprintf " < methodResponse >< params >< param >< value >< struct >< member >< name > Status </ name >< value > Success </ value ></ member >< member >< name > Value </ name >< value >% s </ ...
let _ = let verbose = ref false in Arg . parse [ " - verbose " , Arg . Unit ( fun _ -> verbose := true ) , " Run in verbose mode " ; ] ( fun x -> Printf . fprintf stderr " Ignoring argument : % s " x ) " Test xen - api protocol code " ; let suite = " xen - api " >::: [ " login_fail " >:: test_login_fail ; " login_succe...
type xexp = | Num of int | Var of string | Fn of string * xexp | App of xexp * xexp | If of xexp * xexp * xexp | Equal of xexp * xexp | Raise of xexp | Handle of xexp * int * xexp
type value = | N of int | B of bool | C of closure
type result = | Val of value | Exn of int
let emptyEnv = ( fun x -> raise ( RunError ( " unbound id : " ^ x ) ) )
let bind e x v = ( fun y -> if y = x then v else e y )
let getInt = function | N n -> n | _ -> raise ( TypeError " not an int " )
let getBool = function | B b -> b | _ -> raise ( TypeError " not a bool " )
let getClosure = function | C c -> c | _ -> raise ( TypeError " not a function " )
let rec eval env exp = match exp with | Num n -> Val ( N n ) | Var x -> Val ( env x ) | Fn ( x , e ) -> Val ( C ( x , e , env ) ) | App ( e1 , e2 ) -> ( match eval env e1 with | Val v1 -> let ( x , e_body , env ' ) = getClosure v1 in ( match eval env e2 with | Val v2 -> eval ( bind env ' x v2 ) e_body | Exn n -> Exn n ...
let run : xexp -> result = fun exp -> eval emptyEnv exp
let indent i = let rec iter = function | 0 -> ( ) | n -> ps " " ; iter ( n - 1 ) in nl ( ) ; iter i
let rec pp i exp = match exp with | Num n -> print_int n | Var s -> ps s | Fn ( x , e ) -> ps ( " fn " ^ x ^ " => " ) ; pp i e | App ( e , e ' ) -> ps " ( " ; pp i e ; ps " ) ( " ; pp i e ' ; ps " ) " | If ( e1 , e2 , e3 ) -> indent ( i + 1 ) ; ps " if " ; pp i e1 ; ps " then " ; indent ( i + 2 ) ; pp ( i + 2 ) e2 ; in...
let print = pp 0
let rec is_sugarless = function | Num _ | Var _ -> true | Fn ( _ , e ) -> is_sugarless e | App ( e1 , e2 ) | Equal ( e1 , e2 ) -> is_sugarless e1 && is_sugarless e2 | If ( e1 , e2 , e3 ) -> is_sugarless e1 && is_sugarless e2 && is_sugarless e3 | Raise _ | Handle _ -> false
type t = { po_content : po_content ; translated : SetString . t }
let translations = ref { po_content = empty_po ; translated = SetString . empty }
let default_textdomain = ref None
let current_file = ref " "
let add_translation loc singular plural_opt domain = let t = ! translations in let filepos = let start = loc . Location . loc_start in let fname = match start . Lexing . pos_fname with " " -> ! current_file | fname -> fname in ( fname , start . Lexing . pos_lnum ) in let translated = SetString . add singular t . transl...
let output_translations ? output_file t = let fd = match output_file with Some f -> open_out f | None -> stdout in set_binary_mode_out fd true ; Marshal . to_channel fd t . po_content [ ]
let rec is_like lid = function | [ ] -> false | func :: functions -> ( match lid with | ( Lident f | Ldot ( _ , f ) ) when f = func -> true | _ -> is_like lid functions )
let visit_expr ( iterator : Ast_iterator . iterator ) expr = let loc = expr . pexp_loc in match expr . pexp_desc with | Pexp_apply ( { pexp_desc = Pexp_ident { Asttypes . txt = lid ; _ } ; _ } , ( Asttypes . Nolabel , { pexp_desc = Pexp_constant ( Pconst_string ( singular , _ , _ ) ) ; _ } ) # else { pexp_desc = Pexp_c...
let ast_iterator = { Ast_iterator . default_iterator with expr = visit_expr }
let go fn = current_file := fn ; try let lexbuf = Lexing . from_channel ( open_in fn ) in let structure = Parse . implementation lexbuf in ast_iterator . Ast_iterator . structure ast_iterator structure with exn -> failwith ( fn ^ " : " ^ Printexc . to_string exn )
let ( ) = Arg . parse [ ] go " " ; output_translations ! translations
let hash x = seeded_hash_param 10 100 0 x
let hash_param n1 n2 x = seeded_hash_param n1 n2 0 x
let seeded_hash seed x = seeded_hash_param 10 100 seed x
type ' a t = { mutable size : int ; mutable data : ' a list array ; mutable seed : int ; initial_size : int ; }
let randomized_default = let params = try Sys . getenv " OCAMLRUNPARAM " with Not_found -> try Sys . getenv " CAMLRUNPARAM " with Not_found -> " " in String . contains params ' R '
let randomized = ref randomized_default
let randomize ( ) = randomized := true
let prng = lazy ( Random . State . make_self_init ( ) )
let rec power_2_above x n = if x >= n then x else if x * 2 > Sys . max_array_length then x else power_2_above ( x * 2 ) n
let create ( ? random = ! randomized ) initial_size = let s = power_2_above 16 initial_size in let seed = if random then Random . State . bits ( Lazy . force prng ) else 0 in { initial_size = s ; size = 0 ; seed = seed ; data = Array . make s [ ] }
let clear h = h . size <- 0 ; let len = Array . length h . data in for i = 0 to len - 1 do h . data . ( i ) <- [ ] done
let reset h = let len = Array . length h . data in if Obj . size ( Obj . repr h ) < 4 || len = h . initial_size then clear h else begin h . size <- 0 ; h . data <- Array . make h . initial_size [ ] end
let copy h = { h with data = Array . copy h . data }