home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TPTOOL4.ZIP / OPENSHAR.INC next >
Encoding:
Text File  |  1987-06-04  |  3.2 KB  |  94 lines

  1.  
  2. (*
  3.  * openshar.inc - shared mode file handlers
  4.  *
  5.  * This library allows you to open files in the various sharing
  6.  * modes allowed by DOS 3.x under SHARE.
  7.  *
  8.  * S.H.Smith, 20-may-87
  9.  *
  10.  * Thanks to John W. Wulff who documented these procedures!
  11.  *
  12.  * This routine is implemented as a macro (or an inline procedure).
  13.  * This implementation allows you to use any combination of file types
  14.  * without writing a special handler for each file type.
  15.  *
  16.  * Compile with TSHELL 1.2+ (Available from the Tool Shop BBS 602 279 2673)
  17.  *
  18.  *
  19.  * Usage:
  20.  *    assign(fd,name);
  21.  *    OPEN_SHARE(fd, function, mode, ok);
  22.  *    if ok then  process-file
  23.  *    else        couldn't open
  24.  *
  25.  * Where:
  26.  *    fd          is the file variable to open
  27.  *
  28.  *    function    is the open function, one of:
  29.  *                   reset, rewrite, append
  30.  *
  31.  *    mode        is the file sharing mode, composed of:
  32.  *                   allow_xxx+deny_yyy
  33.  *                where xxx is:  read, write, update and
  34.  *                      yyy is:  all, read, write, nothing
  35.  *
  36.  *    ok          is the result status code, on exit:
  37.  *                   true - open was successful
  38.  *                   false - open failed after n tries
  39.  *
  40.  * Revision history
  41.  *
  42.  *    20-may-87 s.h.smith, initial coding
  43.  *
  44.  *    21-may-87 s.h.smith, changed shared modes to deny nothing to other nodes
  45.  *
  46.  *    22-may-86 s.h.smith, changed modes again.  allow and deny fields are now
  47.  *              specified separately.  'append' doesn't work with deny-none.
  48.  *
  49.  *    04-jun-87 s.h.smith, bracketed OPENSHAR body with begin..end so the
  50.  *              macro can be used with the IF statement.
  51.  *)
  52.  
  53. const
  54.    retry_count        = 10;
  55.    default_mode       = 2;
  56.  
  57.    allow_read         = 0;
  58.    allow_write        = 1;
  59.    allow_update       = 2;
  60.  
  61.    deny_all           = 16;
  62.    deny_write         = 32;
  63.    deny_read          = 48;
  64.    deny_nothing       = 64;
  65.  
  66. var
  67.    open_mode_byte:  byte  absolute cseg:$24fc;  {tp 3.01x only}
  68.                                        { 24c6}  {tp 3.02x only}
  69.  
  70.    open_try_count:  integer;
  71.  
  72.  
  73. #define OPEN_SHARE  {...(fd, function, mode, okstatus) }      \
  74. begin                                                         \
  75.    open_mode_byte := %3;                                      \
  76.    open_try_count := 0;                                       \
  77.    %4 := false;                                               \
  78.                                                               \
  79.    while (open_try_count < retry_count) and (%4 = false) do   \
  80.    begin                                                      \
  81.       {$i-} %2 (%1); {$i+}                                    \
  82.                                                               \
  83.       if ioresult = 0 then                                    \
  84.          %4 := true                                           \
  85.       else                                                    \
  86.          open_try_count := open_try_count + 1;                \
  87.    end;                                                       \
  88.                                                               \
  89.    open_mode_byte := default_mode;                            \
  90. end
  91.  
  92.  
  93.  
  94.