home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / unzip.tar.gz / unzip.tar / unzip / VMS.arc / vms_attr.c < prev    next >
C/C++ Source or Header  |  1991-03-14  |  8KB  |  245 lines

  1. /* 
  2.    [VMS_attr.c, based on] FILE.C, a utility to modify file characteristics.
  3.  
  4.    Written by Joe Meadows Jr, at the Fred Hutchinson Cancer Research Center
  5.    BITNET: JOE@FHCRCVAX
  6.    PHONE: (206) 467-4970
  7.    [...and stripped to the bone for unzip usage by Greg Roelofs.]
  8.  
  9.    There are no restrictions on this code, you may sell it, include it with
  10.    any commercial package, or feed it to a whale.. However, I would appreciate
  11.    it if you kept this comment in the source code so that anyone receiving
  12.    this code knows who to contact in case of problems. Note that I do not
  13.    demand this condition..
  14.  */
  15.  
  16. #include <descrip.h>
  17. #include <rms.h>
  18. #include <stdio.h>
  19. #include <iodef.h>
  20. #include <atrdef.h> /* this gets created with the c3.0 compiler */
  21. #include <fibdef.h> /* this gets created with the c3.0 compiler */
  22.  
  23. #include "fatdef.h"
  24. #include "fchdef.h"
  25. #include "fjndef.h"
  26.  
  27. #define RTYPE     fat$r_rtype_overlay.fat$r_rtype_bits
  28. #define RATTRIB   fat$r_rattrib_overlay.fat$r_rattrib_bits
  29.  
  30. extern char  zipfn[];    /* GRR unzip:  name of file to be modified */
  31. int  old_rtype;        /* save old zipfile attribute so can restore */
  32.  
  33. /* save...
  34. char *cvt_time();
  35. char *format_uic();
  36.  */
  37.  
  38.  
  39.  
  40. int change_zipfile_attributes( restore )   /* GRR unzip:  used to be main() */
  41.   int restore;
  42. {
  43.   static struct FAB Fab;
  44.   static struct NAM Nam;
  45.   static struct fibdef Fib; /* short fib */
  46.  
  47.   static struct dsc$descriptor FibDesc =
  48.     {sizeof(Fib),DSC$K_DTYPE_Z,DSC$K_CLASS_S,&Fib};
  49.   static struct dsc$descriptor_s DevDesc =
  50.     {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,&Nam.nam$t_dvi[1]};
  51.   static struct fatdef Fat;
  52.   static union {
  53.     struct fchdef fch;
  54.     long int dummy;
  55.   } uchar;
  56.   static struct fjndef jnl;
  57.   static long int Cdate[2],Rdate[2],Edate[2],Bdate[2];
  58.   static short int revisions;
  59.   static unsigned long uic;
  60.   static union {
  61.     unsigned short int value;
  62.     struct {
  63.       unsigned system : 4;
  64.       unsigned owner : 4;
  65.       unsigned group : 4;
  66.       unsigned world : 4;
  67.     } bits;
  68.   } prot;
  69.  
  70.   static struct atrdef Atr[] = {
  71.     {sizeof(Fat),ATR$C_RECATTR,&Fat},        /* record attributes */
  72.     {sizeof(uchar),ATR$C_UCHAR,&uchar},      /* File characteristics */
  73.     {sizeof(Cdate),ATR$C_CREDATE,&Cdate[0]}, /* Creation date */
  74.     {sizeof(Rdate),ATR$C_REVDATE,&Rdate[0]}, /* Revision date */
  75.     {sizeof(Edate),ATR$C_EXPDATE,&Edate[0]}, /* Expiration date */
  76.     {sizeof(Bdate),ATR$C_BAKDATE,&Bdate[0]}, /* Backup date */
  77.     {sizeof(revisions),ATR$C_ASCDATES,&revisions}, /* number of revisions */
  78.     {sizeof(prot),ATR$C_FPRO,&prot},         /* file protection  */
  79.     {sizeof(uic),ATR$C_UIC,&uic},            /* file owner */
  80.     {sizeof(jnl),ATR$C_JOURNAL,&jnl},        /* journal flags */
  81.     {0,0,0}
  82.   } ;
  83.  
  84.   static char EName[NAM$C_MAXRSS];
  85.   static char RName[NAM$C_MAXRSS];
  86.   static struct dsc$descriptor_s FileName =
  87.     {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0};
  88.   static struct dsc$descriptor_s string = {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0};
  89.   static short int DevChan;
  90.   static short int iosb[4];
  91.  
  92.   static long int i,status;
  93. /* static char *retval; */
  94.  
  95.  
  96. /*---------------------------------------------------------------------------
  97.     Initialize attribute blocks, parse filename, resolve any wildcards, and
  98.     get the file info.
  99.   ---------------------------------------------------------------------------*/
  100.  
  101.     /* initialize RMS structures, we need a NAM to retrieve the FID */
  102.     Fab = cc$rms_fab;
  103.     Fab.fab$l_fna = zipfn; /* name of file */
  104.     Fab.fab$b_fns = strlen(zipfn);
  105.     Fab.fab$l_nam = &Nam; /* FAB has an associated NAM */
  106.     Nam = cc$rms_nam;
  107.     Nam.nam$l_esa = &EName; /* expanded filename */
  108.     Nam.nam$b_ess = sizeof(EName);
  109.     Nam.nam$l_rsa = &RName; /* resultant filename */
  110.     Nam.nam$b_rss = sizeof(RName);
  111.  
  112.     /* do $PARSE and $SEARCH here */
  113.     status = sys$parse(&Fab);
  114.     if (!(status & 1)) return(status);
  115.  
  116.     /* search for the first file.. If none signal error */
  117.     status = sys$search(&Fab);
  118.     if (!(status & 1)) return(status);
  119.  
  120.     while (status & 1) {
  121.         /* initialize Device name length, note that this points into the NAM
  122.            to get the device name filled in by the $PARSE, $SEARCH services */
  123.         DevDesc.dsc$w_length = Nam.nam$t_dvi[0];
  124.  
  125.         status = sys$assign(&DevDesc,&DevChan,0,0);
  126.         if (!(status & 1)) return(status);
  127.  
  128.         FileName.dsc$a_pointer = Nam.nam$l_name;
  129.         FileName.dsc$w_length = Nam.nam$b_name+Nam.nam$b_type+Nam.nam$b_ver;
  130.  
  131.         /* Initialize the FIB */
  132.         for (i=0;i<3;i++)
  133.             Fib.fib$r_fid_overlay.fib$w_fid[i]=Nam.nam$w_fid[i];
  134.         for (i=0;i<3;i++)
  135.             Fib.fib$r_did_overlay.fib$w_did[i]=Nam.nam$w_did[i];
  136.  
  137.         /* Use the IO$_ACCESS function to return info about the file */
  138.         /* Note, used this way, the file is not opened, and the expiration */
  139.         /* and revision dates are not modified */
  140.         status = sys$qiow(0,DevChan,IO$_ACCESS,&iosb,0,0,
  141.                           &FibDesc,&FileName,0,0,&Atr,0);
  142.         if (!(status & 1)) return(status);
  143.         status = iosb[0];
  144.         if (!(status & 1)) return(status);
  145.  
  146. /* save...
  147.         if ((Cdate[0]==0) && (Cdate[1]==0))
  148.             printf("  /NO%s -\n",t_credate);
  149.         else
  150.             printf("  /%s=\"%s\" -\n",t_credate,cvt_time(Cdate));
  151.  
  152.         if ((Rdate[0]==0) && (Rdate[1]==0))
  153.             printf("  /NO%s",t_revdate);
  154.         else
  155.             printf("  /%s=\"%s\"",t_revdate,cvt_time(Rdate));
  156.  */
  157.  
  158.         if (restore)                /* GRR unzip */
  159.             Fat.RTYPE.fat$v_rtype = old_rtype;
  160.         else {
  161.             old_rtype = Fat.RTYPE.fat$v_rtype;
  162.             Fat.RTYPE.fat$v_rtype = FAT$C_STREAMLF;   /* Unix I/O loves it */
  163.         }
  164.  
  165. /* save...
  166.         status = cli_present(t_credate);
  167.         if (status & 1) {
  168.             status = cli_get_value(t_credate,&retval);
  169.             bintim(retval,Cdate);
  170.         }
  171.         else
  172.             if ((status == CLI$_NEGATED) || (status == CLI$_LOCNEG)) {
  173.                 Cdate[0]=0;
  174.                 Cdate[1]=0;
  175.             };
  176.  
  177.         status = cli_present(t_revdate);
  178.         if (status & 1) {
  179.             status = cli_get_value(t_revdate,&retval);
  180.             bintim(retval,Rdate);
  181.         }
  182.         else
  183.             if ((status == CLI$_NEGATED) || (status == CLI$_LOCNEG)) {
  184.                 Rdate[0]=0;
  185.                 Rdate[1]=0;
  186.             };
  187.  */
  188.  
  189.  
  190.         /* note, part of the FIB was cleared by earlier QIOW, so reset it */
  191.         Fib.fib$r_acctl_overlay.fib$l_acctl = FIB$M_NORECORD;
  192.         for (i=0;i<3;i++)
  193.             Fib.fib$r_fid_overlay.fib$w_fid[i]=Nam.nam$w_fid[i];
  194.         for (i=0;i<3;i++)
  195.             Fib.fib$r_did_overlay.fib$w_did[i]=Nam.nam$w_did[i];
  196.  
  197.         /* Use the IO$_MODIFY function to change info about the file */
  198.         /* Note, used this way, the file is not opened, however this would */
  199.         /* normally cause the expiration and revision dates to be modified. */
  200.         /* Using FIB$M_NORECORD prohibits this from happening. */
  201.         status = sys$qiow(0,DevChan,IO$_MODIFY,&iosb,0,0,
  202.                           &FibDesc,&FileName,0,0,&Atr,0);
  203.         if (!(status & 1)) return(status);
  204.  
  205.         status = iosb[0];
  206.         if (!(status & 1)) return(status);
  207.  
  208.         status = sys$dassgn(DevChan);
  209.         if (!(status & 1)) return(status);
  210.  
  211.         /* look for next file, if none, no big deal.. */
  212.         status = sys$search(&Fab);
  213.     }
  214. } /* end function change_zipfile_attributes() */
  215.  
  216.  
  217. #if 0   /* save for possible later use */ 
  218.  
  219. char *cvt_time(date)
  220.   long int date[2];
  221. {
  222.   static char str[27];
  223.   static struct dsc$descriptor date_str={26,DSC$K_DTYPE_T,DSC$K_CLASS_S,&str};
  224.  
  225.   if ((date[0]==0) && (date[1]==0))
  226.     return("none");
  227.  
  228.   sys$asctim(0,&date_str,date,0);
  229.   str[26]='\0';
  230.  
  231.   return(&str);
  232. }
  233.  
  234. bintim(time,binval)
  235.   char *time;
  236.   long int binval[2];
  237. {
  238.   static struct dsc$descriptor date_str={0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0};
  239.   date_str.dsc$w_length = strlen(time);
  240.   date_str.dsc$a_pointer = time;
  241.  
  242.   sys$bintim(&date_str,binval);
  243. }
  244. #endif /* 0 */ 
  245.