1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 2000-2007 AT&T Knowledge Ventures * 5 * and is licensed under the * 6 * Common Public License, Version 1.0 * 7 * by AT&T Knowledge Ventures * 8 * * 9 * A copy of the License is available at * 10 * http://www.opensource.org/licenses/cpl1.0.txt * 11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12 * * 13 * Information and Software Systems Research * 14 * AT&T Research * 15 * Florham Park NJ * 16 * * 17 * Glenn Fowler <gsf@research.att.com> * 18 * * 19 ***********************************************************************/ 20 #pragma prototyped 21 /* 22 * Glenn Fowler 23 * AT&T Research 24 */ 25 26 static const char usage[] = 27 "[-?\n@(#)$Id: msgget (AT&T Research) 2001-04-21 $\n]" 28 USAGE_LICENSE 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.]" 37 38 "\n" 39 "\nlocale [command:]catalog [set.]number [ text ]\n" 40 "\n" 41 42 "[+SEE ALSO?\biconv\b(1), \bmsgcc\b(1), \bmsggen\b(1)]" 43 ; 44 45 #include <ast.h> 46 #include <error.h> 47 #include <mc.h> 48 49 int 50 main(int argc, char** argv) 51 { 52 register Mc_t* mc; 53 register char* s; 54 char* loc; 55 char* cmd; 56 char* cat; 57 char* msg; 58 int set; 59 int num; 60 Sfio_t* sp; 61 char path[PATH_MAX]; 62 63 NoP(argc); 64 error_info.id = "msgget"; 65 for (;;) 66 { 67 switch (optget(argv, usage)) 68 { 69 case '?': 70 error(ERROR_USAGE|4, "%s", opt_info.arg); 71 continue; 72 case ':': 73 error(2, "%s", opt_info.arg); 74 continue; 75 } 76 break; 77 } 78 argv += opt_info.index; 79 if (error_info.errors || !(loc = *argv++) || !(cmd = *argv++) || !(s = *argv++)) 80 error(ERROR_USAGE|4, "%s", optusage(NiL)); 81 if (streq(s, "-")) 82 set = num = 0; 83 else 84 mcindex(s, NiL, &set, &num); 85 if (!(msg = *argv++)) 86 msg = ""; 87 else if (*argv) 88 error(ERROR_USAGE|4, "%s", optusage(NiL)); 89 if (streq(loc, "-")) 90 loc = 0; 91 if (cat = strchr(cmd, ':')) 92 *cat++ = 0; 93 if (!mcfind(path, loc, cmd, LC_MESSAGES, 0) && (!cat || !mcfind(path, loc, cat, LC_MESSAGES, 0))) 94 { 95 if (cat) 96 *--cat = ':'; 97 error(3, "%s: cannot locate message catalog", cmd); 98 } 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); 103 if (set) 104 s = mcget(mc, set, num, msg); 105 else 106 s = errorx(loc, cmd, cat, msg); 107 sfputr(sfstdout, s, '\n'); 108 return error_info.errors != 0; 109 } 110