home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / TEXTECHO.CMD < prev    next >
OS/2 REXX Batch file  |  1994-11-16  |  4KB  |  133 lines

  1. EXTPROC CEnvi2
  2. //***********************************************************************
  3. //*** TextEcho.cmd - Demonstration of TextBoss.lib.  This starts      ***
  4. //*** ver.1          a DOS or OS/2 window and echos everything on it. ***
  5. //***********************************************************************
  6.  
  7. #include <PMdll.lib>
  8. #include <WinTools.lib>
  9. #include <ClipBrd.lib>
  10. #include <FileIO.lib>
  11. #include <NamePipe.lib>
  12. #include <TextBoss.lib>
  13.  
  14. // Find out if want to echo DOS or OS/2
  15. printf("Echo DOS window, OS/2 window, or Full-Screen OS/2?  (D | O | F) :");
  16. do {
  17.    SessionType = toupper(getch());
  18. } while ( SessionType != 'D'  &&  SessionType != 'O'  && SessionType != 'F' );
  19. printf("%c\n",SessionType);
  20.  
  21. switch ( SessionType ) {
  22.    case 'D':
  23.       SessionName = "DOS Echo Source";
  24.       StartParms = "/WIN /DOS /B command.com /C mode 80,25";
  25.       break;
  26.    case 'O':
  27.       SessionName = "OS/2 Echo Source";
  28.       StartParms = "/WIN /B cmd.exe /C mode 80,25";
  29.       break;
  30.    case 'F':
  31.       SessionName = "Full-Screen OS/2 Echo Source";
  32.       StartParms = "/FS /B /N CEnvi2.exe FSSlave.cmm MySlave CMD.EXE /K mode 80,25";
  33.       break;
  34. }
  35.  
  36. // Start a session in the background
  37. system("mode 80,26");
  38. system("start \"%s\" %s",SessionName,StartParms);
  39. suspend(3000);
  40.  
  41. printf("\nTextEcho has started a windowed session named \"%s\"\n",SessionName);
  42. printf("TextEcho will now attempt to control that session so that what you\n");
  43. printf("type HERE will be typed THERE, and what is displayed THERE will be\n");
  44. printf("displayed HERE.  The effect should be of a VERY SLOW WINDOW.  For\n");
  45. printf("this illusion to work, this OS/2 has been set to 26 lines, and that\n");
  46. printf("session is at 25 lines.  This will work best if that session is visible\n");
  47. printf("and this OS/2 session remains in the foreground.\n");
  48. printf("\n");
  49. printf("When \"%s\" is visible, press any key...",SessionName);
  50. getch();
  51. printf("\n");
  52.  
  53. WindowHandle = GetWindowHandle(SessionName);
  54. if ( NULL == WindowHandle ) {
  55.    printf("Could not locate session named \"%s\"\n",SessionName);
  56.    abort();
  57. }
  58.  
  59. if ( SessionType == 'D' )
  60.    PasteToTextWindow(WindowHandle,"ServeOS2 DOS_ECHO\r");
  61.  
  62. // initialize data to compare when it has changed
  63. PreviousData = "";
  64. PreviousLen = 0;
  65.  
  66. while ( IsWindow(WindowHandle) ) {
  67.  
  68.    // If keys are available, then send them to the window
  69.    if ( kbhit() ) {
  70.       KeysLen = 0;
  71.       do {
  72.          if ( 0 == (Keys[KeysLen] = byte(getch())) ) {
  73.             // extended key, so send any existing ascii string, then
  74.             // send just this extended key
  75.             if ( KeysLen ) {
  76.                Keys[KeysLen] = '\0';
  77.                if ( SessionType == 'D' )
  78.                   SendDosKey("DOS_ECHO",Keys);
  79.                else if ( SessionType == 'O' )
  80.                   SendOS2Key(WindowHandle,Keys);
  81.                else
  82.                   SendFullOS2Key("MySlave",Keys);
  83.             }
  84.             if ( SessionType == 'D' )
  85.                SendDosKey("DOS_ECHO",getch() << 8);
  86.             else if ( SessionType == 'O' )
  87.                SendOS2Key(WindowHandle,getch() << 8);
  88.             else
  89.                SendFullOS2Key("MySlave",getch() << 8);
  90.             KeysLen = 0;
  91.          } else {
  92.             KeysLen++;
  93.          }
  94.       } while( kbhit() );
  95.       if ( KeysLen ) {
  96.          Keys[KeysLen] = '\0';
  97.          if ( SessionType == 'D' )
  98.             SendDosKey("DOS_ECHO",Keys);
  99.          else if ( SessionType == 'O' )
  100.             SendOS2Key(WindowHandle,Keys);
  101.          else
  102.             SendFullOS2Key("MySlave",Keys);
  103.       }
  104.    }
  105.  
  106.    // Read the text in the window, if it has changed
  107.    if ( SessionType == 'F' ) {
  108.       if ( Data = ReadFullOS2Text("MySlave",lColCount,lRowCount,8000) ) {
  109.          DataLen = lColCount * lRowCount;
  110.       }
  111.    } else {
  112.       Data = ReadTextWindow(WindowHandle,DataLen);
  113.    }
  114.    if ( NULL != Data
  115.      && ( PreviousLen != DataLen || memcmp(Data,PreviousData,DataLen) ) ) {
  116.       if ( SessionType == 'F' ) {
  117.          ScreenCursor(0,0);
  118.          printf("%s",Data);
  119.       } else {
  120.          Lines = CopyTextBufferToLines(Data,LineCount);
  121.          for ( row = 0; row < 25; row++ ) {
  122.             ScreenCursor(0,row);
  123.             printf("%-80.80s",Lines[row]);
  124.          }
  125.       }
  126.       PreviousLen = DataLen;
  127.       PreviousData = Data;
  128.    }
  129.  
  130.    suspend(250);
  131.  
  132. }
  133.