home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_1.iso / msdos / clipper / nettos11.a01 / SYNCHRO / LOCKFILE.PRG < prev    next >
Text File  |  1993-02-23  |  3KB  |  115 lines

  1. /*
  2.  * File......: LOCKFILE.PRG
  3.  * Author....: Glenn Scott
  4.  * CIS ID....: 71620,1521
  5.  * Date......: $Date$
  6.  * Revision..: $Revision$
  7.  * Log file..: $Logfile$
  8.  * 
  9.  * This is an original work by Glenn Scott and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log$
  16.  *
  17.  */
  18.  
  19. #include "netto.ch"
  20. #include "ftint86.ch"
  21.  
  22. #define  NO_WAIT    0
  23.  
  24. /*  $DOC$
  25.  *  $FUNCNAME$
  26.  *     FN_LKFISET()
  27.  *  $CATEGORY$
  28.  *     Synchronization
  29.  *  $ONELINER$
  30.  *     Lock file set
  31.  *  $SYNTAX$
  32.  *
  33.  *     fn_lkFiSet( [<nTimeout>] ) -> lSuccess
  34.  *
  35.  *  $ARGUMENTS$
  36.  *
  37.  *     <nTimeOut> is interpreted differently, depending on which 
  38.  *     lockmode the station is currently in.
  39.  *
  40.  *     If the workstation is in "compatibility mode" (lock mode 0), 
  41.  *     then:
  42.  *         
  43.  *                  0     =  Don't Wait  (the default)
  44.  *         Anything else  =  Wait
  45.  *
  46.  *     If the workstation is in "extended lock mode" (lock mode 1),
  47.  *     the  <nTimeOut> is optional number of 1/18th sec ticks to 
  48.  *     wait for the lock; 0 = don't wait (default).
  49.  *
  50.  *  $RETURNS$
  51.  *
  52.  *     <lSuccess>, .t. if the call succeeded, and .f. if it didn't.
  53.  *     If the call fails, you can check fn_error() for one of the 
  54.  *     following:
  55.  *
  56.  *          If you're in compatibility mode (lock mode 0), 
  57.  *          
  58.  *                255      Failure 
  59.  *
  60.  *          If you're in extended mode (lock mode 1)
  61.  *
  62.  *                254      Timeout failure
  63.  *                255      Failure
  64.  *     
  65.  *
  66.  *  $DESCRIPTION$
  67.  *
  68.  *     Use this call after all the files to be locked have been 
  69.  *     logged.  If this call succeeds, you've got all of them 
  70.  *     locked.  If any file can't be locked, this call will fail
  71.  *     and no files will have been locked.
  72.  *
  73.  *  $EXAMPLES$
  74.  *
  75.  *  $SEEALSO$
  76.  *
  77.  *  $INCLUDE$
  78.  *
  79.  *  $END$
  80.  */
  81.  
  82.  
  83. function fn_lkFiSet( nTimeOut )                                // Lock file set
  84.   local aRegs[ INT86_MAX_REGS ], lRes := .f., nCurMode
  85.  
  86.   default nTimeOut to NO_WAIT
  87.  
  88.   nCurMode = fn_getLMod()
  89.  
  90.   if valtype( nTimeOut ) == "N"
  91.  
  92.      aRegs[ AX ] := makehi( 203 )
  93.  
  94.      if nCurMode == 1
  95.        aRegs[ BP ] := nTimeOut
  96.      else
  97.        aRegs[ DX ] := iif( nTimeOut != 0, 1, 0 )
  98.      endif
  99.  
  100.      lRes := ft_int86( INT21, aRegs )
  101.      if lRes
  102.         if UNSIGNED( LOWBYTE( aRegs[ AX ] ) ) # 0
  103.            _fnSetErr( UNSIGNED( LOWBYTE( aRegs[ AX ] ) ) )
  104.            lRes := .f.
  105.         endif
  106.      else
  107.         _fnSetErr( EINT86 )
  108.      endif
  109.  
  110.   else
  111.      _fnSetErr( EBADPARM )
  112.   endif
  113.  
  114.   return lRes
  115.