home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / dbutil.zip / KEY-IN.CMD < prev    next >
OS/2 REXX Batch file  |  1987-02-14  |  4KB  |  158 lines

  1. *     KEY-IN.CMD
  2. *
  3. *   This file will patch a running dBASE application to
  4. *   allow examination of the last keyboard key-press by
  5. *   PEEK (KEY:IN).  Used for aborting a DO WHILE LOOP
  6. *   without terminating program execution.
  7. *
  8. *    Written by: Gene Head
  9. *            2860 NW Skyline Drive
  10. *            Corvallis, Oregon  97330
  11. *            (503)  758-0279
  12. *
  13. *     Last up-date: 12/4/83
  14. *
  15. *      APPLICATION: I wanted to show text files whose lines are saved
  16. *    as continuous records, each record of one 80-character field
  17. *    was a single line of text.  There is no way in dBASE of aborting
  18. *    output without terminating the program.  Using PATCH-IT.CMD
  19. *    the text file was displayed until a control-C was typed from
  20. *    the keyboard using the following dBASE code:
  21. *
  22. *    USE TEXT:FILE
  23. *    DO WHILE .NOT. EOF .AND. PEEK(KEY:PRESS) <> 3
  24. *        ? TRIM(TEXT:LINE)
  25. *    ENDDO
  26. *
  27. *      SYNOPSIS: Whenever a key is pressed the direct console IO
  28. *    routine in dBASE II saves the character at a memory location.
  29. *    This location can't be directly checked because it is set to zero
  30. *    the next time the console is polled and no character is
  31. *    waiting.  So we install one addtional storage byte where the input
  32. *    key is stored but NOT changed until another key is pressed.
  33. *
  34. *    There is no room to make the patch in-line so I chose to use
  35. *    the RAM dedicated to the custom screen handeling, specifically
  36. *    the characters used when you QUIT dBASE II.  Thes characters are
  37. *    saved and can be restored if desired.
  38. *
  39. *    This patch can be made permanent using DDT if you desire and you
  40. *    have the extra room in the screen IO RAM.      
  41. *
  42. *    The old code looks like this:
  43. *
  44. *        MVI    E,0FFH            ;DO DIRECT CONSOLE IO
  45. *        MVI    C,6
  46. *        CALL    5
  47. *        ORA    A
  48. *        RZ
  49. *   JUMP:CODE    STA    VECTOR:1,VECTOR:2
  50. *        RET
  51. *
  52. *        The new code looks like this:
  53. *
  54. *        MVI    E,0FFH            ;DO DIRECT CONSOLE IO
  55. *        MVI    C,6
  56. *        CALL    5
  57. *        ORA    A
  58. *        RZ
  59. *   JUMP:CODE    JUMP    PATCH            ;JUMP TO NEW CODE AREA
  60. *        RET
  61. *
  62. *     PATCH  STA     VECTOR:1,VECTOR:2    ;SAVE TO THE ORIGINAL LOCATION
  63. *        STA    KEY:PRESS        ;SAVE TO THE NEW LOCATION ALSO
  64. *        RET                ;RETURN
  65. *
  66. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
  67.  
  68. *    PATCH-IT.MEM holds the variables if we have already
  69. *             determined the location of the IO routine
  70.  
  71. *  Find the old code
  72. SET TALK OFF
  73. STORE FILE('KEY-IN.MEM') TO PATCHED
  74. IF .NOT. PATCHED
  75.     *  Define start and end of search area
  76.     *  This window may need to be expanded to find the patch
  77.     STORE 14000 TO START
  78.     STORE 20000 TO END
  79.  
  80.            DO WHILE START < END 
  81.  
  82.         *  Look for first matching byte
  83.         IF PEEK(START) = 30
  84.  
  85.                  *  Check next four bytes for exact match
  86.             IF PEEK(START+1) = 255 .AND. PEEK(START+2) = 14;
  87.                      .AND. PEEK(START+3) = 6 .AND. PEEK(START+9) = 50
  88.                           *  START+9 IS NOT A TYPO
  89.             *  Set found flag
  90.             STORE T TO FOUND
  91.  
  92.             *  Save the location of the patch and the vectors
  93.             STORE START + 09 TO JUMP:PATCH
  94.             STORE PEEK(START + 10) TO VECTOR:1
  95.             STORE PEEK(START + 11) TO VECTOR:2
  96.  
  97.             *  Clear the DO-LOOP
  98.             STORE END TO START
  99.  
  100.             ENDIF    Exact match
  101.  
  102.         ENDIF    First byte match
  103.  
  104.        *  Skip to next byte
  105.            STORE START+1 TO START
  106.  
  107.            ENDDO    While START < END
  108.  
  109. RELEASE END, START
  110. SAVE TO KEY-IN.MEM
  111. ELSE
  112.  
  113. *  IF THE MEMORY FILE IS HERE USE IT
  114. RESTORE FROM KEY-IN.MEM
  115. ENDIF  FILE('KEY-IN.MEM')
  116.  
  117. * VERIFY PATCH AREA
  118.         STORE JUMP:PATCH-9 TO START
  119.                  *  Check next four bytes for exact match
  120.             IF PEEK(START+1) = 255 .AND. PEEK(START+2) = 14;
  121.                      .AND. PEEK(START+3) = 6 .AND. PEEK(START+9) = 50
  122.                           *  START+9 IS NOT A TYPO
  123.             ELSE
  124.             ERASE
  125.             ?
  126.     ? 'BAD PATCH DATA.  DELETE FILE "KEY-IN.MEM" AND TRY AGAIN.'
  127.             CANCEL
  128.             ENDIF
  129.  
  130.  
  131. *  Now that we know where to patch let's actually do the patching. . . 
  132.  
  133. * SAVE SCREEN OUTPUT AFTER 'QUIT' DATA IF YOU PLAN TO UN-PATCH LATER
  134. STORE 321 TO ADDRESS
  135. STORE ADDRESS+7 TO KEY:PRESS
  136. STORE PEEK(ADDRESS+1) TO K1
  137. STORE PEEK(ADDRESS+2) TO K2
  138. STORE PEEK(ADDRESS+3) TO K3
  139. STORE PEEK(ADDRESS+4) TO K4
  140. STORE PEEK(ADDRESS+5) TO K5
  141. STORE PEEK(ADDRESS+6) TO K6
  142. STORE PEEK(ADDRESS+7) TO K7
  143.  
  144. * WRITE THE PATCH CODE
  145. POKE ADDRESS, 50,VECTOR:1, VECTOR:2,  50,72,1,  201
  146.  
  147. * WRITE THE NEW EXECUTION PATH
  148. POKE JUMP:PATCH, 195, 65, 1
  149.  
  150. RELEASE ALL EXCEPT K*
  151.  
  152. ENDIF
  153.  
  154. *  To Un-Patch if necessary:
  155.  
  156. *   POKE KEY:PRESS-7, K1,K2,K3,K4,K5,K6,K7
  157.  
  158.