Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
Willy Tarreau | 38ceb55 | 2021-04-02 10:33:38 +0200 | [diff] [blame] | 4 | #include <haproxy/arg.h> |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 5 | |
| 6 | int main(int argc, char **argv) |
| 7 | { |
| 8 | int nbargs, err_arg, mask; |
| 9 | struct arg *argp; |
| 10 | char *err_msg = NULL; |
| 11 | const char *err_ptr = NULL; |
| 12 | |
| 13 | if (argc < 2) { |
| 14 | printf("Usage: %s arg_list [arg_mask]\n" |
| 15 | " mask defaults to 0x86543290\n" |
| 16 | " eg: %s 10k,+20,Host,1.2.3.4,24,::5.6.7.8,120s\n", *argv, *argv); |
| 17 | return 1; |
| 18 | } |
| 19 | |
| 20 | mask = ARG7(0,SIZE,SINT,STR,IPV4,MSK4,IPV6,TIME); |
| 21 | if (argc >= 3) |
| 22 | mask = atoll(argv[2]); |
| 23 | |
| 24 | printf("Using mask=0x%08x\n", mask); |
| 25 | nbargs = make_arg_list(argv[1], strlen(argv[1]), mask, |
Willy Tarreau | 38ceb55 | 2021-04-02 10:33:38 +0200 | [diff] [blame] | 26 | &argp, &err_msg, &err_ptr, &err_arg, NULL); |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 27 | |
| 28 | printf("nbargs=%d\n", nbargs); |
| 29 | if (nbargs < 0) { |
| 30 | printf("err_msg=%s\n", err_msg); free(err_msg); |
| 31 | printf("err_ptr=%s (str+%d)\n", err_ptr, err_ptr - argv[1]); |
| 32 | printf("err_arg=%d\n", err_arg); |
| 33 | return 1; |
| 34 | } |
| 35 | |
| 36 | if (nbargs > 0) { |
| 37 | int arg; |
| 38 | |
| 39 | for (arg = 0; arg < nbargs; arg++) |
| 40 | printf("arg %d: type=%d, int=0x%08x\n", |
Willy Tarreau | 38ceb55 | 2021-04-02 10:33:38 +0200 | [diff] [blame] | 41 | arg, argp[arg].type, *(int*)&argp[arg].data.sint); |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 42 | } |
| 43 | return 0; |
| 44 | } |