1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
typedef struct _PAWLOC const PAWLOC;
typedef struct _PAWLOC_DIG
{
pawd group_num;
pawmbc group_sep;
pawmbc float_dot;
pawhhc group_str[sizeof(pawsd)];
} PAWLOC_DIG;
typedef struct _PAWLOC_SIG
{
pawmbc display_with;
bool precedes_val;
pawhhs precedes_str;
bool spaceout_val;
pawhhs spaceout_str;
pawd location_val;
pawhhc location_str[sizeof(pawsd)];
} PAWLOC_SIG;
typedef struct _PAWLOC_VAL
{
pawhhs title;
pawhhs value;
} PAWLOC_VAL;
typedef enum _PAWLOC_E_VALUE
{
PAWLOC_E_VAL_POS_PRECEDES = 0,
PAWLOC_E_VAL_POS_SPACEOUT,
PAWLOC_E_VAL_POS_LOCATION,
PAWLOC_E_VAL_NEG_PRECEDES,
PAWLOC_E_VAL_NEG_SPACEOUT,
PAWLOC_E_VAL_NEG_LOCATION,
PAWLOC_E_VAL_NUM_DOT, /* . character for normal representations */
PAWLOC_E_VAL_NUM_SEP, /* , character for normal representations */
PAWLOC_E_VAL_NUM_DIV, /* Divide digits into groups of X */
PAWLOC_E_VAL_MON_DOT, /* . character for money representations */
PAWLOC_E_VAL_MON_SEP, /* , character for money representations */
PAWLOC_E_VAL_MON_DIV, /* Divide digits into groups of X */
PAWLOC_E_VAL_MON_SYM, /* $ character for money representations */
PAWLOC_E_VAL_COUNT
} PAWLOC_E_VALUE;
typedef struct PAWLOC_MON
{
pawmbc sym;
pawd req;
pawhhc str[sizeof(pawsd)];
} PAWLOC_MON;
struct _PAWLOC
{
PAWLOC_VAL val[PAWLOC_E_VAL_COUNT];
PAWLOC_MON world, local;
PAWLOC_DIG dig, mon;
PAWLOC_SIG pos, neg;
};
static struct _PAWLOC pawLocale = {NULL};
static void val2txt( pawhhc *dst, pawd val )
{
pawd i;
pawsu tmp = {0};
pawu2s( &tmp, val, PAW_BASE10 );
memset( dst, 0, sizeof(pawsd) * sizeof(pawhhc) );
for ( i = 0; tmp.str[i]; dst[i] = tmp.str[i], ++i );
}
static void txt2mbc( pawmbc *mbc, paws txt )
{ paws2hhs( *mbc, PAWMBC_MAX_LEN, txt, paws_length(txt) ); }
static pawhhs bool2txt( bool val )
{ return val ? PAWHHC_C("true") : PAWHHC_C("false"); }
#include <locale.h>
PAW_API PAWLOC* pawSeekLocale()
{
struct lconv *lc = localeconv();
struct _PAWLOC *loc = &pawLocale;
loc->dig.group_num = *(lc->grouping);
val2txt( loc->dig.group_str, loc->dig.group_num );
txt2mbc( &(loc->dig.float_dot), lc->decimal_point );
txt2mbc( &(loc->dig.group_sep), lc->thousands_sep );
loc->local.req = lc->frac_digits;
loc->world.req = lc->int_frac_digits;
loc->mon.group_num = *(lc->mon_grouping);
val2txt( loc->local.str, loc->local.req );
val2txt( loc->world.str, loc->world.req );
val2txt( loc->mon.group_str, loc->mon.group_num );
txt2mbc( &(loc->local.sym), lc->currency_symbol );
txt2mbc( &(loc->world.sym), lc->int_curr_symbol );
txt2mbc( &(loc->mon.float_dot), lc->mon_decimal_point );
txt2mbc( &(loc->mon.group_sep), lc->mon_thousands_sep );
loc->pos.location_val = lc->p_sign_posn;
loc->pos.precedes_val = lc->p_cs_precedes;
loc->pos.spaceout_val = lc->p_sep_by_space;
txt2mbc( &(loc->pos.display_with), lc->positive_sign );
val2txt( loc->pos.location_str, loc->pos.location_val );
loc->pos.precedes_str = bool2txt( loc->pos.precedes_val );
loc->pos.spaceout_str = bool2txt( loc->pos.spaceout_val );
loc->neg.location_val = lc->n_sign_posn;
loc->neg.precedes_val = lc->n_cs_precedes;
loc->neg.spaceout_val = lc->n_sep_by_space;
txt2mbc( &(loc->neg.display_with), lc->negative_sign );
val2txt( loc->neg.location_str, loc->neg.location_val );
loc->neg.precedes_str = bool2txt( loc->neg.precedes_val );
loc->neg.spaceout_str = bool2txt( loc->neg.spaceout_val );
...
return loc;
}
| |