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