generator: Change optgroups so second element is a list of functions.

Before this commit it was a list of function names (ie. strings)
making it hard if you wanted to get back to the original function
definition.
This commit is contained in:
Richard W.M. Jones
2012-12-10 16:14:42 +00:00
parent 2a2719d889
commit 5802b30ae5
2 changed files with 11 additions and 6 deletions

View File

@@ -360,11 +360,11 @@ and generate_availability_pod () =
pr "=over 4\n";
pr "\n";
List.iter (
fun (group, functions) ->
fun (group, fns) ->
pr "=item B<%s>\n" group;
pr "\n";
pr "The following functions:\n";
List.iter (pr "L</guestfs_%s>\n") functions;
List.iter (pr "L</guestfs_%s>\n") (List.map (fun { name = n } -> n) fns);
pr "\n"
) optgroups;
pr "=back\n";

View File

@@ -26,14 +26,19 @@ let optgroups =
let h = Hashtbl.create 13 in
List.iter (
function
| { name = name; optional = Some group } ->
let names = try Hashtbl.find h group with Not_found -> [] in
Hashtbl.replace h group (name :: names)
| { optional = Some group } as fn ->
let fns = try Hashtbl.find h group with Not_found -> [] in
Hashtbl.replace h group (fn :: fns)
| _ -> ()
) daemon_functions;
let groups = Hashtbl.fold (fun k _ ks -> k :: ks) h [] in
let groups =
List.map (
fun group -> group, List.sort compare (Hashtbl.find h group)
fun group ->
(* Ensure the functions are sorted on the name field. *)
let fns = Hashtbl.find h group in
let cmp { name = n1 } { name = n2 } = compare n1 n2 in
let fns = List.sort cmp fns in
group, fns
) groups in
List.sort (fun x y -> compare (fst x) (fst y)) groups