text stringlengths 0 601k |
|---|
let chr n = if n < 0 || n > 255 then invalid_arg " Char . chr " else unsafe_chr n = " % bytes_unsafe_set " |
let escaped = function | ' ' ' \ -> " ' " \\ | ' ' \\ -> " " \\\\ | ' \ n ' -> " \\ n " | ' \ t ' -> " \\ t " | ' \ r ' -> " \\ r " | ' \ b ' -> " \\ b " | ' ' . . ' ' ~ as c -> let s = bytes_create 1 in bytes_unsafe_set s 0 c ; unsafe_to_string s | c -> let n = code c in let s = bytes_create 4 in bytes_unsafe_set s 0 ... |
let lowercase = function | ' A ' . . ' Z ' | ' \ 192 ' . . ' \ 214 ' | ' \ 216 ' . . ' \ 222 ' as c -> unsafe_chr ( code c + 32 ) | c -> c |
let uppercase = function | ' a ' . . ' z ' | ' \ 224 ' . . ' \ 246 ' | ' \ 248 ' . . ' \ 254 ' as c -> unsafe_chr ( code c - 32 ) | c -> c |
let lowercase_ascii = function | ' A ' . . ' Z ' as c -> unsafe_chr ( code c + 32 ) | c -> c |
let uppercase_ascii = function | ' a ' . . ' z ' as c -> unsafe_chr ( code c - 32 ) | c -> c |
let compare c1 c2 = code c1 - code c2 |
let equal ( c1 : t ) ( c2 : t ) = compare c1 c2 = 0 |
let ( ) = Printexc . record_backtrace true |
let filter_map f l = List . rev @@ List . fold_left ( fun a v -> match f v with Some v ' -> v ' :: a | None -> a ) [ ] l |
let level_of_string = function | " warning " -> Lwt_log . Warning | " notice " -> Lwt_log . Notice | " debug " -> Lwt_log . Debug | _ -> invalid_arg " Unknown verbosity level " |
let go_safe user group = let ( pw , _gr ) = try ( Unix . getpwnam user , Unix . getgrnam group ) with _ -> failwith " No user and / or group _charruad found , please create them . " in Unix . chroot pw . Unix . pw_dir ; Unix . chdir " " ; / let ogid = Unix . getgid ( ) in let oegid = Unix . getegid ( ) in let ouid = Un... |
let read_file f = let ic = open_in f in let n = in_channel_length ic in let buf = Bytes . create n in really_input ic buf 0 n ; close_in ic ; Bytes . to_string buf |
let go_daemon ( ) = Lwt_daemon . daemonize ~ syslog : false ( ) |
let init_log vlevel daemon = Lwt_log_core . Section . ( set_level main vlevel ) ; Lwt_log . default := if daemon then Lwt_log . syslog ~ template " ( :$ date ) ( $ level ) ( $ name ) [ ( $ pid ) ] : ( $ message ) " ~ facility ` : Daemon ~ paths [ " :/ dev / log " ; " / var / run / log " ; " / var / run / syslog " ] ( )... |
let uptime_in_sec ( ) = Mtime_clock . elapsed ( ) |> Mtime . Span . to_s |> Int . of_float |
let maybe_gc db now gbcol = let open Lwt in if ( now - gbcol ) >= 60 then Lwt_log . debug " Garbage collecting . . . " >>= fun ( ) -> return ( Dhcp_server . Lease . garbage_collect db ~ now ( : Int32 . of_int now ) , now + 60 ) else return ( db , gbcol ) |
let rec input config db link gbcol = let open Dhcp_server . Input in let open Lwt in Lwt_rawlink . read_packet link >>= fun buf -> let now = uptime_in_sec ( ) in maybe_gc db now gbcol >>= fun ( db , gbcol ) -> let t = match Dhcp_wire . pkt_of_buf buf ( Cstruct . length buf ) with | Error e -> Lwt_log . error e >>= fun ... |
let ifname_of_address ip_addr interfaces = let ifnet = List . find ( function _name , cidr -> Ipaddr . V4 . compare ip_addr ( Ipaddr . V4 . Prefix . address cidr ) = 0 ) interfaces in match ifnet with name , _ -> name |
let charruad configfile group pidfile user verbosity daemonize = let open Dhcp_server . Config in let open Dhcp_server . Lease in let open Lwt in init_log ( level_of_string verbosity ) daemonize ; let interfaces = Tuntap . getifaddrs_v4 ( ) in let addresses = List . map ( function name , cidr -> ( Ipaddr . V4 . Prefix ... |
let cmd = let configfile = Arg . ( value & opt string " / etc / charruad . conf " & info [ " c " ; " config " ] ~ doc " : Configuration file path . " ) in let group = Arg . ( value & opt string " _charruad " & info [ " g " ; " group " ] ~ doc " : Group to run as . " ) in let pidfile = Arg . ( value & opt string " / run... |
let ( ) = exit ( Cmd . eval cmd ) |
let get_element ( ? f = Str . search_forward ) ~ regexp ( ? start = 0 ) line = try f ( Str . regexp regexp ) line start |> ignore ; Str . matched_string line with _ -> " " |
let get_path = get_element ~ regexp " . . [ ] . . :\\/*</* mli " ? |
let get_pos line = let pos = get_element ~ regexp " [ :: 0 - 9 ] " *: line in int_of_string ( if pos <> " " then String . sub pos 1 @@ String . length pos - 2 else pos ) |
let get_info line = let info = get_element ~ regexp " :: . " *$ ~ f : Str . search_backward ~ start ( : String . length line - 1 ) line in String . sub info 1 ( String . length info - 1 ) |
let sec_part ~ regexp line = Str . string_match ( Str . regexp regexp ) line 0 |
let sec_start = sec_part ~ regexp " : " *=+ |
let sec_end = sec_part ~ regexp " ( :-+\\|\\ Nothing else to report in this section ) " \\ |
let errors = ref 0 |
let error ~ why ~ where ( ) = incr errors ; prerr_string " \ x1b [ 0 ; 31m " ; prerr_string where ; prerr_string " : \ x1b [ 0 ; 37 ; 41m " ; prerr_string why ; prerr_string " \ x1b [ 0m " |> prerr_newline |
let total = ref 0 |
let comp = ref " " |
let nextl = ref " " |
let fnames = ref [ ] |
let dir = ref " " |
let res = ref ( open_in_gen [ Open_creat ] 777 " trash . out " ) |
let fn = ref None |
let in_file = ref ! res |
let old_fn = ref None |
let extend = ref " " |
let normalize fname = let rec block fname pos len = if pos = String . length fname || fname . [ pos ] = ' ' / then String . sub fname ( pos - len ) len else block fname ( pos + 1 ) ( len + 1 ) in let rec normalize acc fname pos = if pos = String . length fname then acc else let blk = block fname pos 0 in if blk = " " |... |
let rec empty file = try let where = input_line file in if where <> " " then ( error ~ why " : Not detected " ~ where ( ) ; incr total ) ; empty file with _ -> close_in file |
let rec empty_fnames ( ? regexp = " . " ) * threshold = function | e :: l -> let extension s = let tmp = Filename . chop_extension s in String . sub s ( String . length tmp ) ( String . length s - String . length tmp ) in if ( try extension e <= extension threshold with _ -> true ) && get_element ~ regexp ~ start : 0 e... |
let is_trash diff eq = let tmp = open_in " trash . out " in if ! in_file <> tmp then ( close_in tmp ; diff ( ) ) else eq |
let rec check_fn name line = let ok = match ! fn with | None -> begin match ! old_fn with | Some str when str = name -> decr total ; error ~ why " : Should not be detected " ~ where : line ( ) ; nextl := " " ; false | _ -> fn := Some name ; let name = normalize ( ! dir ^ name ) in if ( try Filename . chop_extension nam... |
let check_elt ~ f line x = compare x @@ f line |
let check_aux line status = if status > 0 then ( error ~ why ( " : Not detected " ) ~ where : line ( ) ; comp := " " ; false ) else if status < 0 then ( decr total ; error ~ why ( " : Should not be detected " ) ~ where :! nextl ( ) ; nextl := " " ; false ) else true |
let check_value line x = check_elt ~ f : get_info line x |> check_aux line |
let check_pos line pos = check_elt ~ f : get_pos line pos |> check_aux line |
let check_info line info = if ( check_elt ~ f : get_info line info ) <> 0 then ( error ~ why ( " : Expected " : ^ ( get_info line ) ) ~ where :! nextl ( ) ; nextl := " " ; comp := " " ; false ) else true |
let rec section ( ? path = true ) ( ? pos = true ) ( ? value = false ) ( ? info = true ) ( ) = try if ! nextl = " " then ( nextl := input_line ! res ; section ~ path ~ pos ~ value ~ info ( ) ) else if sec_start ! nextl then ( nextl := " " ; comp := " " ; section ~ path ~ pos ~ value ~ info ( ) ) else if sec_end ! nextl... |
let rec sel_section ( ) = fn := None ; old_fn := None ; nextl := " " ; comp := " " ; try match ( input_line ! res ) with | " . > UNUSED EXPORTED VALUES " : as s -> ( try fnames := empty_fnames ~ regexp " . :\\ ml [ a - z0 - 9 ] " *$ " . mli " ! fnames with _ -> ( ) ) ; print_endline s ; print_endline ( input_line ! res... |
let result ( ) = print_string " Total : \ x1b [ 0 ; 34m " ; print_int ! total ; print_string " \ x1b [ 0m \ nFailed : \ x1b [ 0 ; 31m " ; print_int ! errors ; let ratio = ( . - ) 100 . @@ ( . * ) 100 . @@ ( float_of_int ! total |> ( . / ) @@ float_of_int ! errors ) in print_string @@ " \ x1b [ 0m \ nRatio : \ x1b [ 0 ;... |
let rec get_fnames ( ? acc = [ ] ) dir = try if Sys . is_directory dir then acc @ Array . fold_left ( fun l s -> get_fnames ~ acc : l ( normalize ( dir ^ " " / ^ s ) ) ) [ ] @@ Sys . readdir dir else if dir <> " . / check . ml " && Str . string_match ( Str . regexp " . [ */ _a - zA - Z0 - 9 ] . -* ml [ a - z0 - 9 ] " )... |
let ( ) = dir := if ( Array . length Sys . argv ) < 2 then " . " else Sys . argv . ( 1 ) ; res := if ( Array . length Sys . argv ) < 3 then open_in " res . out " else open_in Sys . argv . ( 2 ) ; fnames := List . fast_sort ( fun x y -> let req s = get_element ~ f : Str . search_backward ~ regexp " . :\\ ml [ a - z0 - 9... |
type checkpoint_state = C_stopped | C_running of int64 |
type checkpoint = { mutable c_time : int64 ; mutable c_pid : int ; mutable c_fd : io_channel ; mutable c_valid : bool ; mutable c_report : report option ; mutable c_state : checkpoint_state ; mutable c_parent : checkpoint ; mutable c_breakpoint_version : int ; mutable c_breakpoints : ( pc * int ref ) list ; mutable c_t... |
let rec root = { c_time = _0 ; c_pid = - 2 ; c_fd = std_io ; c_valid = false ; c_report = None ; c_state = C_stopped ; c_parent = root ; c_breakpoint_version = 0 ; c_breakpoints = [ ] ; c_trap_barrier = 0 ; c_code_fragments = [ 0 ] } |
let checkpoints = ref ( [ ] : checkpoint list ) |
let current_checkpoint = ref root |
let current_time ( ) = ! current_checkpoint . c_time |
let current_report ( ) = ! current_checkpoint . c_report |
let current_pc_sp ( ) = match current_report ( ) with | Some { rep_type = Event | Breakpoint ; rep_program_pointer = pc ; rep_stack_pointer = sp } -> Some ( pc , sp ) | _ -> None |
let current_pc ( ) = Option . map fst ( current_pc_sp ( ) ) |
module Stdlib = struct external register_named_value : string -> ' a -> unit = " caml_register_named_value " let ( ) = register_named_value " Pervasives . array_bound_error " ( Invalid_argument " index out of bounds " ) external raise : exn -> ' a = " % raise " external raise_notrace : exn -> ' a = " % raise_notrace " ... |
let create_char_set ( ) = Bytes . make 32 ' \ 000 ' |
let add_in_char_set char_set c = let ind = int_of_char c in let str_ind = ind lsr 3 and mask = 1 lsl ( ind land 0b111 ) in Bytes . set char_set str_ind ( char_of_int ( int_of_char ( Bytes . get char_set str_ind ) lor mask ) ) |
let freeze_char_set char_set = Bytes . to_string char_set |
let rev_char_set char_set = let char_set ' = create_char_set ( ) in for i = 0 to 31 do Bytes . set char_set ' i ( char_of_int ( int_of_char ( String . get char_set i ) lxor 0xFF ) ) done ; Bytes . unsafe_to_string char_set ' |
let is_in_char_set char_set c = let ind = int_of_char c in let str_ind = ind lsr 3 and mask = 1 lsl ( ind land 0b111 ) in int_of_char ( String . get char_set str_ind ) land mask <> 0 |
type ( ' a , ' b , ' c , ' d , ' e , ' f ) param_format_ebb = | Param_format_EBB : ( ' x -> ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' a , ' b , ' c , ' d , ' e , ' f ) param_format_ebb |
let pad_of_pad_opt pad_opt = match pad_opt with | None -> No_padding | Some width -> Lit_padding ( Right , width ) |
let prec_of_prec_opt prec_opt = match prec_opt with None -> No_precision | Some ndec -> Lit_precision ndec |
let param_format_of_ignored_format : type a b c d e f x y . ( a , b , c , d , y , x ) ignored -> ( x , b , c , y , e , f ) fmt -> ( a , b , c , d , e , f ) param_format_ebb = fun ign fmt -> match ign with | Ignored_char -> Param_format_EBB ( Char fmt ) | Ignored_caml_char -> Param_format_EBB ( Caml_char fmt ) | Ignored... |
type ( ' b , ' c ) acc_formatting_gen = | Acc_open_tag of ( ' b , ' c ) acc | Acc_open_box of ( ' b , ' c ) acc | Acc_formatting_lit of ( ' b , ' c ) acc * formatting_lit | Acc_formatting_gen of ( ' b , ' c ) acc * ( ' b , ' c ) acc_formatting_gen | Acc_string_literal of ( ' b , ' c ) acc * string | Acc_char_literal of... |
type ( ' a , ' b ) heter_list = | Cons : ' c * ( ' a , ' b ) heter_list -> ( ' c -> ' a , ' b ) heter_list | Nil : ( ' b , ' b ) heter_list |
type ( ' a , ' b , ' c , ' d , ' e , ' f ) padding_fmtty_ebb = | Padding_fmtty_EBB : ( ' x , ' y ) padding * ( ' y , ' b , ' c , ' d , ' e , ' f ) fmtty -> ( ' x , ' b , ' c , ' d , ' e , ' f ) padding_fmtty_ebb |
type ( ' a , ' b , ' c , ' d , ' e , ' f ) padprec_fmtty_ebb = | Padprec_fmtty_EBB : ( ' x , ' y ) padding * ( ' y , ' z ) precision * ( ' z , ' b , ' c , ' d , ' e , ' f ) fmtty -> ( ' x , ' b , ' c , ' d , ' e , ' f ) padprec_fmtty_ebb |
type ( ' a , ' b , ' c , ' e , ' f ) padding_fmt_ebb = | Padding_fmt_EBB : ( _ , ' x -> ' a ) padding * ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' x , ' b , ' c , ' e , ' f ) padding_fmt_ebb |
type ( ' a , ' b , ' c , ' e , ' f ) precision_fmt_ebb = | Precision_fmt_EBB : ( _ , ' x -> ' a ) precision * ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' x , ' b , ' c , ' e , ' f ) precision_fmt_ebb |
type ( ' p , ' b , ' c , ' e , ' f ) padprec_fmt_ebb = | Padprec_fmt_EBB : ( ' x , ' y ) padding * ( ' y , ' p -> ' a ) precision * ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' p , ' b , ' c , ' e , ' f ) padprec_fmt_ebb |
type ( ' b , ' c , ' e , ' f ) fmt_ebb = | Fmt_EBB : ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt -> ( ' b , ' c , ' e , ' f ) fmt_ebb |
type ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt_fmtty_ebb = | Fmt_fmtty_EBB : ( ' a , ' b , ' c , ' d , ' y , ' x ) fmt * ( ' x , ' b , ' c , ' y , ' e , ' f ) fmtty -> ( ' a , ' b , ' c , ' d , ' e , ' f ) fmt_fmtty_ebb |
type ( ' a , ' b , ' c , ' d , ' e , ' f ) fmtty_fmt_ebb = | Fmtty_fmt_EBB : ( ' a , ' b , ' c , ' d , ' y , ' x ) fmtty * ( ' x , ' b , ' c , ' y , ' e , ' f ) fmt_fmtty_ebb -> ( ' a , ' b , ' c , ' d , ' e , ' f ) fmtty_fmt_ebb |
type fmtty_ebb = Fmtty_EBB : ( ' a , ' b , ' c , ' d , ' e , ' f ) fmtty -> fmtty_ebb |
type padding_ebb = Padding_EBB : ( ' a , ' b ) padding -> padding_ebb |
type precision_ebb = Precision_EBB : ( ' a , ' b ) precision -> precision_ebb |
let default_float_precision fconv = match snd fconv with | Float_f | Float_e | Float_E | Float_g | Float_G | Float_h | Float_H -> - 6 | Float_F -> 12 = " caml_nativeint_format " = " caml_hexstring_of_float " |
type buffer = { mutable ind : int ; mutable bytes : bytes } |
let buffer_create init_size = { ind = 0 ; bytes = Bytes . create init_size } |
let buffer_check_size buf overhead = let len = Bytes . length buf . bytes in let min_len = buf . ind + overhead in if min_len > len then ( let new_len = max ( len * 2 ) min_len in let new_str = Bytes . create new_len in Bytes . blit buf . bytes 0 new_str 0 len ; buf . bytes <- new_str ) |
let buffer_add_char buf c = buffer_check_size buf 1 ; Bytes . set buf . bytes buf . ind c ; buf . ind <- buf . ind + 1 |
let buffer_add_string buf s = let str_len = String . length s in buffer_check_size buf str_len ; String . blit s 0 buf . bytes buf . ind str_len ; buf . ind <- buf . ind + str_len |
let buffer_contents buf = Bytes . sub_string buf . bytes 0 buf . ind |
let char_of_iconv iconv = match iconv with | Int_d | Int_pd | Int_sd | Int_Cd -> ' d ' | Int_i | Int_pi | Int_si | Int_Ci -> ' i ' | Int_x | Int_Cx -> ' x ' | Int_X | Int_CX -> ' X ' | Int_o | Int_Co -> ' o ' | Int_u | Int_Cu -> ' u ' |
let char_of_fconv ( ? cF = ' F ' ) fconv = match snd fconv with | Float_f -> ' f ' | Float_e -> ' e ' | Float_E -> ' E ' | Float_g -> ' g ' | Float_G -> ' G ' | Float_F -> cF | Float_h -> ' h ' | Float_H -> ' H ' |
let char_of_counter counter = match counter with | Line_counter -> ' l ' | Char_counter -> ' n ' | Token_counter -> ' N ' |
let bprint_char_set buf char_set = let rec print_start set = let is_alone c = let before , after = Char . ( chr ( code c - 1 ) , chr ( code c + 1 ) ) in is_in_char_set set c && not ( is_in_char_set set before && is_in_char_set set after ) in if is_alone ' ] ' then buffer_add_char buf ' ] ' ; print_out set 1 ; if is_alo... |
let bprint_padty buf padty = match padty with | Left -> buffer_add_char buf ' ' - | Right -> ( ) | Zeros -> buffer_add_char buf ' 0 ' |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.