Remote protocol working.
[wrappi.git] / generator / wrappi_boilerplate.ml
1 (* wrappi
2  * Copyright (C) 2011 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 open Unix
20 open Printf
21
22 open Wrappi_pr
23
24 let copyright_years =
25   let this_year = 1900 + (localtime (time ())).tm_year in
26   if this_year > 2011 then sprintf "2011-%04d" this_year else "2011"
27
28 (* Generate a header block in a number of standard styles. *)
29 type comment_style =
30   | CStyle | CPlusPlusStyle | HashStyle | OCamlStyle | HaskellStyle
31   | ErlangStyle
32 type license = GPLv2plus | LGPLv2plus
33
34 let generate_header inputs comment license =
35   let c = match comment with
36     | CStyle ->         pr "/* "; " *"
37     | CPlusPlusStyle -> pr "// "; "//"
38     | HashStyle ->      pr "# ";  "#"
39     | OCamlStyle ->     pr "(* "; " *"
40     | HaskellStyle ->   pr "{- "; "  "
41     | ErlangStyle ->    pr "%% "; "% " in
42   pr "wrappi generated file\n";
43   pr "%s WARNING: THIS FILE IS GENERATED FROM:\n" c;
44   List.iter (pr "%s   %s\n" c) inputs;
45   pr "%s ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.\n" c;
46   pr "%s\n" c;
47   pr "%s Copyright (C) %s Red Hat Inc.\n" c copyright_years;
48   pr "%s\n" c;
49   (match license with
50    | GPLv2plus ->
51        pr "%s This program is free software; you can redistribute it and/or modify\n" c;
52        pr "%s it under the terms of the GNU General Public License as published by\n" c;
53        pr "%s the Free Software Foundation; either version 2 of the License, or\n" c;
54        pr "%s (at your option) any later version.\n" c;
55        pr "%s\n" c;
56        pr "%s This program is distributed in the hope that it will be useful,\n" c;
57        pr "%s but WITHOUT ANY WARRANTY; without even the implied warranty of\n" c;
58        pr "%s MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" c;
59        pr "%s GNU General Public License for more details.\n" c;
60        pr "%s\n" c;
61        pr "%s You should have received a copy of the GNU General Public License along\n" c;
62        pr "%s with this program; if not, write to the Free Software Foundation, Inc.,\n" c;
63        pr "%s 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n" c;
64
65    | LGPLv2plus ->
66        pr "%s This library is free software; you can redistribute it and/or\n" c;
67        pr "%s modify it under the terms of the GNU Lesser General Public\n" c;
68        pr "%s License as published by the Free Software Foundation; either\n" c;
69        pr "%s version 2 of the License, or (at your option) any later version.\n" c;
70        pr "%s\n" c;
71        pr "%s This library is distributed in the hope that it will be useful,\n" c;
72        pr "%s but WITHOUT ANY WARRANTY; without even the implied warranty of\n" c;
73        pr "%s MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n" c;
74        pr "%s Lesser General Public License for more details.\n" c;
75        pr "%s\n" c;
76        pr "%s You should have received a copy of the GNU Lesser General Public\n" c;
77        pr "%s License along with this library; if not, write to the Free Software\n" c;
78        pr "%s Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" c;
79   );
80   (match comment with
81    | CStyle -> pr " */\n"
82    | CPlusPlusStyle
83    | ErlangStyle
84    | HashStyle -> ()
85    | OCamlStyle -> pr " *)\n"
86    | HaskellStyle -> pr "-}\n"
87   );
88   pr "\n"