utils.h: add OSMO_STRINGIFY and OSMO_VALUE_STRING macros

OSMO_STRINGIFY particularly allows putting port numbers from a #define into VTY
doc strings, like:

  #define FOO_PORT 2342
  DEFUN(...,
        "Foo UDP port (default: " OSMO_STRINGIFY(FOO_PORT) ")\n")

OSMO_VALUE_STRING creates value_string items with the string being exactly the
enum value's name. Replaces a similar macro def in fsm.c

Change-Id: I857af45ae602bb9a647ba26cf8b0d1b23403b54c
This commit is contained in:
Neels Hofmeyr 2016-12-16 13:43:54 +01:00 committed by Harald Welte
parent 4e72ee0d0f
commit 18080960e1
2 changed files with 9 additions and 7 deletions

View File

@ -15,6 +15,10 @@
#define OSMO_MAX(a, b) ((a) >= (b) ? (a) : (b))
/*! \brief Return the minimum of two specified values */
#define OSMO_MIN(a, b) ((a) >= (b) ? (b) : (a))
/*! \brief Stringify the contents of a macro, e.g. a port number */
#define OSMO_STRINGIFY(x) #x
/*! \brief Make a value_string entry from an enum value name */
#define OSMO_VALUE_STRING(x) { x, OSMO_STRINGIFY(x) }
#include <stdint.h>

View File

@ -476,14 +476,12 @@ void _osmo_fsm_inst_term(struct osmo_fsm_inst *fi,
file, line);
}
#define ENUM_VAL_TO_VALUE_STRING(X) { X, #X }
const struct value_string osmo_fsm_term_cause_names[] = {
ENUM_VAL_TO_VALUE_STRING(OSMO_FSM_TERM_PARENT),
ENUM_VAL_TO_VALUE_STRING(OSMO_FSM_TERM_REQUEST),
ENUM_VAL_TO_VALUE_STRING(OSMO_FSM_TERM_REGULAR),
ENUM_VAL_TO_VALUE_STRING(OSMO_FSM_TERM_ERROR),
ENUM_VAL_TO_VALUE_STRING(OSMO_FSM_TERM_TIMEOUT),
OSMO_VALUE_STRING(OSMO_FSM_TERM_PARENT),
OSMO_VALUE_STRING(OSMO_FSM_TERM_REQUEST),
OSMO_VALUE_STRING(OSMO_FSM_TERM_REGULAR),
OSMO_VALUE_STRING(OSMO_FSM_TERM_ERROR),
OSMO_VALUE_STRING(OSMO_FSM_TERM_TIMEOUT),
{ 0, NULL }
};