Copyright Digital Equipment Corp. All rights reserved.

Example

#include <nl_types.h>
#include <locale.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unixio.h>

 /* This test makes use of all the message catalog routines. catopen  */
 /* opens the catalog ready for reading, then each of the three       */
 /* messages in the catalog are extracted in turn using catgets and   */
 /* printed out. catclose closes the catalog after use.               */
 /* The catalog source file used to create the catalog is as follows: */
 /* $ This is a message file
 * $
 * $quote "
 * $ another comment line
 * $set 1
 * 1 "First set, first message"
 * 2 "second message - This long message uses a backslash \
 * for continuation."
 * $set 2
 * 1 "Second set, first message"                                      */

char *default_msg = "this is the first message.";

main()
{
  nl_catd catalog;
  int msg1,
      msg2,
      retval;

  char *cat = "sys$disk:[]catgets_example.cat"; /*Force local catalog*/

  char *msgtxt;

  char string[128];

  /* Create the message test catalog */

  system("gencat catgets_example.msgx catgets_example.cat") ;

  if ((catalog = catopen(cat, 0)) == (nl_catd) - 1) {
      perror("catopen");
      exit(EXIT_FAILURE);
  }

  msgtxt = catgets(catalog, 1, 1, default_msg);
  printf("%s\n", msgtxt);

  msgtxt = catgets(catalog, 1, 2, default_msg);
  printf("%s\n", msgtxt);

  msgtxt = catgets(catalog, 2, 1, default_msg);
  printf("%s\n", msgtxt);

  if ((retval = catclose(catalog)) == -1) {
      perror("catclose");
      exit(EXIT_FAILURE);
  }

  delete("catgets_example.cat;") ;  /* Remove the test catalog */
}

     Running the example program produces the following result:

       First set, first message
       second message - This long message uses a backslash for
                                                 continuation.
       Second set, first message