Add LGPLv2+ notice to *.api files.
[wrappi.git] / generator / wrappi_c.ml
index 1a04234..3011ab1 100644 (file)
@@ -29,7 +29,7 @@ let c_of_ptype ~param = function
   | 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 *)
+  | TInt -> "int" (* XXX not int, correct type depends on preconditions *)
   | TInt32 -> "int32_t"
   | TInt64 -> "int64_t"
   | TList t -> assert false (* XXX not implemented *)
@@ -43,9 +43,30 @@ let c_of_ptype ~param = function
   | TUnion name -> sprintf "union wrap_%s" name
 
 let c_of_rtype = function
-  | RErr -> "int"
+  | RVoid -> "void"
   | Return t -> c_of_ptype ~param:false t
 
+(* Print the extern... declaration of a single entry point. *)
+let pr_extern_decl 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"
+
 let generate_lib_wrappi_h api =
   generate_header CStyle LGPLv2plus;
 
@@ -71,31 +92,19 @@ typedef struct wrap_h wrap_h;
 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 ", ...";
+  (* Separate the local and remote functions. *)
+  pr "\
+/* Handle functions. */
+";
+  iter_entry_points api (fun ep -> if ep.ep_local then pr_extern_decl ep);
 
-      pr ");\n"
+  pr "\
 
-  );
+/* API entry points. */
+";
+  iter_entry_points api (fun ep -> if not ep.ep_local then pr_extern_decl ep);
 
   pr "\