home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w055 / 4.ddi / SOURCES.LIF / REPEAT.PEL < prev    next >
Encoding:
Text File  |  1990-09-27  |  2.6 KB  |  108 lines

  1. # $Header:   P:/source/ppee/macros/repeat.pev   1.16   09 Aug 1990 17:05:38   skipr  $
  2.  
  3. ##############################################################################
  4. #
  5. #           Sage Software - POLYTRON Division
  6. #             1700 NW 167th Place
  7. #               Beaverton, OR 97006
  8. #
  9. #   Copyright 1990, Sage Software, Inc.
  10. #
  11. #   Permission is hereby granted for licensed users of Sage Professional
  12. #   Editor and PolyAwk to copy and modify this source code for their own
  13. #   personal use.  These derivative works may be distributed only to other
  14. #   licensed Sage Professional Editor and PolyAwk users.  All other usage
  15. #   is prohibited without express written permission from Sage Software.
  16. #
  17. ##############################################################################
  18.  
  19. #### $Workfile:   repeat.pel  $: repeat count support
  20.  
  21.  
  22. global function repeat_key_action() {
  23.  
  24.     local    repeatCount = 0
  25.     local    msg = "Enter repeat count followed by the key to repeat. ["
  26.     local    digit = "zip"
  27.     local    keyToExecute
  28.     local    keyUsedToGetHere = current_key
  29.     local    binding
  30.     local    c
  31.     local    functionId
  32.  
  33.     ###
  34.     ### build the repeat count
  35.     ###
  36.  
  37.     begin_dialog()
  38.     notify( msg 1 "]" )
  39.  
  40.     while (1) {
  41.         while ( chr(c = getchar()) ~ /[0-9]/ ) {
  42.             digit = c - ord("0")
  43.             repeatCount = repeatCount * 10 + digit
  44.             notify( msg repeatCount "]" )
  45.         }
  46.  
  47.         # Esc key to exit
  48.         if ( current_key == KEYCODE_ESC ) {
  49.             notify( "Command canceled" )
  50.             digit = ""
  51.             repeatCount = 0
  52.             break
  53.         }
  54.  
  55.         # repeat key multiplies by four ala Emacs
  56.         if ( current_key == keyUsedToGetHere ) {
  57.             digit = ""
  58.             repeatCount = (repeatCount ? repeatCount : 1) * 4
  59.             notify( msg repeatCount "]" )
  60.         } else {
  61.             break
  62.         }
  63.     }
  64.  
  65.     message( "" )
  66.     end_dialog()
  67.  
  68.     if ( digit == "zip" ) {
  69.         repeatCount = 1
  70.     } else if ( repeatCount < 1 ) {
  71.         return
  72.     }
  73.  
  74.     ###
  75.     ### build the string representation of the key then repeat its action
  76.     ###
  77.  
  78.     keyToExecute = "#" current_key
  79.  
  80.     # eat the character remaining after a DOS two-character sequence
  81.     # (must be done after accessing "current_key")
  82.     if (c == 0) {
  83.         getchar()
  84.     }
  85.  
  86.     binding = keymap_binding( keyToExecute )
  87.     if ( binding !~ /repeat_key_action/ ) {
  88.         if ((functionId = function_id( binding ))) {
  89.             while (repeatCount--) {
  90.                 execute_function( functionId )
  91.             }
  92.         }
  93.     }
  94. }
  95.  
  96.  
  97. ##
  98. ## execute the function bound to a given key
  99. ##
  100.  
  101. global function execute_key_action( keystring ){        #PUBLIC
  102.     local binding = keymap_binding( keystring )
  103.  
  104.     if ( binding && ( binding !~ /execute_key_action/ )){
  105.         return execute_function( binding )
  106.     }
  107. }
  108.