entry_point
-err mknod_char (pathname path, fileperm perm, int64 major, int64 minor)
+err mknod_char (pathname path, fileperm perm, uint64 major, uint64 minor)
<<
return mknod (path, S_IFCHR | perm, makedev (major, minor));
>>
open Printf
-type any_type = TInt32 | TInt64 | Type of string
+type any_type =
+ | TFilePerm
+ | TInt32
+ | TInt64
+ | TPathname
+ | TUInt32
+ | TUInt64
type parameter = string * any_type
}
let string_of_any_type = function
+ | TFilePerm -> "fileperm"
| TInt32 -> "int32"
| TInt64 -> "int64"
- | Type s -> s
+ | TPathname -> "pathname"
+ | TUInt32 -> "uint32"
+ | TUInt64 -> "uint64"
let string_of_return_type = function
| RErr -> "err"
| Return t -> string_of_any_type t
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
-type any_type = TInt32 | TInt64 | Type of string
+type any_type =
+ | TFilePerm
+ | TInt32
+ | TInt64
+ | TPathname
+ | TUInt32
+ | TUInt64
(** Any API parameter or return type. *)
type parameter = string * any_type
let failwithf fs = ksprintf failwith fs
+let isspace c =
+ c = ' '
+ (* || c = '\f' *) || c = '\n' || c = '\r' || c = '\t' (* || c = '\v' *)
+
+let isalnum c =
+ (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')
+
let files_equal n1 n2 =
let cmd = sprintf "cmp -s %s %s" (Filename.quote n1) (Filename.quote n2) in
match Sys.command cmd with
val failwithf : ('a, unit, string, 'b) format4 -> 'a
(** Like [failwith] but supports printf-like arguments. *)
+val isspace : char -> bool
+(** Return true if char is a whitespace character. *)
+
+val isalnum : char -> bool
+(** Return true if char is an alphanumeric character. *)
+
val files_equal : string -> string -> bool
(** [files_equal filename1 filename2] returns true if the files contain
the same content. *)
(* A parameter or return type. *)
any_type: [
- [ "int32" -> <:expr< Wrappi_types.TInt32 >> ]
+ [ "fileperm" -> <:expr< Wrappi_types.TFilePerm >> ]
+ | [ "int32" -> <:expr< Wrappi_types.TInt32 >> ]
| [ "int64" -> <:expr< Wrappi_types.TInt64 >> ]
- | [ t = LIDENT -> <:expr< Wrappi_types.Type $str:t$ >> ]
+ | [ "pathname" -> <:expr< Wrappi_types.TPathname >> ]
+ | [ "uint32" -> <:expr< Wrappi_types.TUInt32 >> ]
+ | [ "uint64" -> <:expr< Wrappi_types.TUInt64 >> ]
];
(* A return type. *)
$(OBJECTS) \
-o $@
-%.cmi: %.mli
+%.cmi: %.mli ../generator-lib/generator_lib.cma
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
%.cmo: %.ml
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
* 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_
extern \"C\" {
#endif
-";
+#include <stdint.h>
+
+/* 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 "\