summaryrefslogtreecommitdiff
path: root/ide/minilib.ml
diff options
context:
space:
mode:
authorGravatar Stephane Glondu <steph@glondu.net>2012-06-04 12:07:52 +0200
committerGravatar Stephane Glondu <steph@glondu.net>2012-06-04 12:07:52 +0200
commit61dc740ed1c3780cccaec00d059a28f0d31d0052 (patch)
treed88d05baf35b9b09a034233300f35a694f9fa6c2 /ide/minilib.ml
parent97fefe1fcca363a1317e066e7f4b99b9c1e9987b (diff)
Imported Upstream version 8.4~gamma0+really8.4beta2upstream/8.4_gamma0+really8.4beta2
Diffstat (limited to 'ide/minilib.ml')
-rw-r--r--ide/minilib.ml47
1 files changed, 35 insertions, 12 deletions
diff --git a/ide/minilib.ml b/ide/minilib.ml
index cec77f3b..4ccb1ccb 100644
--- a/ide/minilib.ml
+++ b/ide/minilib.ml
@@ -64,9 +64,10 @@ let string_map f s =
let subst_command_placeholder s t =
Str.global_replace (Str.regexp_string "%s") t s
-let path_to_list p =
- let sep = Str.regexp (if Sys.os_type = "Win32" then ";" else ":") in
- Str.split sep p
+(* Split the content of a variable such as $PATH in a list of directories.
+ The separators are either ":" in unix or ";" in win32 *)
+
+let path_to_list = Str.split (Str.regexp "[:;]")
(* On win32, the home directory is probably not in $HOME, but in
some other environment variable *)
@@ -76,28 +77,50 @@ let home =
try (Sys.getenv "HOMEDRIVE")^(Sys.getenv "HOMEPATH") with Not_found ->
try Sys.getenv "USERPROFILE" with Not_found -> Filename.current_dir_name
+let opt2list = function None -> [] | Some x -> [x]
+
+let rec lconcat = function
+ | [] -> assert false
+ | [x] -> x
+ | x::l -> Filename.concat x (lconcat l)
+
let xdg_config_home =
try
Filename.concat (Sys.getenv "XDG_CONFIG_HOME") "coq"
with Not_found ->
- Filename.concat home "/.config/coq"
+ lconcat [home;".config";"coq"]
+
+let static_xdg_config_dirs =
+ if Sys.os_type = "Win32" then
+ let base = Filename.dirname (Filename.dirname Sys.executable_name) in
+ [Filename.concat base "config"]
+ else ["/etc/xdg/coq"]
let xdg_config_dirs =
- xdg_config_home :: (try
- List.map (fun dir -> Filename.concat dir "coq") (path_to_list (Sys.getenv "XDG_CONFIG_DIRS"))
- with Not_found -> "/etc/xdg/coq"::(match Coq_config.configdir with |None -> [] |Some d -> [d]))
+ xdg_config_home ::
+ try
+ List.map (fun dir -> Filename.concat dir "coq")
+ (path_to_list (Sys.getenv "XDG_CONFIG_DIRS"))
+ with Not_found -> static_xdg_config_dirs @ opt2list Coq_config.configdir
let xdg_data_home =
try
Filename.concat (Sys.getenv "XDG_DATA_HOME") "coq"
with Not_found ->
- Filename.concat home "/.local/share/coq"
+ lconcat [home;".local";"share";"coq"]
+
+let static_xdg_data_dirs =
+ if Sys.os_type = "Win32" then
+ let base = Filename.dirname (Filename.dirname Sys.executable_name) in
+ [Filename.concat base "share"]
+ else ["/usr/local/share/coq";"/usr/share/coq"]
let xdg_data_dirs =
- xdg_data_home :: (try
- List.map (fun dir -> Filename.concat dir "coq") (path_to_list (Sys.getenv "XDG_DATA_DIRS"))
- with Not_found ->
- "/usr/local/share/coq"::"/usr/share/coq"::(match Coq_config.datadir with |None -> [] |Some d -> [d]))
+ xdg_data_home ::
+ try
+ List.map (fun dir -> Filename.concat dir "coq")
+ (path_to_list (Sys.getenv "XDG_DATA_DIRS"))
+ with Not_found -> static_xdg_data_dirs @ opt2list Coq_config.datadir
let coqtop_path = ref ""