This page was last edited on July 03, 1996
This document describes the cognos message compiler (cogmc). Cogmc is a utility designed to help developers create message files for use with the services messaging APIs such as the message set objects. With this utility users can compile a message file, decompile a message file and generate symbolic message identifiers from a services message file.
It should be noted that cogmc uses the NLS subsystem of services for a number of locale related operations, and as a consequence users should ensure that the appropriate environment variables are set and that a valid coglangtab file is available for the proper operation of the NLS subsystem.
This version of the cognos message compiler is available in the R95a and later versions of services.
|
Win 32 |
Win16 |
UNIX |
Hpxl |
VMS |
Executable | cogmc.exe | na | cogmc | na | na |
The compile mode of cogmc is used to create a compiled message file from one or more source files written in an appropriate syntax. Compiling a message requires that at a minimum the -input, -output and -character_set command options be specified. The character set specification is used to identify the character set used in the input source files, so that cogmc can properly translate the message information to the Unicode character set used in the message files. The specified character set corresponds to a charmap entry in the coglangtab file or one of the predefined character sets ASCII or UNICODE.
The compiled message file is a binary file with all data stored in big-endian format for portability, so that for example, a message file compiled on Windows NT can be manipulated by the message compiler (or messaging API's) compiled on UNIX systems.
Message Construction
The message compiler will construct messages to have one of the two following forms depending upon the prefix specifier used to define the severity class in which the message is found. If the prefix specifier is used:
message text = "<COMPONENT NAME>-<SEVERITY TEXT>-<MESSAGE NAME>, Message text"
Where:
A typical use for messages generated by the message compiler is to act as format strings for language-independent messaging systems. To support this usage, the message compiler provides a simple mechanism for specifying substitutions within a message. The mechanism consists of a single substitution character which must be followed by a single digit (0-9). The specific character used to indicate a substitution sequence is user-definable via the use of the parameter statement of the message source language to make the substitution sequence language and character set independent. Regardless of the character specified in the source file, cogmc will insert a Unicode 0x0001 character in its place in the compiled message file. Thus, API's using cogmc generated message files should look for this character to determine the location in the string where substitutions should be made.
Message and Component Identifiers
Each message and component specified in the message source receive a unique numeric identifier to allow the retrieval of the text of a message without regard to the internal format of the message file. The use of unique message identifiers makes it possible to substitute alternate message files (and thus message text) without having to recompile an application. All identifiers are generated using a hashing function on the Unicode equivalent of the text of the symbolic name of a component or message using the cogStringHash() function of the string objects API. The use of identifiers based on names helps make the message system insensitive to the addition/deletion of messages, since the value of any identifier is independent of every other identifier. The message identifiers used by cogmc are 32-bit integer values constructed in the following manner:
A compiled message file contains extra information in addition to the messages specified in the source files. This information falls into three general categories: version, language and file integrity information. This information can be accessed in the form of strings by extracting one or more reserved messages from the messaging API. Each of these messages is an unadorned string containing only the text of the indicated information. Thus extracting the message MSG_INTERNAL_CRC will return a string of the form "0x1E4A". If the requested information is undefined the message defaults to an empty string, not a NULL pointer. The complete list of internal messages is given in the following table.
Message ID |
Meaning |
MSG_INTERNAL_FILE_LENGTH | The file length information read from the message file header. |
MSG_INTERNAL_CRC | The cyclic-redundancy-code information read from the message file header (hex). |
MSG_INTERNAL_LANGUAGE | Language string specified with the -language option of cogmc. |
MSG_INTERNAL_SERVICES_MAJOR | Services major version id specified with the -services_version option of cogmc. |
MSG_INTERNAL_SERVICES_MINOR | Services minor version id specified with the -services_version option of cogmc |
MSG_INTERNAL_SERVICES_BUILD | Services build id specified with the -services_version option of cogmc. |
MSG_INTERNAL_SERVICES_TEXT | Services descriptor string specified with the -services option of cogmc. |
MSG_INTERNAL_PRODUCT_MAJOR | Product major version id specified with the -services_version option of cogmc. |
MSG_INTERNAL_PRODUCT_MINOR | Product minor version id specified with the -services_version option of cogmc. |
MSG_INTERNAL_PRODUCT_BUILD | Product build id specified with the -services_version option of cogmc. |
MSG_INTERNAL_PRODUCT_TEXT | Product descriptor string specified with the -services option of cogmc. |
MSG_INTERNAL_MESSAGE_COUNT | Number of messages in the message file. |
MSG_INTERNAL_FILE_NAME | Name of the message file (fully qualified path name). |
Examples
The ASCII message source text in example.str can be compiled to the message file example.msg with the following command line:
The header mode of cogmc is used to generate C/C++ compatible symbolic identifiers for each of the messages defined in a message file. In order to generate a header file the -input, -output and -character_set command options must also be specified on the cogmc command line.
The symbolic names are derived from the component and message name information of the message source compiled by cogmc. The general form of a symbolic name is the following:
message symbolic name = <COMPONENT PREFIX>-'MSG'-<MESSAGE NAME>
Where:
In addition, symbols for each component are also defined as follows:
component symbolic name = <COMPONENT NAME>
Where:
<COMPONENT NAME> is the name of the component defined with the component statement.
Example
An C/C++ header file can be extracted from the example message file with the following command:
cogmc -header -input example.msg -output example.h -character_set ASCII
Where message.h will contain the following text:
The decompile mode of cogmc is provided to allow developers to generate user-editable source from an existing compiled message file. To use this mode, the user must specify at a minimum, the -input, -output and character_set options. The generated source code can be recompiled to recreate the initial or modified message file if so desired. This facility is useful if messages need to be modified, added to or removed from an existing message file when the original message source is not available.
Example
Two existing message files exampleA.msg and exampleB.msg can be merged with the following sequence of commands:
cogmc -decompile -input exampleA.msg -output exampleA.str -character_set ASCII
cogmc -decompile -input exampleB.msg -output exampleB.str -character_set ASCII
Now add the following line to exampleA.str:
Now create the merged message file by recompiling exampleA.str.
cogmc -compile -input exampleA.str -output mergeAB.msg -character_set ASCII
The extract mode is provided to aid in the translation of the message compiler language and message to other locales, character sets and languages. The default strings used in the message compiler are 7-bit ASCII encoded English, all of which can be dumped into a compilable source file via the -extract mode of cogmc. Translators can then use this source file as a basis for generating an alternate language/locale version of cogmc by translating the content of the extracted source file to the target language.
Users can then force the message compiler to bypass its default string information and use a message file by one of the following:
Example
A Unicode text file containing the message source equivalent to the default messages of cogmc can be created with the following command:
cogmc -extract -output cogmc.str -character_set UNICODE
The -about mode of the message compiler is used to extract version, file integrity and statistical information about the specified message file. The information retreived is simply the results of extracting the special informational messages from the specified message file. The main uses of this command is to gather information about a message file for installation purposes and to provide a way of verifying that the specified is or is not a valid message file. For example:
cogmc -about -input possiblyvalid.msg
The following is the EBNF specification of the syntax of the message source text accepted by cogmc.
Notes:
The component statement is used to signify that subsequent message definitions are to be associated with the indicated component. This association will continue until another component statement is reached. The component statement consists of the component keyword followed by a single token indicating the name of the component. For example:
component MSG_COMPILER
The name statement is used to associate a short form name with the current component. This name will be used in the message prefix generated by cogmc when compiling a message file. Only one name statement is allowed per component. The name statement consists of the name keyword followed by a single token indicating the short form name of the current component. For example:
name MC
The prefix statement is used to indicate the component prefix used to create symbolic identifiers for messages by cogmc when generating header files. Only one prefix statement is allowed per component. The prefix statement consists of the prefix keyword followed by a single token indicating the prefix code for the current component. For example:
prefix MC
The category statement is used to indicate the severity category to associate with subsequent message definitions. This association will continue until another category or severity statement is reached. Any number of category statements are allowed per component/file. The category statement consists of the category keyword followed by a single token indicating the name of a severity level. Severity levels can referenced before their definition via the severity command. For example:
category error
The include statement is used to specify a source file to be inserted into the input stream at the point where the include statement occurs. This facility allows developers to group messages into separate files as necessary. Any number of include statements may occur in a file and they can be nested as deeply as the memory constraints of the host system will allow.
The surest way to force cogmc to run out of memory is to have an include file recursively include itself! So don't do that.
The include statement consists of the include keyword followed by a single token indicating the name of the file to include. Cogmc will search for the include file in the working directory and then in the directories specified with -include options on the cogmc command line. The message compiler assembles the file specification by appending the indicated filename with each include specification in order to generate a complete file/path specification. For portability, it is best not to include directory information in the filename specified in the include statement, rather use the base file name in the source file and select the directory using the -include command line options.
For example, while both of the following examples of the include statement are valid under MS-DOS, the later is also portable to UNIX:
- include ..\msgs\english.str
- and compile with
- cogmc -compile ...
and
- include english.str
- and compile with
- cogmc -compile -include ../msgs/ ...
The parameter statement is used to specify which character is to be to indicate where substitutions are to be applied in subsequent messages. This specification will be valid until another parameter statement is reached. Any number of parameter statements are allowed per component/file. The parameter statement consists of the parameter keyword followed by a single character indicating the substitution character. For example:
parameter %
<severity> ::= SEVERITY <identifier> <number> <severity text> { PREFIX | NOPREFIX}
The severity statement is used to define a severity category for use with subsequent category statements. It also has the side effect of setting the current message category to the newly defined severity. The severity statement consists of the severity keyword followed by the symbolic name to be assigned to the severity (i.e. error, fatal, warning), a numeric severity level (in the range 0 to 15), a severity code to used when generating message prefixes (i.e. E, F or W) and an prefix/noprefix specification which determines if a generated message prefix is to be prepended to the text of messages in the indicated severity category. Only sixteen severity categories can be defined per message file. Severity codes cannot have multiple definitions. For example:
severity error 14 E prefix
A message definition is assumed to be in progress when a token is encountered at the beginning of a statement that is not one of: component, name, prefix, category, include, parameter, comment, message, severity or /*. The syntax of a message definition is quite simple: an identifier followed by a quoted string. The identifier is interpreted as the message name while the quoted string is taken to be the text of the message being defined. Each message within a component must have a unique name (actually, a unique hash identifier, see -compile). For example:
file_error_message "Invalid file: ^1. Load operation aborted"
Comments are similar in use and syntax to standard C style comments, beginning with /* and ending with */. There is however, an added restriction not found in the C language; comments are not allowed within the body of any statement - only before or after a statement. The following examples are valid uses of comments:
- /* this is a good place for a comment */
- parameter % /* so is this !*/
- /* this is
- good too */ include yetanother.file
The following are examples of invalid comments.
- parameter /* uh-oh! */ %
- include /* this won't work */ afile.str
The following is an example of a valid message source file.
The source language used by Cogmc is sufficiently different from that used in previous message systems that some minor changes will be necessary to enable existing message source files to be used with the newer compiler. The changes fall into three categories; obsolete statements, new required statements and language enhancements.
Obsolete Statements
The previous messaging system allowed two ways of specifying comments in a source files, C style comments and OS400 style curly-braces; { and }. Since cogmc does not support the OS400 style comments, the affected comments must either be removed or the { and } keywords must be replaced with /* and */ respectively.
As the message compiler now generates unique identifiers using a hashing algorithm, the base keyword is no longer used. Simply remove all base statements from the message source files.
New Required Statements
The only new statement that is required to ensure proper compilation is the severity statement. This statement was added to the language to remove the implicit English/ASCII locale of the category statements used in previous message systems. The only remedy is to add the appropriate severity statements to your message source.
Language Enhancements
The major enhancement to the message language introduced with cogmc is the include statement. Previous message systems relied on external preprocessors (such as cpp) to merge include files for later processing by a message compiler. Any include statements in message source files will have to be modified in accordance with the new syntax.