package hxd
Hexdump in OCaml
Install
Dune Dependency
Authors
Maintainers
Sources
hxd-0.3.3.tbz
sha256=4ede235296a5e2a2599776c8bceb4853c164ef7e573570a1edc68a4c0c90433e
sha512=39d42632ea7acc2e9418faefdef91085e420a03c3aa03e04e75f99c9d24a4deb96ff71ad948d208ce562077dd3f6f92f975dc7c006a97cd7eabc1e8a7f5381d0
doc/src/hxd.unix/hxd_unix.ml.html
Source file hxd_unix.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
open Hxd module Unix_scheduler = Make (struct type +'a t = 'a end) type error = Seek let unix = {bind= (fun x f -> f (Unix_scheduler.prj x)); return= Unix_scheduler.inj} let lseek_in_file = let lseek ic pos mode = let mode = match mode with | `CUR -> Unix.SEEK_CUR | `END -> Unix.SEEK_END | `SET -> Unix.SEEK_SET in match Unix.lseek (Unix.descr_of_in_channel ic) pos mode with | res -> Unix_scheduler.inj (Ok res) | exception _exn -> Unix_scheduler.inj (Error Seek) in {lseek} let drain fd max = let tmp = Bytes.create 0x1000 in let rec go cursor = let len = min 0x1000 (max - cursor) in let res = Unix.read fd tmp 0 len in if res = 0 then raise End_of_file ; if cursor + res < max then go (cursor + res) in go 0 let lseek_in_stdin = let lseek ic pos mode = (* XXX(dinosaure): we must must know where we are in [stdin]. *) let cur = try Unix.lseek Unix.stdin 0 SEEK_CUR with _exn -> 0 in match mode with | `CUR when pos >= 0 -> ( try drain (Unix.descr_of_in_channel ic) pos ; Unix_scheduler.inj (Ok (cur + pos)) with End_of_file -> Unix_scheduler.inj (Error Seek)) | `SET when pos >= 0 && cur = 0 -> ( try drain (Unix.descr_of_in_channel ic) pos ; Unix_scheduler.inj (Ok (cur + pos)) with End_of_file -> Unix_scheduler.inj (Error Seek)) | `CUR when pos < 0 -> let pos = Unix.lseek Unix.stdin pos SEEK_CUR in Unix_scheduler.inj (Ok pos) | `SET -> let pos = Unix.lseek Unix.stdin pos SEEK_SET in Unix_scheduler.inj (Ok pos) | _ -> Unix_scheduler.inj (Error Seek) in {lseek} let recv ic buffer ~off ~len = let len = input ic buffer off len in Unix_scheduler.inj (Ok len) let send oc buffer ~off ~len = output oc (Bytes.unsafe_of_string buffer) off len ; Unix_scheduler.inj (Ok len) let generate configuration ic oc seek ppf = let lseek = if ic == stdin then lseek_in_stdin else lseek_in_file in let res = generate configuration unix recv send ic oc lseek seek ppf in match Unix_scheduler.prj res with | Ok () -> Ok () | Error Seek -> Error (`Msg "sorry cannot seek")
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>