File: example.ml

package info (click to toggle)
ocaml-uucd 17.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 224 kB
  • sloc: ml: 4,366; makefile: 6
file content (32 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download | duplicates (2)
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
(*---------------------------------------------------------------------------
   Copyright (c) 2012 The uucd programmers. All rights reserved.
   SPDX-License-Identifier: CC0-1.0
  ---------------------------------------------------------------------------*)

let ucd_or_die inf =
  try
    let ic = if inf = "-" then stdin else open_in inf in
    let d = Uucd.decoder (`Channel ic) in
    match Uucd.decode d with
    | `Ok db -> db
    | `Error e ->
        let (l0, c0), (l1, c1) = Uucd.decoded_range d in
        Printf.eprintf "%s:%d.%d-%d.%d: %s\n%!" inf l0 c0 l1 c1 e;
        exit 1
  with Sys_error e -> Printf.eprintf "%s\n%!" e; exit 1

let ucd_from_marshaled : string -> Uucd.t =
  fun inf -> Marshal.from_channel (open_in inf)

let main () =
  let usage = "test [ucd.xml]" in
  let inf = ref None in
  let anon_fun file = match !inf with
  | Some _ -> raise (Arg.Bad ("Don't now what to do with " ^ file))
  | None -> inf := Some file
  in
  Arg.parse [] anon_fun usage;
  let inf = Option.value ~default:"-" !inf in
  Marshal.to_channel stdout (ucd_or_die inf) []

let () = if !Sys.interactive then () else main ()