xref: /titanic_53/usr/src/cmd/localedef/messages.c (revision 6b5e5868e7ebf1aff3a5abd7d0c4ef0e5fbf3648)
1*6b5e5868SGarrett D'Amore /*
2*6b5e5868SGarrett D'Amore  * This file and its contents are supplied under the terms of the
3*6b5e5868SGarrett D'Amore  * Common Development and Distribution License ("CDDL"), version 1.0.
4*6b5e5868SGarrett D'Amore  * You may only use this file in accordance with the terms version 1.0
5*6b5e5868SGarrett D'Amore  * of the CDDL.
6*6b5e5868SGarrett D'Amore  *
7*6b5e5868SGarrett D'Amore  * A full copy of the text of the CDDL should have accompanied this
8*6b5e5868SGarrett D'Amore  * source.  A copy of the CDDL is also available via the Internet at
9*6b5e5868SGarrett D'Amore  * http://www.illumos.org/license/CDDL.
10*6b5e5868SGarrett D'Amore  */
11*6b5e5868SGarrett D'Amore 
12*6b5e5868SGarrett D'Amore /*
13*6b5e5868SGarrett D'Amore  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
14*6b5e5868SGarrett D'Amore  */
15*6b5e5868SGarrett D'Amore 
16*6b5e5868SGarrett D'Amore /*
17*6b5e5868SGarrett D'Amore  * LC_MESSAGES database generation routines for localedef.
18*6b5e5868SGarrett D'Amore  */
19*6b5e5868SGarrett D'Amore 
20*6b5e5868SGarrett D'Amore #include <stdio.h>
21*6b5e5868SGarrett D'Amore #include <stdlib.h>
22*6b5e5868SGarrett D'Amore #include <errno.h>
23*6b5e5868SGarrett D'Amore #include <sys/types.h>
24*6b5e5868SGarrett D'Amore #include <string.h>
25*6b5e5868SGarrett D'Amore #include <unistd.h>
26*6b5e5868SGarrett D'Amore #include <alloca.h>
27*6b5e5868SGarrett D'Amore #include "localedef.h"
28*6b5e5868SGarrett D'Amore #include "parser.tab.h"
29*6b5e5868SGarrett D'Amore #include "lmessages.h"
30*6b5e5868SGarrett D'Amore 
31*6b5e5868SGarrett D'Amore static struct lc_messages_T msgs;
32*6b5e5868SGarrett D'Amore 
33*6b5e5868SGarrett D'Amore void
34*6b5e5868SGarrett D'Amore init_messages(void)
35*6b5e5868SGarrett D'Amore {
36*6b5e5868SGarrett D'Amore 	(void) memset(&msgs, 0, sizeof (msgs));
37*6b5e5868SGarrett D'Amore }
38*6b5e5868SGarrett D'Amore 
39*6b5e5868SGarrett D'Amore void
40*6b5e5868SGarrett D'Amore add_message(wchar_t *wcs)
41*6b5e5868SGarrett D'Amore {
42*6b5e5868SGarrett D'Amore 	char *str;
43*6b5e5868SGarrett D'Amore 
44*6b5e5868SGarrett D'Amore 	if ((str = to_mb_string(wcs)) == NULL) {
45*6b5e5868SGarrett D'Amore 		INTERR;
46*6b5e5868SGarrett D'Amore 		return;
47*6b5e5868SGarrett D'Amore 	}
48*6b5e5868SGarrett D'Amore 	free(wcs);
49*6b5e5868SGarrett D'Amore 
50*6b5e5868SGarrett D'Amore 	switch (last_kw) {
51*6b5e5868SGarrett D'Amore 	case T_YESSTR:
52*6b5e5868SGarrett D'Amore 		msgs.yesstr = str;
53*6b5e5868SGarrett D'Amore 		break;
54*6b5e5868SGarrett D'Amore 	case T_NOSTR:
55*6b5e5868SGarrett D'Amore 		msgs.nostr = str;
56*6b5e5868SGarrett D'Amore 		break;
57*6b5e5868SGarrett D'Amore 	case T_YESEXPR:
58*6b5e5868SGarrett D'Amore 		msgs.yesexpr = str;
59*6b5e5868SGarrett D'Amore 		break;
60*6b5e5868SGarrett D'Amore 	case T_NOEXPR:
61*6b5e5868SGarrett D'Amore 		msgs.noexpr = str;
62*6b5e5868SGarrett D'Amore 		break;
63*6b5e5868SGarrett D'Amore 	default:
64*6b5e5868SGarrett D'Amore 		free(str);
65*6b5e5868SGarrett D'Amore 		INTERR;
66*6b5e5868SGarrett D'Amore 		break;
67*6b5e5868SGarrett D'Amore 	}
68*6b5e5868SGarrett D'Amore }
69*6b5e5868SGarrett D'Amore 
70*6b5e5868SGarrett D'Amore void
71*6b5e5868SGarrett D'Amore dump_messages(void)
72*6b5e5868SGarrett D'Amore {
73*6b5e5868SGarrett D'Amore 	FILE *f;
74*6b5e5868SGarrett D'Amore 	char *ptr;
75*6b5e5868SGarrett D'Amore 
76*6b5e5868SGarrett D'Amore 	if (msgs.yesstr == NULL) {
77*6b5e5868SGarrett D'Amore 		warn(_("missing field 'yesstr'"));
78*6b5e5868SGarrett D'Amore 		msgs.yesstr = "";
79*6b5e5868SGarrett D'Amore 	}
80*6b5e5868SGarrett D'Amore 	if (msgs.nostr == NULL) {
81*6b5e5868SGarrett D'Amore 		warn(_("missing field 'nostr'"));
82*6b5e5868SGarrett D'Amore 		msgs.nostr = "";
83*6b5e5868SGarrett D'Amore 	}
84*6b5e5868SGarrett D'Amore 
85*6b5e5868SGarrett D'Amore 	/*
86*6b5e5868SGarrett D'Amore 	 * CLDR likes to add : separated lists for yesstr and nostr.
87*6b5e5868SGarrett D'Amore 	 * Legacy Solaris code does not seem to grok this.  Fix it.
88*6b5e5868SGarrett D'Amore 	 */
89*6b5e5868SGarrett D'Amore 	if ((ptr = strchr(msgs.yesstr, ':')) != NULL)
90*6b5e5868SGarrett D'Amore 		*ptr = 0;
91*6b5e5868SGarrett D'Amore 	if ((ptr = strchr(msgs.nostr, ':')) != NULL)
92*6b5e5868SGarrett D'Amore 		*ptr = 0;
93*6b5e5868SGarrett D'Amore 
94*6b5e5868SGarrett D'Amore 	if ((f = open_category()) == NULL) {
95*6b5e5868SGarrett D'Amore 		return;
96*6b5e5868SGarrett D'Amore 	}
97*6b5e5868SGarrett D'Amore 
98*6b5e5868SGarrett D'Amore 	if ((putl_category(msgs.yesexpr, f) == EOF) ||
99*6b5e5868SGarrett D'Amore 	    (putl_category(msgs.noexpr, f) == EOF) ||
100*6b5e5868SGarrett D'Amore 	    (putl_category(msgs.yesstr, f) == EOF) ||
101*6b5e5868SGarrett D'Amore 	    (putl_category(msgs.nostr, f) == EOF)) {
102*6b5e5868SGarrett D'Amore 		return;
103*6b5e5868SGarrett D'Amore 	}
104*6b5e5868SGarrett D'Amore 	close_category(f);
105*6b5e5868SGarrett D'Amore }
106