home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv6.zip / vac22os2 / ibmcobol / samples / toolkit / rexx / api / rxmacdll / rxnlsinf.c < prev    next >
C/C++ Source or Header  |  1996-11-19  |  15KB  |  285 lines

  1. /*******************************************************************/
  2. /*                                                                 */
  3. /* Module Name:        RXNLSINF                                    */
  4. /*                                                                 */
  5. /* Description:        Provide limited NLS support for REXX.       */
  6. /*                                                                 */
  7. /* Function:           Returns country dependent information for   */
  8. /*                     use in formatting currency amounts.         */
  9. /*                                                                 */
  10. /* Entry point:        RxNLSInfo()                                 */
  11. /*                                                                 */
  12. /* Notes:                                                          */
  13. /*                                                                 */
  14. /*   The entry point obeys the calling conventions for REXX        */
  15. /*   external functions.                                           */
  16. /*                                                                 */
  17. /*******************************************************************/
  18.  
  19. /*******************************************************************/
  20. /*                                                                 */
  21. /* Include files.  We use the following:                           */
  22. /*                                                                 */
  23. /*    REXXSAA.H         REXX specific type definitions and         */
  24. /*                      function prototypes.                       */
  25. /*                                                                 */
  26. /*    OS2.H             OS/2 specific type definitions and         */
  27. /*                      function prototypes.                       */
  28. /*                                                                 */
  29. /*    stdlib.h          Standard C library function prototypes.    */
  30. /*                                                                 */
  31. /*    string.h          Standard C library string function         */
  32. /*                      prototypes.                                */
  33. /*                                                                 */
  34. /*******************************************************************/
  35.  
  36. #define     INCL_DOSNLS
  37. #include    <os2.h>
  38. #define INCL_RXFUNC               /* include external function  info */
  39. #include    <rexxsaa.h>
  40. #include    <stdlib.h>
  41. #include    <string.h>
  42.  
  43. /*******************************************************************/
  44. /*                                                                 */
  45. /* Function prototype follows.                                     */
  46. /*                                                                 */
  47. /*******************************************************************/
  48. RexxFunctionHandler RxNLSInfo;
  49.  
  50. /*******************************************************************/
  51. /*                                                                 */
  52. /* Function:            RxNLSInfo()                                */
  53. /*                                                                 */
  54. /* Description:         Return country dependent information.      */
  55. /*                      Please see notes for details.              */
  56. /*                                                                 */
  57. /* Input:               Name of desired information.               */
  58. /*                                                                 */
  59. /* Output:              Desired information.  Please see notes.    */
  60. /*                      Returns 0 if the function executed OK,     */
  61. /*                      -1 otherwise.  The interpreter will        */
  62. /*                      raise an error condition if this function  */
  63. /*                      returns a non-zero result.                 */
  64. /*                                                                 */
  65. /* Effects:             None.                                      */
  66. /*                                                                 */
  67. /* External References: DosQueryCtryInfo()                         */
  68. /*                                                                 */
  69. /* Internal References: none                                       */
  70. /*                                                                 */
  71. /* Notes:                                                          */
  72. /*                                                                 */
  73. /*   This routine takes one parameter.  The form of the call is:   */
  74. /*                                                                 */
  75. /*   NLS_Information = RxNLSInfo( request )                        */
  76. /*                                                                 */
  77. /*   The value of the request parameter determines the information */
  78. /*   returned.  Valid values are:                                  */
  79. /*                                                                 */
  80. /*   request            value returned                             */
  81. /*   -------            --------------                             */
  82. /*                                                                 */
  83. /*   prefix             Currency prefix string.  It is followed by */
  84. /*                      a space if a space should separate the     */
  85. /*                      currency symbol from the value.            */
  86. /*                      If the currency string follows the amount, */
  87. /*                      this request returns an empty string.      */
  88. /*                                                                 */
  89. /*   suffix             Currency suffix string.  If the currency   */
  90. /*                      string preceeds the amount, this request   */
  91. /*                      returns an empty string.                   */
  92. /*                                                                 */
  93. /*   infix              Currency infix string.  This is the        */
  94. /*                      decimal point unless the currency string   */
  95. /*                      goes between the integer and fractional    */
  96. /*                      part of the amount.  In this case, it      */
  97. /*                      is the currency string.                    */
  98. /*                                                                 */
  99. /*   thousand           Thousands separator.                       */
  100. /*                                                                 */
  101. /*   decimal            Decimal separator.                         */
  102. /*                                                                 */
  103. /*   The routine ignores the case of the request parameter.  If    */
  104. /*   the parameter is invalid or the argument count is not one,    */
  105. /*   the function returns an empty string.                         */
  106. /*                                                                 */
  107. /* Error handling:  If this function is called with the wrong      */
  108. /*   number of arguments, or an argument that is not on the        */
  109. /*   list above, then we return with a value of -1, which will     */
  110. /*   raise REXX error 40, "Invalid call to routine", in the        */
  111. /*   REXX program.                                                 */
  112. /*   This function also raises that error if the call to           */
  113. /*   DosQueryCtryInfo produces any non-zero return code.           */
  114. /*                                                                 */
  115. /*******************************************************************/
  116.  
  117. ULONG APIENTRY RxNLSInfo(
  118.    PUCHAR    func,
  119.    ULONG     argc,
  120.    PRXSTRING argv,
  121.    PSZ       que,
  122.    PRXSTRING ret)
  123. {
  124.    COUNTRYINFO     country_data ;      /* Structure to receive      */
  125.                                        /* country-dependent data.   */
  126.    static
  127.       COUNTRYCODE  country_code =      /* Country and code page     */
  128.                    {                   /* desired.                  */
  129.                       0,               /* Default country code.     */
  130.                       0                /* Default code page.        */
  131.                     } ;
  132.  
  133.    PSZ              infix ;            /* Currency infix pointer.   */
  134.  
  135.    ULONG            bytes_returned ;   /* Number of bytes returned  */
  136.                                        /* by DosQueryCtryInfo().    */
  137.  
  138.    LONG             rc = -1 ;          /* Function return value.    */
  139.  
  140.    /*****************************************************************/
  141.    /* If the call to DosGetCntryInfo() fails or the arguments are   */
  142.    /* invalid, we want to return an empty RXSTRING.                 */
  143.    /* So we set the return strlength to 0.                          */
  144.    /*                                                               */
  145.    /* Please note that the REXX interpreter allocates 255 bytes in  */
  146.    /* the return string.  This will suffice for us.                 */
  147.    /*****************************************************************/
  148.  
  149.    ret -> strlength = 0 ;
  150.  
  151.    /*****************************************************************/
  152.    /* If the argument count is valid (i.e.  1) and the argument is  */
  153.    /* not too long, try to get the country dependent information.   */
  154.    /* If the call succeeds, return the information that the caller  */
  155.    /* wants.                                                        */
  156.    /*****************************************************************/
  157.  
  158.    if( ( argc == 1 ) &&                /* Arg count valid?          */
  159.        ( ! DosQueryCtryInfo(           /* Have country info?        */
  160.                 sizeof( country_data ),
  161.                 & country_code,
  162.                 & country_data,
  163.                 & bytes_returned ) ) )
  164.    {
  165.  
  166.       /**************************************************************/
  167.       /* We have the country dependent data in the data structure.  */
  168.       /* Extract the data the caller requested and return it in the */
  169.       /* return buffer.                                             */
  170.       /**************************************************************/
  171.  
  172.       if( ! stricmp( argv->strptr, "PREFIX" ) )
  173.       {
  174.          rc = 0 ;                      /* Function call is OK.     */
  175.  
  176.          /**********************************************************/
  177.          /* Caller has requested currency prefix.  If the currency */
  178.          /* string preceeds the amount, return it.  If a space     */
  179.          /* should follow the currency string, insert a space      */
  180.          /* after the currency string.                             */
  181.          /**********************************************************/
  182.  
  183.          if( ! ( country_data . fsCurrencyFmt & 5 ) )
  184.          {
  185.             ( void ) strcpy( ret -> strptr,
  186.                              country_data . szCurrency ) ;
  187.  
  188.             ret -> strlength =
  189.                         strlen( country_data . szCurrency ) ;
  190.  
  191.             /********************************************************/
  192.             /* If a space should follow the currency string,        */
  193.             /* append one.                                          */
  194.             /********************************************************/
  195.  
  196.             if( ( country_data . fsCurrencyFmt & 1 ) )
  197.             {
  198.                ( void ) strcat( ret -> strptr,
  199.                                 " " ) ;
  200.                ++ ( ret -> strlength ) ;
  201.             }                          /* If a space follows ...    */
  202.          }                             /* If symbol preceeds ...    */
  203.       }                                /* If caller wants prefix ...*/
  204.       else if( ! stricmp( argv->strptr, "SUFFIX" ) )
  205.       {
  206.          rc = 0 ;                      /* Function call is OK.      */
  207.  
  208.          /***********************************************************/
  209.          /* Caller has requested the currency suffix.  If the       */
  210.          /* currency string follows the amount, return the string.  */
  211.          /* Otherwise, leave the returned string empty.             */
  212.          /***********************************************************/
  213.  
  214.          if( ( country_data . fsCurrencyFmt & 5 ) == 1 )
  215.          {
  216.             if( ( country_data . fsCurrencyFmt & 1 ) == 1 )
  217.             {
  218.                ( void ) strcpy( ret -> strptr, " " ) ;
  219.                ret -> strlength = 1 ;
  220.             }
  221.  
  222.             ( void ) strcat( ret -> strptr,
  223.                              country_data . szCurrency ) ;
  224.  
  225.             ret -> strlength +=
  226.                         strlen( country_data . szCurrency ) ;
  227.          }                             /* If string follows amount. */
  228.       }                                /* If Caller wants prefix ...*/
  229.       else if( ! stricmp( argv->strptr, "INFIX" ) )
  230.       {
  231.          rc = 0 ;                      /* Function call is OK ...   */
  232.  
  233.          /***********************************************************/
  234.          /* Caller has requested the currency infix.  If the        */
  235.          /* currency symbol separates the integral and fractional   */
  236.          /* portions of the amount, return the currency string.     */
  237.          /* Otherwise, return the decimal separator.                */
  238.          /***********************************************************/
  239.  
  240.          infix = (                     /* Select the string to      */
  241.             country_data .             /* return...                 */
  242.                fsCurrencyFmt & 4 ) ?
  243.                   country_data . szCurrency :
  244.                   country_data . szDecimal ;
  245.  
  246.             ( void ) strcpy( ret -> strptr,
  247.                              infix ) ;
  248.  
  249.             ret -> strlength =
  250.                         strlen( infix ) ;
  251.  
  252.       }                                /* If caller wants infix ... */
  253.       else if( ! stricmp( argv->strptr, "THOUSAND" ) )
  254.       {
  255.          rc = 0 ;                      /* Function call is OK.      */
  256.  
  257.          /***********************************************************/
  258.          /* Caller has requested thousands separator.  Return same. */
  259.          /***********************************************************/
  260.  
  261.          ( void ) strcpy( ret -> strptr,
  262.                           country_data . szThousandsSeparator ) ;
  263.  
  264.             ret -> strlength =
  265.                         strlen( country_data . szThousandsSeparator ) ;
  266.       }                                /* If thousand separator ..  */
  267.       else if( ! stricmp( argv->strptr, "DECIMAL" ) )
  268.       {
  269.          rc = 0 ;                      /* Call is OK.               */
  270.  
  271.          /***********************************************************/
  272.          /* Caller has requested the decimal point.  Return same.   */
  273.          /***********************************************************/
  274.  
  275.          ( void ) strcpy( ret -> strptr,
  276.                           country_data . szDecimal ) ;
  277.  
  278.             ret -> strlength =
  279.                         strlen( country_data . szDecimal ) ;
  280.       }                                /* If caller wants decimal.  */
  281.    }                                   /* If args & call OK ...     */
  282.    return( rc ) ;
  283. }                                      /* End of function.          */
  284.  
  285.