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

  1. /*static char *SCCSID = "@(#)numerics.c    6.1 92/02/19";*/
  2. /*************************************************************************
  3.  * File Name     : NUMERICS
  4.  *
  5.  * Description   : This sample program demonstrates how to use the
  6.  *                 Bidirectional (Bidi) API NlsConvertBidiNumerics.
  7.  *                 This is an Arabic specific API and it is used to
  8.  *                 to convert the Arabic numerals to Hindu shapes
  9.  *                 for presentation purposes, or vice versa for
  10.  *                 storage purposes.
  11.  *
  12.  * Concepts      : It is advisable that the Numeral should be left as true
  13.  *                 ones (0x30-0x39), for storage and processing.
  14.  *
  15.  * API's         : NlsConvertBidiNumerics
  16.  *
  17.  * Required files: To build and run this sample code the following files
  18.  *                 are needed:
  19.  *                 - NUMERICS.c
  20.  *                 - NUMERICS.DEF
  21.  *                 - NUMERICS.MAK
  22.  *                 - NUMERICS.LNK
  23.  *
  24.  *  Copyright (C) 1991 IBM Corporation
  25.  *
  26.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  27.  *      sample code created by IBM Corporation. This sample code is not
  28.  *      part of any standard or IBM product and is provided to you solely
  29.  *      for  the purpose of assisting you in the development of your
  30.  *      applications.  The code is provided "AS IS", without
  31.  *      warranty of any kind.  IBM shall not be liable for any damages
  32.  *      arising out of your use of the sample code, even if they have been
  33.  *      advised of the possibility of such damages.                                                    *
  34.  ************************************************************************/
  35. #define INCL_DOSERRORS
  36. #define INCL_BDCALLS    /* This is to include the Bidi headers */
  37.  
  38. #include <os2.h>
  39. #include <stdio.h>
  40.  
  41. /*************************************************************************
  42.  * Name          : Main
  43.  *
  44.  * Description   : This is the main part of the program, it calls the
  45.  *                 Bidi API to convert all the Arabic numerals in a
  46.  *                 String to Hindu numerals, according to the value
  47.  *                 of the numerics byte in the Bidi attributes passed.
  48.  *
  49.  * API's         : NlsConvertBidiNumerics
  50.  *
  51.  * Parameters    : This program does not take any command line parameters
  52.  *
  53.  * Returns       : None
  54.  *
  55.  ************************************************************************/
  56. INT main(SHORT sArgc,CHAR **ppArgv)
  57. {
  58.   static CHAR cNumSourceArray[]={'1','2','3','4','5','\0'};
  59.   char cNumTargetArray [6];
  60.  
  61.   /* using the OR operator,we construct the value of the Bidi attributes,
  62.    * the value of the numerics byte indicates conversion to Hindi */
  63.   /* Note that the numeral conversion is not dependant on the
  64.    * value of the orientation byte or on the value of the shaping byte
  65.    * in the Bidi attributes */
  66.  
  67.   ULONG ulBidiAtt = BD_LEVEL
  68.                    | BD_SUPPORT
  69.                    | BDORIENT_RTL
  70.                    | BDNUM_HINDU
  71.                    | BDCSD_AUTOMATIC ;
  72.  
  73.   APIRET RC=0;
  74.   ULONG ulEffect = 0l;
  75.   ULONG ulIncrement = 1l;
  76.   ULONG ulLength = 5l;
  77.   cNumTargetArray[5]='\0';
  78.  
  79.   /* Print the string before it is converted */
  80.   printf ("%s\n", cNumSourceArray);
  81.  
  82.   /* this API will convert all the arabic numerics in a string to hindi  */
  83.   RC = NlsConvertBidiNumerics (ulBidiAtt,
  84.                                ulEffect,
  85.                                cNumSourceArray,
  86.                                cNumTargetArray,
  87.                                ulLength,
  88.                                ulIncrement);
  89.   if (RC!=0)
  90.   {
  91.     printf ("RC=%d\n", RC);
  92.   }
  93.  
  94.   /* Print the string after the conversion */
  95.   printf ("%s\n", cNumTargetArray);
  96.  
  97.  
  98.   printf ("\n\n\n\n Press Enter to end the program \n");
  99.  
  100.  
  101.   /* Wait for Enter to End the program */
  102.   getchar();
  103.  
  104.   return (0);
  105. } /* end of main */
  106.