| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <argp.h> | 
|  | 2 | #include <stdio.h> | 
|  | 3 | #include <stdlib.h> | 
|  | 4 |  | 
|  | 5 | static struct argp_option argp_options[] = { | 
|  | 6 | { "dstaddr", 'd', "ADDR", 0, | 
|  | 7 | "set destination (peer) address to ADDR" }, | 
|  | 8 | { "peer", 'p', "ADDR", OPTION_ALIAS }, | 
|  | 9 | { NULL } | 
|  | 10 | }; | 
|  | 11 |  | 
|  | 12 | static error_t parse_opt (int key, char *arg, struct argp_state *state); | 
|  | 13 |  | 
|  | 14 | static struct argp argp = | 
|  | 15 | { | 
|  | 16 | argp_options, parse_opt | 
|  | 17 | }; | 
|  | 18 |  | 
|  | 19 | static int cnt; | 
|  | 20 |  | 
|  | 21 | static int | 
|  | 22 | do_test (int argc, char *argv[]) | 
|  | 23 | { | 
|  | 24 | int remaining; | 
|  | 25 | argp_parse (&argp, argc, argv, 0, &remaining, NULL); | 
|  | 26 | return cnt != 4; | 
|  | 27 | } | 
|  | 28 |  | 
|  | 29 | static error_t | 
|  | 30 | parse_opt (int key, char *arg, struct argp_state *state) | 
|  | 31 | { | 
|  | 32 | switch (key) | 
|  | 33 | { | 
|  | 34 | case 'd': | 
|  | 35 | case 'p': | 
|  | 36 | printf ("got '%c' with argument '%s'\n", key, arg); | 
|  | 37 | ++cnt; | 
|  | 38 | break; | 
|  | 39 | case 0: | 
|  | 40 | case ARGP_KEY_END: | 
|  | 41 | case ARGP_KEY_NO_ARGS: | 
|  | 42 | case ARGP_KEY_INIT: | 
|  | 43 | case ARGP_KEY_SUCCESS: | 
|  | 44 | case ARGP_KEY_FINI: | 
|  | 45 | // Ignore. | 
|  | 46 | return ARGP_ERR_UNKNOWN; | 
|  | 47 | default: | 
|  | 48 | printf ("invalid key '%x'\n", key); | 
|  | 49 | exit (1); | 
|  | 50 | } | 
|  | 51 | return 0; | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | #define TEST_FUNCTION do_test (argc, argv) | 
|  | 55 | #include "../test-skeleton.c" |