5f9d96f7441383d0eab223a6068f1e0b03003b48
[libguestfs.git] / generator / generator_api_versions.ml
1 (* libguestfs
2  * Copyright (C) 2010 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *)
18
19 (* Please read generator/README first. *)
20
21 open Generator_utils
22
23 let hash = Hashtbl.create 13
24
25 let load_api_versions filename =
26   let chan = open_in filename in
27   let rec loop lineno =
28     let line = input_line chan in
29     let sym, ver =
30       match string_split " " line with
31       | [ sym; ver ] -> sym, ver
32       | _ ->
33           failwithf "%s: %d: invalid input in API versions file"
34             filename lineno in
35     Hashtbl.replace hash sym ver;
36     loop (lineno+1)
37   in
38   (try loop 1 with End_of_file -> ());
39   close_in chan
40
41 let lookup_api_version sym =
42   try Hashtbl.find hash sym
43   with Not_found ->
44     failwithf "API symbol \"%s\" not found in API versions file" sym