Clarify licensing for Debian.
[virt-df.git] / lib / diskimage_lvm2_metadata.ml
1 (* 'df' command for virtual domains.
2    (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
3    http://libvirt.org/
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version,
9    with the OCaml linking exception described in ../COPYING.LIB.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with this library; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19  *)
20
21 (* Part of the parser for LVM2 metadata. *)
22
23 type metadata = metastmt list
24
25 and metastmt = string * metavalue
26
27 and metavalue =
28   | Metadata of metadata                (* name { ... } *)
29   | String of string                    (* name = "..." *)
30   | Int of Int63.t
31   | Float of float
32   | List of metavalue list              (* name = [...] *)
33
34 let rec output_metadata chan md =
35   _output_metadata chan "" md
36
37 and _output_metadata chan prefix = function
38   | [] -> ()
39   | (name, value) :: rest ->
40       output_string chan prefix;
41       output_string chan name;
42       output_string chan " = ";
43       output_metavalue chan prefix value;
44       output_string chan "\n";
45       _output_metadata chan prefix rest
46
47 and output_metavalue chan prefix = function
48   | Metadata md ->
49       output_string chan "{\n";
50       _output_metadata chan (prefix ^ "  ") md;
51       output_string chan prefix;
52       output_string chan "}";
53   | String str ->
54       output_char chan '"';
55       output_string chan str;
56       output_char chan '"';
57   | Int i ->
58       output_string chan (Int63.to_string i)
59   | Float f ->
60       output_string chan (string_of_float f)
61   | List [] -> ()
62   | List [x] -> output_metavalue chan prefix x
63   | List (x :: xs) ->
64       output_metavalue chan prefix x;
65       output_string chan ", ";
66       output_metavalue chan prefix (List xs)