gconfig.ml 1.72 KB
Newer Older
MARCHE Claude's avatar
MARCHE Claude committed
1
2
3
4
5
6
7
8

open Format
open Why

type t = 
    { mutable window_width : int;
      mutable window_height : int;
      mutable tree_width : int;
9
      mutable task_height : int;
MARCHE Claude's avatar
MARCHE Claude committed
10
11
12
13
14
15
    }

let default = 
  { window_width = 1024;
    window_height = 768;
    tree_width = 512;
16
    task_height = 384;
MARCHE Claude's avatar
MARCHE Claude committed
17
18
19
20
21
22
23
24
25
26
27
  }

let conf_file = Filename.concat (Rc.get_home_dir ()) ".whyide.conf"

let save_config config =
  let ch = open_out conf_file in
  let fmt = formatter_of_out_channel ch in
  fprintf fmt "[main]@\n";
  fprintf fmt "width = %d@\n" config.window_width;
  fprintf fmt "height = %d@\n" config.window_height;
  fprintf fmt "tree_width = %d@\n" config.tree_width;
28
  fprintf fmt "task_height = %d@\n" config.task_height;
MARCHE Claude's avatar
MARCHE Claude committed
29
30
31
32
33
34
35
36
  fprintf fmt "@.";
  close_out ch

let load_main c (key, value) = 
  match key with
    | "width" -> c.window_width <- Rc.int value
    | "height" -> c.window_height <- Rc.int value
    | "tree_width" -> c.tree_width <- Rc.int value
37
    | "task_height" -> c.task_height <- Rc.int value
MARCHE Claude's avatar
MARCHE Claude committed
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
68
69
    | s -> 
        eprintf "Warning: ignore unknown key [%s] in whyide config file@." s
        
let load c (key, al) = 
  match key with
    | "main" :: _ ->
        List.iter (load_main c) al
    | s :: _ -> 
        eprintf "Warning: ignored unknown section [%s] in whyide config file@." s
    | [] -> assert false
        
let read_config () =
  try
    let rc = Rc.from_file conf_file in
    let c = default in
    List.iter (load c) rc;
    c
  with
    | Failure "lexing" -> 
        eprintf "Warning: syntax error in whyide config file@.";
        default
    | Not_found ->
        eprintf "Warning: no whyide config file, using default values@.";
        default
    


(*
Local Variables: 
compile-command: "unset LANG; make -C ../.. bin/whyide.opt"
End: 
*)