mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-27 23:22:09 +00:00
MINOR: flags: implement a macro used to dump enums inside masks
Some of our flags have enums inside a mask. The new macro __APPEND_ENUM is able to deal with that by comparing the flag's value against an exact one under the mask. One needs to take care of eliminating the zero value though, otherwise delimiters will not always be properly placed (e.g. if some flags were dumped before and what remains is exactly zero). The bits of the mask are cleared only upon exact matches.
This commit is contained in:
parent
77acaf5af5
commit
7a955b5d73
@ -44,6 +44,10 @@
|
||||
* _(X_FLAG1, _(X_FLAG2, _(X_FLAG3)));
|
||||
* _(~0);
|
||||
* #undef _
|
||||
*
|
||||
* __APPEND_ENUM() works a bit differently in that it takes an additional mask
|
||||
* to isolate bits to compare to the enum's value, and will remove the mask's
|
||||
* bits at once in case of match.
|
||||
*/
|
||||
#ifdef EOF
|
||||
|
||||
@ -70,9 +74,25 @@
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define __APPEND_ENUM(_buf, _len, _del, _flg, _msk, _val, _nam, ...) \
|
||||
do { \
|
||||
size_t _ret = 0; \
|
||||
do { __VA_ARGS__; } while (0); \
|
||||
if (((_flg) & (_msk)) == (_val)) { \
|
||||
(_flg) &= ~(_msk); \
|
||||
_ret = snprintf(_buf, _len, _nam "%s", \
|
||||
(_flg) ? (_del) : ""); \
|
||||
} \
|
||||
if (_ret < _len) { \
|
||||
_len -= _ret; \
|
||||
_buf += _ret; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#else /* EOF not defined => no stdio, do nothing */
|
||||
|
||||
#define __APPEND_FLAG(_buf, _len, _del, _flg, _val, _nam) do { } while (0)
|
||||
#define __APPEND_ENUM(_buf, _len, _del, _flg, _msk, _val, _nam) do { } while (0)
|
||||
|
||||
#endif /* EOF */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user