From 1e791a1f1b6c14536d65442ca853107bd112b7e5 Mon Sep 17 00:00:00 2001 From: malc Date: Sun, 31 Aug 2014 02:01:56 +0400 Subject: [PATCH] Platform juggling --- config.ml | 16 +++++----------- link.c | 34 +++++++++++++++++++++++----------- utils.ml | 9 +++------ 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/config.ml b/config.ml index e874839..a82cc05 100644 --- a/config.ml +++ b/config.ml @@ -463,17 +463,13 @@ let platform_to_string = function | Plinux -> "Linux" | Posx -> "OSX" | Psun -> "Sun" - | Pfreebsd -> "FreeBSD" - | Pdragonflybsd -> "DragonflyBSD" - | Popenbsd -> "OpenBSD" - | Pnetbsd -> "NetBSD" + | Pbsd -> "BSD" | Pcygwin -> "Cygwin" ;; let version () = - Printf.sprintf "llpp version %s, fitz %s, ocaml %s (%s/%dbit)" - Help.version (fz_version ()) Sys.ocaml_version - (platform_to_string platform) Sys.word_size + Printf.sprintf "llpp version %s, fitz %s, ocaml %s/%d bit" + Help.version (fz_version ()) Sys.ocaml_version Sys.word_size ;; let geturl s = @@ -544,16 +540,14 @@ let defconf = ; aalevel = 8 ; urilauncher = (match platform with - | Plinux | Pfreebsd | Pdragonflybsd - | Popenbsd | Pnetbsd | Psun -> "xdg-open \"%s\"" + | Plinux | Psun | Pbsd -> "xdg-open \"%s\"" | Posx -> "open \"%s\"" | Pcygwin -> "cygstart \"%s\"" | Punknown -> "echo %s") ; pathlauncher = "lp \"%s\"" ; selcmd = (match platform with - | Plinux | Pfreebsd | Pdragonflybsd - | Popenbsd | Pnetbsd | Psun -> "xsel -i" + | Plinux | Pbsd | Psun -> "xsel -i" | Posx -> "pbcopy" | Pcygwin -> "wsel" | Punknown -> "cat") diff --git a/link.c b/link.c index 53d7415..ba908c5 100644 --- a/link.c +++ b/link.c @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef __CYGWIN__ #include /* FIONREAD */ @@ -3996,32 +3997,43 @@ CAMLprim value ml_keysymtoutf8 (value keysym_v) CAMLreturn (str_v); } -enum { piunknown, pilinux, piosx, pisun, pifreebsd, - pidragonflybsd, piopenbsd, pinetbsd, picygwin }; +enum { piunknown, pilinux, piosx, pisun, pibsd, picygwin }; CAMLprim value ml_platform (value unit_v) { CAMLparam1 (unit_v); + CAMLlocal2 (tup_v, arr_v); int platid = piunknown; + struct utsname buf; #if defined __linux__ platid = pilinux; #elif defined __CYGWIN__ platid = picygwin; -#elif defined __DragonFly__ - platid = pidragonflybsd; -#elif defined __FreeBSD__ - platid = pifreebsd; -#elif defined __OpenBSD__ - platid = piopenbsd; -#elif defined __NetBSD__ - platid = pinetbsd; +#elif defined __DragonFly__ || defined __FreeBSD__ + || defined __OpenBSD__ || defined __NetBSD__ + platid = pibsd; #elif defined __sun__ platid = pisun; #elif defined __APPLE__ platid = piosx; #endif - CAMLreturn (Val_int (platid)); + if (uname (&buf)) err (1, "uname"); + + tup_v = caml_alloc_tuple (2); + { + char const *sar[] = { + buf.sysname, + buf.release, + buf.version, + buf.machine, + NULL + }; + arr_v = caml_copy_string_array (sar); + } + Field (tup_v, 0) = Val_int (platid); + Field (tup_v, 1) = arr_v; + CAMLreturn (tup_v); } CAMLprim value ml_cloexec (value fd_v) diff --git a/utils.ml b/utils.ml index 097bdbe..927ce4d 100644 --- a/utils.ml +++ b/utils.ml @@ -4,10 +4,7 @@ module E = struct let a = [||];; end;; -type platform = - | Punknown | Plinux | Posx | Psun | Pfreebsd - | Pdragonflybsd | Popenbsd | Pnetbsd | Pcygwin -;; +type platform = | Punknown | Plinux | Posx | Psun | Pbsd | Pcygwin;; let tempfailureretry f a = let rec g () = @@ -20,10 +17,10 @@ external hasdata : Unix.file_descr -> bool = "ml_hasdata";; external toutf8 : int -> string = "ml_keysymtoutf8";; external mbtoutf8 : string -> string = "ml_mbtoutf8";; external popen : string -> (Unix.file_descr * int) list -> unit = "ml_popen";; -external platform : unit -> platform = "ml_platform";; +external platform : unit -> (platform * string array) = "ml_platform";; let now = Unix.gettimeofday;; -let platform = platform ();; +let platform, uname = platform ();; let dolog fmt = Format.ksprintf prerr_endline fmt;; let exntos = function -- 2.11.4.GIT