home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / i18nv104.zip / SAMPLE / CAT / MYCAT.C < prev    next >
C/C++ Source or Header  |  1996-02-13  |  5KB  |  87 lines

  1. /*****************************************************************************/
  2. /***     Global defines.                                                   ***/
  3. /*****************************************************************************/
  4.  
  5. #define BELL 7                          /* Character to print a bell.        */
  6.  
  7. #define EXIT_ERROR  1                   /* The program exited with an error. */
  8.  
  9. /*****************************************************************************/
  10. /***     Include files.                                                    ***/
  11. /*****************************************************************************/
  12.  
  13. #include <stdio.h>                      /* Standard IO.                      */
  14.  
  15. #include <wchar.h>                      /* Wide char functions.              */
  16. #include <locale.h>                     /* Locale-specific information.      */
  17.  
  18. #include "test_msg.h"                   /* Header file for catalog IDs.      */
  19.  
  20. /*****************************************************************************/
  21. /***     Global variables.                                                 ***/
  22. /*****************************************************************************/
  23.  
  24. nl_catd cat_handle;                     /* Handle to catalog file.           */
  25. char *ret_string;                       /* String returned from catgets.     */
  26.  
  27. /*****************************************************************************/
  28. /***     Main program.                                                     ***/
  29. /*****************************************************************************/
  30.  
  31. void main(void)
  32. {
  33.                                         /* Set the locale.                   */
  34.                                         /* Print out the locale we are in for*/
  35.                                         /*  messages.                        */
  36.   setlocale(LC_ALL, "");
  37.   printf("\nName of messaging locale is: %s\n\n",
  38.          setlocale(LC_MESSAGES, NULL));
  39.  
  40.                                         /* Open the catalog.                 */
  41.                                         /*  (using LC_MESSAGES, not LANG via */
  42.                                         /*   the second argument).           */
  43.                                         /* If catalog not found...           */
  44.                                         /*  Print an error message.          */
  45.                                         /*  Exit the program.                */
  46.   cat_handle = catopen(MF_TEST, NL_CAT_LOCALE);
  47.   if (cat_handle == CATD_ERR)
  48.   {
  49.      printf("%cCould not open catalog!\n", BELL);
  50.      exit(EXIT_ERROR);
  51.   }
  52.  
  53.                                         /* Read a message from the catalog.  */
  54.                                         /* Print out the message.            */
  55.   ret_string = catgets(cat_handle, MS_SET2, MSG_1, "No message read.");
  56.   printf("String: %s\n", ret_string);
  57.  
  58.                                         /* Attempt to read a message which is*/
  59.                                         /*  not in the catalog.              */
  60.                                         /* Print out the results.            */
  61.   ret_string = catgets(cat_handle, 400, 500, "No message read.\n");
  62.   printf("String: %s\n", ret_string);
  63.  
  64.                                         /* Read a message so we can put in   */
  65.                                         /*  positional arguments.            */
  66.                                         /* Print a header.                   */
  67.                                         /* Print the string with four        */
  68.                                         /*  positional arguments.            */
  69.                                         /*  (NOTE: the order of the arguments*/
  70.                                         /*   in the printf call is NOT the   */
  71.                                         /*   order in which they are printed */
  72.                                         /*   in the output string.           */
  73.   ret_string = catgets(cat_handle, MS_SET1, MSG_1, "No message read.\n");
  74.   printf("String: ");
  75.   printf(ret_string, "myfile.sys", "3/29/94", "5:04PM", "PS");
  76.  
  77.                                         /* Close the catalog.                */
  78.   catclose(cat_handle);
  79.  
  80.                                         /* Now try to read a message from    */
  81.                                         /*  a catalog with an invalid handle.*/
  82.                                         /* This should return back the       */
  83.                                         /*  default message.                 */
  84.   ret_string = catgets(cat_handle, MS_SET1, MSG_1, "No catalog open.\n");
  85.   printf("\nString: %s\n", ret_string);
  86. }
  87.