Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/proto/arg.h |
| 3 | * This file contains functions and macros declarations for generic argument parsing. |
| 4 | * |
| 5 | * Copyright 2012 Willy Tarreau <w@1wt.eu> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _PROTO_ARG_H |
| 23 | #define _PROTO_ARG_H |
| 24 | |
| 25 | #include <types/arg.h> |
| 26 | |
| 27 | /* Some macros used to build some arg list. We can declare various argument |
| 28 | * combinations from 0 to 7 args using a single 32-bit integer. The first |
| 29 | * argument of these macros is always the mandatory number of arguments, and |
| 30 | * remaining ones are optional args. Note: ARGM() may also be used to return |
| 31 | * the number of mandatory arguments in a mask. |
| 32 | */ |
| 33 | #define ARGM(m) \ |
David Carlier | 15073a3 | 2016-03-15 19:00:35 +0000 | [diff] [blame] | 34 | (uint64_t)(m & ARGM_MASK) |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 35 | |
| 36 | #define ARG1(m, t1) \ |
David Carlier | 15073a3 | 2016-03-15 19:00:35 +0000 | [diff] [blame] | 37 | (ARGM(m) + ((uint64_t)ARGT_##t1 << (ARGM_BITS))) |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 38 | |
| 39 | #define ARG2(m, t1, t2) \ |
David Carlier | 15073a3 | 2016-03-15 19:00:35 +0000 | [diff] [blame] | 40 | (ARG1(m, t1) + ((uint64_t)ARGT_##t2 << (ARGM_BITS + ARGT_BITS))) |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 41 | |
| 42 | #define ARG3(m, t1, t2, t3) \ |
David Carlier | 15073a3 | 2016-03-15 19:00:35 +0000 | [diff] [blame] | 43 | (ARG2(m, t1, t2) + ((uint64_t)ARGT_##t3 << (ARGM_BITS + ARGT_BITS * 2))) |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 44 | |
| 45 | #define ARG4(m, t1, t2, t3, t4) \ |
David Carlier | 15073a3 | 2016-03-15 19:00:35 +0000 | [diff] [blame] | 46 | (ARG3(m, t1, t2, t3) + ((uint64_t)ARGT_##t4 << (ARGM_BITS + ARGT_BITS * 3))) |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 47 | |
| 48 | #define ARG5(m, t1, t2, t3, t4, t5) \ |
David Carlier | 15073a3 | 2016-03-15 19:00:35 +0000 | [diff] [blame] | 49 | (ARG4(m, t1, t2, t3, t4) + ((uint64_t)ARGT_##t5 << (ARGM_BITS + ARGT_BITS * 4))) |
| 50 | |
| 51 | #define ARG6(m, t1, t2, t3, t4, t5, t6) \ |
| 52 | (ARG5(m, t1, t2, t3, t4, t5) + ((uint64_t)ARGT_##t6 << (ARGM_BITS + ARGT_BITS * 5))) |
| 53 | |
| 54 | #define ARG7(m, t1, t2, t3, t4, t5, t6, t7) \ |
| 55 | (ARG6(m, t1, t2, t3, t4, t5, t6) + ((uint64_t)ARGT_##t7 << (ARGM_BITS + ARGT_BITS * 6))) |
| 56 | |
| 57 | #define ARG8(m, t1, t2, t3, t4, t5, t6, t7, t8) \ |
| 58 | (ARG7(m, t1, t2, t3, t4, t5, t6, t7) + ((uint64_t)ARGT_##t8 << (ARGM_BITS + ARGT_BITS * 7))) |
| 59 | |
| 60 | #define ARG9(m, t1, t2, t3, t4, t5, t6, t7, t8, t9) \ |
| 61 | (ARG8(m, t1, t2, t3, t4, t5, t6, t7, t8) + ((uint64_t)ARGT_##t9 << (ARGM_BITS + ARGT_BITS * 8))) |
| 62 | |
| 63 | #define ARG10(m, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) \ |
| 64 | (ARG9(m, t1, t2, t3, t4, t5, t6, t7, t8, t9) + ((uint64_t)ARGT_##t10 << (ARGM_BITS + ARGT_BITS * 9))) |
| 65 | |
| 66 | #define ARG11(m, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) \ |
| 67 | (ARG10(m, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) + ((uint64_t)ARGT_##t11 << (ARGM_BITS + ARGT_BITS * 10))) |
| 68 | |
| 69 | #define ARG12(m, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) \ |
| 70 | (ARG11(m, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) + ((uint64_t)ARGT_##t12 << (ARGM_BITS + ARGT_BITS * 11))) |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 71 | |
Thierry FOURNIER | 49f45af | 2014-12-08 19:50:43 +0100 | [diff] [blame] | 72 | /* Mapping between argument number and literal description. */ |
| 73 | extern const char *arg_type_names[]; |
| 74 | |
Willy Tarreau | 2e845be | 2012-10-19 19:49:09 +0200 | [diff] [blame] | 75 | /* This dummy arg list may be used by default when no arg is found, it helps |
| 76 | * parsers by removing pointer checks. |
| 77 | */ |
Willy Tarreau | 3d241e7 | 2015-01-19 18:44:07 +0100 | [diff] [blame] | 78 | extern struct arg empty_arg_list[ARGM_NBARGS]; |
Willy Tarreau | 2e845be | 2012-10-19 19:49:09 +0200 | [diff] [blame] | 79 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 80 | struct arg_list *arg_list_clone(const struct arg_list *orig); |
| 81 | struct arg_list *arg_list_add(struct arg_list *orig, struct arg *arg, int pos); |
David Carlier | 15073a3 | 2016-03-15 19:00:35 +0000 | [diff] [blame] | 82 | int make_arg_list(const char *in, int len, uint64_t mask, struct arg **argp, |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 83 | char **err_msg, const char **err_ptr, int *err_arg, |
| 84 | struct arg_list *al); |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 85 | |
| 86 | #endif /* _PROTO_ARG_H */ |
| 87 | |
| 88 | /* |
| 89 | * Local variables: |
| 90 | * c-indent-level: 8 |
| 91 | * c-basic-offset: 8 |
| 92 | * End: |
| 93 | */ |