File: check_version.ml

package info (click to toggle)
js-of-ocaml 1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,464 kB
  • sloc: ml: 21,533; makefile: 325
file content (32 lines) | stat: -rw-r--r-- 715 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
open Pervasives

let parse_version s =
  let rec aux s =
    try
      let (i,rest) = Scanf.sscanf s ".%i%s" (fun i s -> i,s) in
      i::(aux rest)
    with
      | _ -> []
  in
  let (major,minor) = Scanf.sscanf s " %i%s" (fun i s -> i,s) in
  major::(aux minor)

let rec get_version_line () =
  let s = Pervasives.input_line Pervasives.stdin in
  try
    Scanf.sscanf s "version: %s" parse_version
  with
    | _ -> get_version_line ()

let check () =
  let version_to_match = parse_version (Sys.argv.(1)) in
  try
    if version_to_match <= get_version_line ()
    then exit 1
    else exit 0
  with
    | End_of_file ->
      print_endline "malformed input: no version number";
      exit 0

let () = check ()