Fix to work against OCaml 3.08.3.
[ocaml-ancient.git] / ocaml_version.ml
diff --git a/ocaml_version.ml b/ocaml_version.ml
new file mode 100644 (file)
index 0000000..3367f93
--- /dev/null
@@ -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