text
stringlengths 12
786k
|
---|
type variable_option = [ ` Blanked | ` Non_ignorable | ` Shifted | ` Shift_Trimmed ] |
type precision = [ ` Primary | ` Secondary | ` Tertiary | ` Quaternary ] |
module type Type = sig type text type index val compare : ? locale : string -> ? prec : precision -> ? variable : variable_option -> text -> text -> int val sort_key : ? locale : string -> ? prec : precision -> ? variable : variable_option -> text -> string val compare_with_key : ? locale : string -> ? prec : precision -> ? variable : variable_option -> string -> text -> int val search_with_key : ? locale : string -> ? prec : precision -> ? variable : variable_option -> string -> text -> index -> ( index * index ) index val search : ? locale : string -> ? prec : precision -> ? variable : variable_option -> text -> text -> index -> ( index * index ) index end |
module Make ( Config : ConfigInt . Type ) Type ( Text : UnicodeString . Type ) Type = struct module Unidata = Unidata . Make ( MakeConfig ) MakeConfig module UCharInfo = UCharInfo . Make ( MakeConfig ) MakeConfig let logical_order_exception_tbl = UCharInfo . load_property_tbl ` Logical_Order_Exception let is_logical_order_exception u = UCharTbl . Bool . get logical_order_exception_tbl u let rec rearrange_aux x pos = if pos > XString . length x - 2 then ( ) else let u = XString . get x pos in if is_logical_order_exception u then begin XString . set x pos ( XString . get x ( pos + 1 ) 1 ) 1 ; XString . set x ( pos + 1 ) 1 u ; rearrange_aux x ( pos + 2 ) 2 end else rearrange_aux x ( pos + 1 ) 1 let rearrange x = rearrange_aux x 0 let remove_ignorable ce_tbl x = let rec loop0 i = if XString . length x <= i then ( ) else let u = XString . get x i in match Unidata . ce ce_tbl u with [ ( [ ] , [ ce ] ce ) ce ] ce when ce = Unidata . complete_ignorable -> loop1 ( i + 1 ) 1 i | _ -> loop0 ( i + 1 ) 1 and loop1 i k = if XString . length x <= i then begin XString . shrink x k ; end else let u = XString . get x i in match Unidata . ce ce_tbl u with [ ( [ ] , [ ce ] ce ) ce ] ce when ce = Unidata . complete_ignorable -> loop1 ( i + 1 ) 1 k | _ -> XString . set x k u ; loop1 ( i + 1 ) 1 ( k + 1 ) 1 in loop0 0 let noncharacter_code_point_tbl = UCharInfo . load_property_tbl ` Noncharacter_Code_Point let is_noncharacter_code_point u = UCharTbl . Bool . get noncharacter_code_point_tbl u let reverse s = if Bytes . length s = 0 then ( ) else let last = Bytes . length s - 1 in for i = 0 to last / 2 do let c = Bytes . get s i in Bytes . set s i ( Bytes . get s ( last - i ) i ) i ; Bytes . set s ( last - i ) i c done let shiftright x i j = for k = j downto i do XString . set x ( k + 1 ) 1 ( XString . get x k ) k done let rec remove_chars x i = function [ ] -> i | j :: rest -> shiftright x i ( j - 1 ) 1 ; remove_chars x ( i + 1 ) 1 rest let trim start_regular key = let rec loop i = if i > 0 && ( Char . code key [ . i - 1 ] 1 ) 1 lsl 8 lor ( Char . code key [ . i ] i ) i > start_regular then loop ( i - 2 ) 2 else String . sub key 0 ( i + 1 ) 1 in loop ( String . length key - 1 ) 1 let is_variable variable_top ce = Unidata . primary ce <> 0 && Unidata . primary ce <= variable_top let is_ignorable ce = Unidata . primary ce = 0 let add_i16 buf n = Buffer . add_char buf ( Char . unsafe_chr ( n lsr 8 ) 8 ) 8 ; Buffer . add_char buf ( Char . unsafe_chr ( n land 255 ) 255 ) 255 let add_byte buf n = Buffer . add_char buf ( Char . unsafe_chr n ) n type non_ignorable_keybuf = { non_ignorable_col_info : Unidata . col_info ; non_ignorable_prec : precision ; non_ignorable_primary : Buffer . t ; non_ignorable_secondary : Buffer . t ; non_ignorable_tertiary : Buffer . t ; non_ignorable_quaternary : Buffer . t ; mutable non_ignorable_count : int } int let addce_non_ignorable keybuf ce = let w1 = Unidata . primary ce in if w1 <> 0 && w1 <> keybuf . non_ignorable_col_info . hiraganaQ_weight then add_i16 keybuf . non_ignorable_primary w1 ; match keybuf . non_ignorable_prec with ` Primary -> ( ) | _ -> let w2 = Unidata . secondary ce in if w2 <> 0 then add_byte keybuf . non_ignorable_secondary w2 ; match keybuf . non_ignorable_prec with ` Secondary -> ( ) | _ -> let w3 = Unidata . tertiary ce in if w3 <> 0 then add_byte keybuf . non_ignorable_tertiary w3 ; match keybuf . non_ignorable_prec with ` Tertiary -> ( ) | _ -> if not keybuf . non_ignorable_col_info . hiraganaQ then ( ) else if w1 = keybuf . non_ignorable_col_info . hiraganaQ_weight then begin if keybuf . non_ignorable_count > 0 then begin add_i16 keybuf . non_ignorable_quaternary ( 1 + keybuf . non_ignorable_count ) non_ignorable_count ; keybuf . non_ignorable_count <- 0 ; end ; add_i16 keybuf . non_ignorable_quaternary 1 ; end else begin keybuf . non_ignorable_count <- keybuf . non_ignorable_count + 1 ; if keybuf . non_ignorable_count = 0xffff - 1 then begin add_i16 keybuf . non_ignorable_quaternary 0xffff ; keybuf . non_ignorable_count <- 0 ; end end let terminate_non_ignorable keybuf = let c = keybuf . non_ignorable_count in if c > 0 then add_i16 keybuf . non_ignorable_quaternary ( 1 + c ) c type blanked_keybuf = { blanked_col_info : Unidata . col_info ; blanked_prec : precision ; blanked_primary : Buffer . t ; blanked_secondary : Buffer . t ; blanked_tertiary : Buffer . t ; blanked_quaternary : Buffer . t ; mutable blanked_after_variable : bool ; mutable blanked_count : int } int let addce_blanked keybuf ce = if is_ignorable ce && keybuf . blanked_after_variable then ( ) else if is_variable keybuf . blanked_col_info . variable_top ce then keybuf . blanked_after_variable <- true else begin keybuf . blanked_after_variable <- false ; let w1 = Unidata . primary ce in if w1 <> 0 && w1 <> keybuf . blanked_col_info . hiraganaQ_weight then add_i16 keybuf . blanked_primary w1 ; match keybuf . blanked_prec with ` Primary -> ( ) | _ -> let w2 = Unidata . secondary ce in if w2 <> 0 then add_byte keybuf . blanked_secondary w2 ; match keybuf . blanked_prec with ` Secondary -> ( ) | _ -> let w3 = Unidata . tertiary ce in if w3 <> 0 then add_byte keybuf . blanked_tertiary w3 ; match keybuf . blanked_prec with ` Tertiary -> ( ) | _ -> if not keybuf . blanked_col_info . hiraganaQ then ( ) else if w1 = keybuf . blanked_col_info . hiraganaQ_weight then begin if keybuf . blanked_count > 0 then begin add_i16 keybuf . blanked_quaternary ( 1 + keybuf . blanked_count ) blanked_count ; keybuf . blanked_count <- 0 end ; add_i16 keybuf . blanked_quaternary 1 ; end else begin keybuf . blanked_count <- keybuf . blanked_count + 1 ; if keybuf . blanked_count = 0xffff - 1 then begin add_i16 keybuf . blanked_quaternary 0xffff ; keybuf . blanked_count <- 0 end end end let terminate_blanked keybuf = let c = keybuf . blanked_count in if c > 0 then add_i16 keybuf . blanked_quaternary ( 1 + c ) c type shifted_keybuf = { shifted_col_info : Unidata . col_info ; shifted_prec : precision ; shifted_primary : Buffer . t ; shifted_secondary : Buffer . t ; shifted_tertiary : Buffer . t ; shifted_quaternary : Buffer . t ; mutable shifted_after_variable : bool ; mutable shifted_count : int } int let start_regular keybuf = if keybuf . shifted_col_info . hiraganaQ then keybuf . shifted_col_info . hiraganaQ_weight else keybuf . shifted_col_info . variable_top let addce_shifted keybuf ce = let start_regular = start_regular keybuf in if is_ignorable ce && keybuf . shifted_after_variable then ( ) else if is_variable keybuf . shifted_col_info . variable_top ce then begin keybuf . shifted_after_variable <- true ; match keybuf . shifted_prec with ` Quaternary -> if keybuf . shifted_count > 0 then begin add_i16 keybuf . shifted_quaternary ( start_regular + keybuf . shifted_count ) shifted_count ; keybuf . shifted_count <- 0 end ; add_i16 keybuf . shifted_quaternary ( Unidata . primary ce ) ce ; | _ -> ( ) end else begin keybuf . shifted_after_variable <- false ; let w1 = Unidata . primary ce in if w1 <> 0 && w1 <> keybuf . shifted_col_info . hiraganaQ_weight then add_i16 keybuf . shifted_primary w1 ; match keybuf . shifted_prec with ` Primary -> ( ) | _ -> let w2 = Unidata . secondary ce in if w2 <> 0 then add_byte keybuf . shifted_secondary w2 ; match keybuf . shifted_prec with ` Secondary -> ( ) | _ -> let w3 = Unidata . tertiary ce in if w3 <> 0 then add_byte keybuf . shifted_tertiary w3 ; match keybuf . shifted_prec with ` Tertiary -> ( ) | _ -> if is_ignorable ce then ( ) else if w1 = keybuf . shifted_col_info . hiraganaQ_weight && keybuf . shifted_col_info . hiraganaQ then begin if keybuf . shifted_count > 0 then begin add_i16 keybuf . shifted_quaternary ( start_regular + keybuf . shifted_count ) shifted_count ; keybuf . shifted_count <- 0 end ; add_i16 keybuf . shifted_quaternary w1 end else begin keybuf . shifted_count <- keybuf . shifted_count + 1 ; if keybuf . shifted_count = 0xffff - start_regular then begin add_i16 keybuf . shifted_quaternary 0xffff ; keybuf . shifted_count <- 0 end end end let terminate_shifted keybuf = let c = keybuf . shifted_count in if c > 0 then add_i16 keybuf . shifted_quaternary ( ( start_regular keybuf ) keybuf + c ) c let terminate_shift_trimmed keybuf = let k4 = Buffer . contents keybuf . shifted_quaternary in let k4 = trim ( start_regular keybuf ) keybuf k4 in Buffer . clear keybuf . shifted_quaternary ; Buffer . add_string keybuf . shifted_quaternary k4 type keybuf = Non_ignorable of non_ignorable_keybuf | Blanked of blanked_keybuf | Shifted of shifted_keybuf | Shift_Trimmed of shifted_keybuf let create_keybuf prec col_info = match col_info . Unidata . variable_option with ` Non_ignorable -> Non_ignorable { non_ignorable_col_info = col_info ; non_ignorable_prec = prec ; non_ignorable_primary = Buffer . create 0 ; non_ignorable_secondary = Buffer . create 0 ; non_ignorable_tertiary = Buffer . create 0 ; non_ignorable_quaternary = Buffer . create 0 ; non_ignorable_count = 0 } 0 | ` Blanked -> Blanked { blanked_col_info = col_info ; blanked_prec = prec ; blanked_primary = Buffer . create 0 ; blanked_secondary = Buffer . create 0 ; blanked_tertiary = Buffer . create 0 ; blanked_quaternary = Buffer . create 0 ; blanked_after_variable = false ; blanked_count = 0 } 0 | ` Shifted -> Shifted { shifted_col_info = col_info ; shifted_prec = prec ; shifted_primary = Buffer . create 0 ; shifted_secondary = Buffer . create 0 ; shifted_tertiary = Buffer . create 0 ; shifted_quaternary = Buffer . create 0 ; shifted_after_variable = false ; shifted_count = 0 } 0 | ` Shift_Trimmed -> Shift_Trimmed { shifted_col_info = col_info ; shifted_prec = prec ; shifted_primary = Buffer . create 0 ; shifted_secondary = Buffer . create 0 ; shifted_tertiary = Buffer . create 0 ; shifted_quaternary = Buffer . create 0 ; shifted_after_variable = false ; shifted_count = 0 } 0 let col_info_of_keybuf = function Non_ignorable b -> b . non_ignorable_col_info | Blanked b -> b . blanked_col_info | Shifted b | Shift_Trimmed b -> b . shifted_col_info let precision_of_keybuf = function Non_ignorable b -> b . non_ignorable_prec | Blanked b -> b . blanked_prec | Shifted b | Shift_Trimmed b -> b . shifted_prec let primary_of_keybuf = function Non_ignorable b -> b . non_ignorable_primary | Blanked b -> b . blanked_primary | Shifted b | Shift_Trimmed b -> b . shifted_primary let secondary_of_keybuf = function Non_ignorable b -> b . non_ignorable_secondary | Blanked b -> b . blanked_secondary | Shifted b | Shift_Trimmed b -> b . shifted_secondary let tertiary_of_keybuf = function Non_ignorable b -> b . non_ignorable_tertiary | Blanked b -> b . blanked_tertiary | Shifted b | Shift_Trimmed b -> b . shifted_tertiary let quaternary_of_keybuf = function Non_ignorable b -> b . non_ignorable_quaternary | Blanked b -> b . blanked_quaternary | Shifted b | Shift_Trimmed b -> b . shifted_quaternary let addce keybuf ce = match keybuf with Non_ignorable keybuf -> addce_non_ignorable keybuf ce | Blanked keybuf -> addce_blanked keybuf ce | Shifted keybuf | Shift_Trimmed keybuf -> addce_shifted keybuf ce let terminate = function Non_ignorable keybuf -> terminate_non_ignorable keybuf | Blanked keybuf -> terminate_blanked keybuf | Shifted keybuf -> terminate_shifted keybuf | Shift_Trimmed keybuf -> terminate_shift_trimmed keybuf let rec add_list keybuf = function [ ] -> ( ) | e :: rest -> addce keybuf e ; add_list keybuf rest let implicit_ce cebuf u = let n = UChar . uint_code u in if n < 0 || n > 0x10ffff || ( match UCharInfo . general_category u with ` Cs -> true | _ -> false ) false || is_noncharacter_code_point u then addce cebuf Unidata . complete_ignorable else let base = if n >= 0x4e00 && n <= 0x9fff then 0xfb40 else if n >= 0x3400 && n <= 0x4dbf then 0xfb80 else if n >= 0x20000 && n <= 0x2a6df then 0xfb80 else 0xfbc0 in let a = base + n lsr 15 in let b = ( n land 0x7fff ) 0x7fff lor 0x8000 in addce cebuf ( Unidata . compose_ce a 1 1 ) 1 ; addce cebuf ( Unidata . compose_ce b 0 0 ) 0 let rec match_us2 x i c ' = function [ ] -> [ ] | ( u :: rest ) rest as us -> if i >= XString . length x then raise Exit else let u ' = XString . get x i in let c = UCharInfo . combined_class u ' in if c ' = 0 || c = 0 || c ' = c then raise Exit else if UChar . eq u u ' then i :: ( match_us2 x ( i + 1 ) 1 c ' rest ) rest else match_us2 x ( i + 1 ) 1 c us let rec match_us1 x i = function [ ] -> i | ( u :: rest ) rest as us -> if i >= XString . length x then raise Exit else let u ' = XString . get x i in if UChar . eq u u ' then match_us1 x ( i + 1 ) 1 rest else let ps = match_us2 x ( i + 1 ) 1 ( UCharInfo . combined_class u ' ) u ' us in remove_chars x i ps let rec longest_match ce_buf x i = function [ ] -> assert false | ( us , ces ) ces :: rest -> try let j = match_us1 x i us in add_list ce_buf ces ; j with Exit -> longest_match ce_buf x i rest let getce keybuf x i = let col_info = col_info_of_keybuf keybuf in let hiraganaQ_mark = Unidata . compose_ce col_info . hiraganaQ_weight 0 0 in let rec loop i = if i >= XString . length x then ( ) else let u = XString . get x i in ( match UCharInfo . script u with ` Hiragana when col_info . hiraganaQ -> addce keybuf hiraganaQ_mark | _ -> ( ) ) ; let i ' = match Unidata . ce col_info . tbl u with [ ] -> implicit_ce keybuf u ; i + 1 | [ ( [ ] , [ ce ] ce ) ce ] ce -> addce keybuf ce ; i + 1 | info -> longest_match keybuf x ( i + 1 ) 1 info in loop i ' in loop i let getkey keybuf = let col_info = col_info_of_keybuf keybuf in let prec = precision_of_keybuf keybuf in terminate keybuf ; let buf1 = primary_of_keybuf keybuf in ( match prec with ` Primary -> ( ) | _ -> add_i16 buf1 0 ; let buf2 = secondary_of_keybuf keybuf in if col_info . french_accent then let key2 = Buffer . to_bytes buf2 in reverse key2 ; Buffer . add_bytes buf1 key2 else Buffer . add_buffer buf1 buf2 ; match prec with ` Secondary -> ( ) | _ -> add_i16 buf1 0 ; Buffer . add_buffer buf1 ( tertiary_of_keybuf keybuf ) keybuf ; match prec with ` Tertiary -> ( ) | _ -> add_i16 buf1 0 ; Buffer . add_buffer buf1 ( quaternary_of_keybuf keybuf ) keybuf ) keybuf ; Buffer . contents buf1 type text = Text . t type index = Text . index module NF = UNF . Make ( MakeConfig ) MakeConfig ( MakeConfigText ) MakeConfigText let sort_key_aux col_info prec t = let x = XString . make 0 ( UChar . chr_of_uint 0 ) 0 in NF . put_nfd x t ; rearrange x ; remove_ignorable col_info . Unidata . tbl x ; let cebuf = create_keybuf prec col_info in getce cebuf x 0 ; getkey cebuf let sort_key ? locale ? prec ? variable text = let col_info = let default = Unidata . get_col_info ? locale ( ) in match variable with None -> default | Some v -> { default with variable_option = v } v in let prec = match prec with None -> ( match col_info . variable_option with ` Shifted | ` Shift_Trimmed -> ` Quaternary | _ -> ` Tertiary ) Tertiary | Some prec -> prec in sort_key_aux col_info prec text let rec primaries_of_ces col_info = function [ ] -> [ ] | ce :: rest -> let w = let w = Unidata . primary ce in if w = col_info . Unidata . hiraganaQ_weight then 0 else match col_info . variable_option with ` Non_ignorable -> w | _ -> if is_variable col_info . variable_top ce then 0 else w in if w = 0 then primaries_of_ces col_info rest else w :: primaries_of_ces col_info rest let rec inc_end i = ` Inc ( [ ] , i , lazy ( inc_end i ) i ) i let inc_prim col_info ( ` Inc ( Incces , i , f ) f ) f = let rec loop i f ws = let ` Inc ( ces , i ' , f ) f = Lazy . force f in if ces = [ ] then ` Inc ( ws , i , lazy ( inc_end i ) i ) i else match primaries_of_ces col_info ces with [ ] -> loop i ' f ws | ws ' -> ` Inc ( ws , i , lazy ( loop i ' f ws ' ) ws ' ) ws ' in loop i f ( primaries_of_ces col_info ces ) ces let implicit_ce_list u = let n = UChar . uint_code u in if n < 0 || n > 0x10ffff || match UCharInfo . general_category u with ` Cs -> true | _ -> false || is_noncharacter_code_point u then [ Unidata . complete_ignorable ] complete_ignorable else let base = if n >= 0x4e00 && n <= 0x9fff then 0xfb40 else if n >= 0x3400 && n <= 0x4dbf then 0xfb80 else if n >= 0x20000 && n <= 0x2a6df then 0xfb80 else 0xfbc0 in let a = base + n lsr 15 in let b = ( n land 0x7fff ) 0x7fff lor 0x8000 in [ Unidata . compose_ce a 1 1 ; Unidata . compose_ce b 0 0 ] 0 let rec inc_match_us2 i f us0 us1 c ' = function [ ] -> ` Match ( us0 @ us1 , i , f ) f | ( u :: rest ) rest as us -> match us1 with [ ] -> let ` Inc ( us1 , i , f ) f = Lazy . force f in if us1 = [ ] then ` Not_Match else inc_match_us2 i f us0 us1 c ' us | u ' :: r ' -> let c = UCharInfo . combined_class u ' in if c ' = 0 || c = 0 || c ' = c then ` Not_Match else if UChar . eq u u ' then inc_match_us2 i f us0 r ' c ' rest else inc_match_us2 i f ( us0 @ [ u ' ] u ' ) u ' r ' c us let rec inc_match_us1 i f us1 = function [ ] -> ` Match ( us1 , i , f ) f | ( u :: rest ) rest as us -> match us1 with [ ] -> let ` Inc ( us1 , i , f ) f = Lazy . force f in if us1 = [ ] then ` Not_Match else inc_match_us1 i f us1 us | u ' :: r ' -> if UChar . eq u u ' then inc_match_us1 i f r ' rest else inc_match_us2 i f [ u ' ] u ' r ' ( UCharInfo . combined_class u ' ) u ' us let rec inc_longest_match us i f = function [ ] -> ` Not_Match | ( us1 , ces ) ces :: rest -> match inc_match_us1 i f us us1 with ` Match ( us , i , f ) f -> ` Match ( ces , us , i , f ) f | ` Not_Match -> inc_longest_match us i f rest let get_next_ce col_info i f u us = match Unidata . ce col_info . Unidata . tbl u with [ ] -> ( implicit_ce_list u , us , i , f ) f | [ ( [ ] , ces ) ces ] ces -> ( ces , us , i , f ) f | info -> match inc_longest_match us i f info with ` Not_Match -> ( implicit_ce_list u , us , i , f ) f | ` Match ( ces , us , i , f ) f -> ( ces , us , i , f ) f let get_ces col_info f t i = let hiraganaQ_mark = Unidata . compose_ce col_info . Unidata . hiraganaQ_weight 0 0 in let rec loop i f a = function [ ] -> ( match Lazy . force f with ` Inc ( [ ] , i , _ ) _ -> ` Inc ( a , i , lazy ( inc_end i ) i ) i | ` Inc ( us , i ' , f ) f -> match a with [ ] -> loop i ' f a us | _ -> ` Inc ( a , i , lazy ( loop i ' f [ ] us ) us ) us ) us | u :: us -> let a = match UCharInfo . script u with ` Hiragana when col_info . hiraganaQ -> a @ [ hiraganaQ_mark ] hiraganaQ_mark | _ -> a in let ces , us , i , f = get_next_ce col_info i f u us in loop i f ( a @ ces ) ces us in let ` Inc ( us , i , f ) f = f t i in loop i f [ ] us let inc_prep col_info f t i = let rec loop i f prev a = function [ ] -> ( match a , prev with [ ] , _ | _ , [ _ ] _ -> ( match Lazy . force f with ` Inc ( [ ] , i , _ ) _ -> ` Inc ( a @ prev , i , lazy ( inc_end i ) i ) i | ` Inc ( us , i , f ) f -> loop i f prev a us ) us | _ -> ` Inc ( a , i , lazy ( loop i f [ ] [ ] [ ] ) ) ) | u :: rest -> match Unidata . ce col_info . Unidata . tbl u with [ ( [ ] , [ ce ] ce ) ce ] ce when ce = Unidata . complete_ignorable -> loop i f prev a rest | _ -> match prev with [ ] -> if is_logical_order_exception u then loop i f [ u ] u a rest else loop i f [ ] ( a @ [ u ] u ) u rest | [ u0 ] u0 -> loop i f [ ] ( a @ [ u ; u0 ] u0 ) u0 rest | _ -> assert false in let ` Inc ( us , i , f ) f = f t i in loop i f [ ] [ ] us let inc_ce col_info t i = get_ces col_info ( inc_prep col_info NF . nfd_inc ) nfd_inc t i let key_of_inc prec col_info x = let keybuf = create_keybuf prec col_info in let rec loop ( ` Inc ( Incces , _ , f ) f ) f = add_list keybuf ces ; match ces with [ ] -> ( ) | _ -> loop ( Lazy . force f ) f in loop x ; getkey keybuf let null_weight f = match Lazy . force f with ` Inc ( [ ] , _ , _ ) _ -> true | _ -> false let inc_compare prec col_info t1 t2 = let rec loop f1 f2 ws1 ws2 = match ws1 , ws2 with w1 :: rest1 , w2 :: rest2 -> let sgn = w1 - w2 in if sgn = 0 then loop f1 f2 rest1 rest2 else sgn | [ ] , ws2 -> let ` Inc ( ws1 , _ , f1 ) f1 = Lazy . force f1 in if ws1 = [ ] then if ws2 = [ ] && null_weight f2 then 0 else ~- 1 else loop f1 f2 ws1 ws2 | ws1 , [ ] -> let ` Inc ( ws2 , _ , f2 ) f2 = Lazy . force f2 in if ws2 = [ ] then 1 else loop f1 f2 ws1 ws2 in let x1 = inc_ce col_info t1 ( Text . nth t1 0 ) 0 in let x2 = inc_ce col_info t2 ( Text . nth t1 0 ) 0 in let ` Inc ( ws1 , _ , g1 ) g1 = inc_prim col_info x1 in let ` Inc ( ws2 , _ , g2 ) g2 = inc_prim col_info x2 in let sgn = loop g1 g2 ws1 ws2 in if sgn <> 0 then sgn else match prec with ` Primary -> 0 | _ -> let key1 = key_of_inc prec col_info x1 in let key2 = key_of_inc prec col_info x2 in Pervasives . compare key1 key2 let compare ? locale ? prec ? variable t1 t2 = let col_info = let default = Unidata . get_col_info ? locale ( ) in match variable with None -> default | Some v -> { default with variable_option = v } v in let prec = match prec with None -> ( match col_info . variable_option with ` Shifted | ` Shift_Trimmed -> ` Quaternary | _ -> ` Tertiary ) Tertiary | Some prec -> prec in inc_compare prec col_info t1 t2 let get_weight k i = ( Char . code k [ . i ] i ) i lsl 8 lor ( Char . code k [ . i + 1 ] 1 ) 1 let rec primary_length k i = if String . length k <= i || get_weight k i = 0 then i else primary_length k ( i + 2 ) 2 let inc_compare_key prec col_info k t = let k_len = primary_length k 0 in let rec loop f ws i = match ws with w :: rest -> if k_len <= i then ~- 1 else let w ' = get_weight k i in let sgn = w ' - w in if sgn = 0 then loop f rest ( i + 2 ) 2 else sgn | [ ] -> let ` Inc ( ws , _ , f ) f = Lazy . force f in if ws = [ ] then if k_len = i then 0 else if k_len > i then 1 else assert false else loop f ws i in let x = inc_ce col_info t ( Text . nth t 0 ) 0 in let ` Inc ( ws , _ , g ) g = inc_prim col_info x in let sgn = loop g ws 0 in if sgn <> 0 then sgn else match prec with ` Primary -> 0 | _ -> let key = key_of_inc prec col_info x in Pervasives . compare k key let compare_with_key ? locale ? prec ? variable k t = let col_info = let default = Unidata . get_col_info ? locale ( ) in match variable with None -> default | Some v -> { default with variable_option = v } v in let prec = match prec with None -> ( match col_info . variable_option with ` Shifted | ` Shift_Trimmed -> ` Quaternary | _ -> ` Tertiary ) Tertiary | Some prec -> prec in inc_compare_key prec col_info k t let search_common col_info prec k t loc = let k_len = primary_length k 0 in let rec null i f = let ` Inc ( ces , j , f ) f = Lazy . force f in if primaries_of_ces col_info ces = [ ] then null j f else i in let rec test_match i f j = function w :: rest -> if k_len <= j then raise Exit else let w ' = get_weight k j in if w ' = w then test_match i f ( j + 2 ) 2 rest else raise Exit | [ ] -> if k_len = j then ( i , null i f ) f else let ` Inc ( ces , i , f ) f = Lazy . force f in if ces = [ ] then raise Exit else test_match i f j ( primaries_of_ces col_info ces ) ces in let keys loc f i j ces = let keybuf = create_keybuf prec col_info in add_list keybuf ces ; let rec loop f ks = let ` Inc ( ces , loc , f ) f = Lazy . force f in if Text . compare_index t loc j > 0 || ces = [ ] then ks else begin add_list keybuf ces ; if Text . compare_index t loc i >= 0 then loop f ( ( getkey keybuf , i ) i :: ks ) ks else loop f ks end in if Text . compare_index t loc i >= 0 then loop f [ ( getkey keybuf , i ) i ] i else loop f [ ] in let rec scan loc f = let ` Inc ( ces , i , f ) f = Lazy . force f in if ces = [ ] then raise Not_found else try let ( i , j ) j = test_match i f 0 ( primaries_of_ces col_info ces ) ces in match prec with ` Primary -> ( loc , j ) j | _ -> let ks = keys loc f i j ces in try ( loc , List . assoc k ks ) ks with Not_found -> raise Exit with Exit -> scan i f in scan loc ( lazy ( inc_ce col_info t loc ) loc ) loc let search_with_key ? locale ? prec ? variable k t loc = let col_info = let default = Unidata . get_col_info ? locale ( ) in match variable with None -> default | Some v -> { default with variable_option = v } v in let prec = match prec with None -> ( match col_info . variable_option with ` Shifted | ` Shift_Trimmed -> ` Quaternary | _ -> ` Tertiary ) Tertiary | Some prec -> prec in search_common col_info prec k t loc let search ? locale ? prec ? variable t0 t loc = let k = sort_key ? locale ? prec ? variable t0 in search_with_key ? locale ? prec ? variable k t loc end |
type t = ( int32 , int32_elt , c_layout ) c_layout Array1 . t |
let rec validate_aux ( a : t ) t i = if i >= Array1 . dim a then ( ) else match Int32 . to_int ( Int32 . shift_right a { . i } i 31 ) 31 with 0 -> validate_aux a ( i + 1 ) 1 | _ -> raise Malformed_code |
let validate ( a : t ) t = validate_aux a 0 |
let look ( a : t ) t i : UChar . t = UChar . chr_of_uint ( Int32 . to_int a { . i } i ) i |
let length ( a : t ) t = Array1 . dim a |
let next _ i = i + 1 |
let prev _ i = i - 1 |
let move ( _ : t ) t i c = i + c |
let first _ = 0 |
let last ( a : t ) t = Array1 . dim a - 1 |
let out_of_range ( a : t ) t i = i < 0 || i >= Array1 . dim a |
let compare_index _ i j = i - j |
let nth ( _ : t ) t c = c |
let get ( a : t ) t c = look a c |
let rec iter_aux proc ( a : t ) t i = if i >= Array1 . dim a then ( ) else begin proc ( look a i ) i ; iter_aux proc a ( i + 1 ) 1 end |
let iter proc ( a : t ) t = iter_aux proc a 0 |
let init len f = let a = Array1 . create int32 c_layout len in for i = 0 to len - 1 do a { . i } i <- Int32 . of_int ( UChar . uint_code ( f i ) i ) i done ; a |
module Buf = struct type buf = { init_size : int ; mutable pos : index ; mutable contents : t } t let create n = let contents = Array1 . create int32 c_layout n in { init_size = n ; pos = 0 ; contents = contents } contents let clear buf = buf . pos <- 0 let reset buf = buf . contents <- Array1 . create int32 c_layout buf . init_size ; buf . pos <- 0 let contents buf = let a = Array1 . create int32 c_layout buf . pos in let src = Array1 . sub buf . contents 0 buf . pos in Array1 . blit src a ; a let resize buf n = if Array1 . dim buf . contents >= n then ( ) else let a = Array1 . create int32 c_layout ( 2 * n ) n in let a ' = Array1 . sub a 0 ( Array1 . dim buf . contents ) contents in Array1 . blit buf . contents a ' ; buf . contents <- a let add_char buf u = resize buf ( buf . pos + 1 ) 1 ; buf . contents { . buf . pos } pos <- Int32 . of_int ( UChar . uint_code u ) u ; buf . pos <- buf . pos + 1 let add_string buf ( a : t ) t = let len = buf . pos + Array1 . dim a in resize buf len ; let b = Array1 . sub buf . contents buf . pos ( Array1 . dim a ) a in Array1 . blit a b ; buf . pos <- len let add_buffer buf1 buf2 = let len = buf1 . pos + buf2 . pos in resize buf1 len ; let a = Array1 . sub buf2 . contents 0 buf2 . pos in let b = Array1 . sub buf1 . contents buf1 . pos buf2 . pos in Array1 . blit a b ; buf1 . pos <- len end |
let compare ( a : t ) t ( b : t ) t = match Array1 . dim a - Array1 . dim b with 0 -> Pervasives . compare a b | sgn -> sgn |
type genome = [ ` dm3 | ` droSim1 | ` hg18 | ` hg19 | ` hg38 | ` mm8 | ` mm9 | ` mm10 | ` sacCer2 ] |
let string_of_genome = function | ` dm3 -> " dm3 " | ` droSim1 -> " droSim1 " | ` hg18 -> " hg18 " | ` hg19 -> " hg19 " | ` hg38 -> " hg38 " | ` mm8 -> " mm8 " | ` mm9 -> " mm9 " | ` mm10 -> " mm10 " | ` sacCer2 -> " sacCer2 " |
let genome_of_string = function | " dm3 " -> Some ` dm3 | " droSim1 " -> Some ` droSim1 | " hg18 " -> Some ` hg18 | " hg19 " -> Some ` hg19 | " hg38 " -> Some ` hg38 | " mm8 " -> Some ` mm8 | " mm9 " -> Some ` mm9 | " mm10 " -> Some ` mm10 | " sacCer2 " -> Some ` sacCer2 | _ -> None method format : [ ` twobit ] inherit binary_file end inherit tsv method header : [ ` no ] method f1 : string method f2 : int end method format : [ ` bigBed ] inherit binary_file end inherit bed3 method f4 : float end method format : [ ` wig ] inherit text end method format : [ ` bigWig ] inherit binary_file end |
let img = [ docker_image ~ account " : pveber " ~ name " : ucsc - kent " ~ tag " : 330 " ( ) ] |
type chromosome_sequences = [ ` ucsc_chromosome_sequences ] directory |
let chromosome_sequence org chr = let org = string_of_genome org in let url = sprintf " ftp :// hgdownload . cse . ucsc . edu / goldenPath /% s / chromosomes /% s . fa . gz " org chr in let descr = sprintf " ucsc_gb . chromosome_sequence ( % s , % s ) " org chr in Workflow . shell ~ descr [ Bistro_unix . Cmd . wget ~ dest ( : tmp // " seq . fa . gz " ) ( Workflow . string url ) ; cmd " gunzip " [ tmp // " seq . fa . gz " ] ; cmd " mv " [ tmp // " seq . fa . gz " ; dest ] ; ] |
let chromosome_sequences org = let org = string_of_genome org in let url = sprintf " ftp :// hgdownload . cse . ucsc . edu / goldenPath /% s / chromosomes " /* org in Workflow . shell ~ descr ( : sprintf " ucsc_gb . chromosome_sequences ( % s ) " org ) [ mkdir_p dest ; cd dest ; Bistro_unix . Cmd . wget ( Workflow . string url ) ; cmd " gunzip " [ string " . * gz " ] ] |
let genome_sequence org = let chr_seqs = chromosome_sequences org in Workflow . shell ~ descr " : ucsc_gb . genome_sequence " [ cmd " bash " [ opt " - c " string " ' shopt - s nullglob ; cat $ 0 { / chr . ? fa , chr . ?? fa , chr . ??? fa , chr . ???? fa } > $ 1 ' " ; dep chr_seqs ; dest ] ] |
let genome_2bit_sequence_dir org = let org = string_of_genome org in let url = sprintf " ftp :// hgdownload . cse . ucsc . edu / goldenPath /% s / bigZips /% s . 2bit " org org in Workflow . shell ~ descr ( : sprintf " ucsc_gb . 2bit_sequence ( % s ) " org ) [ mkdir dest ; cd dest ; Bistro_unix . Cmd . wget ( Workflow . string url ) ; ] |
let genome_2bit_sequence org = Workflow . select ( genome_2bit_sequence_dir org ) [ ( string_of_genome org ) ^ " . 2bit " ] |
let twoBitToFa twobits bed = Workflow . shell ~ descr " : ucsc_gb . twoBitToFa " ~ img [ cmd " twoBitToFa " [ opt ' " - bed " dep bed ; dep twobits ; dest ] ] |
let faToTwoBit fa = Workflow . shell ~ descr " : ucsc_gb . faToTwoBit " ~ img [ cmd " faToTwoBit " [ dep fa ; dest ] ] |
let fetchChromSizes org = Workflow . shell ~ descr " : ucsc_gb . fetchChromSizes " ~ img [ cmd " fetchChromSizes " ~ stdout : dest [ string ( string_of_genome org ) ; ] ] |
let bedClip org bed = Workflow . shell ~ descr " : ucsc_gb . bedClip " ~ img [ cmd " bedClip - verbose = 2 " [ dep bed ; dep org ; dest ; ] ] |
let bedGraphToBigWig org bg = let tmp = seq [ tmp ; string " / sorted . bedGraph " ] in Workflow . shell ~ descr " : bedGraphToBigWig " ~ img [ cmd " sort " ~ stdout : tmp [ string " - k1 , 1 " ; string " - k2 , 2n " ; dep bg ; ] ; cmd " bedGraphToBigWig " [ tmp ; dep ( fetchChromSizes org ) ; dest ; ] ] |
let bedToBigBed_command org bed = let tmp = seq [ tmp ; string " / sorted . bed " ] in let sort = cmd " sort " ~ stdout : tmp [ string " - k1 , 1 " ; string " - k2 , 2n " ; dep bed ; ] in let bedToBigBed = cmd " bedToBigBed " [ tmp ; dep ( fetchChromSizes org ) ; dest ; ] in [ sort ; bedToBigBed ] |
let bedToBigBed org = let f bed = Workflow . shell ~ descr " : ucsc_gb . bedToBigBed " ~ img ( bedToBigBed_command org bed ) in function | ` bed3 bed -> f bed | ` bed5 bed -> f bed |
let bedToBigBed_failsafe org = let f bed = let test = cmd " test " [ string " ! - s " ; dep bed ] in let touch = cmd " touch " [ dest ] in let cmd = or_list [ and_list [ test ; touch ] ; and_list ( bedToBigBed_command org bed ) ; ] in Workflow . shell ~ img [ cmd ] in function | ` bed3 bed -> f bed | ` bed5 bed -> f bed |
module Lift_over = struct class type chain_file = object inherit regular_file_t method format : [ ` lift_over_chain_file ] end type ' a output = [ ` ucsc_lift_over of ' a ] directory let chain_file ~ org_from ~ org_to = let org_from = string_of_genome org_from and org_to = string_of_genome org_to in let url = sprintf " ftp :// hgdownload . cse . ucsc . edu / goldenPath /% s / liftOver /% sTo % s . over . chain . gz " org_from org_from ( String . capitalize org_to ) in Bistro_unix . ( gunzip ( wget url ) ) let bed ~ org_from ~ org_to bed = let chain_file = chain_file ~ org_from ~ org_to in Workflow . shell ~ descr " : ucsc . liftOver " ~ img [ mkdir_p dest ; cmd " liftOver " [ dep bed ; dep chain_file ; dest // " mapped . bed " ; dest // " unmapped . bed " ; ] ; ] let mapped x = Workflow . select x [ " mapped . bed " ] let unmapped x = Workflow . select x [ " unmapped . bed " ] end |
type assembly = [ ` dm3 | ` droSim1 | ` hg18 | ` hg19 | ` hg38 | ` mm8 | ` mm9 | ` mm10 | ` sacCer2 ] |
let string_of_assembly = function | ` dm3 -> " dm3 " | ` droSim1 -> " droSim1 " | ` hg18 -> " hg18 " | ` hg19 -> " hg19 " | ` hg38 -> " hg38 " | ` mm8 -> " mm8 " | ` mm9 -> " mm9 " | ` mm10 -> " mm10 " | ` sacCer2 -> " sacCer2 " |
type track_attribute = [ | ` name of string | ` description of string | ` type_ of track_type | ` visibility of [ ` hide | ` full | ` dense | ` pack | ` squish ] | ` color of color | ` itemRgb of bool | ` colorByStrand of color * color | ` useScore of bool | ` group of string | ` priority of int | ` db of assembly | ` offset of int | ` maxItems of int | ` url of string | ` htmlUrl of string | ` bigDataUrl of string ] ` bam | ` bedDetail | ` bedGraph | ` bigBed | ` bigWig | ` broadPeak | ` narrowPeak | ` array | ` vcf | ` wig ] |
let string_of_track_type = function | ` bam -> " bam " | ` bedDetail -> " bedDetail " | ` bedGraph -> " bedGraph " | ` bigBed -> " bigBed " | ` bigWig -> " bigWig " | ` broadPeak -> " broadPeak " | ` narrowPeak -> " narrowPeak " | ` array -> " array " | ` vcf -> " vcf " | ` wig -> " wig " |
let unparse_track_attribute buf = function | ` name n -> bprintf buf " name " =\% s " " \ n | ` description d -> bprintf buf " description " =\% s " " \ d | ` type_ t -> bprintf buf " type =% s " ( string_of_track_type t ) t | ` visibility v -> let v = match v with | ` full -> " full " | ` dense -> " dense " | ` hide -> " hide " | ` pack -> " pack " | ` squish -> " squish " in bprintf buf " visibility =% s " v | ` color ( r , g , b ) b -> bprintf buf " color =% d , % d , % d " r g b | ` itemRgb b -> if b then bprintf buf " itemRgb = On " | ` colorByStrand ( ( r , g , b ) b , ( r ' , g ' , b ' ) b ' ) b ' -> bprintf buf " color =% d , % d , % d % d , % d , % d " r g b r ' g ' b ' | ` useScore b -> bprintf buf " useScore =% d " ( if b then 1 else 0 ) 0 | ` group g -> bprintf buf " group " =\% s " " \ g | ` priority p -> bprintf buf " priority =% d " p | ` db assembly -> bprintf buf " db =% s " ( string_of_assembly assembly ) assembly | ` offset o -> bprintf buf " offset =% d " o | ` maxItems m -> bprintf buf " maxItems =% d " m | ` url u -> bprintf buf " url =% s " u | ` htmlUrl u -> bprintf buf " htmlUrl =% s " u | ` bigDataUrl u -> bprintf buf " bigDataUrl =% s " u |
let track_line opts = let buf = Buffer . create 1024 in bprintf buf " track " ; List . iter ~ f ( : unparse_track_attribute buf ) buf opts ; Buffer . contents buf |
type url_param = [ | ` pix of int | ` hgt_labelWidth of int | ` textSize of int ] |
let base db = main_server ^ " / cgi - bin / hgTracks ? db " = ^ ( string_of_assembly db ) db |
let string_of_position ( chr , maybe_pos ) maybe_pos = chr ^ ( match maybe_pos with | None -> " " | Some ( a , b ) b -> sprintf " :% d -% d " a b ) |
let encode_url_param = function | ` pix n -> sprintf " pix =% d " n | ` hgt_labelWidth n -> sprintf " hgt . labelWidth =% d " n | ` textSize n -> sprintf " textSize =% d " n |
let encode_url_params xs = List . map ~ f : encode_url_param xs |> String . concat ~ sep " " :& |
let custom_track_url ( ? params = [ ] ) ~ db ~ position ~ data_url ( ) = sprintf " % s & position =% s & hgt . customText =% s % s " ( base db ) db ( string_of_position position ) position data_url ( encode_url_params params ) params |
let bigData_custom_track_url ( ? params = [ ] ) ~ db ~ position ~ track ( ) = let escaped_custom_text = Uri . pct_encode ~ component ` : Query ( track_line track ) track in sprintf " % s & position =% s & hgct_customText =% s % s " ( base db ) db ( string_of_position position ) position escaped_custom_text ( encode_url_params params ) params |
type fs = { fs_id : string ; fs_name : string ; fs_supports_unix_owners : bool ; fs_can_mount : bool ; fs_can_create : bool ; fs_max_label_len : int ; fs_supports_label_rename : bool ; fs_supports_online_label_rename : bool ; fs_supports_fsck : bool ; fs_supports_online_fsck : bool ; fs_supports_resize_enlarge : bool ; fs_supports_online_resize_enlarge : bool ; fs_supports_resize_shrink : bool ; fs_supports_online_resize_shrink : bool ; } |
type job = { job_device : UDisks_device . t ; job_in_progress : bool ; job_is_cancellable : bool ; job_id : string ; job_num_tasks : int ; job_cur_task : int ; job_cur_task_id : string ; job_cur_task_percentage : float ; } |
let daemon ( ) = let % lwt bus = OBus_bus . system ( ) in return ( OBus_peer . make bus " org . freedesktop . UDisks " ) |
let proxy daemon = OBus_proxy . make daemon [ " org " ; " freedesktop " ; " UDisks " ] |
let make_device context path = UDisks_device . of_proxy ( OBus_proxy . make ( OBus_context . sender context ) path ) |
let make_adapter context path = UDisks_adapter . of_proxy ( OBus_proxy . make ( OBus_context . sender context ) path ) |
let make_expander context path = UDisks_expander . of_proxy ( OBus_proxy . make ( OBus_context . sender context ) path ) |
let make_port context path = UDisks_port . of_proxy ( OBus_proxy . make ( OBus_context . sender context ) path ) |
let enumerate_adapters daemon = let % lwt ( context , devices ) = OBus_method . call_with_context m_EnumerateAdapters ( proxy daemon ) ( ) in return ( List . map ( make_adapter context ) devices ) |
let enumerate_expanders daemon = let % lwt ( context , devices ) = OBus_method . call_with_context m_EnumerateExpanders ( proxy daemon ) ( ) in return ( List . map ( make_expander context ) devices ) |
let enumerate_ports daemon = let % lwt ( context , devices ) = OBus_method . call_with_context m_EnumeratePorts ( proxy daemon ) ( ) in return ( List . map ( make_port context ) devices ) |
let enumerate_devices daemon = let % lwt ( context , devices ) = OBus_method . call_with_context m_EnumerateDevices ( proxy daemon ) ( ) in return ( List . map ( make_device context ) devices ) |
let enumerate_device_files daemon = OBus_method . call m_EnumerateDeviceFiles ( proxy daemon ) ( ) |
let find_device_by_device_file daemon ~ device_file = let % lwt ( context , device ) = OBus_method . call_with_context m_FindDeviceByDeviceFile ( proxy daemon ) device_file in return ( make_device context device ) |
let find_device_by_major_minor daemon ~ device_major ~ device_minor = let % lwt ( context , device ) = OBus_method . call_with_context m_FindDeviceByMajorMinor ( proxy daemon ) ( device_major , device_minor ) in return ( make_device context device ) |
let drive_inhibit_all_polling daemon ~ options = OBus_method . call m_DriveInhibitAllPolling ( proxy daemon ) options |
let drive_uninhibit_all_polling daemon ~ cookie = OBus_method . call m_DriveUninhibitAllPolling ( proxy daemon ) cookie |
let drive_set_all_spindown_timeouts daemon ~ timeout_seconds ~ options = let timeout_seconds = Int32 . of_int timeout_seconds in OBus_method . call m_DriveSetAllSpindownTimeouts ( proxy daemon ) ( timeout_seconds , options ) |
let drive_unset_all_spindown_timeouts daemon ~ cookie = OBus_method . call m_DriveUnsetAllSpindownTimeouts ( proxy daemon ) cookie |
let linux_lvm2_vgstart daemon ~ uuid ~ options = OBus_method . call m_LinuxLvm2VGStart ( proxy daemon ) ( uuid , options ) |
let linux_lvm2_vgstop daemon ~ uuid ~ options = OBus_method . call m_LinuxLvm2VGStop ( proxy daemon ) ( uuid , options ) |
let linux_lvm2_vgset_name daemon ~ uuid ~ name = OBus_method . call m_LinuxLvm2VGSetName ( proxy daemon ) ( uuid , name ) |
let linux_lvm2_vgadd_pv daemon ~ uuid ~ physical_volume ~ options = let physical_volume = OBus_proxy . path ( UDisks_device . to_proxy physical_volume ) in OBus_method . call m_LinuxLvm2VGAddPV ( proxy daemon ) ( uuid , physical_volume , options ) |
let linux_lvm2_vgremove_pv daemon ~ vg_uuid ~ pv_uuid ~ options = OBus_method . call m_LinuxLvm2VGRemovePV ( proxy daemon ) ( vg_uuid , pv_uuid , options ) |
let linux_lvm2_lvset_name daemon ~ group_uuid ~ uuid ~ name = OBus_method . call m_LinuxLvm2LVSetName ( proxy daemon ) ( group_uuid , uuid , name ) |
let linux_lvm2_lvstart daemon ~ group_uuid ~ uuid ~ options = OBus_method . call m_LinuxLvm2LVStart ( proxy daemon ) ( group_uuid , uuid , options ) |
let linux_lvm2_lvremove daemon ~ group_uuid ~ uuid ~ options = OBus_method . call m_LinuxLvm2LVRemove ( proxy daemon ) ( group_uuid , uuid , options ) |
let linux_lvm2_lvcreate daemon ~ group_uuid ~ name ~ size ~ num_stripes ~ stripe_size ~ num_mirrors ~ options ~ fstype ~ fsoptions = let num_stripes = Int32 . of_int num_stripes in let num_mirrors = Int32 . of_int num_mirrors in let % lwt ( context , created_device ) = OBus_method . call_with_context m_LinuxLvm2LVCreate ( proxy daemon ) ( group_uuid , name , size , num_stripes , stripe_size , num_mirrors , options , fstype , fsoptions ) in return ( make_device context created_device ) |
let linux_md_start daemon ~ components ~ options = let components = List . map ( fun c -> OBus_proxy . path ( UDisks_device . to_proxy c ) ) components in let % lwt ( context , device ) = OBus_method . call_with_context m_LinuxMdStart ( proxy daemon ) ( components , options ) in return ( make_device context device ) |
let linux_md_create daemon ~ components ~ level ~ stripe_size ~ name ~ options = let components = List . map ( fun c -> OBus_proxy . path ( UDisks_device . to_proxy c ) ) components in let % lwt ( context , device ) = OBus_method . call_with_context m_LinuxMdCreate ( proxy daemon ) ( components , level , stripe_size , name , options ) in return ( make_device context device ) |
let inhibit daemon = OBus_method . call m_Inhibit ( proxy daemon ) ( ) |
let uninhibit daemon ~ cookie = OBus_method . call m_Uninhibit ( proxy daemon ) cookie |
let device_added daemon = OBus_signal . map_with_context make_device ( OBus_signal . make s_DeviceAdded ( proxy daemon ) ) |
let device_removed daemon = OBus_signal . map_with_context make_device ( OBus_signal . make s_DeviceRemoved ( proxy daemon ) ) |
let device_changed daemon = OBus_signal . map_with_context make_device ( OBus_signal . make s_DeviceChanged ( proxy daemon ) ) |
let device_job_changed daemon = OBus_signal . map_with_context ( fun context ( device , job_in_progress , job_is_cancellable , job_id , job_num_tasks , job_cur_task , job_cur_task_id , job_cur_task_percentage ) -> { job_device = make_device context device ; job_in_progress = job_in_progress ; job_is_cancellable = job_is_cancellable ; job_id = job_id ; job_num_tasks = Int32 . to_int job_num_tasks ; job_cur_task = Int32 . to_int job_cur_task ; job_cur_task_id = job_cur_task_id ; job_cur_task_percentage = job_cur_task_percentage ; } ) ( OBus_signal . make s_DeviceJobChanged ( proxy daemon ) ) |
let adapter_added daemon = OBus_signal . map_with_context make_adapter ( OBus_signal . make s_AdapterAdded ( proxy daemon ) ) |
let adapter_removed daemon = OBus_signal . map_with_context make_adapter ( OBus_signal . make s_AdapterRemoved ( proxy daemon ) ) |
let adapter_changed daemon = OBus_signal . map_with_context make_adapter ( OBus_signal . make s_AdapterChanged ( proxy daemon ) ) |
let expander_added daemon = OBus_signal . map_with_context make_expander ( OBus_signal . make s_ExpanderAdded ( proxy daemon ) ) |
let expander_removed daemon = OBus_signal . map_with_context make_expander ( OBus_signal . make s_ExpanderRemoved ( proxy daemon ) ) |
let expander_changed daemon = OBus_signal . map_with_context make_expander ( OBus_signal . make s_ExpanderChanged ( proxy daemon ) ) |
let port_added daemon = OBus_signal . map_with_context make_port ( OBus_signal . make s_PortAdded ( proxy daemon ) ) |
let port_removed daemon = OBus_signal . map_with_context make_port ( OBus_signal . make s_PortRemoved ( proxy daemon ) ) |
let port_changed daemon = OBus_signal . map_with_context make_port ( OBus_signal . make s_PortChanged ( proxy daemon ) ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.