1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 2000-2010 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A/*
1N/A * Glenn Fowler
1N/A * AT&T Research
1N/A */
1N/A
1N/Astatic const char usage[] =
1N/A"[-?\n@(#)$Id: msgget (AT&T Research) 2001-04-21 $\n]"
1N/AUSAGE_LICENSE
1N/A"[+NAME?msgget - get a message from a message catalog]"
1N/A"[+DESCRIPTION?\bmsgget\b gets the message corresponding to the parameters."
1N/A" If \alocale\a is \b-\b then the current locale is used. \acommand\a"
1N/A" may be specified for command specific messages. \acatalog\a specifies"
1N/A" the message catalog name. [\aset\a.]]\anumber\a identifies the message"
1N/A" by message \anumber\a and an optional message \aset\a; if specified as"
1N/A" \b-\b then the message set and number are determined by looking up"
1N/A" \atext\a in the corresponding \bC\b locale message catalog.]"
1N/A
1N/A"\n"
1N/A"\nlocale [command:]catalog [set.]number [ text ]\n"
1N/A"\n"
1N/A
1N/A"[+SEE ALSO?\biconv\b(1), \bmsgcc\b(1), \bmsggen\b(1)]"
1N/A;
1N/A
1N/A#include <ast.h>
1N/A#include <error.h>
1N/A#include <mc.h>
1N/A
1N/Aint
1N/Amain(int argc, char** argv)
1N/A{
1N/A register Mc_t* mc;
1N/A register char* s;
1N/A char* loc;
1N/A char* cmd;
1N/A char* cat;
1N/A char* msg;
1N/A int set;
1N/A int num;
1N/A Sfio_t* sp;
1N/A char path[PATH_MAX];
1N/A
1N/A NoP(argc);
1N/A error_info.id = "msgget";
1N/A for (;;)
1N/A {
1N/A switch (optget(argv, usage))
1N/A {
1N/A case '?':
1N/A error(ERROR_USAGE|4, "%s", opt_info.arg);
1N/A continue;
1N/A case ':':
1N/A error(2, "%s", opt_info.arg);
1N/A continue;
1N/A }
1N/A break;
1N/A }
1N/A argv += opt_info.index;
1N/A if (error_info.errors || !(loc = *argv++) || !(cmd = *argv++) || !(s = *argv++))
1N/A error(ERROR_USAGE|4, "%s", optusage(NiL));
1N/A if (streq(s, "-"))
1N/A set = num = 0;
1N/A else
1N/A mcindex(s, NiL, &set, &num);
1N/A if (!(msg = *argv++))
1N/A msg = "";
1N/A else if (*argv)
1N/A error(ERROR_USAGE|4, "%s", optusage(NiL));
1N/A if (streq(loc, "-"))
1N/A loc = 0;
1N/A if (cat = strchr(cmd, ':'))
1N/A *cat++ = 0;
1N/A if (!mcfind(loc, cmd, LC_MESSAGES, 0, path, sizeof(path)) && (!cat || !mcfind(loc, cat, LC_MESSAGES, 0, path, sizeof(path))))
1N/A {
1N/A if (cat)
1N/A *--cat = ':';
1N/A error(3, "%s: cannot locate message catalog", cmd);
1N/A }
1N/A if (!(sp = sfopen(NiL, path, "r")))
1N/A error(ERROR_SYSTEM|3, "%s: cannot read message catalog", path);
1N/A if (!(mc = mcopen(sp)))
1N/A error(3, "%s: invalid message catalog", path);
1N/A if (set)
1N/A s = mcget(mc, set, num, msg);
1N/A else
1N/A s = errorx(loc, cmd, cat, msg);
1N/A sfputr(sfstdout, s, '\n');
1N/A return error_info.errors != 0;
1N/A}