(* wrappi * Copyright (C) 2011 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) open Wrappi_types open Wrappi_utils open Wrappi_pr open Wrappi_boilerplate open Printf 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 -> "intXXX" (* XXX 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 | RErr -> "int" | Return t -> c_of_ptype ~param:false t let generate_lib_wrappi_h api = generate_header CStyle LGPLv2plus; pr "\ /* Please read the wrappi(1) man page for full documentation. If you * are not familiar with man pages or don't have the documentation * installed, it is also available online at http://wrappi.org/ */ #ifndef WRAPPI_H_ #define WRAPPI_H_ #ifdef __cplusplus extern \"C\" { #endif #include /* The handle. */ typedef struct wrap_h wrap_h; /* Connection management. */ extern wrap_h *wrap_create (void); extern void wrap_close (wrap_h *w); /* API entry points. */ "; iter_entry_points api ( fun ep -> let ret, req, opt = ep.ep_ftype in pr "extern %s wrap_%s (wrap_h *w" (c_of_rtype ret) 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" ); pr "\ #ifdef __cplusplus } #endif #endif /* WRAPPI_H_ */ " let generate api = output_to "lib/wrappi.h" generate_lib_wrappi_h api