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 / invstr.c__ / invstr.c
Encoding:
C/C++ Source or Header  |  1993-03-12  |  6.0 KB  |  171 lines

  1. /*static char *SCCSID = "@(#)invstr.c    6.1 92/02/19";*/
  2. /*************************************************************************
  3.  * File Name     : INVSTR.C
  4.  *
  5.  * Description   : This sample program demonstrates how to use the API
  6.  *                 NlsInverseString. This Bidirectional (Bidi) API is used
  7.  *                 to invert a string from Right To Left, to Left To Right
  8.  *                 and vice versa.
  9.  *
  10.  * Concepts      : Inversion of strings is usually required when converting
  11.  *                 logically ordered characters to visual ordering,
  12.  *                 depending on the orientation of the presentation device
  13.  *                 (screen, printer..)
  14.  *                 Example:
  15.  *                    static CHAR [] ={'f','i','l','e'};
  16.  *                 This string will be in a readable format if it is
  17.  *                 displayed on a LTR screen, however in order to display
  18.  *                 and read it on a RTL screen we should invert it.
  19.  *
  20.  * API's         : NlsInverseString
  21.  *                 VioWrtCharStr
  22.  *                 VioScrollUp
  23.  *                 VioWrtCellStr
  24.  *                 VioSetCurType
  25.  *
  26.  * Required files: To build and run this sample code the following files
  27.  *                 are needed:
  28.  *                 - INVSTR.C
  29.  *                 - INVSTR.DEF
  30.  *                 - INVSTR.MAK
  31.  *                 - INVSTR.LNK
  32.  *
  33.  *  Copyright (C) 1991 IBM Corporation
  34.  *
  35.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  36.  *      sample code created by IBM Corporation. This sample code is not
  37.  *      part of any standard or IBM product and is provided to you solely
  38.  *      for  the purpose of assisting you in the development of your
  39.  *      applications.  The code is provided "AS IS", without
  40.  *      warranty of any kind.  IBM shall not be liable for any damages
  41.  *      arising out of your use of the sample code, even if they have been
  42.  *      advised of the possibility of such damages.                                                    *
  43.  ************************************************************************/
  44.  
  45. #define INCL_BASE
  46. #define INCL_DOSERRORS
  47. #define INCL_BDCALLS    /* This is to include the Bidi headers */
  48.  
  49. #include <os2.h>
  50. #include <string.h>
  51. #include <stdlib.h>
  52. #include <stdio.h>
  53. #include <conio.h>
  54.  
  55. #define HIDE -1                        /* PARAMATER TO HIDE THE SCREEN*/
  56. #define RESTORE 0                      /* paramater to restore the screen */
  57.  
  58. VOID SetCur(INT);
  59.  
  60.  
  61. char string[35] = {'S', 0x78, 't', 0x1e, 'r', 0x49, 'i' ,0x71, 'n',0x4f, 'g',
  62.                   0x2a, ' ',0x0f, 't',0x5f, 'o',0x78, ' ', 0x0f, 'I', 0x5d, 'n',
  63.                   0x70, 'v', 0x5e, 'e', 0x06, 'r', 0x6e, 't', 0x78, '\0'
  64.                    };
  65.                 /* this is the string to reverse, each character is followed */
  66.                 /* by its attributes.                                        */
  67.                 /* In fact this simulates the case of reversing a screen     */
  68.                 /* buffer.                                                   */
  69.  
  70. /*************************************************************************
  71.  * Name          : Main
  72.  *
  73.  * Description   : This is the main part of the program, it first clear
  74.  *                 the screen and then hide the cursor. The string to be
  75.  *                 inverted will be displayed before and after the
  76.  *                 NlsinvsrseString is called.
  77.  *                 Here we will show how to use the API, and what are
  78.  *                 the parameters needed.
  79.  *
  80.  * API's         : NlsInverseString
  81.  *                 VioWrtCharStr
  82.  *                 VioScrollUp
  83.  *                 VioWrtCellStr
  84.  *
  85.  *
  86.  * Parameters    : This program does not take any command line parameters
  87.  *
  88.  * Returns       : None
  89.  *
  90.  ************************************************************************/
  91.  
  92. INT main(SHORT sArgc,CHAR **ppArgv)
  93. {
  94.    APIRET RC;
  95.  
  96.    /* Use the VioScrollUp API to clear the screen */
  97.    VioScrollUp(0, 0, 24, 79, -1," \x07", 0);
  98.  
  99.    /* Call the SetCur() procedure to hide the Cursor */
  100.    SetCur(HIDE);
  101.  
  102.    RC = VioWrtCharStr("Here is the string we want to invert:",38, 4, 10, 0l);
  103.  
  104.    /* Write to the Screen the String needed to be inverted */
  105.    RC = VioWrtCellStr(string, strlen(string),7, 10, 0);
  106.  
  107.    /* Call the NlsInverseString to invert cells of lenght 2 in the string,
  108.     * here the source can equal to target but they should not overlap  */
  109.    RC = NlsInverseString( string, string, strlen(string), 2);
  110.  
  111.    if (RC != 0)
  112.    {
  113.       printf("\nError in calling the API, RC=%ld\n",RC);
  114.       return(1);
  115.    }
  116.  
  117.    RC = VioWrtCharStr("Now after calling the API NlsInveseString,",
  118.                        44, 10, 10, 0l);
  119.    RC = VioWrtCharStr("we will get the following inverted string:",
  120.                        43, 11, 10, 0l);
  121.  
  122.    /* Write the string after inversion on the screen */
  123.    RC = VioWrtCellStr(string, strlen(string),14, 10, 0);
  124.  
  125.    RC=VioWrtCharStr("Note that each character is still keeping its attribute !",
  126.                      60, 17, 10, 0l);
  127.  
  128.    RC = VioWrtCharStr("Press Enter to exit the program",32, 23, 20, 0l);
  129.  
  130.    /* Wait for the Enter Key to end the program */
  131.    getchar();
  132.  
  133.    /* Clear the screnn */
  134.    RC = VioScrollUp(0, 0, 24, 79, -1," \x07", 0);
  135.  
  136.    /* Restor the cursor position */
  137.    SetCur(RESTORE);
  138.  
  139.    return(0);
  140.  
  141. } /* End of Main */
  142.  
  143. /*************************************************************************
  144.  * Name          : SETCUR
  145.  *
  146.  * Description   : This function hides or restores the cursor position.
  147.  *
  148.  * API's         : VioSetCurType
  149.  *
  150.  * Parameters    : (INT flag)
  151.  *                 flag indicates whether we want ot hide or restore
  152.  *                 the cursor.
  153.  *
  154.  * Returns       : None
  155.  *
  156.  ************************************************************************/
  157. VOID SetCur(INT flag)
  158. {
  159.    HVIO HVIOhandle = 0;
  160.    VIOCURSORINFO cursor;
  161.  
  162.    cursor.yStart  = 3;
  163.    cursor.cEnd    = 5;
  164.    cursor.cx      = 0;
  165.    cursor.attr    = flag;
  166.  
  167.    VioSetCurType(&cursor, HVIOhandle);
  168.  
  169. } /* End of SetCurr */
  170.  
  171.