1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 2000-2009 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
19 ***********************************************************************/
26 static const char usage
[] =
27 "[-?\n@(#)$Id: msgget (AT&T Research) 2001-04-21 $\n]"
29 "[+NAME?msgget - get a message from a message catalog]"
30 "[+DESCRIPTION?\bmsgget\b gets the message corresponding to the parameters."
31 " If \alocale\a is \b-\b then the current locale is used. \acommand\a"
32 " may be specified for command specific messages. \acatalog\a specifies"
33 " the message catalog name. [\aset\a.]]\anumber\a identifies the message"
34 " by message \anumber\a and an optional message \aset\a; if specified as"
35 " \b-\b then the message set and number are determined by looking up"
36 " \atext\a in the corresponding \bC\b locale message catalog.]"
39 "\nlocale [command:]catalog [set.]number [ text ]\n"
42 "[+SEE ALSO?\biconv\b(1), \bmsgcc\b(1), \bmsggen\b(1)]"
50 main(int argc
, char** argv
)
64 error_info
.id
= "msgget";
67 switch (optget(argv
, usage
))
70 error(ERROR_USAGE
|4, "%s", opt_info
.arg
);
73 error(2, "%s", opt_info
.arg
);
78 argv
+= opt_info
.index
;
79 if (error_info
.errors
|| !(loc
= *argv
++) || !(cmd
= *argv
++) || !(s
= *argv
++))
80 error(ERROR_USAGE
|4, "%s", optusage(NiL
));
84 mcindex(s
, NiL
, &set
, &num
);
88 error(ERROR_USAGE
|4, "%s", optusage(NiL
));
91 if (cat
= strchr(cmd
, ':'))
93 if (!mcfind(path
, loc
, cmd
, LC_MESSAGES
, 0) && (!cat
|| !mcfind(path
, loc
, cat
, LC_MESSAGES
, 0)))
97 error(3, "%s: cannot locate message catalog", cmd
);
99 if (!(sp
= sfopen(NiL
, path
, "r")))
100 error(ERROR_SYSTEM
|3, "%s: cannot read message catalog", path
);
101 if (!(mc
= mcopen(sp
)))
102 error(3, "%s: invalid message catalog", path
);
104 s
= mcget(mc
, set
, num
, msg
);
106 s
= errorx(loc
, cmd
, cat
, msg
);
107 sfputr(sfstdout
, s
, '\n');
108 return error_info
.errors
!= 0;