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. */
36 ctxopt_init(argv
[0], "stop_if_non_option=Yes "
37 "allow_abbreviations=Yes ");
39 /* Create a new context with its allowed options. */
40 /* """"""""""""""""""""""""""""""""""""""""""""""" */
41 ctxopt_new_ctx("main", "[name... #<string>...]");
43 /* Attach parameters to the name option */
44 /* """""""""""""""""""""""""""""""""""" */
45 ctxopt_add_opt_settings(parameters
, "name", "-n -name");
47 /* Attach a callback action to the name option */
48 /* """"""""""""""""""""""""""""""""""""""""""" */
49 ctxopt_add_opt_settings(actions
, "name", name_action
, NULL
);
51 /* Parse and check the command line options */
52 /* """""""""""""""""""""""""""""""""""""""" */
53 ctxopt_analyze(argc
- 1, argv
+ 1, &nb_rem_args
, &rem_args
);
55 /* Manage the remaining non options */
56 /* """""""""""""""""""""""""""""""" */
59 printf("Non-arguments are not allowed.\n");
63 /* Execute the call back actions in sequence */
64 /* """"""""""""""""""""""""""""""""""""""""" */
67 /* prints the default messages when there is no command line argument. */
68 /* """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" */
70 printf("Hello world.\n");