Commit be1326ff authored by MARCHE Claude's avatar MARCHE Claude
Browse files

datadir

parent fb40392c
......@@ -42,15 +42,32 @@ let error ?loc e = match loc with
(* lib and shared dirs *)
let libdir =
try
Sys.getenv "WHY3LIB"
with Not_found -> Config.libdir
(* are we executed with an implicit path or not ?
cmd -> yes (dirname = ".", is_implicit = yes)
/... -> no (dirname = "/...", is_implicit = no)
./t -> no (dirname = ".", is_implicit = no)
bin/t -> no (dirname = "bin", is_implicit = yes)
*)
let implicit_path =
let s = Sys.argv.(0) in
Filename.is_implicit s &&
Filename.dirname s = Filename.current_dir_name
let libdir =
if implicit_path then
try
Sys.getenv "WHY3LIB"
with Not_found -> Config.libdir
else "."
let datadir =
try
Sys.getenv "WHY3DATA"
with Not_found -> Config.datadir
if implicit_path then
try
Sys.getenv "WHY3DATA"
with Not_found -> Config.datadir
else "share"
......
......@@ -40,6 +40,9 @@ val from_file : string -> (string list * (string * rc_value) list) list
@raise Not_found is f does not exists
@raise Failure "lexing" in case of incorrect syntax *)
val to_file : string -> (string list * (string * rc_value) list) list -> unit
(** write the records into the file [f] *)
val get_home_dir : unit -> string
(** returns the home dir of the user *)
......
......@@ -147,18 +147,44 @@ and string_val key = parse
{
let from_file f =
let c =
try open_in f
with Sys_error _ -> raise Not_found
(*
let c =
try open_in f
with Sys_error _ -> raise Not_found
(*
Format.eprintf "Cannot open file %s@." f;
exit 1
*)
in
current := [];
let lb = from_channel c in
record lb;
close_in c;
List.rev !current
*)
in
current := [];
let lb = from_channel c in
record lb;
close_in c;
List.rev !current
open Format
open Pp
let print_value fmt = function
| RCint n -> fprintf fmt "%d" n
| RCbool b -> fprintf fmt "%b" b
| RCfloat f -> fprintf fmt "%f" f
| RCstring s -> fprintf fmt "\"%s\"" s
| RCident i -> fprintf fmt "%s" i
let record fmt (keys,fl) =
fprintf fmt "[%a]@\n" (print_list space pp_print_string) keys;
List.iter
(fun (f,v) -> fprintf fmt "%s = %a@\n" f print_value v)
fl;
fprintf fmt "@."
let to_file f l =
let c =
try open_out f
with Sys_error _ -> raise Not_found
in
let fmt = formatter_of_out_channel c in
List.iter (record fmt) l;
close_out c
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment