daemon: debug segv correct use of dereferencing NULL.
[libguestfs.git] / generator / generator_docstrings.ml
1 (* libguestfs
2  * Copyright (C) 2009-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 Unix
22 open Printf
23
24 open Generator_types
25 open Generator_utils
26 open Generator_pr
27
28 (* Handling for function flags. *)
29 let progress_message =
30   "This long-running command can generate progress notification messages
31 so that the caller can display a progress bar or indicator.
32 To receive these messages, the caller must register a progress
33 event callback.  See L<guestfs(3)/GUESTFS_EVENT_PROGRESS>."
34
35 let protocol_limit_warning =
36   "Because of the message protocol, there is a transfer limit
37 of somewhere between 2MB and 4MB.  See L<guestfs(3)/PROTOCOL LIMITS>."
38
39 let deprecation_notice ?(prefix = "") flags =
40   try
41     let alt =
42       find_map (function DeprecatedBy str -> Some str | _ -> None) flags in
43     let txt =
44       sprintf "I<This function is deprecated.>
45 In new code, use the L</%s%s> call instead.
46
47 Deprecated functions will not be removed from the API, but the
48 fact that they are deprecated indicates that there are problems
49 with correct use of these functions." prefix alt in
50     Some txt
51   with
52     Not_found -> None
53
54 let copyright_years =
55   let this_year = 1900 + (localtime (time ())).tm_year in
56   if this_year > 2009 then sprintf "2009-%04d" this_year else "2009"
57
58 (* Generate a header block in a number of standard styles. *)
59 type comment_style =
60     CStyle | CPlusPlusStyle | HashStyle | OCamlStyle | HaskellStyle
61   | ErlangStyle
62 type license = GPLv2plus | LGPLv2plus
63
64 let generate_header ?(extra_inputs = []) comment license =
65   let inputs = "generator/generator_*.ml" :: extra_inputs in
66   let c = match comment with
67     | CStyle ->         pr "/* "; " *"
68     | CPlusPlusStyle -> pr "// "; "//"
69     | HashStyle ->      pr "# ";  "#"
70     | OCamlStyle ->     pr "(* "; " *"
71     | HaskellStyle ->   pr "{- "; "  "
72     | ErlangStyle ->    pr "%% "; "% " in
73   pr "libguestfs generated file\n";
74   pr "%s WARNING: THIS FILE IS GENERATED FROM:\n" c;
75   List.iter (pr "%s   %s\n" c) inputs;
76   pr "%s ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.\n" c;
77   pr "%s\n" c;
78   pr "%s Copyright (C) %s Red Hat Inc.\n" c copyright_years;
79   pr "%s\n" c;
80   (match license with
81    | GPLv2plus ->
82        pr "%s This program is free software; you can redistribute it and/or modify\n" c;
83        pr "%s it under the terms of the GNU General Public License as published by\n" c;
84        pr "%s the Free Software Foundation; either version 2 of the License, or\n" c;
85        pr "%s (at your option) any later version.\n" c;
86        pr "%s\n" c;
87        pr "%s This program is distributed in the hope that it will be useful,\n" c;
88        pr "%s but WITHOUT ANY WARRANTY; without even the implied warranty of\n" c;
89        pr "%s MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" c;
90        pr "%s GNU General Public License for more details.\n" c;
91        pr "%s\n" c;
92        pr "%s You should have received a copy of the GNU General Public License along\n" c;
93        pr "%s with this program; if not, write to the Free Software Foundation, Inc.,\n" c;
94        pr "%s 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n" c;
95
96    | LGPLv2plus ->
97        pr "%s This library is free software; you can redistribute it and/or\n" c;
98        pr "%s modify it under the terms of the GNU Lesser General Public\n" c;
99        pr "%s License as published by the Free Software Foundation; either\n" c;
100        pr "%s version 2 of the License, or (at your option) any later version.\n" c;
101        pr "%s\n" c;
102        pr "%s This library is distributed in the hope that it will be useful,\n" c;
103        pr "%s but WITHOUT ANY WARRANTY; without even the implied warranty of\n" c;
104        pr "%s MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n" c;
105        pr "%s Lesser General Public License for more details.\n" c;
106        pr "%s\n" c;
107        pr "%s You should have received a copy of the GNU Lesser General Public\n" c;
108        pr "%s License along with this library; if not, write to the Free Software\n" c;
109        pr "%s Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" c;
110   );
111   (match comment with
112    | CStyle -> pr " */\n"
113    | CPlusPlusStyle
114    | ErlangStyle
115    | HashStyle -> ()
116    | OCamlStyle -> pr " *)\n"
117    | HaskellStyle -> pr "-}\n"
118   );
119   pr "\n"