<<
w->error_flag = 0;
>>
+
+(*
+event error ???
+*)
struct stat buf;
if (stat (path, &buf) == -1) {
- error_errno ("stat: %s", path);
+ set_error_errno ("stat: %s", path);
return -1;
}
void mknod_char (pathname path, fileperm perm, uint64 major, uint64 minor)
<<
if (mknod (path, S_IFCHR | perm, makedev (major, minor)) == -1) {
- error_errno ("mknod: %s", path);
+ set_error_errno ("mknod: %s", path);
return -1;
}
return 0;
wrappi_c.cmi:
wrappi_c.cmo: wrappi_pr.cmi wrappi_boilerplate.cmi wrappi_c.cmi
wrappi_c.cmx: wrappi_pr.cmx wrappi_boilerplate.cmx wrappi_c.cmi
-wrappi_main.cmo: wrappi_pr.cmi wrappi_c.cmi
-wrappi_main.cmx: wrappi_pr.cmx wrappi_c.cmx
+wrappi_c_impl.cmi:
+wrappi_c_impl.cmo: wrappi_pr.cmi wrappi_boilerplate.cmi wrappi_c_impl.cmi
+wrappi_c_impl.cmx: wrappi_pr.cmx wrappi_boilerplate.cmx wrappi_c_impl.cmi
+wrappi_main.cmo: wrappi_pr.cmi wrappi_c_impl.cmi wrappi_c.cmi
+wrappi_main.cmx: wrappi_pr.cmx wrappi_c_impl.cmx wrappi_c.cmx
wrappi_pr.cmi:
wrappi_pr.cmo: wrappi_pr.cmi
wrappi_pr.cmx: wrappi_pr.cmi
SOURCES = \
wrappi_boilerplate.mli \
wrappi_boilerplate.ml \
+ wrappi_c_impl.mli \
+ wrappi_c_impl.ml \
wrappi_c.mli \
wrappi_c.ml \
wrappi_main.ml \
OBJECTS = \
wrappi_pr.cmo \
wrappi_boilerplate.cmo \
+ wrappi_c_impl.cmo \
wrappi_c.cmo \
wrappi_main.cmo
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
+(** Generate the C bindings. *)
+
val generate : Wrappi_types.api -> unit
--- /dev/null
+(* 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 Camlp4.PreCast
+
+open Wrappi_utils
+open Wrappi_types
+open Wrappi_boilerplate
+open Wrappi_pr
+
+open Printf
+
+let generate_implementation ep =
+ generate_header CStyle LGPLv2plus;
+
+ pr "\
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include \"wrappi.h\"
+
+#include \"internal.h\"
+
+"
+
+ (* Depending on whether this is a local or remote function, include
+ * different definitions here.
+ *)
+ (*if ep.ep_local then ... *)
+
+(* Make a unique, reproducible filename for each entry point. *)
+let filename_of_ep ep =
+ let filename = Loc.file_name ep.ep_loc in
+ let filename = Filename.basename filename in
+ let filename =
+ try Filename.chop_extension filename
+ with Invalid_argument _ -> filename in
+ let filename = sprintf "%s-%s.c" filename ep.ep_name in
+ filename
+
+let generate_lib_implementation_files_mk api =
+ generate_header HashStyle GPLv2plus;
+
+ let eps = StringMap.bindings api.api_entry_points in
+ let cmp (a, _) (b, _) = compare a b in
+ let eps = List.sort cmp eps in
+ let eps = List.map snd eps in
+
+ let rec loop = function
+ | [] -> ()
+ | [ep] -> pr "\t%s\n" (filename_of_ep ep)
+ | ep :: eps -> pr "\t%s \\\n" (filename_of_ep ep); loop eps
+ in
+
+ pr "local_implementation_files := \\\n";
+
+ loop (List.filter (fun ep -> ep.ep_local) eps);
+
+ pr "\n";
+ pr "remote_implementation_files := \\\n";
+
+ loop (List.filter (fun ep -> not ep.ep_local) eps)
+
+let generate api =
+ let gitignores = ref [] in
+
+ iter_entry_points api (
+ fun ep ->
+ let filename = filename_of_ep ep in
+
+ gitignores := ("/" ^ filename) :: !gitignores;
+
+ output_to ("lib/" ^ filename) generate_implementation ep
+ );
+
+ let gitignores = List.rev !gitignores in
+ output_to "lib/.gitignore"
+ (fun () -> List.iter (pr "%s\n") gitignores) ();
+
+ output_to "lib/implementation_files.mk"
+ generate_lib_implementation_files_mk api
--- /dev/null
+(* 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.
+ *)
+
+(** Generate the C implementation of the library. *)
+
+val generate : Wrappi_types.api -> unit
exit 1);
(* Generate code. *)
+ Wrappi_c_impl.generate api;
Wrappi_c.generate api;
printf "generated %d lines of code in %d files\n"
--- /dev/null
+/error-clear_error.c
+/handle-connect.c
+/error-error.c
+/filesize-filesize.c
+/mkdir-mkdir.c
+/mknod-mknod_char.c
+/handle-set_hostname.c
+/handle-set_scheme.c
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+include implementation_files.mk
+
include_HEADERS = wrappi.h
lib_LTLIBRARIES = libwrappi.la
libwrappi_la_SOURCES = \
wrappi.h \
- wrappi.c
+ wrappi.c \
+ $(local_implementation_files) \
+ $(remote_implementation_files)
--- /dev/null
+# wrappi generated file
+# WARNING: THIS FILE IS GENERATED FROM:
+# generator/wrappi_*.ml
+# ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
+#
+# 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.
+
+local_implementation_files := \
+ error-clear_error.c \
+ handle-connect.c \
+ error-error.c \
+ handle-set_hostname.c \
+ handle-set_scheme.c
+
+remote_implementation_files := \
+ filesize-filesize.c \
+ mkdir-mkdir.c \
+ mknod-mknod_char.c