home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / OS2 / CENV2_19.ZIP / BUGHUNT.CMD < prev    next >
OS/2 REXX Batch file  |  1994-03-08  |  4KB  |  85 lines

  1. @echo off
  2. REM *************************************************************************
  3. REM *** BugHunt.cmd - Example program for using the ClipBoard routines in ***
  4. REM *** ver.1         ClipBrd.lib.  This is a very silly program that     ***
  5. REM ***               searches every few seconds for the text of "bug"    ***
  6. REM ***               anywhere in the clipboard text.                     ***
  7. REM ***                                                                   ***
  8. REM ***               This program also demonstrates the unusual          ***
  9. REM ***               technique of calling CEnvi to execute code contain  ***
  10. REM ***               within the source of another CEnvi program.         ***
  11. REM *************************************************************************
  12.  
  13. REM ******************************************************
  14. REM *** Install the rest of this code to stay resident ***
  15. REM ******************************************************
  16.  
  17. start "BugHunt" /N /B /WIN /MIN CEnvi "#include 'BugHunt.cmd,,,/*RESIDENT*/'"
  18. call WinSet BugHunt HIDE
  19. EXIT
  20.  
  21. /*RESIDENT*/
  22.  
  23. #define  BUGHUNT_FREQUENCY    5   // how many seconds to wait between hunts
  24.  
  25. #include <ClipBrd.lib>
  26. #include <MsgBox.lib>
  27.  
  28.  
  29. MessageBox("This program will search for\n"
  30.            "bugs in your clipboard. That\n"
  31.            "is, it will search for the\n"
  32.            "word \"bug\" (case-insensitive)\n"
  33.            "and ask you if you want to\n"
  34.            "delete the clipboard if a\n"
  35.            "\"bug\" is found.",
  36.            "EXTERMINATOR!");
  37.  
  38.  
  39. for(;;) {   // FOREVER
  40.    ClipText = GetClipboardData(CF_TEXT);
  41.    if ( ClipText != NULL ) {
  42.       // check clipboard, case-insensitive, for the "bug" string
  43.       while ( NULL != (ClipText = strpbrk(ClipText,"Bb")) ) {
  44.          // check if the rest of this is "ug"
  45.          if ( !memicmp(++ClipText,"ug",2) ) {
  46.             if ( ExterminationWanted() )
  47.                ExterminateTheClipboard();
  48.             break;
  49.          }
  50.       }
  51.    }
  52.    suspend(BUGHUNT_FREQUENCY * 1000);
  53. }
  54.  
  55. ExterminationWanted() // Return TRUE if user wants to delete the clipboard
  56. {
  57.    return ( MBID_YES == MessageBox("A bug has been found in\n"
  58.                                    "the clipboard. Should the\n"
  59.                                    "clipboard be exterminated?",
  60.                                    "EXTERMINATOR!",
  61.                                    MB_WARNING|MB_MOVEABLE|MB_YESNO) );
  62. }
  63.  
  64. ExterminateTheClipboard() // spawn message program to run while this program
  65. {                         // deletes the text in the clipboard.
  66.    // Run another CEnvi process to tell that extermination is happening.
  67.    // That other program will read the code from this program; weird, huh!
  68.    system("start /N /WIN /MAX CEnvi \"#include <BugHunt.cmd,,//Exterminator!>\" ");ugh
  69.    // while that's going on, we'll simultaneously delete the clipboard
  70.    PutClipboardData(NULL);
  71. }
  72.  
  73.  
  74. // The text below, which is a comment in this program, is the CODE for another
  75. // instance of CEnvi which was spawned above in the ExterminateTheClipboard()
  76. // routine.  Since Windows is multitasking (sort of) this code will be running
  77. // while the original instance of CEnvi is deleting the clipboard.
  78.  
  79. //Exterminator!   for ( i = 0; i < 100; i++ ) {
  80. //Exterminator!      printf("Bug!\tEEEK!\t");
  81. //Exterminator!   }
  82. //Exterminator!   suspend(500);
  83. //Exterminator!   printf("\nCLIPBOARD EXTERMINATED!");
  84. //Exterminator!   suspend(500);
  85.