home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / steward8.zip / LockOpen.cmd < prev    next >
OS/2 REXX Batch file  |  1996-04-03  |  1KB  |  56 lines

  1. /* ------------------------------------------------------------------ */
  2. /*
  3.  * LockOpen
  4.  *
  5.  * Lock this file from other Steward processes
  6.  *
  7.  */
  8.  
  9. TRUE = 1
  10. FALSE = 0
  11.  
  12. LockOpen: 
  13.  
  14. parse arg FileName Mode
  15.  
  16. /* Try to lock the file first */
  17. rc = Lock(FileName)
  18.  
  19. if rc = FALSE then return FALSE
  20.  
  21. /* Now open the actual file */
  22. if Mode = 'READ' then
  23.   rc = stream(FileName, 'C', 'OPEN READ')
  24. else if Mode = 'WRITE' then
  25.   rc = stream(FileName, 'C', 'OPEN WRITE')
  26. else
  27.   return FALSE
  28.  
  29. /* Check the value returned from the opening */
  30. parse var rc state ':' code
  31.  
  32. if Mode = 'READ' & state = 'NOTREADY' & code = '110' then do
  33.   /* assume trying to read non-existent file, so create it */
  34.   rc = stream(FileName, 'C', 'OPEN WRITE')
  35.   rc = stream(FileName, 'C', 'CLOSE')
  36.   rc = stream(FileName, 'C', 'OPEN READ')
  37.   parse var rc state ':' code
  38.   end  
  39.  
  40. do while state = 'NOTREADY' & code = '32'
  41.   call SysSleep 1
  42.   if Mode = 'READ' then
  43.     rc = stream(FileName, 'C', 'OPEN READ')
  44.   else if Mode = 'WRITE' then
  45.     rc = stream(FileName, 'C', 'OPEN WRITE')
  46.   parse var rc state ':'
  47.   end
  48.  
  49. /* We had an error attempting to open the file */
  50. if state <> 'READY' then
  51.   return FALSE
  52.  
  53. return TRUE
  54.  
  55. /* ------------------------------------------------------------------ */
  56.