6 /* Callback functions */
7 /* ****************** */
10 user_action(char * ctx_name
, char * opt_name
, char * param
, int nb_values
,
11 char ** values
, int nb_opt_data
, void ** opt_data
, int nb_ctx_data
,
14 printf("User %s\n", values
[0]);
18 groups_action(char * ctx_name
, char * opt_name
, char * param
, int nb_values
,
19 char ** values
, int nb_opt_data
, void ** opt_data
,
20 int nb_ctx_data
, void ** ctx_data
)
24 printf("Groups %s", values
[0]);
26 for (v
= 1; v
< nb_values
; v
++)
27 printf(", %s", values
[v
]);
36 main(int argc
, char * argv
[])
38 int nb_rem_args
= 0; /* Nb of remaining unprocessed arguments. */
39 char ** rem_args
= NULL
; /* Remaining arguments string array. */
41 /* initialize ctxopt */
42 /* """"""""""""""""" */
43 ctxopt_init(argv
[0], "stop_if_non_option=Yes "
44 "allow_abbreviations=no ");
46 /* Create new contexts with their allowed options */
47 /* """""""""""""""""""""""""""""""""""""""""""""" */
48 ctxopt_new_ctx("main", "[user>ctx1... #<string>]");
49 ctxopt_new_ctx("ctx1", "group #<string>...");
51 /* Attach parameters to options */
52 /* """""""""""""""""""""""""""" */
53 ctxopt_add_opt_settings(parameters
, "user", "-u -user");
54 ctxopt_add_opt_settings(parameters
, "group", "-g -groups");
56 /* Attach a callback action to options */
57 /* """"""""""""""""""""""""""""""""""" */
58 ctxopt_add_opt_settings(actions
, "user", user_action
, NULL
);
59 ctxopt_add_opt_settings(actions
, "group", groups_action
, NULL
);
61 /* Parse and check the command line options */
62 /* """""""""""""""""""""""""""""""""""""""" */
63 ctxopt_analyze(argc
- 1, argv
+ 1, &nb_rem_args
, &rem_args
);
65 /* Execute registered actions in sequence */
66 /* """""""""""""""""""""""""""""""""""""" */