gtpc2m8fC/C++ Language Support User's Guide

tpf_msg-Issue a Message

This function sends informational or error messages to the terminal. The message is provided as a structure containing the message number, severity code, routing information, and message text.

Format

#include <c$mesg.h>
 
void tpf_msg(const char *prefix,TPF_MSG *msg,va_list arg_ptr)

prefix
A 4-byte character string used for prefixing the output message.

msg
A pointer to the TPF_MSG structure to be used.

arg_ptr
An argument pointer list provided by the va_start function. It provides an undefined number of arguments.

Normal Return

Void.

Error Return

Not applicable.

Programming Considerations

Examples

The following example shows how the tpf_msg function is used. The message handler (which is send_message() in this example) must be in a separate function to reduce system overhead.

#include <tpfapi.h>
#include <c$mesg.h>
  .
  .
/*      POSIX Note                                                    */
/*The following defines should be done in the c$mesg.h header file.   */
/*The prefix can be a symbolic name such as OLDR or                   */
/*the program name from the caller.  A                                */
/*symbolic name is easier to handle in an automated                   */
/*environment than the program name; however, the                     */
/*program name provides fast access to the segment                    */
/*where the message originated.  A possible solution to               */
/*meet both requirements is shown in MSG_THREE.                       */
 
#define MSG_ONE    1
#define MSG_TWO    2
#define MSG_THREE  3
#define MSG_FOUR   4
#define FCT_PFX    "OLDR"

  ·
  ·
  ·
void send_message(const char *prefix,long nbr, ...) { TPF_MSG msg[] = { { 0,WTOPC_ERROR,WTOPC_EBROUT, "INVALID MESSAGE NUMBER %d PASSED TO FUNCTION" }, { MSG_ONE,WTOPC_INFO,WTOPC_EBROUT+WTOPC_RO, "INFO MSG FLOAT %f LONG %ld\n" "NEW LINE\nSTRING %s" }, { MSG_TWO,WTOPC_ERROR,WTOPC_EBROUT, "SIMPLE ERROR MESSAGE" }, { MSG_THREE,WTOPC_ERROR,WTOPC_EBROUT, "%s - ACTIVATE ERROR\n" "LOADSET %s WAS NOT AVAILABLE FOR USER %06lX" } }; va_list arg_ptr; if ((nbr<0) || (nbr>=(sizeof(msg)/sizeof(TPF_MSG)))) { send_message(prefix,0,nbr); } else { va_start(arg_ptr,nbr); tpf_msg(prefix,&msg[nbr],arg_ptr); va_end(arg_ptr); } return; } . . . long main() { send_message(FCT_PFX,MSG_ONE,1.23,999,"HELLO WORLD"); send_message(FCT_PFX,MSG_TWO); send_message(FCT_PFX,MSG_THREE,"PROG","S011200",terminal); send_message(FCT_PFX,MSG_FOUR); exit(0); } . . .

Output:

OLDR0001I 12.35.48 INFO MSG FLOAT 1.230000 LONG 999
NEW LINE
STRING HELLO WORLD
OLDR0002E 12.35.48 SIMPLE ERROR MESSAGE
OLDR0003E 12.35.48 PROG - ACTIVATE ERROR
LOADSET S011200 WAS NOT AVAILABLE FOR USER 0F120E
OLDR0000E 12.35.48 INVALID MSG NUMBER 4

Related Information