1
1
open Base
2
2
open Stdio
3
3
4
+ let find_number ~pos str =
5
+ let len = String. length str in
6
+ let rec skip_other ~pos =
7
+ if pos = len then pos
8
+ else
9
+ match str.[pos] with
10
+ | '0' ..'9' -> pos
11
+ | _ -> skip_other ~pos: (pos + 1 )
12
+ in
13
+ let pos = skip_other ~pos in
14
+ let rec loop ~pos =
15
+ if pos = len then [] , pos
16
+ else match str.[pos] with
17
+ | '0' ..'9' as c ->
18
+ let acc, next = loop ~pos: (pos + 1 ) in
19
+ String. make 1 c :: acc, next
20
+ | _ -> [] , pos
21
+ in
22
+ let number_lst, next = loop ~pos in
23
+ String. concat number_lst, next
24
+
4
25
let () =
5
26
let module C = Configurator. V1 in
6
27
C. main ~name: " postgresql" (fun _c ->
@@ -17,40 +38,24 @@ let () =
17
38
let print_fail () =
18
39
eprintf " Unable to find versions from line '%s', cmd: '%s'" line cmd
19
40
in
41
+ let exit_fail () = print_fail () ; Caml. exit 1 in
20
42
try
21
43
let first_space = String. index_exn line ' ' in
22
- let first_dot = String. index_exn line '.' in
23
- let first_part =
24
- let len = first_dot - first_space - 1 in
25
- String. sub line ~pos: (first_space + 1 ) ~len
26
- in
27
- let second_part =
28
- let len = String. length line - first_dot - 1 in
29
- String. sub line ~pos: (first_dot + 1 ) ~len
30
- in
31
- let search_version s =
32
- let version = ref " " in
33
- let stop = ref false in
34
- let check_car c =
35
- let ascii = Char. to_int c in
36
- if (ascii > = 48 && ascii < = 57 && not ! stop) then
37
- version := ! version ^ (String. make 1 c)
38
- else stop := true
39
- in
40
- let () = String. iter ~f: check_car s in
41
- ! version
44
+ let major, next = find_number ~pos: first_space line in
45
+ let minor =
46
+ (* Can also handle release candidates *)
47
+ let c = line.[next] in
48
+ if Char. (c = '.' ) then fst (find_number ~pos: next line)
49
+ else if Char. (c <> 'r' || line.[next + 1 ] <> 'c' ) then exit_fail ()
50
+ else " 0"
42
51
in
43
- let major = search_version first_part in
44
- let minor = search_version second_part in
45
- if String. (major <> " " && minor <> " " ) then
52
+ if String. (major = " " || minor = " " ) then exit_fail ()
53
+ else
46
54
" -DPG_OCAML_MAJOR_VERSION=" ^ major,
47
55
" -DPG_OCAML_MINOR_VERSION=" ^ minor
48
- else begin
49
- print_fail () ;
50
- Caml. exit 1
51
- end
52
56
with exn -> print_fail () ; raise exn
53
57
in
58
+ eprintf " major: %s, minor: %s" major minor;
54
59
let conf = {
55
60
C.Pkg_config.
56
61
cflags = [pgsql_includedir; major; minor];
0 commit comments