home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / i18nv102.zip / SAMPLE / ALIAS / ALIASTST.C next >
C/C++ Source or Header  |  1995-08-28  |  6KB  |  148 lines

  1. /*****************************************************************************/
  2. /***     Include files                                                     ***/
  3. /*****************************************************************************/
  4.  
  5. #include <stdio.h>                      /* Standard IO functions.            */
  6. #include <stdlib.h>                     /* Needed for getenv call.           */
  7. #include <wchar.h>                      /* XPG/4 library.                    */
  8.  
  9. /*****************************************************************************/
  10. /***     Global defines                                                    ***/
  11. /*****************************************************************************/
  12.  
  13. #define TEST_ALIAS "my_french_alias"    /* Locale alias to use.              */
  14.  
  15. /*****************************************************************************/
  16. /***     Global variables                                                  ***/
  17. /*****************************************************************************/
  18.  
  19. char ret_string[LOCALE_STR_LEN];        /* Return string from find_locale API*/
  20. int ret_val;                            /* Return value from APIs.           */
  21.  
  22. /*****************************************************************************/
  23. /***     Main program                                                      ***/
  24. /*****************************************************************************/
  25.  
  26. void main(void)
  27. {
  28.                                         /* Find the path of the alias table. */
  29.                                         /* Print results of get call.        */
  30.   ret_val = get_alias_table_path(ret_string);
  31.   if   (ret_val == ALIAS_OK)
  32.   {
  33.        printf("\nPath of alias table is: %s\n", ret_string);
  34.   }
  35.   else
  36.   {
  37.        printf("\nCould not locate the alias table!\n");
  38.   }
  39.  
  40.                                         /* Make sure that test alias is not  */
  41.                                         /*  in the alias table.              */
  42.                                         /* Print results of remove call.     */
  43.   ret_val = remove_locale_alias(TEST_ALIAS);
  44.   if   (ret_val == ALIAS_OK)
  45.   {
  46.        printf("Removed the test alias.\n");
  47.   }
  48.   else
  49.   {
  50.        printf("Test alias was not removed.\n");
  51.   }
  52.  
  53.                                         /* Try to find test alias in table.  */
  54.                                         /* If found, print value found.      */
  55.                                         /* Else, report that it wasn't found.*/
  56.   ret_val = find_locale_alias(TEST_ALIAS, ret_string);
  57.   if   (ret_val == ALIAS_OK)
  58.   {
  59.        printf("Located the test alias.  Value of alias is: %s\n", ret_string);
  60.   }
  61.   else
  62.   {
  63.        printf("Test alias was not found in the table.\n");
  64.   }
  65.  
  66.                                         /* Add a test alias in the table.    */
  67.                                         /* Print status of add API.          */
  68.   ret_val = add_locale_alias(TEST_ALIAS, "fr_fr.437");
  69.   if   (ret_val == ALIAS_OK)
  70.   {
  71.        printf("Test alias added to the table.\n");
  72.   }
  73.   else
  74.   {
  75.        printf("Test alias could not be added to the table.\n");
  76.   }
  77.  
  78.                                         /* Try to find test alias in table.  */
  79.                                         /* If found, print value found.      */
  80.                                         /* Else, report that it wasn't found.*/
  81.   ret_val = find_locale_alias(TEST_ALIAS, ret_string);
  82.   if   (ret_val == ALIAS_OK)
  83.   {
  84.        printf("Located the test alias.  Value of alias is: %s\n", ret_string);
  85.   }
  86.   else
  87.   {
  88.        printf("Test alias was not found in the table.\n");
  89.   }
  90.  
  91.                                         /* Map a common locale name.         */
  92.                                         /* Report the results.               */
  93.   map_string_to_locale("en_us", ret_string);
  94.   printf("Mapped: en_us to: %s\n", ret_string);
  95.  
  96.                                         /* Map a locale name with optional   */
  97.                                         /*  codepage number following.       */
  98.                                         /* Report the results.               */
  99.   map_string_to_locale("ja_jp.932", ret_string);
  100.   printf("Mapped: ja_jp.932 to: %s\n", ret_string);
  101.  
  102.                                         /* Try to remap a string that should */
  103.                                         /*  not be legal.                    */
  104.                                         /* Report the results.               */
  105.   ret_val = map_string_to_locale("1234ABC", ret_string);
  106.   if   (ret_val == ALIAS_OK)
  107.   {
  108.        printf("Mapping of 1234ABC worked, when it should not have!\n");
  109.   }
  110.   else
  111.   {
  112.        printf("Could not remap the locale string 1234ABC\n");
  113.   }
  114.  
  115.                                         /* If the LANG environment variable  */
  116.                                         /*  is not defined...                */
  117.                                         /*  Report this.                     */
  118.                                         /* Else, remap it, and report it.    */
  119.   if   (getenv("LANG") == NULL)
  120.   {
  121.        printf("LANG environment variable not defined.  Cannot map it.\n");
  122.   }
  123.   else
  124.   {
  125.        ret_val = map_string_to_locale(getenv("LANG"), ret_string);
  126.        if   (ret_val == ALIAS_OK)
  127.        {
  128.             printf("LANG environment variable remapped to: %s\n",
  129.                    ret_string);
  130.        }
  131.        else
  132.        {
  133.             printf("LANG environment variable could not be remapped.\n");
  134.        }
  135.   }
  136.  
  137.                                         /* Use the mapping API to look the   */
  138.                                         /*  string up in the alias table, and*/
  139.                                         /*  then to remap it.                */
  140.                                         /* Report the results.               */
  141.   map_string_to_locale(TEST_ALIAS, ret_string);
  142.   printf("Used mapping to look up in alias table.  ");
  143.   printf("Mapped: %s to: %s\n", TEST_ALIAS, ret_string);
  144.  
  145.                                         /* Make sure that test alias is gone.*/
  146.   remove_locale_alias(TEST_ALIAS);
  147. }
  148.