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_MESSAGES 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 <alloca.h> 276b5e5868SGarrett D'Amore #include "localedef.h" 286b5e5868SGarrett D'Amore #include "parser.tab.h" 296b5e5868SGarrett D'Amore #include "lmessages.h" 306b5e5868SGarrett D'Amore 316b5e5868SGarrett D'Amore static struct lc_messages_T msgs; 326b5e5868SGarrett D'Amore 336b5e5868SGarrett D'Amore void 346b5e5868SGarrett D'Amore init_messages(void) 356b5e5868SGarrett D'Amore { 366b5e5868SGarrett D'Amore (void) memset(&msgs, 0, sizeof (msgs)); 376b5e5868SGarrett D'Amore } 386b5e5868SGarrett D'Amore 396b5e5868SGarrett D'Amore void 406b5e5868SGarrett D'Amore add_message(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_YESSTR: 526b5e5868SGarrett D'Amore msgs.yesstr = str; 536b5e5868SGarrett D'Amore break; 546b5e5868SGarrett D'Amore case T_NOSTR: 556b5e5868SGarrett D'Amore msgs.nostr = str; 566b5e5868SGarrett D'Amore break; 576b5e5868SGarrett D'Amore case T_YESEXPR: 586b5e5868SGarrett D'Amore msgs.yesexpr = str; 596b5e5868SGarrett D'Amore break; 606b5e5868SGarrett D'Amore case T_NOEXPR: 616b5e5868SGarrett D'Amore msgs.noexpr = str; 626b5e5868SGarrett D'Amore break; 636b5e5868SGarrett D'Amore default: 646b5e5868SGarrett D'Amore free(str); 656b5e5868SGarrett D'Amore INTERR; 666b5e5868SGarrett D'Amore break; 676b5e5868SGarrett D'Amore } 686b5e5868SGarrett D'Amore } 696b5e5868SGarrett D'Amore 706b5e5868SGarrett D'Amore void 716b5e5868SGarrett D'Amore dump_messages(void) 726b5e5868SGarrett D'Amore { 736b5e5868SGarrett D'Amore FILE *f; 746b5e5868SGarrett D'Amore char *ptr; 756b5e5868SGarrett D'Amore 766b5e5868SGarrett D'Amore if (msgs.yesstr == NULL) { 776b5e5868SGarrett D'Amore warn(_("missing field 'yesstr'")); 786b5e5868SGarrett D'Amore msgs.yesstr = ""; 796b5e5868SGarrett D'Amore } 806b5e5868SGarrett D'Amore if (msgs.nostr == NULL) { 816b5e5868SGarrett D'Amore warn(_("missing field 'nostr'")); 826b5e5868SGarrett D'Amore msgs.nostr = ""; 836b5e5868SGarrett D'Amore } 846b5e5868SGarrett D'Amore 856b5e5868SGarrett D'Amore /* 866b5e5868SGarrett D'Amore * CLDR likes to add : separated lists for yesstr and nostr. 876b5e5868SGarrett D'Amore * Legacy Solaris code does not seem to grok this. Fix it. 886b5e5868SGarrett D'Amore */ 896b5e5868SGarrett D'Amore if ((ptr = strchr(msgs.yesstr, ':')) != NULL) 906b5e5868SGarrett D'Amore *ptr = 0; 916b5e5868SGarrett D'Amore if ((ptr = strchr(msgs.nostr, ':')) != NULL) 926b5e5868SGarrett D'Amore *ptr = 0; 936b5e5868SGarrett D'Amore 946b5e5868SGarrett D'Amore if ((f = open_category()) == NULL) { 956b5e5868SGarrett D'Amore return; 966b5e5868SGarrett D'Amore } 976b5e5868SGarrett D'Amore 986b5e5868SGarrett D'Amore if ((putl_category(msgs.yesexpr, f) == EOF) || 996b5e5868SGarrett D'Amore (putl_category(msgs.noexpr, f) == EOF) || 1006b5e5868SGarrett D'Amore (putl_category(msgs.yesstr, f) == EOF) || 1016b5e5868SGarrett D'Amore (putl_category(msgs.nostr, f) == EOF)) { 1026b5e5868SGarrett D'Amore return; 1036b5e5868SGarrett D'Amore } 1046b5e5868SGarrett D'Amore close_category(f); 1056b5e5868SGarrett D'Amore } 106