X-Git-Url: http://git.annexia.org/?p=ocaml-ancient.git;a=blobdiff_plain;f=ocaml_version.ml;fp=ocaml_version.ml;h=3367f9388f2b8a210b0184470aef5c543862bc88;hp=0000000000000000000000000000000000000000;hb=d636bf12b0e8a8d6c7f9ad96d24984c24a145930;hpb=2fcf5fb16af9a096fcedea637d4c5dd453f94db5 diff --git a/ocaml_version.ml b/ocaml_version.ml new file mode 100644 index 0000000..3367f93 --- /dev/null +++ b/ocaml_version.ml @@ -0,0 +1,25 @@ +(* Get the major or minor part of the OCaml version string. + * This doesn't seem t be present in header files (at least not in 3.08.x). + * $Id: ocaml_version.ml,v 1.1 2006-10-31 14:39:50 rich Exp $ + *) +type t = Major | Minor +let usage () = failwith "ocaml_version major|minor" +let t = + if Array.length Sys.argv < 2 then + usage () + else match Sys.argv.(1) with + | "major" -> Major + | "minor" -> Minor + | _ -> usage () +let ocaml_version = Sys.ocaml_version +let i = String.index ocaml_version '.' +let s = + match t with + | Major -> String.sub ocaml_version 0 i + | Minor -> + let j = + try String.index_from ocaml_version (i+1) '.' + with Not_found -> String.length ocaml_version in + String.sub ocaml_version (i+1) (j-i-1) +let s = string_of_int (int_of_string s) ;; +print_endline s