blob: 91c1acde70e741cc58aed77004b26321e1a343d0 [file] [log] [blame]
Willy Tarreau2ac57182012-04-19 15:24:50 +02001/*
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) \
Willy Tarreau3d241e72015-01-19 18:44:07 +010034 (m & ARGM_MASK)
Willy Tarreau2ac57182012-04-19 15:24:50 +020035
36#define ARG1(m, t1) \
Willy Tarreau3d241e72015-01-19 18:44:07 +010037 (ARGM(m) + (ARGT_##t1 << (ARGM_BITS)))
Willy Tarreau2ac57182012-04-19 15:24:50 +020038
39#define ARG2(m, t1, t2) \
Willy Tarreau3d241e72015-01-19 18:44:07 +010040 (ARG1(m, t1) + (ARGT_##t2 << (ARGM_BITS + ARGT_BITS)))
Willy Tarreau2ac57182012-04-19 15:24:50 +020041
42#define ARG3(m, t1, t2, t3) \
Willy Tarreau3d241e72015-01-19 18:44:07 +010043 (ARG2(m, t1, t2) + (ARGT_##t3 << (ARGM_BITS + ARGT_BITS * 2)))
Willy Tarreau2ac57182012-04-19 15:24:50 +020044
45#define ARG4(m, t1, t2, t3, t4) \
Willy Tarreau3d241e72015-01-19 18:44:07 +010046 (ARG3(m, t1, t2, t3) + (ARGT_##t4 << (ARGM_BITS + ARGT_BITS * 3)))
Willy Tarreau2ac57182012-04-19 15:24:50 +020047
48#define ARG5(m, t1, t2, t3, t4, t5) \
Willy Tarreau3d241e72015-01-19 18:44:07 +010049 (ARG4(m, t1, t2, t3, t4) + (ARGT_##t5 << (ARGM_BITS + ARGT_BITS * 4)))
Willy Tarreau2ac57182012-04-19 15:24:50 +020050
Thierry FOURNIER49f45af2014-12-08 19:50:43 +010051/* Mapping between argument number and literal description. */
52extern const char *arg_type_names[];
53
Willy Tarreau2e845be2012-10-19 19:49:09 +020054/* This dummy arg list may be used by default when no arg is found, it helps
55 * parsers by removing pointer checks.
56 */
Willy Tarreau3d241e72015-01-19 18:44:07 +010057extern struct arg empty_arg_list[ARGM_NBARGS];
Willy Tarreau2e845be2012-10-19 19:49:09 +020058
Willy Tarreaua4312fa2013-04-02 16:34:32 +020059struct arg_list *arg_list_clone(const struct arg_list *orig);
60struct arg_list *arg_list_add(struct arg_list *orig, struct arg *arg, int pos);
Willy Tarreau2ac57182012-04-19 15:24:50 +020061int make_arg_list(const char *in, int len, unsigned int mask, struct arg **argp,
Willy Tarreaua4312fa2013-04-02 16:34:32 +020062 char **err_msg, const char **err_ptr, int *err_arg,
63 struct arg_list *al);
Willy Tarreau2ac57182012-04-19 15:24:50 +020064
65#endif /* _PROTO_ARG_H */
66
67/*
68 * Local variables:
69 * c-indent-level: 8
70 * c-basic-offset: 8
71 * End:
72 */