X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=generator%2Fwrappi_c.ml;h=62fb48d2e8b5e19bc8dcda6cb8eb39bba4886c62;hb=68483fce4f959886866af28c1c3342c2a6fcb410;hp=f6e9afcc9eb166ac2e33f164e2d04512541fe61c;hpb=ff4a39eec0c3d92b7fda62341e0734e07d5d2987;p=wrappi.git diff --git a/generator/wrappi_c.ml b/generator/wrappi_c.ml index f6e9afc..62fb48d 100644 --- a/generator/wrappi_c.ml +++ b/generator/wrappi_c.ml @@ -16,13 +16,34 @@ * 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_any_type = function + | TFilePerm -> "int" + | TInt32 -> "int32_t" + | TInt64 -> "int64_t" + | TPathname -> "const char *" + | TUInt32 -> "uint32_t" + | TUInt64 -> "uint64_t" + +let c_of_return_type = function + | RErr -> "int" + | Return t -> c_of_any_type 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_ @@ -30,10 +51,32 @@ let generate_lib_wrappi_h api = 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. */ +"; + List.iter ( + fun ep -> + pr "extern %s wrap_%s (wrap_h *w, %s);\n" + (c_of_return_type ep.ep_return) + ep.ep_name + (String.concat ", " + (List.map ( + fun (name, t) -> + let t = c_of_any_type t in + let last_char = t.[String.length t - 1] in + let sep = if isalnum last_char then " " else "" in + sprintf "%s%s%s" t sep name + ) ep.ep_params)) + ) api.api_entry_points; pr "\