gettxt -- retrieve a text string


cc ...-lc

#include <unistd.h>

char *gettxt (const char *msgid, const char *dflt_str);


gettxt(S) retrieves a text string from a message file generated by the mkmsgs(CP) utility. The arguments to the function are a message identification msgid and a default string dflt_str to be used if the retrieval fails.

For gettxt( ) to retrieve text strings from a message database, the msgid argument must have the following structure:


indicates the message database that contains the localized version of the text string. It can be up to 225 characters long. You can use any character values except null and the ASCII codes ``/'' (slash) and ``:'' (colon). The syntax for msgfilename is


If archivename is specified, then gettxt( ) accesses the message database in an archive directory. The environment variable NLSPATH specifies the pathname for the message database, substituting filename for %N and archivename for %A. (See the explanation of NLSPATH, below.)

must be a positive number that indicates the index of the string in the message database.
If msgfilename does not exist in the locale (specified by the last call to setlocale(S) using the categories LC_ALL or LC_MESSAGES), or if the message number is out of bounds, gettxt( ) tries to retrieve the message from the C locale. If this second retrieval fails, gettxt( ) uses dflt_str.

If msgfilename is omitted, gettxt( ) tries to retrieve the string from the default catalog specified by the last call to setcat(S).

If NLSPATH does not exist in the environment, or if a message catalog can not be opened in any of the paths specified by NLSPATH, then the following default paths are used:







is the value of the LC_MESSAGES category

is the language component from the LC_MESSAGES category

is the territory component from the LC_MESSAGES category

is the optional archive component of the message catalog name

is the file component of the message catalog name
If the optional archive component is not in the message catalog name, %A is omitted from the NLSPATH definition.

%L can be viewed as the language in which the text strings are written. It is specified by the LC_MESSAGES category of setlocale( ), which is C by default.

You can change the language of the messages by invoking setlocale( ) with appropriate arguments.

You can also specify a language by setting environment variables (but only if the calling program calls setlocale(LC_MESSAGES,"") or setlocale(LC_ALL,""). The first of the following environment variables with a nonempty value is used: LC_ALL, LC_MESSAGES, and LANG.

If the locale is explicitly changed (via setlocale( )), the pointers returned by gettxt( ) may no longer be valid.


gettxt( ) overwrites the string buffer each time it is called. To preserve the data, applications must copy it.

Return values

gettxt( ) returns a pointer to the text string it retrieved.


If gettxt( ) outputs

Message not found!!

it indicates that gettxt( ) cannot retrieve the text string because of one of the following conditions:


In the following code fragment, test is the name of the file that contains the messages and 10 is the message number.
   gettxt("test:10", "hello world");
   gettxt("test:10", "");
   gettxt(":10", "hello world");

See also

catgets(S), environ(M), mkmsgs(CP), pfmt(S), setcat(S), setlocale(S)

Standards conformance

gettxt(S) is not part of any currently supported standard; it was developed by UNIX System Laboratories, Inc. and is maintained by The SCO Group.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003