text
stringlengths 12
786k
|
---|
module Transform = struct open Result . Monad_infix let explode_key_value loc s = try let by_space = String . split_on_chars s ~ on [ : ' ' ; ' \ n ' ; ' \ t ' ; ' \ r ' ] r ' |> List . filter ~ f ( : String ( ) . <> ) " " in Ok ( List . map by_space ~ f ( : fun s -> begin match String . split ~ on : ' = ' s with | [ key ; value ] -> ( key , value ) value | _ -> raise Caml . Not_found end ) end ) end with Caml . Not_found -> Error ( ` cannot_parse_key_values ( loc , s ) s ) s let rec next ~ tags p = let open Lines . Buffer in let assoc_find ~ missing l v = match List . Assoc . find ~ equal : String . equal l v with | Some v -> Ok v | None -> Error missing in let assoc_find_map ~ missing ~ wrong ~ f l v = match List . Assoc . find ~ equal : String . equal l v with | Some v -> ( try Ok ( f v ) v with _ -> Error wrong ) wrong | None -> Error missing in match ( next_line p :> string option ) option with | Some " " -> if tags . Tags . allow_empty_lines then ` output ( Error ( ` empty_line ( current_position p ) p ) p ) p else next ~ tags p | Some l when tags . Tags . sharp_comments && String . is_prefix l ~ prefix " " :# -> ` output ( Ok ( ` comment String ( . sub l ~ pos : 1 ~ len ( : length l - 1 ) 1 ) 1 ) 1 ) 1 | Some l when String . is_prefix l ~ prefix " : fixedStep " -> let output_m = explode_key_value ( current_position p ) p String ( . chop_prefix_exn l ~ prefix " : fixedStep ) " >>= fun assoc -> assoc_find assoc " chrom " ~ missing ( ` : missing_chrom_value ( current_position p , l ) l ) l >>= fun chrom -> assoc_find_map assoc " start " ~ missing ( ` : missing_start_value ( current_position p , l ) l ) l ~ f : Int . of_string ~ wrong ( ` : wrong_start_value ( current_position p , l ) l ) l >>= fun start -> assoc_find_map assoc " step " ~ missing ( ` : missing_step_value ( current_position p , l ) l ) l ~ f : Int . of_string ~ wrong ( ` : wrong_step_value ( current_position p , l ) l ) l >>= fun step -> begin match List . Assoc . find ~ equal : String . equal assoc " span " with | None -> Ok ( ` fixed_step_state_change ( chrom , start , step , None ) None ) None | Some span -> begin match Option . try_with ( fun ( ) -> Int . of_string span ) span with | Some i -> Ok ( ` fixed_step_state_change ( chrom , start , step , Some i ) i ) i | None -> Error ( ` wrong_span_value ( current_position p , span ) span ) span end end in ` output output_m | Some l when String . is_prefix l ~ prefix " : variableStep " -> let output_m = explode_key_value ( current_position p ) p String ( . chop_prefix_exn l ~ prefix " : variableStep ) " >>= fun assoc -> assoc_find assoc " chrom " ~ missing ( ` : missing_chrom_value ( current_position p , l ) l ) l >>= fun chrom -> begin match List . Assoc . find ~ equal : String . equal assoc " span " with | None -> Ok ( ` variable_step_state_change ( chrom , None ) None ) None | Some span -> begin match Option . try_with ( fun ( ) -> Int . of_string span ) span with | Some i -> Ok ( ` variable_step_state_change ( chrom , Some i ) i ) i | None -> Error ( ` wrong_span_value ( current_position p , span ) span ) span end end in ` output output_m | Some l -> let by_space = String . split_on_chars l ~ on [ : ' ' ; ' \ n ' ; ' \ t ' ; ' \ r ' ] r ' |> List . filter ~ f ( : String ( ) . <> ) " " in begin match by_space with | [ one_value ] -> ( try ` output ( Ok ( ` fixed_step_value Float ( . of_string one_value ) one_value ) one_value ) one_value with _ -> ` output ( Error ( ` wrong_fixed_step_value ( current_position p , l ) l ) l ) l ) l | [ fst_val ; snd_val ] snd_val -> ( try ` output ( Ok ( ` variable_step_value ( Int . of_string fst_val , Float . of_string snd_val ) snd_val ) snd_val ) snd_val with _ -> ` output ( Error ( ` wrong_variable_step_value ( current_position p , l ) l ) l ) l ) l | [ chr ; b ; e ; v ; ] -> ( try ` output ( Ok ( ` bed_graph_value ( chr , Int . of_string b , Int . of_string e , Float . of_string v ) v ) v ) v with _ -> ` output ( Error ( ` wrong_bed_graph_value ( current_position p , l ) l ) l ) l ) l | l -> ` output ( Error ( ` unrecognizable_line ( current_position p , l ) l ) l ) l end | None -> ` not_ready let string_to_item ? filename ( ? tags = Tags . default ) default ( ) = let name = sprintf " wig_parser :% s " Option ( . value ~ default " " :<> filename ) filename in let next = next ~ tags in Lines . Transform . make_merge_error ~ name ? filename ~ next ( ) let item_to_string ( ? tags = Tags . default ) default ( ) = let to_string = function | ` comment c -> if tags . Tags . sharp_comments then sprintf " #% s \ n " c else " " | ` variable_step_state_change ( chrom , span ) span -> sprintf " variableStep chrom =% s % s \ n " chrom Option ( . value_map ~ default " " : span ~ f ( : sprintf " span =% d ) ) " | ` variable_step_value ( pos , v ) v -> sprintf " % d % g \ n " pos v | ` fixed_step_state_change ( chrom , start , step , span ) span -> sprintf " fixedStep chrom =% s start =% d step =% d % s \ n " chrom start step Option ( . value_map ~ default " " : span ~ f ( : sprintf " span =% d ) ) " | ` fixed_step_value v -> sprintf " % g \ n " v | ` bed_graph_value ( chrom , start , stop , v ) v -> sprintf " % s % d % d % g \ n " chrom start stop v in Tfxm . of_function ~ name " : wig_to_string " to_string let item_to_bed_graph ( ) = let queue = Queue . create ( ) in let current_state = ref None in Tfxm . make ~ name " : wig_to_variable_step " ( ) ~ feed ( : function | ` comment _ -> ( ) | ` bed_graph_value already_done -> Queue . enqueue queue ( ` output ( Ok already_done ) already_done ) already_done | ` variable_step_state_change ( chrom , span ) span -> current_state := Some ( ` variable ( chrom , span ) span ) span | ` variable_step_value ( pos , v ) v -> begin match ! current_state with | Some ( ` variable ( chrom , span ) span ) span -> let stop = pos + Option ( . value ~ default : 1 span ) span - 1 in Queue . enqueue queue ( ` output ( Ok ( chrom , pos , stop , v ) v ) v ) v | _ -> Queue . enqueue queue ( ` output ( Error ( ` not_in_variable_step_state ) not_in_variable_step_state ) not_in_variable_step_state ) not_in_variable_step_state end | ` fixed_step_state_change ( chrom , start , step , span ) span -> current_state := Some ( ` fixed ( chrom , start , step , span , 0 ) 0 ) 0 | ` fixed_step_value v -> begin match ! current_state with | Some ( ` fixed ( chrom , start , step , span , current ) current ) current -> let pos = start + ( step * current ) current in let stop = pos + Option ( . value ~ default : 1 span ) span - 1 in Queue . enqueue queue ( ` output ( Ok ( chrom , pos , stop , v ) v ) v ) v ; current_state := Some ( ` fixed ( chrom , start , step , span , current + 1 ) 1 ) 1 | _ -> Queue . enqueue queue ( ` output ( Error ( ` not_in_fixed_step_state ) not_in_fixed_step_state ) not_in_fixed_step_state ) not_in_fixed_step_state end ) end ~ next ( : fun stopped -> match Queue . dequeue queue with | None -> if stopped then ` end_of_stream else ` not_ready | Some v -> v ) v end |
let error_to_exn e = Error e |
let in_channel_to_item_stream ( ? buffer_size = 65536 ) 65536 ? filename ? tags inp = let x = Transform . string_to_item ? filename ? tags ( ) in Tfxm ( . in_channel_strings_to_stream inp x ~ buffer_size ) buffer_size |
let in_channel_to_item_stream_exn ? buffer_size ? filename ? tags inp = Stream . result_to_exn ~ error_to_exn ( in_channel_to_item_stream ? filename ? buffer_size ? tags inp ) inp |
let in_channel_to_bed_graph ( ? buffer_size = 65536 ) 65536 ? filename ? tags inp = let x = Transform . string_to_item ? filename ? tags ( ) in let y = Transform . item_to_bed_graph ( ) in Tfxm ( . compose_results x y ~ on_error ( : function ` left x -> x | ` right x -> x ) x |> in_channel_strings_to_stream ~ buffer_size inp ) |
let in_channel_to_bed_graph_exn ? buffer_size ? filename ? tags inp = Stream . result_to_exn ~ error_to_exn ( in_channel_to_bed_graph ? filename ? buffer_size ? tags inp ) inp |
let item_to_string ( ? tags = Tags . default ) default = function | ` comment c -> if tags . Tags . sharp_comments then sprintf " #% s \ n " c else " " | ` variable_step_state_change ( chrom , span ) span -> sprintf " variableStep chrom =% s % s \ n " chrom Option ( . value_map ~ default " " : span ~ f ( : sprintf " span =% d ) ) " | ` variable_step_value ( pos , v ) v -> sprintf " % d % g \ n " pos v | ` fixed_step_state_change ( chrom , start , step , span ) span -> sprintf " fixedStep chrom =% s start =% d step =% d % s \ n " chrom start step Option ( . value_map ~ default " " : span ~ f ( : sprintf " span =% d ) ) " | ` fixed_step_value v -> sprintf " % g \ n " v | ` bed_graph_value ( chrom , start , stop , v ) v -> sprintf " % s % d % d % g \ n " chrom start stop v |
type rope = | Menu_link of string * rope | Leaf of string | Leaf_unquoted of string | Node of rope * rope | Node3 of string * rope list * string | Nodelist of rope list |
let reg0 ' = Str . regexp_string " WIKIBACKSLASHWIKI " |
let reg0 = Str . regexp_string " " \\ |
let reg1 = Str . regexp_string " _ " |
let reg2 = Str . regexp_string " " $ |
let reg3 = Str . regexp_string " " & |
let reg4 = Str . regexp_string " " % |
let reg5 = Str . regexp_string " " # |
let reg6 = Str . regexp_string " " ^ |
let reg7 = Str . regexp_string " " - |
let regs = [ ( reg0 , " WIKIBACKSLASHWIKI " ) ; ( reg1 , " \\ _ " ) ; ( reg2 , " " ) ; \\$ ( reg3 , " " ) ; \\& ( reg4 , " " ) ; \\% ( reg5 , " $\\ sharp " ) ; $ ( reg6 , " " ) ; \\^ ( Str . regexp_string " { " , " { " ) ; \\ ( Str . regexp_string " } " , " } " ) ; \\ ( Str . regexp_string " " , ~ " { \\ texttildelow } " ) ; ( reg0 ' , " $\\ backslash " ) ; $ ] |
let escape s = List . fold_left ( fun s ( reg , subst ) -> Str . global_replace reg subst s ) s regs |
let escape_ref s = let s = Str . global_replace reg1 " " = s in let s = Str . global_replace reg2 " " + s in let s = Str . global_replace reg3 " , " s in let s = Str . global_replace reg4 " ; " s in let s = Str . global_replace reg5 " " * s in s |
let escape_label s = List . fold_left ( fun s ( reg , subst ) -> Str . global_replace reg subst s ) s [ reg7 , " " ; : reg1 , " " ; - reg4 , " - pc " ] |
let reg_u = Str . regexp_string " " ~>> |
let regs_unquoted = [ ( reg_u , " " ) ; >> ] |
let escape_code s = List . fold_left ( fun s ( reg , subst ) -> Str . global_replace reg subst s ) s regs_unquoted |
let rec print_rope = function | Menu_link _ -> print_string " { \\ bfseries ** Error in menu } " | Leaf s -> print_string ( escape s ) | Leaf_unquoted s -> print_string ( escape_code s ) | Node ( r1 , r2 ) -> print_rope r1 ; print_rope r2 | Node3 ( s1 , rl , s2 ) -> print_string s1 ; List . iter print_rope rl ; print_string s2 | Nodelist l -> List . iter print_rope l |
let offset = try int_of_string Sys . argv . ( 2 ) with _ -> 0 |
let label_prefix = escape_label Sys . argv . ( 1 ) |
let sect n = match n + offset with | 1 -> Leaf_unquoted " \ n \\ part { " | 2 -> Leaf_unquoted " \ n \\ chapter { " | 3 -> Leaf_unquoted " \ n \\ section { " | 4 -> Leaf_unquoted " \ n \\ subsection { " | 5 -> Leaf_unquoted " \ n \\ subsubsection { " | 6 -> Leaf_unquoted " \ n \\ paragraph { " | _ -> Leaf_unquoted " \ n \ n { " |
let close_sect ? id ( ) = match id with | Some id -> Node3 ( " } \ n \\ label { " , [ Leaf_unquoted id ] , " } \ n " ) | None -> Leaf_unquoted " } \ n " |
let get_id attribs = try Some ( label_prefix ^ " " : ^ escape_label ( List . assoc " id " attribs ) ) with Not_found -> None |
let is_inline = ref 0 |
module LatexBuilder = struct type href = string type param = unit type phrasing_without_interactive = rope Lwt . t type phrasing = rope Lwt . t type flow = rope Lwt . t type flow_without_interactive = rope Lwt . t type uo_list = rope Lwt . t let list x = x let flow x = x let phrasing x = x let section_elem _ x = Lwt_list . map_s ( fun x -> x ) x >>= fun l -> Lwt . return ( Nodelist l ) let chars s = Lwt . return ( Leaf s ) let strong_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> Lwt . return ( Node3 ( " { \\ bfseries " , inlinelist , " } " ) ) let em_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> Lwt . return ( Node3 ( " \\ emph { " , inlinelist , " } " ) ) let br_elem attribs = Lwt . return ( Leaf_unquoted " \\ mbox { } " ) \\\\ let img_elem attribs addr alt = Lwt . return ( Node3 ( " \\ includegraphics { " , [ Leaf addr ] , " } " ) ) let tt_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> Lwt . return ( Node3 ( " { \\ tt " , inlinelist , " } " ) ) let monospace_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> Lwt . return ( Node3 ( " { \\ tt " , inlinelist , " } " ) ) let underlined_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> Lwt . return ( Node3 ( " \\ underline { " , inlinelist , " } " ) ) let linethrough_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> Lwt . return ( Node3 ( " \\ linethrough { " , inlinelist , " } " ) ) let subscripted_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> Lwt . return ( Node3 ( " $ _ { \\ mbox { " , inlinelist , " } } " ) ) $ let superscripted_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> Lwt . return ( Node3 ( " { $^\\ mbox { " , inlinelist , " } } " ) ) $ let nbsp = Lwt . return ( Leaf_unquoted " " ) ~ let endash = Lwt . return ( Leaf_unquoted " " ) -- let emdash = Lwt . return ( Leaf_unquoted " " ) --- let a_elem_phrasing attribs addr c = Lwt_list . map_s ( fun x -> x ) c >>= fun c -> Lwt . return ( Node ( Node3 ( " \\ hyperref [ " , [ Leaf ( escape_ref addr ) ] , " ] { " ) , Node ( Nodelist c , Leaf_unquoted " } " ) ) ) let a_elem_flow = a_elem_phrasing let make_href _ a fragment = match fragment with | None -> a | Some f -> a " " ^#^ f let p_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> if ! is_inline > 0 then Lwt . return ( Nodelist inlinelist ) else Lwt . return ( Node3 ( " \ n " , inlinelist , " \ n \ n " ) ) let pre_elem attribs stringlist = Lwt . return ( Node3 ( " \ n \\ begin { verbatim } \ n " , List . map ( fun s -> Leaf_unquoted s ) stringlist , " \\ end { verbatim } \ n \\ medskip \ n \ n \\ noindent " ) ) let h1_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> let id = Some label_prefix in Lwt . return ( Nodelist [ sect 2 ; Nodelist inlinelist ; close_sect ? id ( ) ] ) let h2_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> let id = get_id attribs in Lwt . return ( Nodelist [ sect 3 ; Nodelist inlinelist ; close_sect ? id ( ) ] ) let h3_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> let id = get_id attribs in Lwt . return ( Nodelist [ sect 4 ; Nodelist inlinelist ; close_sect ? id ( ) ] ) let h4_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> let id = get_id attribs in Lwt . return ( Nodelist [ sect 5 ; Nodelist inlinelist ; close_sect ? id ( ) ] ) let h5_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> let id = get_id attribs in Lwt . return ( Nodelist [ sect 6 ; Nodelist inlinelist ; close_sect ? id ( ) ] ) let h6_elem attribs inlinelist = Lwt_list . map_s ( fun x -> x ) inlinelist >>= fun inlinelist -> let id = get_id attribs in Lwt . return ( Nodelist [ sect 7 ; Nodelist inlinelist ; close_sect ? id ( ) ; Leaf " \ n " ] ) let ul_elem attribs l = Lwt_list . map_s ( fun ( il , flopt , _ ) -> Lwt_list . map_s ( fun x -> x ) il >>= fun il -> match flopt with | None -> Lwt . return ( Node ( Leaf_unquoted " \\ item " , Nodelist il ) ) | Some fl -> fl >>= fun fl -> Lwt . return ( Node ( Node ( Leaf_unquoted " \\ item " , Nodelist il ) , fl ) ) ) l >>= fun l -> Lwt . return ( Node3 ( " \ n \\ begin { itemize } \ n " , l , " \ n \\ end { itemize } \ n " ) ) let ol_elem attribs l = Lwt_list . map_s ( fun ( il , flopt , _ ) -> Lwt_list . map_s ( fun x -> x ) il >>= fun il -> match flopt with | None -> Lwt . return ( Node3 ( " \ n \\ item " , il , " " ) ) | Some fl -> fl >>= fun fl -> Lwt . return ( Node3 ( " \ n \\ item " , il [ @ fl ] , " " ) ) ) l >>= fun l -> Lwt . return ( Node3 ( " \ n \\ begin { enumerate } \ n " , l , " \ n \\ end { enumerate } \ n " ) ) let dl_elem attribs l = let rec aux = function | ( true , title , _ ) ( :: false , c , _ ) :: l -> ( Lwt_list . map_s ( fun x -> x ) title >>= fun title -> Lwt_list . map_s ( fun x -> x ) c >>= fun c -> aux l >>= fun l -> Lwt . return ( Node3 ( " \ n \\ item [ { " , title ( @ Leaf_unquoted " } ] " :: c ) , " " ) :: l ) ) | ( true , title , _ ) :: l -> ( Lwt_list . map_s ( fun x -> x ) title >>= fun title -> aux l >>= fun l -> Lwt . return ( Node3 ( " \ n \\ item [ { " , title , " } ] " ) :: l ) ) | ( false , c , _ ) :: l -> ( Lwt_list . map_s ( fun x -> x ) c >>= fun c -> aux l >>= fun l -> Lwt . return ( Nodelist ( ( Leaf_unquoted " \ n \\ item [ ] " ) :: c ) :: l ) ) | [ ] -> Lwt . return [ ] in aux l >>= fun l -> Lwt . return ( Node3 ( " \ n \\ begin { description } \ n " , l , " \ n \\ end { description } \ n " ) ) let hr_elem _ = Lwt . return ( Leaf_unquoted " \ n \ n " ) let table_elem _ l = let rec get_colspan = function | [ ] -> 1 | ( " colspan " , v ) :: _ -> int_of_string v | _ :: l -> get_colspan l in let nbcol = match l with | [ ] -> 0 | l1 :: _ -> List . fold_left ( fun nb ( _ , attrs , _ ) -> nb + get_colspan attrs ) 0 ( fst l1 ) in let sizecol = " p { " ^ string_of_float ( 1 . . / float nbcol ) " ^\\ textwidth } " in let rec aux n v = if n = 0 then [ ] else v :: aux ( n - 1 ) v in let format = String . concat " " ( aux nbcol sizecol ) in let make_multicol header nb l = if not header && nb = 1 then Nodelist l else Node3 ( " \\ multicolumn { " ^ string_of_int nb ^ " } { l } { \\ begin { minipage } { " ^ string_of_float ( float nb . / float nbcol ) ^ " \\ textwidth } " ^ ( if header then " \\ centering " else " " ) , l , " \\ end { minipage } } " ) in let l = List . map ( fun ( il , _ ) -> ( match il with | [ ] -> Lwt . return [ ] | ( header , attrs , a ) :: ll -> Lwt_list . map_s ( fun x -> x ) a >>= fun a -> let a = make_multicol header ( get_colspan attrs ) a in Lwt_list . map_s ( fun ( header , attrs , i ) -> Lwt_list . map_s ( fun x -> x ) i >>= fun i -> let i = make_multicol header ( get_colspan attrs ) i in Lwt . return ( Node ( Leaf_unquoted " " , & i ) ) ) ll >>= fun r -> Lwt . return ( a :: r ) ) >>= fun r -> Lwt . return ( Node ( Nodelist r , Leaf_unquoted " \\\\\ n " ) ) ) l in Lwt_list . map_s ( fun x -> x ) l >>= fun l -> Lwt . return ( Node3 ( " \ n \\ noindent \ n \\ begin { tabular } { " ^ format " } ^\ n " , l , " \\ end { tabular } \ n " ) ) let inline i = i let error s = Lwt . return ( Node3 ( " { \\ bfseries Error { \\ em " , [ Leaf s ] , " } } " ) ) type syntax_extension = ( flow , ( href * attribs * flow_without_interactive ) , phrasing_without_interactive , ( href * attribs * phrasing_without_interactive ) ) ext_kind let errmsg ( ? err = Leaf " Unsupported plugin " ) name = Lwt . return ( Nodelist [ Leaf_unquoted " { \\ bfseries ** Plugin error { \\ em " ; Leaf name ; Leaf_unquoted " } ( " ; err ; Leaf_unquoted " ) } " ] ) let plugin_fun : ( string -> bool * ( param , syntax_extension ) plugin ) ref = ref ( fun name -> ( true , ( fun ( ) args content -> ` Flow5 ( errmsg name ) ) ) ) let plugin name = ! plugin_fun name let plugin_action _ _ _ _ _ _ = ( ) let link_action _ _ _ _ _ = ( ) end |
let builder = ( module LatexBuilder : Wikicreole . Builder with type param = unit and type flow = rope Lwt . t ) |
let tex_of_wiki s = Lwt_list . map_s ( fun x -> x ) ( Wikicreole . from_string ~ sectioning : false ( ) builder s ) |
let inlinetex_of_wiki s = incr is_inline ; tex_of_wiki s >>= fun r -> decr is_inline ; Lwt . return r |
let unsup = " unsupported syntax in menu " |
let failed _ _ = failwith unsup |
let failed1 _ = failwith unsup |
let offset_file = open_out " . latex_of_wiki_offsets " |
let item i attribs il = Lwt_list . map_s ( fun x -> x ) il >>= function | Menu_link ( addr , _ ) :: _ -> output_string offset_file addr ; output_string offset_file " " ; output_string offset_file ( string_of_int ( i - 2 ) ) ; output_string offset_file " \ n " ; flush offset_file ; Lwt . return ( Node3 ( " \\ input { " , [ Leaf addr ] , " } \ n " ) ) | il -> output_string offset_file " " ; === Lwt . return ( Nodelist [ sect i ; Nodelist il ; close_sect ( ) ] ) |
let plugin_fun = function | _ -> ( true , fun ( ) args content -> ` Phrasing_without_interactive ( Lwt . return ( Leaf " " ) ) ) |
module LatexMenuBuilder = struct include Wiki_latex . LatexBuilder let p_elem = failed let pre_elem = failed let h1_elem = item 1 let h2_elem = item 2 let h3_elem = item 3 let h4_elem = item 4 let h5_elem = item 5 let h6_elem = item 6 let ol_elem = failed let dl_elem = failed let hr_elem = failed1 let table_elem = failed let a_elem_phrasing attribs addr c = Lwt_list . map_s ( fun x -> x ) c >>= fun c -> Lwt . return ( Menu_link ( addr , Node ( Nodelist c , Leaf " } " ) ) ) let a_elem_flow = a_elem_phrasing let ul_elem = failed let plugin_fun = plugin_fun end |
let builder = ( module LatexMenuBuilder : Wikicreole . Builder with type param = unit and type flow = rope Lwt . t ) |
let menu_of_wiki s = Lwt_list . map_s ( fun x -> x ) ( Wikicreole . from_string ~ sectioning : false ( ) builder s ) |
let rec dir_writer lst = match lst with Root s :: tl -> ( s " " ) ( ^:\\^ dir_writer tl ) | [ CurrentDir Short ] -> " " | lst -> let dir_writer_aux cmp = match cmp with Root s -> s | ParentDir -> " . . " | CurrentDir _ -> " . " | Component s -> s in String . concat " " \\ ( List . map dir_writer_aux lst ) |
let dir_reader str = let fn_part_of_string = function | " . . " -> ParentDir | " . " -> CurrentDir Long | str -> Component str in let fn_part_split str = let lst = List . flatten ( List . map ( StringExt . split ~ map : fn_part_of_string ' ' ) \\ ( StringExt . split ~ map ( : fun s -> s ) ' ' / str ) ) in match lst with | Component " " :: tl -> tl | lst -> lst in try let drive_letter , str = StringExt . break_at_first ' ' : str in Root drive_letter :: ( fn_part_split str ) with Not_found -> fn_part_split str |
let fast_is_current fn = if String . length fn = 0 || fn = " . " then true else if fn . [ 0 ] <> ' . ' then false else raise CannotHandleFast |
let fast_is_parent fn = if fn = " . . " then true else if String . length fn < 2 || fn . [ 0 ] <> ' . ' || fn . [ 1 ] <> ' . ' then false else raise CannotHandleFast |
let path_writer lst = String . concat " ; " lst |
let path_reader str = StringExt . split ~ map ( : fun s -> s ) ' ; ' str |
let top_left = I . string A . ( fg blue ) " " β |
let top_right = I . string A . ( fg blue ) " " β |
let bottom_right = I . string A . ( fg blue ) " " β |
let bottom_left = I . string A . ( fg blue ) " " β |
let top = I . uchar A . ( fg blue ) ( Uchar . of_int 0x2501 ) |
let side = I . uchar A . ( fg blue ) ( Uchar . of_int 0x2503 ) |
let left = I . string A . ( fg blue ) " " β« |
let right = I . string A . ( fg blue ) " " β£ |
type t = { title : string ; cursor : int ; image : image ; refresh : Goodboy . State . t -> image ; } |
let make ~ cursor ~ title ~ refresh state = let image = refresh state in { cursor ; image ; refresh ; title ; } |
let down_cursor t i = if t . cursor - i < 0 then { t with cursor = 0 ; } else { t with cursor = t . cursor - i } |
let up_cursor t i = let image_h = I . height t . image in if t . cursor + i > image_h then { t with cursor = image_h } else { t with cursor = t . cursor + i } |
let set_cursor t i = { t with cursor = i ; } |
let refresh t state = { t with image = t . refresh state ; } |
let with_window ~ title i = let w = I . width i in let h = I . height i in let title = let title = I . string A . ( fg yellow ) title in I . ( ( hsnap ~ align ` : Middle w ( left <|> title <|> right ) ) </> ( top_left <|> top w 1 <|> top_right ) ) in let bottom = I . ( ( bottom_left <|> top w 1 <|> bottom_right ) ) in let left = side 1 ( h + 1 ) |> I . hpad 0 w in let right = side 1 ( h + 1 ) in let win = I . ( ( title |> vpad 0 h <-> bottom ) </> ( left <|> right ) ) in I . ( ( hpad 1 0 i |> vpad 1 2 ) </> win ) |
let render ~ window_h { image ; cursor ; title ; _ } = let image_h = I . height image in let crop_top = if cursor < window_h then 0 else cursor - window_h in let crop_bottom = if cursor + window_h > image_h then 0 else image_h - crop_top - window_h in let i = I . ( vcrop crop_top crop_bottom image |> vsnap window_h ) in with_window ~ title i |
module T = struct include Value . Make_subtype ( struct let name = " window " let here = [ % here ] let is_in_subtype = Value . is_window end ) let equal = eq end |
type window = t [ @@ deriving sexp_of ] |
module Edges = struct type t = { bottom : int ; left : int ; right : int ; top : int } [ @@ deriving sexp_of ] include Valueable . Make ( struct type nonrec t = t let type_ = Value . Type . ( map ( tuple int ( tuple int ( tuple int ( tuple int unit ) ) ) ) ~ name [ :% sexp " Window . Tree . Position_and_size . t " ] ) ~ of_ ( : fun ( left , ( top , ( right , ( bottom , ( ) ) ) ) ) -> { bottom ; left ; right ; top } ) ~ to_ ( : fun { bottom ; left ; right ; top } -> left , ( top , ( right , ( bottom , ( ) ) ) ) ) ; ; end ) end |
module Tree = struct module Direction = struct module T = struct type t = | Left_to_right | Top_to_bottom [ @@ deriving enumerate , sexp_of ] end include T let is_top_to_bottom = function | Left_to_right -> false | Top_to_bottom -> true ; ; include Valueable . Make ( struct type nonrec t = t let type_ = Value . Type . enum [ % sexp " Window . Tree . Direction . t " ] ( module T ) ( is_top_to_bottom >> Value . of_bool ) ; ; end ) end type t = | Combination of { children : t list ; direction : Direction . t ; edges : Edges . t } | Window of window [ @@ deriving sexp_of ] let tuple_type = Value . Type . ( tuple Direction . t ( tuple Edges . t ( list value ) ) ) let rec of_value_exn value = match T . is_in_subtype value with | true -> Window ( T . of_value_exn value ) | false -> let direction , ( edges , children ) = Value . Type . of_value_exn tuple_type value in let children = List . map children ~ f : of_value_exn in Combination { children ; direction ; edges } ; ; let rec to_value = function | Window window -> T . to_value window | Combination { children ; direction ; edges } -> Value . Type . to_value tuple_type ( direction , ( edges , List . map children ~ f : to_value ) ) ; ; let type_ = Value . Type . create [ % message " Window . Tree . t " ] [ % sexp_of : t ] of_value_exn to_value ; ; let t = type_ let parent_exn t window = let rec aux t ~ parent = match t with | Window window ' -> ( match T . equal window window ' with | true -> Some parent | false -> None ) | Combination { children ; direction = _ ; edges = _ } -> List . find_map children ~ f ( : aux ~ parent : t ) in match aux t ~ parent : t with | Some t -> t | None -> raise_s [ % message " Window not in this tree . " ( window : window ) ~ _ ( : t : t ) ] ; ; end |
module type BoundedQueueWithCounter = sig type ' a t val empty : int -> ' a t val create : int -> ' a -> ' a t val is_empty : ' a t -> bool val is_full : ' a t -> bool val size : ' a t -> int val enqueue : ' a -> ' a t -> ' a t val dequeue : ' a t -> ' a option * ' a t val count : ' a t -> int val fold : ( ' b -> ' a -> ' b ) -> ' b -> ' a t -> ' b val to_list : ' a t -> ' a list end |
module Window : BoundedQueueWithCounter = struct type ' a t = { data : ( ' a list ) * ( ' a list ) ; maxsize : int ; size : int ; count : int } let empty n = if n = 0 then failwith " Cannot create queue of size 0 " ! else { data = ( [ ] , [ ] ) ; maxsize = n ; size = n ; count = 0 } let create n i = let rec gen l acc i = if l = 0 then acc else gen ( l - 1 ) ( i :: acc ) i in if n = 0 then failwith " Cannot create queue of size 0 " ! else let initdata = gen n [ ] i in { data = ( initdata , [ ] ) ; maxsize = n ; size = n ; count = 0 } let is_empty q = ( q . size = 0 ) let is_full q = ( q . size = q . maxsize ) let size q = q . size let rec dequeue q = match q . data with | h :: t , b -> ( Some h , { q with data = ( t , b ) ; size = q . size - 1 } ) [ ] , [ ] | -> ( None , q ) [ ] , | h :: t -> dequeue { q with data = ( List . rev ( h :: t ) , [ ] ) } let rec enqueue item q = if is_full q then dequeue q |> snd |> enqueue item else match q . data with | f , b -> { q with data = ( f , item :: b ) ; size = q . size + 1 ; count = q . count + 1 } let count q = q . count let to_list q = ( fst q . data ) ( @ snd q . data |> List . rev ) let fold f init q = List . fold_left f init ( to_list q ) end |
let winnow w h = let global_pos i w = let c = Window . count w in let s = Window . size w in c - ( s - 1 - i ) in let mincheck ( ( minval , minpos ) , count ) x = if x <= minval then ( ( x , count ) , count + 1 ) else ( ( minval , minpos ) , count + 1 ) in let rec winnowhelper hashes window acc n ( v , p ) = if n = List . length hashes then acc else begin let nexthash = List . nth hashes n in let new_window = Window . enqueue nexthash window in if nexthash <= v then let new_acc = ( nexthash , global_pos ( Window . size new_window - 1 ) new_window ) :: acc in winnowhelper hashes new_window new_acc ( n + 1 ) ( nexthash , Window . size new_window - 1 ) else begin let p = p - 1 in if p < 0 then let new_min = fst ( Window . fold mincheck ( ( max_int , 0 ) , 0 ) new_window ) in let new_acc = ( fst new_min , global_pos ( snd new_min ) new_window ) :: acc in winnowhelper hashes new_window new_acc ( n + 1 ) new_min else winnowhelper hashes new_window acc ( n + 1 ) ( v , p ) end end in let window = Window . create w max_int in let res = winnowhelper h window [ ] 0 ( max_int , 0 ) in res |
let main ( ) = let top = opentk ( ) in let mbar = Frame . create top [ Relief Raised ; BorderWidth ( Pixels 2 ) ] and dummy = Frame . create top [ Width ( Centimeters 10 . ) ; Height ( Centimeters 5 . ) ] in pack [ mbar ; dummy ] [ Side Side_Top ; Fill Fill_X ] ; let file = Menubutton . create mbar [ Text " File " ; UnderlinedChar 0 ] and edit = Menubutton . create mbar [ Text " Edit " ; UnderlinedChar 0 ] and graphics = Menubutton . create mbar [ Text " Graphics " ; UnderlinedChar 0 ] and text = Menubutton . create mbar [ Text " Text " ; UnderlinedChar 0 ] and view = Menubutton . create mbar [ Text " View " ; UnderlinedChar 0 ] and help = Menubutton . create mbar [ Text " Help " ; UnderlinedChar 0 ] in pack [ file ; edit ; graphics ; text ; view ] [ Side Side_Left ] ; pack [ help ] [ Side Side_Right ] ; let m = Menu . create text [ ] in let bold = Textvariable . create ( ) and italic = Textvariable . create ( ) and underline = Textvariable . create ( ) in Menu . add_checkbutton m [ Label " Bold " ; Variable bold ] ; Menu . add_checkbutton m [ Label " Italic " ; Variable italic ] ; Menu . add_checkbutton m [ Label " Underline " ; Variable underline ] ; Menu . add_separator m ; let font = Textvariable . create ( ) in Menu . add_radiobutton m [ Label " Times " ; Variable font ; Value " times " ] ; Menu . add_radiobutton m [ Label " Helvetica " ; Variable font ; Value " helvetica " ] ; Menu . add_radiobutton m [ Label " Courier " ; Variable font ; Value " courier " ] ; Menu . add_separator m ; Menu . add_command m [ Label " Insert Bullet " ; Command ( function ( ) -> print_string " Insert Bullet \ n " ; flush stdout ) ] ; Menu . add_command m [ Label " Margins and Tags . . . " ; Command ( function ( ) -> print_string " margins \ n " ; flush stdout ) ] ; Menubutton . configure text [ Menu m ] ; mainLoop ( ) |
let _ = Printexc . catch main ( ) |
let of_int = function | 0 -> Some ( Success ) | 1 -> Some ( Invalid_function ) | 2 -> Some ( File_not_found ) | 3 -> Some ( Path_not_found ) | 4 -> Some ( Too_many_open_files ) | 5 -> Some ( Access_denied ) | 6 -> Some ( Invalid_handle ) | 7 -> Some ( Arena_trashed ) | 8 -> Some ( Not_enough_memory ) | 9 -> Some ( Invalid_block ) | 10 -> Some ( Bad_environment ) | 11 -> Some ( Bad_format ) | 12 -> Some ( Invalid_access ) | 13 -> Some ( Invalid_data ) | 14 -> Some ( Outofmemory ) | 15 -> Some ( Invalid_drive ) | 16 -> Some ( Current_directory ) | 17 -> Some ( Not_same_device ) | 18 -> Some ( No_more_files ) | 19 -> Some ( Write_protect ) | 20 -> Some ( Bad_unit ) | 21 -> Some ( Not_ready ) | 22 -> Some ( Bad_command ) | 23 -> Some ( Crc ) | 24 -> Some ( Bad_length ) | 25 -> Some ( Seek ) | 26 -> Some ( Not_dos_disk ) | 27 -> Some ( Sector_not_found ) | 28 -> Some ( Out_of_paper ) | 29 -> Some ( Write_fault ) | 30 -> Some ( Read_fault ) | 31 -> Some ( Gen_failure ) | 32 -> Some ( Sharing_violation ) | 33 -> Some ( Lock_violation ) | 34 -> Some ( Wrong_disk ) | 36 -> Some ( Sharing_buffer_exceeded ) | 38 -> Some ( Handle_eof ) | 39 -> Some ( Handle_disk_full ) | 50 -> Some ( Not_supported ) | 51 -> Some ( Rem_not_list ) | 52 -> Some ( Dup_name ) | 53 -> Some ( Bad_netpath ) | 54 -> Some ( Network_busy ) | 55 -> Some ( Dev_not_exist ) | 56 -> Some ( Too_many_cmds ) | 57 -> Some ( Adap_hdw_err ) | 58 -> Some ( Bad_net_resp ) | 59 -> Some ( Unexp_net_err ) | 60 -> Some ( Bad_rem_adap ) | 61 -> Some ( Printq_full ) | 62 -> Some ( No_spool_space ) | 63 -> Some ( Print_cancelled ) | 64 -> Some ( Netname_deleted ) | 65 -> Some ( Network_access_denied ) | 66 -> Some ( Bad_dev_type ) | 67 -> Some ( Bad_net_name ) | 68 -> Some ( Too_many_names ) | 69 -> Some ( Too_many_sess ) | 70 -> Some ( Sharing_paused ) | 71 -> Some ( Req_not_accep ) | 72 -> Some ( Redir_paused ) | 80 -> Some ( File_exists ) | 82 -> Some ( Cannot_make ) | 83 -> Some ( Fail_I24 ) | 84 -> Some ( Out_of_structures ) | 85 -> Some ( Already_assigned ) | 86 -> Some ( Invalid_password ) | 87 -> Some ( Invalid_parameter ) | 88 -> Some ( Net_write_fault ) | 89 -> Some ( No_proc_slots ) | 100 -> Some ( Too_many_semaphores ) | 101 -> Some ( Excl_sem_already_owned ) | 102 -> Some ( Sem_is_set ) | 103 -> Some ( Too_many_sem_requests ) | 104 -> Some ( Invalid_at_interrupt_time ) | 105 -> Some ( Sem_owner_died ) | 106 -> Some ( Sem_user_limit ) | 107 -> Some ( Disk_change ) | 108 -> Some ( Drive_locked ) | 109 -> Some ( Broken_pipe ) | 110 -> Some ( Open_failed ) | 111 -> Some ( Buffer_overflow ) | 112 -> Some ( Disk_full ) | 113 -> Some ( No_more_search_handles ) | 114 -> Some ( Invalid_target_handle ) | 117 -> Some ( Invalid_category ) | 118 -> Some ( Invalid_verify_switch ) | 119 -> Some ( Bad_driver_level ) | 120 -> Some ( Call_not_implemented ) | 121 -> Some ( Sem_timeout ) | 122 -> Some ( Insufficient_buffer ) | 123 -> Some ( Invalid_name ) | 124 -> Some ( Invalid_level ) | 125 -> Some ( No_volume_label ) | 126 -> Some ( Mod_not_found ) | 127 -> Some ( Proc_not_found ) | 128 -> Some ( Wait_no_children ) | 129 -> Some ( Child_not_complete ) | 130 -> Some ( Direct_access_handle ) | 131 -> Some ( Negative_seek ) | 132 -> Some ( Seek_on_device ) | 133 -> Some ( Is_join_target ) | 134 -> Some ( Is_joined ) | 135 -> Some ( Is_substed ) | 136 -> Some ( Not_joined ) | 137 -> Some ( Not_substed ) | 138 -> Some ( Join_to_join ) | 139 -> Some ( Subst_to_subst ) | 140 -> Some ( Join_to_subst ) | 141 -> Some ( Subst_to_join ) | 142 -> Some ( Busy_drive ) | 143 -> Some ( Same_drive ) | 144 -> Some ( Dir_not_root ) | 145 -> Some ( Dir_not_empty ) | 146 -> Some ( Is_subst_path ) | 147 -> Some ( Is_join_path ) | 148 -> Some ( Path_busy ) | 149 -> Some ( Is_subst_target ) | 150 -> Some ( System_trace ) | 151 -> Some ( Invalid_event_count ) | 152 -> Some ( Too_many_muxwaiters ) | 153 -> Some ( Invalid_list_format ) | 154 -> Some ( Label_too_long ) | 155 -> Some ( Too_many_tcps ) | 156 -> Some ( Signal_refused ) | 157 -> Some ( Discarded ) | 158 -> Some ( Not_locked ) | 159 -> Some ( Bad_threadid_addr ) | 160 -> Some ( Bad_arguments ) | 161 -> Some ( Bad_pathname ) | 162 -> Some ( Signal_pending ) | 164 -> Some ( Max_thrds_reached ) | 167 -> Some ( Lock_failed ) | 170 -> Some ( Busy ) | 171 -> Some ( Device_support_in_progress ) | 173 -> Some ( Cancel_violation ) | 174 -> Some ( Atomic_locks_not_supported ) | 180 -> Some ( Invalid_segment_number ) | 182 -> Some ( Invalid_ordinal ) | 183 -> Some ( Already_exists ) | 186 -> Some ( Invalid_flag_number ) | 187 -> Some ( Sem_not_found ) | 188 -> Some ( Error_invalid_starting_codeseg ) | 189 -> Some ( Invalid_stackseg ) | 190 -> Some ( Invalid_moduletype ) | 191 -> Some ( Invalid_exe_signature ) | 192 -> Some ( Exe_marked_invalid ) | 193 -> Some ( Bad_exe_format ) | 194 -> Some ( Iterated_data_exceeds_64k ) | 195 -> Some ( Invalid_minallocsize ) | 196 -> Some ( Dynlink_from_invalid_ring ) | 197 -> Some ( Iopl_not_enabled ) | 198 -> Some ( Invalid_segdpl ) | 199 -> Some ( Autodataseg_exceeds_64k ) | 200 -> Some ( Ring2seg_must_be_movable ) | 201 -> Some ( Reloc_chain_xeeds_seglim ) | 202 -> Some ( Infloop_in_reloc_chain ) | 203 -> Some ( Envvar_not_found ) | 205 -> Some ( No_signal_sent ) | 206 -> Some ( Filename_exced_range ) | 207 -> Some ( Ring2_stack_in_use ) | 208 -> Some ( Meta_expansion_too_long ) | 209 -> Some ( Invalid_signal_number ) | 210 -> Some ( Thread_1_inactive ) | 212 -> Some ( Locked ) | 214 -> Some ( Too_many_modules ) | 215 -> Some ( Nesting_not_allowed ) | 216 -> Some ( Exe_machine_type_mismatch ) | 217 -> Some ( Exe_cannot_modify_signed_binary ) | 218 -> Some ( Exe_cannot_modify_strong_signed_binary ) | 220 -> Some ( File_checked_out ) | 221 -> Some ( Checkout_required ) | 222 -> Some ( Bad_file_type ) | 223 -> Some ( File_too_large ) | 224 -> Some ( Forms_auth_required ) | 225 -> Some ( Virus_infected ) | 226 -> Some ( Virus_deleted ) | 229 -> Some ( Pipe_local ) | 230 -> Some ( Bad_pipe ) | 231 -> Some ( Pipe_busy ) | 232 -> Some ( No_data ) | 233 -> Some ( Pipe_not_connected ) | 234 -> Some ( More_data ) | 240 -> Some ( Vc_disconnected ) | 254 -> Some ( Invalid_ea_name ) | 255 -> Some ( Ea_list_inconsistent ) | 258 -> Some ( Wait_timeout ) | 259 -> Some ( No_more_items ) | 266 -> Some ( Cannot_copy ) | 267 -> Some ( Directory ) | 275 -> Some ( Eas_didnt_fit ) | 276 -> Some ( Ea_file_corrupt ) | 277 -> Some ( Ea_table_full ) | 278 -> Some ( Invalid_ea_handle ) | 282 -> Some ( Eas_not_supported ) | 288 -> Some ( Not_owner ) | 298 -> Some ( Too_many_posts ) | 299 -> Some ( Partial_copy ) | 300 -> Some ( Oplock_not_granted ) | 301 -> Some ( Invalid_oplock_protocol ) | 302 -> Some ( Disk_too_fragmented ) | 303 -> Some ( Delete_pending ) | 304 -> Some ( Incompatible_with_global_short_name_registry_setting ) | 305 -> Some ( Short_names_not_enabled_on_volume ) | 306 -> Some ( Security_stream_is_inconsistent ) | 307 -> Some ( Invalid_lock_range ) | 308 -> Some ( Image_subsystem_not_present ) | 309 -> Some ( Notification_guid_already_defined ) | 310 -> Some ( Invalid_exception_handler ) | 311 -> Some ( Duplicate_privileges ) | 312 -> Some ( No_ranges_processed ) | 313 -> Some ( Not_allowed_on_system_file ) | 314 -> Some ( Disk_resources_exhausted ) | 315 -> Some ( Invalid_token ) | 316 -> Some ( Device_feature_not_supported ) | 317 -> Some ( Mr_mid_not_found ) | 318 -> Some ( Scope_not_found ) | 319 -> Some ( Undefined_scope ) | 320 -> Some ( Invalid_cap ) | 321 -> Some ( Device_unreachable ) | 322 -> Some ( Device_no_resources ) | 323 -> Some ( Data_checksum_error ) | 324 -> Some ( Intermixed_kernel_ea_operation ) | 326 -> Some ( File_level_trim_not_supported ) | 327 -> Some ( Offset_alignment_violation ) | 328 -> Some ( Invalid_field_in_parameter_list ) | 329 -> Some ( Operation_in_progress ) | 330 -> Some ( Bad_device_path ) | 331 -> Some ( Too_many_descriptors ) | 332 -> Some ( Scrub_data_disabled ) | 333 -> Some ( Not_redundant_storage ) | 334 -> Some ( Resident_file_not_supported ) | 335 -> Some ( Compressed_file_not_supported ) | 336 -> Some ( Directory_not_supported ) | 337 -> Some ( Not_read_from_copy ) | 350 -> Some ( Fail_noaction_reboot ) | 351 -> Some ( Fail_shutdown ) | 352 -> Some ( Fail_restart ) | 353 -> Some ( Max_sessions_reached ) | 400 -> Some ( Thread_mode_already_background ) | 401 -> Some ( Thread_mode_not_background ) | 402 -> Some ( Process_mode_already_background ) | 403 -> Some ( Process_mode_not_background ) | 487 -> Some ( Invalid_address ) | _ -> None |
type t = | Success | Invalid_function | File_not_found | Path_not_found | Too_many_open_files | Access_denied | Invalid_handle | Arena_trashed | Not_enough_memory | Invalid_block | Bad_environment | Bad_format | Invalid_access | Invalid_data | Outofmemory | Invalid_drive | Current_directory | Not_same_device | No_more_files | Write_protect | Bad_unit | Not_ready | Bad_command | Crc | Bad_length | Seek | Not_dos_disk | Sector_not_found | Out_of_paper | Write_fault | Read_fault | Gen_failure | Sharing_violation | Lock_violation | Wrong_disk | Sharing_buffer_exceeded | Handle_eof | Handle_disk_full | Not_supported | Rem_not_list | Dup_name | Bad_netpath | Network_busy | Dev_not_exist | Too_many_cmds | Adap_hdw_err | Bad_net_resp | Unexp_net_err | Bad_rem_adap | Printq_full | No_spool_space | Print_cancelled | Netname_deleted | Network_access_denied | Bad_dev_type | Bad_net_name | Too_many_names | Too_many_sess | Sharing_paused | Req_not_accep | Redir_paused | File_exists | Cannot_make | Fail_I24 | Out_of_structures | Already_assigned | Invalid_password | Invalid_parameter | Net_write_fault | No_proc_slots | Too_many_semaphores | Excl_sem_already_owned | Sem_is_set | Too_many_sem_requests | Invalid_at_interrupt_time | Sem_owner_died | Sem_user_limit | Disk_change | Drive_locked | Broken_pipe | Open_failed | Buffer_overflow | Disk_full | No_more_search_handles | Invalid_target_handle | Invalid_category | Invalid_verify_switch | Bad_driver_level | Call_not_implemented | Sem_timeout | Insufficient_buffer | Invalid_name | Invalid_level | No_volume_label | Mod_not_found | Proc_not_found | Wait_no_children | Child_not_complete | Direct_access_handle | Negative_seek | Seek_on_device | Is_join_target | Is_joined | Is_substed | Not_joined | Not_substed | Join_to_join | Subst_to_subst | Join_to_subst | Subst_to_join | Busy_drive | Same_drive | Dir_not_root | Dir_not_empty | Is_subst_path | Is_join_path | Path_busy | Is_subst_target | System_trace | Invalid_event_count | Too_many_muxwaiters | Invalid_list_format | Label_too_long | Too_many_tcps | Signal_refused | Discarded | Not_locked | Bad_threadid_addr | Bad_arguments | Bad_pathname | Signal_pending | Max_thrds_reached | Lock_failed | Busy | Device_support_in_progress | Cancel_violation | Atomic_locks_not_supported | Invalid_segment_number | Invalid_ordinal | Already_exists | Invalid_flag_number | Sem_not_found | Error_invalid_starting_codeseg | Invalid_stackseg | Invalid_moduletype | Invalid_exe_signature | Exe_marked_invalid | Bad_exe_format | Iterated_data_exceeds_64k | Invalid_minallocsize | Dynlink_from_invalid_ring | Iopl_not_enabled | Invalid_segdpl | Autodataseg_exceeds_64k | Ring2seg_must_be_movable | Reloc_chain_xeeds_seglim | Infloop_in_reloc_chain | Envvar_not_found | No_signal_sent | Filename_exced_range | Ring2_stack_in_use | Meta_expansion_too_long | Invalid_signal_number | Thread_1_inactive | Locked | Too_many_modules | Nesting_not_allowed | Exe_machine_type_mismatch | Exe_cannot_modify_signed_binary | Exe_cannot_modify_strong_signed_binary | File_checked_out | Checkout_required | Bad_file_type | File_too_large | Forms_auth_required | Virus_infected | Virus_deleted | Pipe_local | Bad_pipe | Pipe_busy | No_data | Pipe_not_connected | More_data | Vc_disconnected | Invalid_ea_name | Ea_list_inconsistent | Wait_timeout | No_more_items | Cannot_copy | Directory | Eas_didnt_fit | Ea_file_corrupt | Ea_table_full | Invalid_ea_handle | Eas_not_supported | Not_owner | Too_many_posts | Partial_copy | Oplock_not_granted | Invalid_oplock_protocol | Disk_too_fragmented | Delete_pending | Incompatible_with_global_short_name_registry_setting | Short_names_not_enabled_on_volume | Security_stream_is_inconsistent | Invalid_lock_range | Image_subsystem_not_present | Notification_guid_already_defined | Invalid_exception_handler | Duplicate_privileges | No_ranges_processed | Not_allowed_on_system_file | Disk_resources_exhausted | Invalid_token | Device_feature_not_supported | Mr_mid_not_found | Scope_not_found | Undefined_scope | Invalid_cap | Device_unreachable | Device_no_resources | Data_checksum_error | Intermixed_kernel_ea_operation | File_level_trim_not_supported | Offset_alignment_violation | Invalid_field_in_parameter_list | Operation_in_progress | Bad_device_path | Too_many_descriptors | Scrub_data_disabled | Not_redundant_storage | Resident_file_not_supported | Compressed_file_not_supported | Directory_not_supported | Not_read_from_copy | Fail_noaction_reboot | Fail_shutdown | Fail_restart | Max_sessions_reached | Thread_mode_already_background | Thread_mode_not_background | Process_mode_already_background | Process_mode_not_background | Invalid_address |
type telnet_command = | SUBNEG_END [ @ id 240 ] | NOP [ @ id 241 ] | DATA_MARK [ @ id 242 ] | BREAK [ @ id 243 ] | INTERRUPT_PROCESS [ @ id 244 ] | ABORT_OUTPUT [ @ id 245 ] | ARE_YOU_THERE [ @ id 246 ] | ERASE_CHARACTER [ @ id 247 ] | ERASE_LINE [ @ id 248 ] | GO_AHEAD [ @ id 249 ] | SUBNEG [ @ id 250 ] | WILL [ @ id 251 ] | WILL_NOT [ @ id 252 ] | DO [ @ id 253 ] | DO_NOT [ @ id 254 ] | IAC [ @ id 255 ] [ @@ uint8_t ] [ @@ sexp ] ] [ %% cenum |
type telnet_option = | Binary_Transmission | Echo | Reconnection | Suppress_Go_Ahead | Approx_Message_Size_Negotiation | Status | Timing_Mark | Remote_Controlled_Trans_and_Echo | Output_Line_Width | Output_Page_Size | Output_Carriage_Return_Disposition | Output_Horizontal_Tab_Stops | Output_Horizontal_Tab_Disposition | Output_Formfeed_Disposition | Output_Vertical_Tabstops | Output_Vertical_Tab_Disposition | Output_Linefeed_Disposition | Extended_ASCII | Logout | Byte_Macro | Data_Entry_Terminal | SUPDUP | SUPDUP_Output | Send_Location | Terminal_Type | End_of_Record | TACACS_User_Identification | Output_Marking | Terminal_Location_Number | Telnet_3270_Regime | X_3_PAD | Negotiate_About_Window_Size | Terminal_Speed | Remote_Flow_Control | Linemode | X_Display_Location | Environment_Option | Authentication_Option | Encryption_Option | New_Environment_Option | TN3270E | XAUTH | CHARSET | Telnet_Remote_Serial_Port | Com_Port_Control_Option | Telnet_Suppress_Local_Echo | Telnet_Start_TLS | KERMIT | SEND_URL | FORWARD_X | TELOPT_PRAGMA_LOGON [ @ id 138 ] | TELOPT_SSPI_LOGON | TELOPT_PRAGMA_HEARTBEAT | Extended_Options_List [ @ id 255 ] [ @@ uint8_t ] [ @@ sexp ] ] |
type pc = int * int |
let _read_pc conn = let % lwt frag_num = Lwt_io . BE . read_int conn . io . in_ in let % lwt pos = Lwt_io . BE . read_int conn . io . in_ in Lwt . return ( frag_num , pos ) pos |
let _write_pc conn ( frag_num , pos ) pos = Lwt_io . BE . write_int conn . io . out frag_num ; % lwt Lwt_io . BE . write_int conn . io . out pos |
let set_fork_mode conn mode = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' K ' ; % lwt Lwt_io . BE . write_int conn . io . out ( match mode with ` Fork_child -> 0 | ` Fork_parent -> 1 ) 1 ) 1 |
let set_event conn pc = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' e ' ; % lwt _write_pc conn pc ) pc |
let set_breakpoint conn pc = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' B ' ; % lwt _write_pc conn pc ) pc |
let reset_instr conn pc = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' i ' ; % lwt _write_pc conn pc ) pc |
let set_trap_barrier conn pos = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' b ' ; % lwt Lwt_io . BE . write_int conn . io . out pos ) pos |
let checkpoint conn = Lwt_conn . atomic conn ( fun conn -> if Sys . win32 then raise Operation_system_unsupported else Lwt_io . write_char conn . io . out ' c ' ; % lwt let % lwt pid = Lwt_io . BE . read_int conn . io . in_ in if pid = - 1 then assert false else Lwt . return pid ) pid |
type execution_summary = [ ` Event | ` Breakpoint | ` Exited | ` Trap_barrier | ` Uncaught_exc | ` Debug_info of int Ident . Map . t * ( Instruct . debug_event list * string list ) list list | ` Code_loaded of int | ` Code_unloaded of int ] |
let go conn steps = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' g ' ; % lwt Lwt_io . BE . write_int conn . io . out steps ; % lwt let % lwt summary = match % lwt Lwt_io . read_char conn . io . in_ with | ' e ' -> Lwt . return ` Event | ' b ' -> Lwt . return ` Breakpoint | ' x ' -> Lwt . return ` Exited | ' s ' -> Lwt . return ` Trap_barrier | ' u ' -> Lwt . return ` Uncaught_exc | ' D ' -> let % lwt ( evls : Instruct . debug_event list array ) array = Lwt_io . read_value conn . io . in_ in let evls = evls |> Array . to_seq |> Seq . map ( fun evl -> ( evl , [ ] ) ) |> List . of_seq in Lwt . return ( ` Debug_info ( Ident . Map . empty , evls ) evls ) evls | ' L ' -> let % lwt frag_num = Lwt_io . BE . read_int conn . io . in_ in Lwt . return ( ` Code_loaded frag_num ) frag_num | ' U ' -> let % lwt frag_num = Lwt_io . BE . read_int conn . io . in_ in Lwt . return ( ` Code_unloaded frag_num ) frag_num | _ -> assert false in let % lwt executed_steps = Lwt_io . BE . read_int conn . io . in_ in let % lwt sp = Lwt_io . BE . read_int conn . io . in_ in let % lwt pc = _read_pc conn in Lwt . return ( executed_steps , summary , match ( sp , pc ) pc with 0 , ( - 1 , 0 ) 0 -> None | _ -> Some ( sp , pc ) pc ) ) |
let wait conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' w ' ) ' w ' |
let stop conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' s ' ) ' s ' |
let initial_frame conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' 0 ' ; % lwt let % lwt stack_pos = Lwt_io . BE . read_int conn . io . in_ in let % lwt pc = _read_pc conn in Lwt . return ( stack_pos , pc ) pc ) pc |
let get_frame conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' f ' ; % lwt let % lwt stack_pos = Lwt_io . BE . read_int conn . io . in_ in let % lwt pc = _read_pc conn in Lwt . return ( stack_pos , pc ) pc ) pc |
let set_frame conn stack_pos = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' S ' ; % lwt Lwt_io . BE . write_int conn . io . out stack_pos ) stack_pos |
let up_frame conn stacksize = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' U ' ; % lwt Lwt_io . BE . write_int conn . io . out stacksize ; % lwt let % lwt stack_pos = Lwt_io . BE . read_int conn . io . in_ in let % lwt res = if stack_pos = - 1 then Lwt . return None else let % lwt pc = _read_pc conn in Lwt . return ( Some ( stack_pos , pc ) pc ) pc in Lwt . return res ) res |
let _read_remote_value conn = Lwt_io . read_string_exactly conn . io . in_ ( Sys . word_size / 8 ) 8 |
let _write_remote_value conn rv = Lwt_io . write conn . io . out rv |
let get_local conn index = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' L ' ; % lwt Lwt_io . BE . write_int conn . io . out index ; % lwt let % lwt rv = _read_remote_value conn in Lwt . return rv ) rv |
let get_environment conn index = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' E ' ; % lwt Lwt_io . BE . write_int conn . io . out index ; % lwt let % lwt rv = _read_remote_value conn in Lwt . return rv ) rv |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.