16b5e5868SGarrett D'Amore /* 26b5e5868SGarrett D'Amore * This file and its contents are supplied under the terms of the 36b5e5868SGarrett D'Amore * Common Development and Distribution License ("CDDL"), version 1.0. 4*5aec55ebSGarrett D'Amore * You may only use this file in accordance with the terms of version 5*5aec55ebSGarrett D'Amore * 1.0 of the CDDL. 66b5e5868SGarrett D'Amore * 76b5e5868SGarrett D'Amore * A full copy of the text of the CDDL should have accompanied this 86b5e5868SGarrett D'Amore * source. A copy of the CDDL is also available via the Internet at 96b5e5868SGarrett D'Amore * http://www.illumos.org/license/CDDL. 106b5e5868SGarrett D'Amore */ 116b5e5868SGarrett D'Amore 126b5e5868SGarrett D'Amore /* 136b5e5868SGarrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved. 146b5e5868SGarrett D'Amore */ 156b5e5868SGarrett D'Amore 166b5e5868SGarrett D'Amore /* 176b5e5868SGarrett D'Amore * LC_NUMERIC database generation routines for localedef. 186b5e5868SGarrett D'Amore */ 196b5e5868SGarrett D'Amore 206b5e5868SGarrett D'Amore #include <stdio.h> 216b5e5868SGarrett D'Amore #include <stdlib.h> 226b5e5868SGarrett D'Amore #include <errno.h> 236b5e5868SGarrett D'Amore #include <sys/types.h> 246b5e5868SGarrett D'Amore #include <string.h> 256b5e5868SGarrett D'Amore #include <unistd.h> 266b5e5868SGarrett D'Amore #include "localedef.h" 276b5e5868SGarrett D'Amore #include "parser.tab.h" 286b5e5868SGarrett D'Amore #include "lnumeric.h" 296b5e5868SGarrett D'Amore 306b5e5868SGarrett D'Amore static struct lc_numeric_T numeric; 316b5e5868SGarrett D'Amore 326b5e5868SGarrett D'Amore void 336b5e5868SGarrett D'Amore init_numeric(void) 346b5e5868SGarrett D'Amore { 356b5e5868SGarrett D'Amore (void) memset(&numeric, 0, sizeof (numeric)); 366b5e5868SGarrett D'Amore } 376b5e5868SGarrett D'Amore 386b5e5868SGarrett D'Amore void 396b5e5868SGarrett D'Amore add_numeric_str(wchar_t *wcs) 406b5e5868SGarrett D'Amore { 416b5e5868SGarrett D'Amore char *str; 426b5e5868SGarrett D'Amore 436b5e5868SGarrett D'Amore if ((str = to_mb_string(wcs)) == NULL) { 446b5e5868SGarrett D'Amore INTERR; 456b5e5868SGarrett D'Amore return; 466b5e5868SGarrett D'Amore } 476b5e5868SGarrett D'Amore free(wcs); 486b5e5868SGarrett D'Amore 496b5e5868SGarrett D'Amore switch (last_kw) { 506b5e5868SGarrett D'Amore case T_DECIMAL_POINT: 516b5e5868SGarrett D'Amore numeric.decimal_point = str; 526b5e5868SGarrett D'Amore break; 536b5e5868SGarrett D'Amore case T_THOUSANDS_SEP: 546b5e5868SGarrett D'Amore numeric.thousands_sep = str; 556b5e5868SGarrett D'Amore break; 566b5e5868SGarrett D'Amore default: 576b5e5868SGarrett D'Amore free(str); 586b5e5868SGarrett D'Amore INTERR; 596b5e5868SGarrett D'Amore break; 606b5e5868SGarrett D'Amore } 616b5e5868SGarrett D'Amore } 626b5e5868SGarrett D'Amore 636b5e5868SGarrett D'Amore void 646b5e5868SGarrett D'Amore reset_numeric_group(void) 656b5e5868SGarrett D'Amore { 666b5e5868SGarrett D'Amore free((char *)numeric.grouping); 676b5e5868SGarrett D'Amore numeric.grouping = NULL; 686b5e5868SGarrett D'Amore } 696b5e5868SGarrett D'Amore 706b5e5868SGarrett D'Amore void 716b5e5868SGarrett D'Amore add_numeric_group(int n) 726b5e5868SGarrett D'Amore { 736b5e5868SGarrett D'Amore char *s; 746b5e5868SGarrett D'Amore 756b5e5868SGarrett D'Amore if (numeric.grouping == NULL) { 766b5e5868SGarrett D'Amore (void) asprintf(&s, "%d", n); 776b5e5868SGarrett D'Amore } else { 786b5e5868SGarrett D'Amore (void) asprintf(&s, "%s;%d", numeric.grouping, n); 796b5e5868SGarrett D'Amore } 806b5e5868SGarrett D'Amore if (s == NULL) 816b5e5868SGarrett D'Amore errf(_("out of memory")); 826b5e5868SGarrett D'Amore 836b5e5868SGarrett D'Amore free((char *)numeric.grouping); 846b5e5868SGarrett D'Amore numeric.grouping = s; 856b5e5868SGarrett D'Amore } 866b5e5868SGarrett D'Amore 876b5e5868SGarrett D'Amore void 886b5e5868SGarrett D'Amore dump_numeric(void) 896b5e5868SGarrett D'Amore { 906b5e5868SGarrett D'Amore FILE *f; 916b5e5868SGarrett D'Amore 926b5e5868SGarrett D'Amore if ((f = open_category()) == NULL) { 936b5e5868SGarrett D'Amore return; 946b5e5868SGarrett D'Amore } 956b5e5868SGarrett D'Amore 966b5e5868SGarrett D'Amore if ((putl_category(numeric.decimal_point, f) == EOF) || 976b5e5868SGarrett D'Amore (putl_category(numeric.thousands_sep, f) == EOF) || 986b5e5868SGarrett D'Amore (putl_category(numeric.grouping, f) == EOF)) { 996b5e5868SGarrett D'Amore return; 1006b5e5868SGarrett D'Amore } 1016b5e5868SGarrett D'Amore close_category(f); 1026b5e5868SGarrett D'Amore } 103