2 * Copyright (C) 2011 Red Hat Inc.
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.
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.
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.
22 open Wrappi_boilerplate
26 let c_of_ptype ~param = function
28 | TBuffer -> assert false (* XXX not implemented *)
29 | TEnum name -> sprintf "enum wrap_%s" name
30 | TFile -> if param then "const char *" else "char *"
31 | THash t -> if param then "char * const *" else "char **"
32 | TInt -> "int" (* XXX not int, correct type depends on preconditions *)
35 | TList t -> assert false (* XXX not implemented *)
36 | TNullable TString -> if param then "const char *" else "char *"
37 | TNullable _ -> assert false (* XXX may be implemented in future *)
38 | TString -> if param then "const char *" else "char *"
39 | TStruct name -> sprintf "struct wrap_%s" name
40 | TTypedef name -> assert false (* should never happen *)
41 | TUInt32 -> "uint32_t"
42 | TUInt64 -> "uint64_t"
43 | TUnion name -> sprintf "union wrap_%s" name
45 let c_of_rtype = function
47 | RStaticString -> "const char *"
48 | Return t -> c_of_ptype ~param:false t
50 (* Print the extern... declaration of a single entry point. *)
51 let pr_extern_decl ep =
52 let ret, req, opt = ep.ep_ftype in
53 pr "extern %s wrap_%s (wrap_h *w" (c_of_rtype ret) ep.ep_name;
55 (* Required parameters. *)
58 let t = c_of_ptype ~param:true t in
59 let sep = (* "const char *" - omit space after asterisk *)
60 let len = String.length t in
61 if isalnum t.[len-1] then " " else "" in
62 pr ", %s%s%s" t sep name
65 (* Optional parameters. *)
71 let generate_lib_wrappi_h api =
72 generate_header CStyle LGPLv2plus;
75 /* Please read the wrappi(1) man page for full documentation. If you
76 * are not familiar with man pages or don't have the documentation
77 * installed, it is also available online at http://wrappi.org/
90 typedef struct wrap_h wrap_h;
92 /* Connection management. */
93 extern wrap_h *wrap_create (void);
94 extern void wrap_close (wrap_h *w);
98 (* Separate the local and remote functions. *)
100 /* Handle functions. */
102 iter_entry_points api (fun ep -> if ep.ep_local then pr_extern_decl ep);
106 /* API entry points. */
108 iter_entry_points api (fun ep -> if not ep.ep_local then pr_extern_decl ep);
116 #endif /* WRAPPI_H_ */
120 output_to "lib/wrappi.h" generate_lib_wrappi_h api