home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / SLEEP.PRG < prev    next >
Text File  |  1992-10-17  |  3KB  |  114 lines

  1. /*
  2.  * File......: SLEEP.PRG
  3.  * Author....: Leo Letendre             
  4.  * CIS ID....: 73607,233
  5.  * Date......: $Date:   17 Oct 1992 16:18:18  $
  6.  * Revision..: $Revision:   1.1  $
  7.  * Log file..: $Logfile:   C:/nanfor/src/sleep.prv  $
  8.  * 
  9.  * This is an original work by Leo Letendre and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   C:/nanfor/src/sleep.prv  $
  16.  * 
  17.  *    Rev 1.1   17 Oct 1992 16:18:18   GLENN
  18.  * Leo cleaned up the doc and file header.
  19.  * 
  20.  *    Rev 1.0   01 Jul 1992 02:19:12   GLENN
  21.  * Initial revision.
  22.  *
  23.  */
  24.  
  25. #ifdef FT_TEST
  26.  
  27.   * Test routine
  28.   * Invoke by running SLEEP 1.0 to sleep 1.0 seconds
  29.   *
  30.  
  31.   FUNCTION MAIN(nSleep)
  32.  
  33.        ? "Time is now: " + time() 
  34.        FT_SLEEP(VAL(nSleep))
  35.        ? "Time is now: " + time() 
  36.  
  37.   RETURN ( nil )
  38.  
  39. #endif
  40.  
  41. /*  $DOC$
  42.  *  $FUNCNAME$
  43.  *     FT_SLEEP
  44.  *  $CATEGORY$
  45.  *     Menus/Prompts
  46.  *  $ONELINER$
  47.  *     Wait for a specified amount of time
  48.  *  $SYNTAX$
  49.  *     FT_SLEEP( <nSeconds>, [<nInitial>] ) -> nil
  50.  *  $ARGUMENTS$
  51.  *    <nSeconds> is the number of seconds to pause
  52.  *
  53.  *    <nInitial> is an optional clock value (from a call to SECONDS())
  54.  *               from which the <nSeconds> seconds are to elapse. Useful
  55.  *               for setting a minimum time between the start of events 
  56.  *               which could take a variable amount of time due to the 
  57.  *               execution of intervening code.
  58.  *  $RETURNS$
  59.  *     NIL
  60.  *  $DESCRIPTION$
  61.  *     This routine will wait a specified period of time. It provides
  62.  *     resolution based upon the execution of the SECONDS() function.
  63.  *     It does not use an input state such as INKEY(). The specified time
  64.  *     is the minimum time sleeping and will usually be slightly longer.
  65.  *
  66.  *     The second optional argument allows one to begin timing an event
  67.  *     prior to executing some operation. This is useful when, for example,
  68.  *     you input a key or mouse click and wish to do something but still want
  69.  *     to note if the user double entered (mouse or key) within a certain time
  70.  *     which in turn may have meaning within your program's context.
  71.  *
  72.  *     The routine correctly handles passing through midnight but will not
  73.  *     work for more than 24 hours.
  74.  *  $EXAMPLES$
  75.  *     Example 1:
  76.  *         FT_SLEEP(10.0)    && Sleep for 10.0 seconds
  77.  *     Example 2:
  78.  *         nTime=SECONDS()   && usually after some interupt from mouse or
  79.  *                           && keyboard
  80.  *
  81.  *         ... intervening code ...
  82.  *
  83.  *         FT_SLEEP(0.5, nTime) && Sleep until the sytem clock is 
  84.  *                              && nTime+0.5 seconds.
  85.  *
  86.  *  $END$
  87.  */
  88.  
  89. FUNCTION FT_SLEEP( nSeconds, nInitial )
  90.  
  91.   IF nInitial == NIL .OR. VALTYPE( nInitial ) != "N"
  92.        nInitial := SECONDS()
  93.   ENDIF
  94.  
  95.   // correct for running at midnight
  96.  
  97.   IF nInitial + nSeconds > 86399
  98.        nInitial -= 86399
  99.      *  Wait until midnight
  100.      DO WHILE SECONDS() > 100  // no problem with a _very_ slow machine
  101.      ENDDO
  102.   ENDIF
  103.  
  104.   // calculate final time
  105.  
  106.   nSeconds += ninitial
  107.  
  108.   // Loop until we are done
  109.  
  110.   DO WHILE ( SECONDS() < nSeconds )
  111.   ENDDO
  112.  
  113.   RETURN NIL
  114.