Skip to content

Commit

Permalink
generator: add always-available optgroups
Browse files Browse the repository at this point in the history
Support the possibility to have optional groups always enabled (e.g.
because they were present in the past, and they need to be kept for
users).
Add and use few helper optgroups-related functions to deal also with
them.
  • Loading branch information
ptoscano committed May 21, 2014
1 parent 865f640 commit 50ed922
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
24 changes: 20 additions & 4 deletions generator/daemon.ml
Expand Up @@ -713,11 +713,27 @@ and generate_daemon_optgroups_c () =
pr "#include \"optgroups.h\"\n";
pr "\n";

if optgroups_retired <> [] then (
pr "static int\n";
pr "dummy_available (void)\n";
pr "{\n";
pr " return 1;\n";
pr "}\n";
pr "\n";

List.iter (
fun group ->
pr "#define optgroup_%s_available dummy_available\n" group;
) optgroups_retired;

pr "\n";
);

pr "struct optgroup optgroups[] = {\n";
List.iter (
fun (group, _) ->
fun group ->
pr " { \"%s\", optgroup_%s_available },\n" group group
) optgroups;
) optgroups_names_all;
pr " { NULL, NULL }\n";
pr "};\n"

Expand All @@ -729,9 +745,9 @@ and generate_daemon_optgroups_h () =
pr "\n";

List.iter (
fun (group, _) ->
fun group ->
pr "extern int optgroup_%s_available (void);\n" group
) optgroups;
) optgroups_names;

pr "\n";

Expand Down
22 changes: 22 additions & 0 deletions generator/optgroups.ml
Expand Up @@ -19,8 +19,16 @@
(* Please read generator/README first. *)

open Types
open Utils
open Actions

(* The list of optional groups which need to be in the daemon as always
* available. These are "retired" as they no longer appear in the
* list of functions.
*)
let optgroups_retired = [
]

(* Create list of optional groups. *)
let optgroups =
let h = Hashtbl.create 13 in
Expand All @@ -42,3 +50,17 @@ let optgroups =
group, fns
) groups in
List.sort (fun x y -> compare (fst x) (fst y)) groups

let optgroups_names =
fst (List.split optgroups)

let optgroups_names_all =
List.sort compare (optgroups_names @ optgroups_retired)

let () =
let file = "generator/optgroups.ml" in
List.iter (
fun x ->
if List.mem x optgroups_names then
failwithf "%s: optgroups_retired list contains optgroup with functions (%s)" file x
) optgroups_retired

0 comments on commit 50ed922

Please sign in to comment.