From 969e7bcfc36c8b36fbcbce7bcbf34594b68d8280 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sat, 23 Jan 2021 06:12:27 -0700 Subject: [PATCH] POSIX.xs: Use macro to reduce complexity This #defines a macro and uses it to populate a structure, so that strings don't have to be typed twice. --- ext/POSIX/POSIX.xs | 54 +++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index a3b0fffbe0e0..3d9e03d6ae1f 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -1578,26 +1578,32 @@ struct lconv_offset { size_t offset; }; +/* Create e.g., + {"thousands_sep", STRUCT_OFFSET(struct lconv, thousands_sep)}, + */ +#define LCONV_ENTRY(name) \ + {STRINGIFY(name), STRUCT_OFFSET(struct lconv, name)} + static const struct lconv_offset lconv_strings[] = { #ifdef USE_LOCALE_NUMERIC - {"decimal_point", STRUCT_OFFSET(struct lconv, decimal_point)}, - {"thousands_sep", STRUCT_OFFSET(struct lconv, thousands_sep)}, + LCONV_ENTRY(decimal_point), + LCONV_ENTRY(thousands_sep), # ifndef NO_LOCALECONV_GROUPING - {"grouping", STRUCT_OFFSET(struct lconv, grouping)}, + LCONV_ENTRY(grouping), # endif #endif #ifdef USE_LOCALE_MONETARY - {"int_curr_symbol", STRUCT_OFFSET(struct lconv, int_curr_symbol)}, - {"currency_symbol", STRUCT_OFFSET(struct lconv, currency_symbol)}, - {"mon_decimal_point", STRUCT_OFFSET(struct lconv, mon_decimal_point)}, + LCONV_ENTRY(int_curr_symbol), + LCONV_ENTRY(currency_symbol), + LCONV_ENTRY(mon_decimal_point), # ifndef NO_LOCALECONV_MON_THOUSANDS_SEP - {"mon_thousands_sep", STRUCT_OFFSET(struct lconv, mon_thousands_sep)}, + LCONV_ENTRY(mon_thousands_sep), # endif # ifndef NO_LOCALECONV_MON_GROUPING - {"mon_grouping", STRUCT_OFFSET(struct lconv, mon_grouping)}, + LCONV_ENTRY(mon_grouping), # endif - {"positive_sign", STRUCT_OFFSET(struct lconv, positive_sign)}, - {"negative_sign", STRUCT_OFFSET(struct lconv, negative_sign)}, + LCONV_ENTRY(positive_sign), + LCONV_ENTRY(negative_sign), #endif {NULL, 0} }; @@ -1619,21 +1625,21 @@ static const struct lconv_offset lconv_strings[] = { static const struct lconv_offset lconv_integers[] = { #ifdef USE_LOCALE_MONETARY - {"int_frac_digits", STRUCT_OFFSET(struct lconv, int_frac_digits)}, - {"frac_digits", STRUCT_OFFSET(struct lconv, frac_digits)}, - {"p_cs_precedes", STRUCT_OFFSET(struct lconv, p_cs_precedes)}, - {"p_sep_by_space", STRUCT_OFFSET(struct lconv, p_sep_by_space)}, - {"n_cs_precedes", STRUCT_OFFSET(struct lconv, n_cs_precedes)}, - {"n_sep_by_space", STRUCT_OFFSET(struct lconv, n_sep_by_space)}, - {"p_sign_posn", STRUCT_OFFSET(struct lconv, p_sign_posn)}, - {"n_sign_posn", STRUCT_OFFSET(struct lconv, n_sign_posn)}, + LCONV_ENTRY(int_frac_digits), + LCONV_ENTRY(frac_digits), + LCONV_ENTRY(p_cs_precedes), + LCONV_ENTRY(p_sep_by_space), + LCONV_ENTRY(n_cs_precedes), + LCONV_ENTRY(n_sep_by_space), + LCONV_ENTRY(p_sign_posn), + LCONV_ENTRY(n_sign_posn), #ifdef HAS_LC_MONETARY_2008 - {"int_p_cs_precedes", STRUCT_OFFSET(struct lconv, int_p_cs_precedes)}, - {"int_p_sep_by_space", STRUCT_OFFSET(struct lconv, int_p_sep_by_space)}, - {"int_n_cs_precedes", STRUCT_OFFSET(struct lconv, int_n_cs_precedes)}, - {"int_n_sep_by_space", STRUCT_OFFSET(struct lconv, int_n_sep_by_space)}, - {"int_p_sign_posn", STRUCT_OFFSET(struct lconv, int_p_sign_posn)}, - {"int_n_sign_posn", STRUCT_OFFSET(struct lconv, int_n_sign_posn)}, + LCONV_ENTRY(int_p_cs_precedes), + LCONV_ENTRY(int_p_sep_by_space), + LCONV_ENTRY(int_n_cs_precedes), + LCONV_ENTRY(int_n_sep_by_space), + LCONV_ENTRY(int_p_sign_posn), + LCONV_ENTRY(int_n_sign_posn), #endif #endif {NULL, 0}