fish: Use a perfect hash for faster command lookups.
[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 callback.  See L<guestfs(3)/guestfs_set_progress_callback>."
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 danger_will_robinson =
40   "B<This command is dangerous.  Without careful use you
41 can easily destroy all your data>."
42
43 let deprecation_notice flags =
44   try
45     let alt =
46       find_map (function DeprecatedBy str -> Some str | _ -> None) flags in
47     let txt =
48       sprintf "This function is deprecated.
49 In new code, use the C<%s> call instead.
50
51 Deprecated functions will not be removed from the API, but the
52 fact that they are deprecated indicates that there are problems
53 with correct use of these functions." alt in
54     Some txt
55   with
56     Not_found -> None
57
58 let copyright_years =
59   let this_year = 1900 + (localtime (time ())).tm_year in
60   if this_year > 2009 then sprintf "2009-%04d" this_year else "2009"
61
62 (* Generate a header block in a number of standard styles. *)
63 type comment_style =
64     CStyle | CPlusPlusStyle | HashStyle | OCamlStyle | HaskellStyle
65 type license = GPLv2plus | LGPLv2plus
66
67 let generate_header ?(extra_inputs = []) comment license =
68   let inputs = "generator/generator_*.ml" :: extra_inputs in
69   let c = match comment with
70     | CStyle ->         pr "/* "; " *"
71     | CPlusPlusStyle -> pr "// "; "//"
72     | HashStyle ->      pr "# ";  "#"
73     | OCamlStyle ->     pr "(* "; " *"
74     | HaskellStyle ->   pr "{- "; "  " in
75   pr "libguestfs generated file\n";
76   pr "%s WARNING: THIS FILE IS GENERATED FROM:\n" c;
77   List.iter (pr "%s   %s\n" c) inputs;
78   pr "%s ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.\n" c;
79   pr "%s\n" c;
80   pr "%s Copyright (C) %s Red Hat Inc.\n" c copyright_years;
81   pr "%s\n" c;
82   (match license with
83    | GPLv2plus ->
84        pr "%s This program is free software; you can redistribute it and/or modify\n" c;
85        pr "%s it under the terms of the GNU General Public License as published by\n" c;
86        pr "%s the Free Software Foundation; either version 2 of the License, or\n" c;
87        pr "%s (at your option) any later version.\n" c;
88        pr "%s\n" c;
89        pr "%s This program is distributed in the hope that it will be useful,\n" c;
90        pr "%s but WITHOUT ANY WARRANTY; without even the implied warranty of\n" c;
91        pr "%s MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" c;
92        pr "%s GNU General Public License for more details.\n" c;
93        pr "%s\n" c;
94        pr "%s You should have received a copy of the GNU General Public License along\n" c;
95        pr "%s with this program; if not, write to the Free Software Foundation, Inc.,\n" c;
96        pr "%s 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n" c;
97
98    | LGPLv2plus ->
99        pr "%s This library is free software; you can redistribute it and/or\n" c;
100        pr "%s modify it under the terms of the GNU Lesser General Public\n" c;
101        pr "%s License as published by the Free Software Foundation; either\n" c;
102        pr "%s version 2 of the License, or (at your option) any later version.\n" c;
103        pr "%s\n" c;
104        pr "%s This library is distributed in the hope that it will be useful,\n" c;
105        pr "%s but WITHOUT ANY WARRANTY; without even the implied warranty of\n" c;
106        pr "%s MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n" c;
107        pr "%s Lesser General Public License for more details.\n" c;
108        pr "%s\n" c;
109        pr "%s You should have received a copy of the GNU Lesser General Public\n" c;
110        pr "%s License along with this library; if not, write to the Free Software\n" c;
111        pr "%s Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" c;
112   );
113   (match comment with
114    | CStyle -> pr " */\n"
115    | CPlusPlusStyle
116    | HashStyle -> ()
117    | OCamlStyle -> pr " *)\n"
118    | HaskellStyle -> pr "-}\n"
119   );
120   pr "\n"