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. 45aec55ebSGarrett D'Amore * You may only use this file in accordance with the terms of version 55aec55ebSGarrett 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 /* 13*2d08521bSGarrett D'Amore * Copyright 2013 Garrett D'Amore <garrett@damore.org> 146b5e5868SGarrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved. 156b5e5868SGarrett D'Amore */ 166b5e5868SGarrett D'Amore 176b5e5868SGarrett D'Amore /* 186b5e5868SGarrett D'Amore * LC_NUMERIC database generation routines for localedef. 196b5e5868SGarrett D'Amore */ 206b5e5868SGarrett D'Amore 216b5e5868SGarrett D'Amore #include <stdio.h> 226b5e5868SGarrett D'Amore #include <stdlib.h> 236b5e5868SGarrett D'Amore #include <errno.h> 246b5e5868SGarrett D'Amore #include <sys/types.h> 256b5e5868SGarrett D'Amore #include <string.h> 266b5e5868SGarrett D'Amore #include <unistd.h> 276b5e5868SGarrett D'Amore #include "localedef.h" 286b5e5868SGarrett D'Amore #include "parser.tab.h" 296b5e5868SGarrett D'Amore #include "lnumeric.h" 306b5e5868SGarrett D'Amore 31*2d08521bSGarrett D'Amore static struct lc_numeric numeric; 326b5e5868SGarrett D'Amore 336b5e5868SGarrett D'Amore void 346b5e5868SGarrett D'Amore init_numeric(void) 356b5e5868SGarrett D'Amore { 366b5e5868SGarrett D'Amore (void) memset(&numeric, 0, sizeof (numeric)); 376b5e5868SGarrett D'Amore } 386b5e5868SGarrett D'Amore 396b5e5868SGarrett D'Amore void 406b5e5868SGarrett D'Amore add_numeric_str(wchar_t *wcs) 416b5e5868SGarrett D'Amore { 426b5e5868SGarrett D'Amore char *str; 436b5e5868SGarrett D'Amore 446b5e5868SGarrett D'Amore if ((str = to_mb_string(wcs)) == NULL) { 456b5e5868SGarrett D'Amore INTERR; 466b5e5868SGarrett D'Amore return; 476b5e5868SGarrett D'Amore } 486b5e5868SGarrett D'Amore free(wcs); 496b5e5868SGarrett D'Amore 506b5e5868SGarrett D'Amore switch (last_kw) { 516b5e5868SGarrett D'Amore case T_DECIMAL_POINT: 526b5e5868SGarrett D'Amore numeric.decimal_point = str; 536b5e5868SGarrett D'Amore break; 546b5e5868SGarrett D'Amore case T_THOUSANDS_SEP: 556b5e5868SGarrett D'Amore numeric.thousands_sep = str; 566b5e5868SGarrett D'Amore break; 576b5e5868SGarrett D'Amore default: 586b5e5868SGarrett D'Amore free(str); 596b5e5868SGarrett D'Amore INTERR; 606b5e5868SGarrett D'Amore break; 616b5e5868SGarrett D'Amore } 626b5e5868SGarrett D'Amore } 636b5e5868SGarrett D'Amore 646b5e5868SGarrett D'Amore void 656b5e5868SGarrett D'Amore reset_numeric_group(void) 666b5e5868SGarrett D'Amore { 676b5e5868SGarrett D'Amore free((char *)numeric.grouping); 686b5e5868SGarrett D'Amore numeric.grouping = NULL; 696b5e5868SGarrett D'Amore } 706b5e5868SGarrett D'Amore 716b5e5868SGarrett D'Amore void 726b5e5868SGarrett D'Amore add_numeric_group(int n) 736b5e5868SGarrett D'Amore { 746b5e5868SGarrett D'Amore char *s; 756b5e5868SGarrett D'Amore 766b5e5868SGarrett D'Amore if (numeric.grouping == NULL) { 776b5e5868SGarrett D'Amore (void) asprintf(&s, "%d", n); 786b5e5868SGarrett D'Amore } else { 796b5e5868SGarrett D'Amore (void) asprintf(&s, "%s;%d", numeric.grouping, n); 806b5e5868SGarrett D'Amore } 816b5e5868SGarrett D'Amore if (s == NULL) 826b5e5868SGarrett D'Amore errf(_("out of memory")); 836b5e5868SGarrett D'Amore 846b5e5868SGarrett D'Amore free((char *)numeric.grouping); 856b5e5868SGarrett D'Amore numeric.grouping = s; 866b5e5868SGarrett D'Amore } 876b5e5868SGarrett D'Amore 886b5e5868SGarrett D'Amore void 896b5e5868SGarrett D'Amore dump_numeric(void) 906b5e5868SGarrett D'Amore { 916b5e5868SGarrett D'Amore FILE *f; 926b5e5868SGarrett D'Amore 936b5e5868SGarrett D'Amore if ((f = open_category()) == NULL) { 946b5e5868SGarrett D'Amore return; 956b5e5868SGarrett D'Amore } 966b5e5868SGarrett D'Amore 976b5e5868SGarrett D'Amore if ((putl_category(numeric.decimal_point, f) == EOF) || 986b5e5868SGarrett D'Amore (putl_category(numeric.thousands_sep, f) == EOF) || 996b5e5868SGarrett D'Amore (putl_category(numeric.grouping, f) == EOF)) { 1006b5e5868SGarrett D'Amore return; 1016b5e5868SGarrett D'Amore } 1026b5e5868SGarrett D'Amore close_category(f); 1036b5e5868SGarrett D'Amore } 104