home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / os2tk21j / rexx / samples / rxmacdll / rxnlsinf.c__ / rxnlsinf.c
Encoding:
C/C++ Source or Header  |  1993-03-12  |  15.3 KB  |  286 lines

  1. /*static char *SCCSID = "@(#)rxnlsinf.c    6.1 91/09/20";*/
  2.  
  3. /*******************************************************************/
  4.  
  5. /*                                                                 */
  6.  
  7. /* Module Name:        RXNLSINF                                    */
  8.  
  9. /*                                                                 */
  10.  
  11. /* Description:        Provide limited NLS support for REXX.       */
  12.  
  13. /*                                                                 */
  14.  
  15. /* Function:           Returns country dependent information for   */
  16.  
  17. /*                     use in formatting currency amounts.         */
  18.  
  19. /*                                                                 */
  20.  
  21. /* Entry point:        RxNLSInfo()                                 */
  22.  
  23. /*                                                                 */
  24.  
  25. /* Notes:                                                          */
  26.  
  27. /*                                                                 */
  28.  
  29. /*   The entry point obeys the calling conventions for REXX        */
  30.  
  31. /*   external functions.                                           */
  32.  
  33. /*                                                                 */
  34.  
  35. /*******************************************************************/
  36.  
  37.  
  38.  
  39. /*******************************************************************/
  40.  
  41. /*                                                                 */
  42.  
  43. /* Include files.  We use the following:                           */
  44.  
  45. /*                                                                 */
  46.  
  47. /*    REXXSAA.H         REXX specific type definitions and         */
  48.  
  49. /*                      function prototypes.                       */
  50.  
  51. /*                                                                 */
  52.  
  53. /*    OS2.H             OS/2 specific type definitions and         */
  54.  
  55. /*                      function prototypes.                       */
  56.  
  57. /*                                                                 */
  58.  
  59. /*    stdlib.h          Standard C library function prototypes.    */
  60.  
  61. /*                                                                 */
  62.  
  63. /*    string.h          Standard C library string function         */
  64.  
  65. /*                      prototypes.                                */
  66.  
  67. /*                                                                 */
  68.  
  69. /*******************************************************************/
  70.  
  71.  
  72.  
  73. #define     INCL_DOSNLS
  74.  
  75. #include    <os2.h>
  76.  
  77. #define INCL_RXFUNC               /* include external function  info */
  78.  
  79. #include    <rexxsaa.h>
  80.  
  81. #include    <stdlib.h>
  82.  
  83. #include    <string.h>
  84.  
  85.  
  86.  
  87. /*******************************************************************/
  88.  
  89. /*                                                                 */
  90.  
  91. /* Function prototype follows.                                     */
  92.  
  93. /*                                                                 */
  94.  
  95. /*******************************************************************/
  96.  
  97. RexxFunctionHandler RxNLSInfo;
  98.  
  99.  
  100.  
  101. /*******************************************************************/
  102.  
  103. /*                                                                 */
  104.  
  105. /* Function:            RxNLSInfo()                                */
  106.  
  107. /*                                                                 */
  108.  
  109. /* Description:         Return country dependent information.      */
  110.  
  111. /*                      Please see notes for details.              */
  112.  
  113. /*                                                                 */
  114.  
  115. /* Input:               Name of desired information.               */
  116.  
  117. /*                                                                 */
  118.  
  119. /* Output:              Desired information.  Please see notes.    */
  120.  
  121. /*                      Returns 0 if the function executed OK,     */
  122.  
  123. /*                      -1 otherwise.  The interpreter will        */
  124.  
  125. /*                      raise an error condition if this function  */
  126.  
  127. /*                      returns a non-zero result.                 */
  128.  
  129. /*                                                                 */
  130.  
  131. /* Effects:             None.                                      */
  132.  
  133. /*                                                                 */
  134.  
  135. /* External References: DosQueryCtryInfo()                         */
  136.  
  137. /*                                                                 */
  138.  
  139. /* Internal References: none                                       */
  140.  
  141. /*                                                                 */
  142.  
  143. /* Notes:                                                          */
  144.  
  145. /*                                                                 */
  146.  
  147. /*   This routine takes one parameter.  The form of the call is:   */
  148.  
  149. /*                                                                 */
  150.  
  151. /*   NLS_Information = RxNLSInfo( request )                        */
  152.  
  153. /*                                                                 */
  154.  
  155. /*   The value of the request parameter determines the information */
  156.  
  157. /*   returned.  Valid values are:                                  */
  158.  
  159. /*                                                                 */
  160.  
  161. /*   request            value returned                             */
  162.  
  163. /*   -------            --------------                             */
  164.  
  165. /*                                                                 */
  166.  
  167. /*   prefix             Currency prefix string.  It is followed by */
  168.  
  169. /*                      a space if a space should separate the     */
  170.  
  171. /*                      currency symbol from the value.            */
  172.  
  173. /*                      If the currency string follows the amount, */
  174.  
  175. /*                      this request returns an empty string.      */
  176.  
  177. /*                                                                 */
  178.  
  179. /*   suffix             Currency suffix string.  If the currency   */
  180.  
  181. /*                      string preceeds the amount, this request   */
  182.  
  183. /*                      returns an empty string.                   */
  184.  
  185. /*                                                                 */
  186.  
  187. /*   infix              Currency infix string.  This is the        */
  188.  
  189. /*                      decimal point unless the currency string   */
  190.  
  191. /*                      goes between the integer and fractional    */
  192.  
  193. /*                      part of the amount.  In this case, it      */
  194.  
  195. /*                      is the currency string.                    */
  196.  
  197. /*                                                                 */
  198.  
  199. /*   thousand           Thousands separator.                       */
  200.  
  201. /*                                                                 */
  202.  
  203. /*   decimal            Decimal separator.                         */
  204.  
  205. /*                                                                 */
  206.  
  207. /*   The routine ignores the case of the request parameter.  If    */
  208.  
  209. /*   the parameter is invalid or the argument count is not one,    */
  210.  
  211. /*   the function returns an empty string.                         */
  212.  
  213. /*                                                                 */
  214.  
  215. /* Error handling:  If this function is called with the wrong      */
  216.  
  217. /*   number of arguments, or an argument that is not on the        */
  218.  
  219. /*   list above, then we return with a value of -1, which will     */
  220.  
  221. /*   raise REXX error 40, "Invalid call to routine", in the        */
  222.  
  223. /*   REXX program.                                                 */
  224.  
  225. /*   This function also raises that error if the call to           */
  226.  
  227. /*   DosQueryCtryInfo produces any non-zero return code.           */
  228.  
  229. /*                                                                 */
  230.  
  231. /*******************************************************************/
  232.  
  233.  
  234.  
  235. ULONG APIENTRY RxNLSInfo(
  236.  
  237.    PUCHAR    func,
  238.  
  239.    ULONG     argc,
  240.  
  241.    PRXSTRING argv,
  242.  
  243.    PSZ       que,
  244.  
  245.    PRXSTRING ret)
  246.  
  247. {
  248.  
  249.    COUNTRYINFO     country_data ;      /* Structure to receive      */
  250.  
  251.                                        /* country-dependent data.   */
  252.  
  253.    static
  254.  
  255.       COUNTRYCODE  country_code =      /* Country and code page     */
  256.  
  257.                    {                   /* desired.                  */
  258.  
  259.                       0,               /* Default country code.     */
  260.  
  261.                       0                /* Default code page.        */
  262.  
  263.                     } ;
  264.  
  265.  
  266.  
  267.    PSZ              infix ;            /* Currency infix pointer.   */
  268.  
  269.  
  270.  
  271.    ULONG            bytes_returned ;   /* Number of bytes returned  */
  272.  
  273.                                        /* by DosQueryCtryInfo().    */
  274.  
  275.  
  276.  
  277.    LONG             rc = -1 ;          /* Function return value.    */
  278.  
  279.  
  280.  
  281.    /*****************************************************************/
  282.  
  283.    /* If the call to DosGetCntryInfo() fails or the arguments are   */
  284.  
  285.    /* invalid, we want to return an empty RXSTRING.                 */
  286.  
  287.    /* So we set the return strlength to 0.                          */
  288.  
  289.    /*                                                               */
  290.  
  291.    /* Please note that the REXX interpreter allocates 255 bytes in  */
  292.  
  293.    /* the return string.  This will suffice for us.                 */
  294.  
  295.    /*****************************************************************/
  296.  
  297.  
  298.  
  299.    ret -> strlength = 0 ;
  300.  
  301.  
  302.  
  303.    /*****************************************************************/
  304.  
  305.    /* If the argument count is valid (i.e.  1) and the argument is  */
  306.  
  307.    /* not too long, try to get the country dependent information.   */
  308.  
  309.    /* If the call succeeds, return the information that the caller  */
  310.  
  311.    /* wants.                                                        */
  312.  
  313.    /*****************************************************************/
  314.  
  315.  
  316.  
  317.    if( ( argc == 1 ) &&                /* Arg count valid?          */
  318.  
  319.        ( ! DosQueryCtryInfo(           /* Have country info?        */
  320.  
  321.                 sizeof( country_data ),
  322.  
  323.                 & country_code,
  324.  
  325.                 & country_data,
  326.  
  327.                 & bytes_returned ) ) )
  328.  
  329.    {
  330.  
  331.  
  332.  
  333.       /**************************************************************/
  334.  
  335.       /* We have the country dependent data in the data structure.  */
  336.  
  337.       /* Extract the data the caller requested and return it in the */
  338.  
  339.       /* return buffer.                                             */
  340.  
  341.       /**************************************************************/
  342.  
  343.  
  344.  
  345.       if( ! stricmp( argv->strptr, "PREFIX" ) )
  346.  
  347.       {
  348.  
  349.          rc = 0 ;                      /* Function call is OK.     */
  350.  
  351.  
  352.  
  353.          /**********************************************************/
  354.  
  355.          /* Caller has requested currency prefix.  If the currency */
  356.  
  357.          /* string preceeds the amount, return it.  If a space     */
  358.  
  359.          /* should follow the currency string, insert a space      */
  360.  
  361.          /* after the currency string.                             */
  362.  
  363.          /**********************************************************/
  364.  
  365.  
  366.  
  367.          if( ! ( country_data . fsCurrencyFmt & 5 ) )
  368.  
  369.          {
  370.  
  371.             ( void ) strcpy( ret -> strptr,
  372.  
  373.                              country_data . szCurrency ) ;
  374.  
  375.  
  376.  
  377.             ret -> strlength =
  378.  
  379.                         strlen( country_data . szCurrency ) ;
  380.  
  381.  
  382.  
  383.             /********************************************************/
  384.  
  385.             /* If a space should follow the currency string,        */
  386.  
  387.             /* append one.                                          */
  388.  
  389.             /********************************************************/
  390.  
  391.  
  392.  
  393.             if( ( country_data . fsCurrencyFmt & 1 ) )
  394.  
  395.             {
  396.  
  397.                ( void ) strcat( ret -> strptr,
  398.  
  399.                                 " " ) ;
  400.  
  401.                ++ ( ret -> strlength ) ;
  402.  
  403.             }                          /* If a space follows ...    */
  404.  
  405.          }                             /* If symbol preceeds ...    */
  406.  
  407.       }                                /* If caller wants prefix ...*/
  408.  
  409.       else if( ! stricmp( argv->strptr, "SUFFIX" ) )
  410.  
  411.       {
  412.  
  413.          rc = 0 ;                      /* Function call is OK.      */
  414.  
  415.  
  416.  
  417.          /***********************************************************/
  418.  
  419.          /* Caller has requested the currency suffix.  If the       */
  420.  
  421.          /* currency string follows the amount, return the string.  */
  422.  
  423.          /* Otherwise, leave the returned string empty.             */
  424.  
  425.          /***********************************************************/
  426.  
  427.  
  428.  
  429.          if( ( country_data . fsCurrencyFmt & 5 ) == 1 )
  430.  
  431.          {
  432.  
  433.             if( ( country_data . fsCurrencyFmt & 1 ) == 1 )
  434.  
  435.             {
  436.  
  437.                ( void ) strcpy( ret -> strptr, " " ) ;
  438.  
  439.                ret -> strlength = 1 ;
  440.  
  441.             }
  442.  
  443.  
  444.  
  445.             ( void ) strcat( ret -> strptr,
  446.  
  447.                              country_data . szCurrency ) ;
  448.  
  449.  
  450.  
  451.             ret -> strlength +=
  452.  
  453.                         strlen( country_data . szCurrency ) ;
  454.  
  455.          }                             /* If string follows amount. */
  456.  
  457.       }                                /* If Caller wants prefix ...*/
  458.  
  459.       else if( ! stricmp( argv->strptr, "INFIX" ) )
  460.  
  461.       {
  462.  
  463.          rc = 0 ;                      /* Function call is OK ...   */
  464.  
  465.  
  466.  
  467.          /***********************************************************/
  468.  
  469.          /* Caller has requested the currency infix.  If the        */
  470.  
  471.          /* currency symbol separates the integral and fractional   */
  472.  
  473.          /* portions of the amount, return the currency string.     */
  474.  
  475.          /* Otherwise, return the decimal separator.                */
  476.  
  477.          /***********************************************************/
  478.  
  479.  
  480.  
  481.          infix = (                     /* Select the string to      */
  482.  
  483.             country_data .             /* return...                 */
  484.  
  485.                fsCurrencyFmt & 4 ) ?
  486.  
  487.                   country_data . szCurrency :
  488.  
  489.                   country_data . szDecimal ;
  490.  
  491.  
  492.  
  493.             ( void ) strcpy( ret -> strptr,
  494.  
  495.                              infix ) ;
  496.  
  497.  
  498.  
  499.             ret -> strlength =
  500.  
  501.                         strlen( infix ) ;
  502.  
  503.  
  504.  
  505.       }                                /* If caller wants infix ... */
  506.  
  507.       else if( ! stricmp( argv->strptr, "THOUSAND" ) )
  508.  
  509.       {
  510.  
  511.          rc = 0 ;                      /* Function call is OK.      */
  512.  
  513.  
  514.  
  515.          /***********************************************************/
  516.  
  517.          /* Caller has requested thousands separator.  Return same. */
  518.  
  519.          /***********************************************************/
  520.  
  521.  
  522.  
  523.          ( void ) strcpy( ret -> strptr,
  524.  
  525.                           country_data . szThousandsSeparator ) ;
  526.  
  527.  
  528.  
  529.             ret -> strlength =
  530.  
  531.                         strlen( country_data . szThousandsSeparator ) ;
  532.  
  533.       }                                /* If thousand separator ..  */
  534.  
  535.       else if( ! stricmp( argv->strptr, "DECIMAL" ) )
  536.  
  537.       {
  538.  
  539.          rc = 0 ;                      /* Call is OK.               */
  540.  
  541.  
  542.  
  543.          /***********************************************************/
  544.  
  545.          /* Caller has requested the decimal point.  Return same.   */
  546.  
  547.          /***********************************************************/
  548.  
  549.  
  550.  
  551.          ( void ) strcpy( ret -> strptr,
  552.  
  553.                           country_data . szDecimal ) ;
  554.  
  555.  
  556.  
  557.             ret -> strlength =
  558.  
  559.                         strlen( country_data . szDecimal ) ;
  560.  
  561.       }                                /* If caller wants decimal.  */
  562.  
  563.    }                                   /* If args & call OK ...     */
  564.  
  565.    return( rc ) ;
  566.  
  567. }                                      /* End of function.          */
  568.  
  569.  
  570.  
  571.