xref: /onnv-gate/usr/src/cmd/ast/msgcc/msgget.c (revision 10898:1883b621b3ea)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*10898Sroland.mainz@nrubsig.org *          Copyright (c) 2000-2009 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                                                                      *
194887Schin ***********************************************************************/
204887Schin #pragma prototyped
214887Schin /*
224887Schin  * Glenn Fowler
234887Schin  * AT&T Research
244887Schin  */
254887Schin 
264887Schin static const char usage[] =
274887Schin "[-?\n@(#)$Id: msgget (AT&T Research) 2001-04-21 $\n]"
284887Schin USAGE_LICENSE
294887Schin "[+NAME?msgget - get a message from a message catalog]"
304887Schin "[+DESCRIPTION?\bmsgget\b gets the message corresponding to the parameters."
314887Schin "	If \alocale\a is \b-\b then the current locale is used. \acommand\a"
324887Schin "	may be specified for command specific messages. \acatalog\a specifies"
334887Schin "	the message catalog name. [\aset\a.]]\anumber\a identifies the message"
344887Schin "	by message \anumber\a and an optional message \aset\a; if specified as"
354887Schin "	\b-\b then the message set and number are determined by looking up"
364887Schin "	\atext\a in the corresponding \bC\b locale message catalog.]"
374887Schin 
384887Schin "\n"
394887Schin "\nlocale [command:]catalog [set.]number [ text ]\n"
404887Schin "\n"
414887Schin 
424887Schin "[+SEE ALSO?\biconv\b(1), \bmsgcc\b(1), \bmsggen\b(1)]"
434887Schin ;
444887Schin 
454887Schin #include <ast.h>
464887Schin #include <error.h>
474887Schin #include <mc.h>
484887Schin 
494887Schin int
main(int argc,char ** argv)504887Schin main(int argc, char** argv)
514887Schin {
524887Schin 	register Mc_t*	mc;
534887Schin 	register char*	s;
544887Schin 	char*		loc;
554887Schin 	char*		cmd;
564887Schin 	char*		cat;
574887Schin 	char*		msg;
584887Schin 	int		set;
594887Schin 	int		num;
604887Schin 	Sfio_t*		sp;
614887Schin 	char		path[PATH_MAX];
624887Schin 
634887Schin 	NoP(argc);
644887Schin 	error_info.id = "msgget";
654887Schin 	for (;;)
664887Schin 	{
674887Schin 		switch (optget(argv, usage))
684887Schin 		{
694887Schin 		case '?':
704887Schin 			error(ERROR_USAGE|4, "%s", opt_info.arg);
714887Schin 			continue;
724887Schin 		case ':':
734887Schin 			error(2, "%s", opt_info.arg);
744887Schin 			continue;
754887Schin 		}
764887Schin 		break;
774887Schin 	}
784887Schin 	argv += opt_info.index;
794887Schin 	if (error_info.errors || !(loc = *argv++) || !(cmd = *argv++) || !(s = *argv++))
804887Schin 		error(ERROR_USAGE|4, "%s", optusage(NiL));
814887Schin 	if (streq(s, "-"))
824887Schin 		set = num = 0;
834887Schin 	else
844887Schin 		mcindex(s, NiL, &set, &num);
854887Schin 	if (!(msg = *argv++))
864887Schin 		msg = "";
874887Schin 	else if (*argv)
884887Schin 		error(ERROR_USAGE|4, "%s", optusage(NiL));
894887Schin 	if (streq(loc, "-"))
904887Schin 		loc = 0;
914887Schin 	if (cat = strchr(cmd, ':'))
924887Schin 		*cat++ = 0;
934887Schin 	if (!mcfind(path, loc, cmd, LC_MESSAGES, 0) && (!cat || !mcfind(path, loc, cat, LC_MESSAGES, 0)))
944887Schin 	{
954887Schin 		if (cat)
964887Schin 			*--cat = ':';
974887Schin 		error(3, "%s: cannot locate message catalog", cmd);
984887Schin 	}
994887Schin 	if (!(sp = sfopen(NiL, path, "r")))
1004887Schin 		error(ERROR_SYSTEM|3, "%s: cannot read message catalog", path);
1014887Schin 	if (!(mc = mcopen(sp)))
1024887Schin 		error(3, "%s: invalid message catalog", path);
1034887Schin 	if (set)
1044887Schin 		s = mcget(mc, set, num, msg);
1054887Schin 	else
1064887Schin 		s = errorx(loc, cmd, cat, msg);
1074887Schin 	sfputr(sfstdout, s, '\n');
1084887Schin 	return error_info.errors != 0;
1094887Schin }
110