United States-English |
|
|
HP-UX Reference > Mmkcatdefs(1)HP-UX 11i Version 3: February 2007 |
|
NAMEmkcatdefs — preprocess a message source file DESCRIPTIONThe mkcatdefs command preprocesses a message source file to do one or more of the following operations. These operations ease maintenance of compilable programs, scripts, or both:
See gencat(1) for a description of fundamental rules that govern the format of a message source file. The only difference between gencat and mkcatdefs is that with gencat you must input a number to identify each message set and message, while mkcatdefs accepts either a number or a symbolic name. Options
The mkcatdefs command sends message source data to standard output. This output is suitable as input to the gencat program. You can use the right angle bracket (>) character to write the preprocessed message source code to a file, and then use this file as input to the gencat command. Each message set and message in program source code must have a unique number or symbolic name. You can enable use of these symbolic identifiers in a program by including them in the message source file input to the mkcatdefs command. Symbolic identifiers can contain English letters, digits, and underscores; however, the first character cannot be a digit or an underscore. The mkcatdefs command converts symbolic names specified in the message source file to numeric constants. One restriction is that mkcatdefs does not convert symbolic names included in a $delset command. Therefore, if your message source file contains $delset commands to delete message sets, those commands must identify the sets to be deleted by their numeric constant identifiers. The mkcatdefs program is designed to create new message catalogs, not to change existing ones incrementally. The sets specified in source_file are assigned numbers in ascending order, starting at 1. Within each set, messages are also assigned numbers in ascending order, starting at 1. If you explicitly assign a message to a number in your source_file, mkcatdefs continues its ascending series with that number. RestrictionsSymbolic identifiers for message sets, messages, and default message strings are an ease-of-maintenance feature for program source code and shell scripts; however, symbolic references are a proprietary extension to the XSH standard and might not be supported on all systems conforming to this standard. Symbolic identifiers for message sets and messages provide ease of maintenance by reducing the need to change references in program source code when a catalog is revised. However, use of symbolic identifiers does not insulate a program from run-time problems if it uses the catgets() function to retrieve messages from a catalog, the catalog is revised, and the program is not recompiled with a new version of the catname_msg.h file. That is because the XSH standard constrains the run-time behavior of catgets() to the use of numeric identifiers, and the numeric constants mapped to the symbolic identifiers can change when a message catalog is rebuilt. The mappings of numeric constants to symbols change if the following kinds of revisions were made to the corresponding message source file (or files) and a catalog is rebuilt:
Therefore, if these kinds of changes were made to message source code and a catalog was rebuilt, programs must be recompiled with a version of catname_msg.h that was generated from the revised message source file or files. If care is taken to maintain the ordinal position of existing message sets and messages when the message source file is changed (assuming, of course, that program source code is not changed to refer to any new or deleted message sets and messages), recompilation with a revised version of catname_msg.h is not necessary. Symbolic names for message sets and messages must be unique across all message sets included in the catalog. By implication, this also means that these symbolic names must be unique across all message source files specified as input to the mkcatdefs command. See the EXAMPLES section for an illustration of techniques that provide insulation from changes in how numeric constants are mapped to symbolic identifiers for message sets and messages. EXTERNAL INFLUENCESEnvironment VariablesLANG provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, it defaults to C (see lang(5)). LC_ALL, when set to a non-empty string value, overrides the values of all other internationalization variables. LC_MESSAGES determines the language in which error messages are displayed. EXAMPLESThe following example shows a message source file that contains one message set and uses a mix of symbolic and numeric identifiers for messages: $quote " Use a double quotation mark to delimit message text $set MSFAC Message Facility - symbolic identifiers SYM_FORM "Symbolic identifiers can contain only letters \ and digits and the _ (underscore character)\n" 5 "You can mix symbolic identifiers and numbers \n" $quote MSG_H Remember to include the "_msg.h" file in your program\n In this example, the $quote command sets the quote character to " (double quote), then disables it before the last message, which contains double quotes. When you process the file with mkcatdefs, the modified source is written to standard output. Standard output can either be redirected to a file using the > redirection symbol or piped to gencat. Assume that the preceding file is named symb.src. It can be processed with mkcatdefs as follows: $ mkcatdefs symb symb.src >symb.msg The symb.msg file contains the following preprocessed message source code: $quote " Use a double quotation mark to delimit message text $ delset 1 $set 1 Message Facility - symbolic identifiers 1 "Symbolic identifiers can contain only letters \ and digits and the _ (underscore character)\n" 5 "You can mix symbolic identifiers and numbers \n" $quote 6 Remember to include the "_msg.h" file in your program\n Note that the assigned message numbers are noncontiguous because the symb.src file contained the specific message number 5. The mkcatdefs program always assigns the previous number plus 1 to the next symbolic identifier. The generated symb_msg.h file contains the following: #ifndef _H_SYMB_MSG #define _H_SYMB_MSG #include <limits.h> #include <nl_types.h> #define MF_SYMB "symb" /* The following was generated from symb.src. */ /* definitions for set MSFAC */ #define MSFAC 1 #define SYM_FORM 1 #define MSG_H 6 #endif Note that mkcatdefs also created the symbol MF_SYMB by prepending MF_ to catname using uppercase letters. The mkcatdefs command assumes that the name of the generated catalog should be catname.cat, and generates this symbol for your use with the catopen function. Because this include file contains include statements for limits.h and nl_types.h, you do not need to explicitly include these files in your application program. (The nl_types.h header file defines special data types required by the message facility routines.) The following set of examples shows how to enable and use symbolic identifiers for sets, messages, and default message strings. The message source file PFF.src used for this set of examples contains the following lines: $quote " $set INFO GREET "Welcome to the Fact Finder program!\n" BYE "Good-bye. Please come again.\n" ENTER "Please enter the type of product \ you are interested in: " $set RESULTS NADA "Sorry, we have no information on that \ kind of product.\n" FOUND "The following products were found: " $set PROBLEMS SERVCONN "Cannot connect to server. Try again later.\n" BUSYDAY "Still searching. Please wait...\n" The following command creates a message catalog that includes a .sh file that can be executed in a POSIX, Bourne, or Korn shell script to define symbolic identifiers for default message strings: % mkcatdefs -h -m -e sh PFF PFF.src | gencat PFF.cat - mkcatdefs: PFF_msg.h is created. mkcatdefs: PFF_msg.sh is created. The following command creates an include file for use in program source code, as well as a copy of the preprocessed source code that was input directly to the gencat command in the preceding example: % mkcatdefs -m -e h PFF PFF.src > PFF.msg mkcatdefs: PFF_msg.h is created The following cat and dspcat commands show what is included in the .sh, .h, and message catalog files created from these commands: % cat PFF_msg.sh # # Default messages generated from PFF.src # DEF_GREET='Welcome to the Product Fact Finder program!\n' DEF_BYE='Good-bye. Please come again.\n' DEF_ENTER='Please enter the type of product you are interested in: ' DEF_NADA='Sorry, we have no information on that kind of product.\n' DEF_FOUND='The following products were found: ' DEF_SERVCONN='Cannot connect to server. Try again later.\n' DEF_BUSYDAY='Still searching. Please wait...\n' % cat PFF_msg.h #ifndef _H_PFF_MSG #define _H_PFF_MSG #include <limits.h> #include <nl_types.h> #define MF_PFF "PFF" /* The following was generated from PFF.src. */ /* definitions for set INFO */ #define INFO 1 #define GREET 1 #define BYE 2 #define ENTER 3 /* definitions for set RESULTS */ #define RESULTS 2 #define NADA 1 #define FOUND 2 /* definitions for set PROBLEMS */ #define PROBLEMS 3 #define SERVCONN 1 #define BUSYDAY 2 #endif /* Default messages generated from PFF.src */ #define DEF_GREET "Welcome to the Product Fact Finder program!\n" #define DEF_BYE "Good-bye. Please come again.\n" #define DEF_ENTER "Please enter the type of product \ you are interested in: " #define DEF_NADA "Sorry, we have no information on that \ kind of product.\n" #define DEF_FOUND "The following products were found: " #define DEF_SERVCONN "Cannot connect to server. Try again later.\n" #define DEF_BUSYDAY "Still searching. Please wait...\n" #endif % dspcat PFF.cat 1 : 1 Welcome to the Product Fact Finder program! 1 : 2 Good-bye. Please come again. 1 : 3 Please enter the type of product you are interested in: 2 : 1 Sorry, we have no information on that kind of product. 2 : 2 The following products were found: 3 : 1 Cannot connect to server. Try again later. 3 : 2 Still searching. Please wait... In this catalog, there are three message sets defined from those specified in the message source file. When displaying messages from this catalog, the dspmsg command uses numbers as set and message identifiers. For example: % dspmsg -s 1 PFF.cat 1 Welcome to the Product Fact Finder program! The following script illustrates the use of symbols for default message strings. By default, dspmsg searches for message catalogs first in the appropriate locale directory subordinate to /usr/lib/nls/msg and then in the current directory: #! /bin/sh # # test_dspmsg.sh . . . . ./PFF_msg.sh . . . dspmsg -s 1 PFF.cat 1 "${DEF_GREET}" . . . The dspmsg command in this script displays the message string: % ./test_dspmsg.sh Welcome to the Product Fact Finder program! A default message string is typically English text, whereas a translated message is displayed if a translated version of the catalog is available for the locale. The advantage of using symbols for default message strings is to ensure that only one copy of the original message strings needs to be maintained. When message strings must be maintained both in message source files, in calls to catgets(), and in dspmsg commands, inconsistencies are likely to develop between different instances of what is intended to be the same string. A message can be displayed as the message string alone or as the message string preceded by its message identifier. See dspmsg(1) for examples of using the dspmsg command to display message strings preceded by their identifiers. |
Printable version | ||
|