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 -> "intXXX" (* XXX 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 | Return t -> c_of_ptype ~param:false t
49 let generate_lib_wrappi_h api =
50 generate_header CStyle LGPLv2plus;
53 /* Please read the wrappi(1) man page for full documentation. If you
54 * are not familiar with man pages or don't have the documentation
55 * installed, it is also available online at http://wrappi.org/
68 typedef struct wrap_h wrap_h;
70 /* Connection management. */
71 extern wrap_h *wrap_create (void);
72 extern void wrap_close (wrap_h *w);
74 /* API entry points. */
77 iter_entry_points api (
79 let ret, req, opt = ep.ep_ftype in
80 pr "extern %s wrap_%s (wrap_h *w" (c_of_rtype ret) ep.ep_name;
82 (* Required parameters. *)
85 let t = c_of_ptype ~param:true t in
86 let sep = (* "const char *" - omit space after asterisk *)
87 let len = String.length t in
88 if isalnum t.[len-1] then " " else "" in
89 pr ", %s%s%s" t sep name
92 (* Optional parameters. *)
106 #endif /* WRAPPI_H_ */
110 output_to "lib/wrappi.h" generate_lib_wrappi_h api