Example of retrieving a message from a catalog

This example has three parts: the message source file, the command used to generate the message catalog file, and an example program using the message catalog.

  1. The following example shows the example.msg message source file:
    $quote "
    $ every message catalog should have a beginning set number.
    $set MS_SET1
    MSG1 "Hello world\n"
    MSG2 "Good Morning\n"
    ERRMSG1 "example: 1000.220 Read permission is denied for the file
    %s.\n"
    $set MS_SET2
    MSG3 "Howdy\n"
  2. The following command uses the example.msg message source file to generate the example.h header file and the example.cat catalog file in the current directory:
    runcat example example.msg
  3. The following example program uses the example.h header file and accesses the example.cat catalog file:
    #include <locale.h>
    #include <nl_types.h>
    #include "example_msg.h" /*contains definitions for symbolic
                               identifiers*/
    main()
    {
            nl_catd catd;
            int error;
    
            (void)setlocale(LC_ALL, "");
    
            catd = catopen(MF_EXAMPLE, NL_CAT_LOCALE);
            /*
            ** Get the message number 1 from the first set.
            */
            printf( catgets(catd,MS_SET1,MSG1,"Hello world\n") );
    
            /*
            ** Get the message number 1 from the second set.
            */
            printf( catgets(catd, MS_SET2, MSG3,"Howdy\n") );
            /*
            ** Display an error message.
            */
            printf( catgets(catd, MS_SET1, ERRMSG1,"example: 100.220
                    Permission is denied to read the file %s.\n") ,
                    filename);
            catclose(catd);
    }