Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 57 lines (46 sloc) 2.364 kB
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
44d0185 @Aqua-Ye [cleanup] mlstate_platform.ml: removed strange characters
Aqua-Ye authored
18 (**
19 This module offers utility functions to have run-time dispatch or conditional execution over platform specific implementation.
20 *)
21
22 (** The platform type, essentially the same as the ocaml platform type *)
23 type mlstate_platform = Unix | Cygwin | Windows
24
25 (** the current platform value *)
26 let mlstate_platform = match Sys.os_type with
27 | "Unix" -> Unix
28 | "Cygwin" -> Cygwin
29 | "Windows"
30 | "Win32" -> Windows
31 | _ -> failwith ("mlstate_platform : unknown platform "^(Sys.os_type))
32
33 (** on_PLATFORM f is a conditional execution of the given function if mlstate_platform matches PLATFORM *)
34
35 let apply_f f = ignore (f ())
36 let not_apply_f _ = ()
37
38 (** Function argument is executed on both Unix and Cygwin *)
39 let on_unixes = if mlstate_platform = Unix || mlstate_platform = Cygwin then apply_f else not_apply_f
40 (** Function argument is executed on Unix only *)
41 let on_unix = if mlstate_platform = Unix then apply_f else not_apply_f
42 (** Function argument is executed on Cygwin only *)
43 let on_cygwin = if mlstate_platform = Cygwin then apply_f else not_apply_f
44 (** Function argument is executed on Windows only *)
45 let on_windows = if mlstate_platform = Windows then apply_f else not_apply_f
46
47 (** Select the good function,
48 unix and windows implementation are mandatory.
49 cygwin implemention can be ommited, in this case the unix implementation is used as fallback
50 all function are taken as input, only the good one is returned
51 *)
52 let platform_dependent ~unix ?(cygwin=unix) ~windows () =
53 match mlstate_platform with
54 | Unix -> unix
55 | Cygwin -> cygwin
56 | Windows -> windows
Something went wrong with that request. Please try again.