File: netunidata.ml

package info (click to toggle)
ocamlnet 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 51,764 kB
  • ctags: 16,446
  • sloc: ml: 148,419; ansic: 10,989; sh: 1,885; makefile: 1,355
file content (44 lines) | stat: -rw-r--r-- 894 bytes parent folder | download | duplicates (3)
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
(* $Id$ *)

let dir = ref Netuniconfig.net_db_dir

let enable() =
  Netdb.enable_db_loaders true

let disable() =
  Netdb.enable_db_loaders false

let net_db_dir() =
  !dir

let set_net_db_dir d =
  dir := d

let load_file key =
  let filename = Filename.concat !dir key ^ ".netdb" in
  if Sys.file_exists filename then (
    let ch = open_in_bin filename in
    try
      let n = in_channel_length ch in
      let v = Bytes.make n '\000' in
      really_input ch v 0 n;
      close_in ch;
      Bytes.unsafe_to_string v
    with exn ->
      close_in ch;
      raise exn
  )
  else
    failwith ("Ocamlnet: Cannot find the lookup table `" ^ key ^ 
		"' which is supposed to be available as file " ^ 
		  filename)

let load key =
  let s = Netdb.read_db key in
  Netdb.set_db key s


let load_charset cs =
  let n = Netconversion.internal_name cs in
  load("cmapf." ^ n);
  load("cmapr." ^ n)