+let c_of_ptype ~param = function
+ | TBool -> "int"
+ | TBuffer -> assert false (* XXX not implemented *)
+ | TEnum name -> sprintf "enum wrap_%s" name
+ | TFile -> if param then "const char *" else "char *"
+ | THash t -> if param then "char * const *" else "char **"
+ | TInt -> "int" (* XXX not int, correct type depends on preconditions *)
+ | TInt32 -> "int32_t"
+ | TInt64 -> "int64_t"
+ | TList t -> assert false (* XXX not implemented *)
+ | TNullable TString -> if param then "const char *" else "char *"
+ | TNullable _ -> assert false (* XXX may be implemented in future *)
+ | TString -> if param then "const char *" else "char *"
+ | TStruct name -> sprintf "struct wrap_%s" name
+ | TTypedef name -> assert false (* should never happen *)
+ | TUInt32 -> "uint32_t"
+ | TUInt64 -> "uint64_t"
+ | TUnion name -> sprintf "union wrap_%s" name
+
+let c_of_rtype = function
+ | RVoid -> "void"
+ | Return t -> c_of_ptype ~param:false t
+
+let pr_decl ep =
+ let ret, req, opt = ep.ep_ftype in
+ pr "%s\n" (c_of_rtype ret);
+ pr "wrap_%s (wrap_h *w" ep.ep_name;
+
+ (* Required parameters. *)
+ List.iter (
+ fun (name, t, _) ->
+ let t = c_of_ptype ~param:true t in
+ let sep = (* "const char *" - omit space after asterisk *)
+ let len = String.length t in
+ if isalnum t.[len-1] then " " else "" in
+ pr ", %s%s%s" t sep name
+ ) req;
+
+ (* Optional parameters. *)
+ if opt <> [] then
+ pr ", ...";
+
+ pr ")\n"
+