home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / acpcopy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-21  |  2.8 KB  |  116 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: acpcopy.c,v 1.7 1995/10/21 18:23:59 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    ACPcopy.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    23 Feb 1985, from code in 'pipefunc' written 16 Nov 1984
  9.  * Last update:
  10.  *        18 Mar 1995, prototypes
  11.  *        23 Feb 1985, to make a general-access routine
  12.  *
  13.  * Function:    Use ACP to copy attributes from one file to another.
  14.  *
  15.  * Arguments:    code    Determines the actual attributes to be copied:
  16.  *            <0:0>    Copy file protection
  17.  *            <1:1>    Copy file creation date
  18.  *            <2:2>    Make resulting file writeable (overwrites input protection)
  19.  *        iname    Full name of input file
  20.  *        oname    Full name of output file
  21.  */
  22.  
  23. #include    <starlet.h>
  24. #include    <rms.h>
  25. #include    <descrip.h>
  26. #include    <iodef.h>
  27. #include    <stsdef.h>
  28. #include    <string.h>
  29.  
  30. #include    "bool.h"
  31. #include    "acp.h"
  32. #include    "rmsio.h"
  33. #include    "rmsinit.h"
  34. #include    "acpcopy.h"
  35.  
  36. /*
  37.  * The FIB-data is static, because it is copied (by two calls on 'pipefunc2')
  38.  * from the input to the output file.
  39.  */
  40. static    FIB    fib;
  41. static    ATR    atr[3];            /* Size: 1 more than max attributes */
  42. static    short    short_fpro;        /* 1: File-protection            */
  43. static    uint    quad_credate[2];    /* 2: File-creation-date        */
  44.  
  45. static    int    acpcopy2 (int code, char *filespec);
  46.  
  47. void    acpcopy (int code, char *iname, char *oname)
  48. {
  49.     if (code > 0)
  50.     {
  51.         if (acpcopy2 (code, iname))
  52.             acpcopy2 (0, oname);
  53.     }
  54. }
  55.  
  56. /*
  57.  * Lookup/Modify attributes using ACP:
  58.  */
  59. static
  60. int    acpcopy2 (int code, char *filespec)
  61. {
  62.     RMS_STUFF;
  63.     uint    iosb[2];
  64.     short    chnl;
  65.     int    j    = 0;
  66.     int    func;
  67.     struct    dsc$descriptor    DSC_name;
  68.     struct    dsc$descriptor    fibDSC;
  69.  
  70.     /* macro $DESCRIPTOR(DSC_name, rsa) */
  71.     DSC_name.dsc$w_length  = sizeof(rsa) - 1;
  72.     DSC_name.dsc$b_dtype   = DSC$K_DTYPE_T;
  73.     DSC_name.dsc$b_class   = DSC$K_CLASS_S;
  74.     DSC_name.dsc$a_pointer = rsa;
  75.  
  76.     rmsinit_fab (&fab, &nam, nullC, filespec);
  77.     rmsinit_nam (&nam, esa, rsa);
  78.  
  79.     sys(sys$parse(&fab))                return(FALSE);
  80.     sys(sys$search(&fab))                return(FALSE);
  81.  
  82.     DSC_name.dsc$w_length = nam.nam$b_rsl;
  83.     sys(sys$assign (&DSC_name, &chnl, 0, 0))    return(FALSE);
  84.  
  85.     fibDSC.dsc$w_length = sizeof(FIB);
  86.     fibDSC.dsc$a_pointer = (char *)&fib;
  87.     memset (&fib, 0, sizeof(fib));
  88.     memcpy (fib.fib$w_fid, nam.nam$w_fid, 6);
  89.  
  90. #define    SET(type,size,addr) {\
  91.     atr[j].atr$w_type = type;\
  92.     atr[j].atr$w_size = size;\
  93.     atr[j++].atr$l_addr = (char *)addr;}
  94.  
  95.     if (!code)
  96.     {
  97.         func = IO$_MODIFY;
  98.         fib.fib$l_acctl = FIB$M_WRITECK;
  99.     }
  100.     else
  101.     {
  102.         func = IO$_ACCESS;
  103.         short_fpro = 0xfd00;    /* (S:RWED,O:RWED,G:RE,W)    */
  104.         if (code & 1)    SET(ATR$C_FPRO,ATR$S_FPRO,&short_fpro)
  105.         if (code & 2)    SET(ATR$C_CREDATE,ATR$S_CREDATE,&quad_credate)
  106.  
  107.         atr[j].atr$w_size = atr[j].atr$w_type = 0;
  108.     }
  109.  
  110.     sys(sys$qiow (0, chnl, func, iosb, 0, 0,
  111.             &fibDSC, 0,0,0, &atr[0],0))    return (FALSE);
  112.     if (code & 4)    short_fpro &= ~ 0xf0;    /* Give owner full rights */
  113.     status = sys$dassgn (chnl);
  114.     return (TRUE);
  115. }
  116.