* == there are functions returning both RStruct (_, structname)
* and RStructList (_, structname)
*)
-let rstructs_used =
+let rstructs_used_by functions =
(* ||| is a "logical OR" for rstructs_used_t *)
let (|||) a b =
match a, b with
| RStruct (_, structname) -> update structname RStructOnly
| RStructList (_, structname) -> update structname RStructListOnly
| _ -> ()
- ) all_functions;
+ ) functions;
(* return key->values as a list of (key,value) *)
Hashtbl.fold (fun key value xs -> (key, value) :: xs) h []
-(* debug:
-let () =
- List.iter (
- function
- | sn, RStructOnly -> printf "%s RStructOnly\n" sn
- | sn, RStructListOnly -> printf "%s RStructListOnly\n" sn
- | sn, RStructAndList -> printf "%s RStructAndList\n" sn
- ) rstructs_used
-*)
-
(* Used for testing language bindings. *)
type callt =
| CallString of string
| name, FString ->
pr " printf (\"%%s%s: %%s\\n\", indent, %s->%s);\n" name typ name
| name, FUUID ->
- pr " printf (\"%s: \");\n" name;
+ pr " printf (\"%%s%s: \", indent);\n" name;
pr " for (i = 0; i < 32; ++i)\n";
- pr " printf (\"%%s%%c\", indent, %s->%s[i]);\n" typ name;
+ pr " printf (\"%%c\", %s->%s[i]);\n" typ name;
pr " printf (\"\\n\");\n"
| name, FBuffer ->
pr " printf (\"%%s%s: \", indent);\n" name;
pr " for (i = 0; i < %s->%s_len; ++i)\n" typ name;
pr " if (c_isprint (%s->%s[i]))\n" typ name;
- pr " printf (\"%%s%%c\", indent, %s->%s[i]);\n" typ name;
+ pr " printf (\"%%c\", %s->%s[i]);\n" typ name;
pr " else\n";
- pr " printf (\"%%s\\\\x%%02x\", indent, %s->%s[i]);\n" typ name;
+ pr " printf (\"\\\\x%%02x\", %s->%s[i]);\n" typ name;
pr " printf (\"\\n\");\n"
| name, (FUInt64|FBytes) ->
pr " printf (\"%%s%s: %%\" PRIu64 \"\\n\", indent, %s->%s);\n"
(* generate the function for typ *)
emit_print_list_function typ
| typ, _ -> () (* empty *)
- ) rstructs_used;
+ ) (rstructs_used_by all_functions);
(* Emit a print_TYPE function definition only if that function is used. *)
List.iter (
function
- | typ, RStructOnly ->
+ | typ, (RStructOnly | RStructAndList) ->
pr "static void print_%s (struct guestfs_%s *%s)\n" typ typ typ;
pr "{\n";
pr " print_%s_indent (%s, \"\");\n" typ typ;
pr "}\n";
pr "\n";
| typ, _ -> () (* empty *)
- ) rstructs_used;
+ ) (rstructs_used_by all_functions);
(* run_<action> actions *)
List.iter (
(* generate the function for typ *)
emit_ocaml_copy_list_function typ
| typ, _ -> () (* empty *)
- ) rstructs_used;
+ ) (rstructs_used_by all_functions);
(* The wrappers. *)
List.iter (
(* generate the function for typ *)
emit_put_list_function typ
| typ, _ -> () (* empty *)
- ) rstructs_used;
+ ) (rstructs_used_by all_functions);
(* Python wrapper functions. *)
List.iter (