Fix error path if realloc call fails.
[ocaml-ancient.git] / ocaml_version.ml
1 (* Get the major or minor part of the OCaml version string.
2  * This doesn't seem t be present in header files (at least not in 3.08.x).
3  *)
4 type t = Major | Minor
5 let usage () = failwith "ocaml_version major|minor"
6 let t =
7   if Array.length Sys.argv < 2 then
8     usage ()
9   else match Sys.argv.(1) with
10   | "major" -> Major
11   | "minor" -> Minor
12   | _ -> usage ()
13 let ocaml_version = Sys.ocaml_version
14 let i = String.index ocaml_version '.'
15 let s =
16   match t with
17   | Major -> String.sub ocaml_version 0 i
18   | Minor ->
19       let j =
20         try String.index_from ocaml_version (i+1) '.'
21         with Not_found -> String.length ocaml_version in
22       String.sub ocaml_version (i+1) (j-i-1)
23 let s = string_of_int (int_of_string s) ;;
24 print_endline s