6 /* Callback functions */
7 /* ****************** */
10 name_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
,
16 printf("Hello %s", values
[0]); /* First command line argument after name *
19 for (v
= 1; v
< nb_values
; v
++) /* Other command line arguments. */
20 printf(", %s", values
[v
]);
29 main(int argc
, char * argv
[])
31 int nb_rem_args
= 0; /* Nb of remaining unprocessed arguments. */
32 char ** rem_args
= NULL
; /* Remaining arguments string array. */
38 /* Create a new context with its allowed options. */
39 /* """"""""""""""""""""""""""""""""""""""""""""""" */
40 ctxopt_new_ctx("main", "[name... #<string>...]");
42 /* Attach parameters to the name option */
43 /* """""""""""""""""""""""""""""""""""" */
44 ctxopt_add_opt_settings(parameters
, "name", "-n -name");
46 /* Attach a callback action to the name option */
47 /* """"""""""""""""""""""""""""""""""""""""""" */
48 ctxopt_add_opt_settings(actions
, "name", name_action
, NULL
);
50 /* Parse and check the command line options */
51 /* """""""""""""""""""""""""""""""""""""""" */
52 ctxopt_analyze(argc
- 1, argv
+ 1, &nb_rem_args
, &rem_args
);
54 /* Manage the remaining non options */
55 /* """""""""""""""""""""""""""""""" */
58 printf("Non-arguments are not allowed.\n");
62 /* Execute the call back actions in sequence */
63 /* """"""""""""""""""""""""""""""""""""""""" */
66 /* prints the default messages when there is no command line argument. */
67 /* """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" */
69 printf("Hello world.\n");