home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / unzip / vms_attr.c < prev    next >
C/C++ Source or Header  |  1994-11-04  |  9KB  |  284 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. #if defined (VAX_COMPILE)
  24. #include "fatdef.h"
  25. #include "fchdef.h"
  26. #else
  27. #include <fatdef.h>
  28. #include <fchdef.h>
  29. #endif
  30.  
  31. #include "fjndef.h"
  32.  
  33. #define RTYPE     fat$r_rtype_overlay.fat$r_rtype_bits
  34. #define RATTRIB   fat$r_rattrib_overlay.fat$r_rattrib_bits
  35.  
  36. extern char  zipfn[];    /* GRR unzip:  name of file to be modified */
  37. int  old_rtype;        /* save old zipfile attribute so can restore */
  38.  
  39. /* save...
  40. char *cvt_time();
  41. char *format_uic();
  42.  */
  43.  
  44.  
  45.  
  46. int change_zipfile_attributes( restore )   /* GRR unzip:  used to be main() */
  47.   int restore;
  48. {
  49.   static struct FAB Fab;
  50.   static struct NAM Nam;
  51.   static struct fibdef Fib; /* short fib */
  52.  
  53.   static struct dsc$descriptor FibDesc =
  54.     {sizeof(Fib),DSC$K_DTYPE_Z,DSC$K_CLASS_S,&Fib};
  55.   static struct dsc$descriptor_s DevDesc =
  56.     {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,&Nam.nam$t_dvi[1]};
  57. #if defined (VAX_COMPILE)
  58.   static struct fatdef Fat;
  59. #else
  60.   static FAT Fat;
  61. #endif
  62.   static union {
  63. #if defined (VAX_COMPILE)
  64.     struct fchdef fch;
  65. #else
  66.     FCH fch;
  67. #endif
  68.     long int dummy;
  69.   } uchar;
  70.   static struct fjndef jnl;
  71.   static long int Cdate[2],Rdate[2],Edate[2],Bdate[2];
  72.   static short int revisions;
  73.   static unsigned long uic;
  74.   static union {
  75.     unsigned short int value;
  76.     struct {
  77.       unsigned system : 4;
  78.       unsigned owner : 4;
  79.       unsigned group : 4;
  80.       unsigned world : 4;
  81.     } bits;
  82.   } prot;
  83.  
  84.   static struct atrdef Atr[] = {
  85.     {sizeof(Fat),ATR$C_RECATTR,&Fat},        /* record attributes */
  86.     {sizeof(uchar),ATR$C_UCHAR,&uchar},      /* File characteristics */
  87.     {sizeof(Cdate),ATR$C_CREDATE,&Cdate[0]}, /* Creation date */
  88.     {sizeof(Rdate),ATR$C_REVDATE,&Rdate[0]}, /* Revision date */
  89.     {sizeof(Edate),ATR$C_EXPDATE,&Edate[0]}, /* Expiration date */
  90.     {sizeof(Bdate),ATR$C_BAKDATE,&Bdate[0]}, /* Backup date */
  91.     {sizeof(revisions),ATR$C_ASCDATES,&revisions}, /* number of revisions */
  92.     {sizeof(prot),ATR$C_FPRO,&prot},         /* file protection  */
  93.     {sizeof(uic),ATR$C_UIC,&uic},            /* file owner */
  94.     {sizeof(jnl),ATR$C_JOURNAL,&jnl},        /* journal flags */
  95.     {0,0,0}
  96.   } ;
  97.  
  98.   static char EName[NAM$C_MAXRSS];
  99.   static char RName[NAM$C_MAXRSS];
  100.   static struct dsc$descriptor_s FileName =
  101.     {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0};
  102.   static struct dsc$descriptor_s string = {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0};
  103.   static short int DevChan;
  104.   static short int iosb[4];
  105.  
  106.   static long int i,status;
  107. /* static char *retval; */
  108.  
  109.  
  110. /*---------------------------------------------------------------------------
  111.     Initialize attribute blocks, parse filename, resolve any wildcards, and
  112.     get the file info.
  113.   ---------------------------------------------------------------------------*/
  114.  
  115.     /* initialize RMS structures, we need a NAM to retrieve the FID */
  116.     Fab = cc$rms_fab;
  117.     Fab.fab$l_fna = zipfn; /* name of file */
  118.     Fab.fab$b_fns = strlen(zipfn);
  119.     Fab.fab$l_nam = &Nam; /* FAB has an associated NAM */
  120.     Nam = cc$rms_nam;
  121.     Nam.nam$l_esa = &EName; /* expanded filename */
  122.     Nam.nam$b_ess = sizeof(EName);
  123.     Nam.nam$l_rsa = &RName; /* resultant filename */
  124.     Nam.nam$b_rss = sizeof(RName);
  125.  
  126.     /* do $PARSE and $SEARCH here */
  127.     status = sys$parse(&Fab);
  128.     if (!(status & 1)) return(status);
  129.  
  130.     /* search for the first file.. If none signal error */
  131.     status = sys$search(&Fab);
  132.     if (!(status & 1)) return(status);
  133.  
  134.     while (status & 1) {
  135.         /* initialize Device name length, note that this points into the NAM
  136.            to get the device name filled in by the $PARSE, $SEARCH services */
  137.         DevDesc.dsc$w_length = Nam.nam$t_dvi[0];
  138.  
  139.         status = sys$assign(&DevDesc,&DevChan,0,0);
  140.         if (!(status & 1)) return(status);
  141.  
  142.         FileName.dsc$a_pointer = Nam.nam$l_name;
  143.         FileName.dsc$w_length = Nam.nam$b_name+Nam.nam$b_type+Nam.nam$b_ver;
  144.  
  145. #if defined(VAX_COMPILE)
  146.         /* Initialize the FIB */
  147.         for (i=0;i<3;i++)
  148.             Fib.fib$r_fid_overlay.fib$w_fid[i]=Nam.nam$w_fid[i];
  149.         for (i=0;i<3;i++)
  150.             Fib.fib$r_did_overlay.fib$w_did[i]=Nam.nam$w_did[i];
  151. #else
  152.         /* Initialize the FIB */
  153.         for (i=0;i<3;i++)
  154.             Fib.fib$w_fid[i]=Nam.nam$w_fid[i];
  155.         for (i=0;i<3;i++)
  156.             Fib.fib$w_did[i]=Nam.nam$w_did[i];
  157. #endif
  158.  
  159.         /* Use the IO$_ACCESS function to return info about the file */
  160.         /* Note, used this way, the file is not opened, and the expiration */
  161.         /* and revision dates are not modified */
  162.         status = sys$qiow(0,DevChan,IO$_ACCESS,&iosb,0,0,
  163.                           &FibDesc,&FileName,0,0,&Atr,0);
  164.         if (!(status & 1)) return(status);
  165.         status = iosb[0];
  166.         if (!(status & 1)) return(status);
  167.  
  168. /* save...
  169.         if ((Cdate[0]==0) && (Cdate[1]==0))
  170.             printf("  /NO%s -\n",t_credate);
  171.         else
  172.             printf("  /%s=\"%s\" -\n",t_credate,cvt_time(Cdate));
  173.  
  174.         if ((Rdate[0]==0) && (Rdate[1]==0))
  175.             printf("  /NO%s",t_revdate);
  176.         else
  177.             printf("  /%s=\"%s\"",t_revdate,cvt_time(Rdate));
  178.  */
  179.  
  180. #if defined(VAX_COMPILE)
  181.         if (restore)                /* GRR unzip */
  182.             Fat.RTYPE.fat$v_rtype = old_rtype;
  183.         else {
  184.             old_rtype = Fat.RTYPE.fat$v_rtype;
  185.             Fat.RTYPE.fat$v_rtype = FAT$C_STREAMLF;   /* Unix I/O loves it */
  186.         }
  187. #else
  188.         if (restore)                /* GRR unzip */
  189.             Fat.fat$v_rtype = old_rtype;
  190.         else {
  191.             old_rtype = Fat.fat$v_rtype;
  192.             Fat.fat$v_rtype = FAT$C_STREAMLF;   /* Unix I/O loves it */
  193.         }
  194. #endif
  195.  
  196. /* save...
  197.         status = cli_present(t_credate);
  198.         if (status & 1) {
  199.             status = cli_get_value(t_credate,&retval);
  200.             bintim(retval,Cdate);
  201.         }
  202.         else
  203.             if ((status == CLI$_NEGATED) || (status == CLI$_LOCNEG)) {
  204.                 Cdate[0]=0;
  205.                 Cdate[1]=0;
  206.             };
  207.  
  208.         status = cli_present(t_revdate);
  209.         if (status & 1) {
  210.             status = cli_get_value(t_revdate,&retval);
  211.             bintim(retval,Rdate);
  212.         }
  213.         else
  214.             if ((status == CLI$_NEGATED) || (status == CLI$_LOCNEG)) {
  215.                 Rdate[0]=0;
  216.                 Rdate[1]=0;
  217.             };
  218.  */
  219.  
  220.  
  221.         /* note, part of the FIB was cleared by earlier QIOW, so reset it */
  222. #if defined(VAX_COMPILE)
  223.         Fib.fib$r_acctl_overlay.fib$l_acctl = FIB$M_NORECORD;
  224.         for (i=0;i<3;i++)
  225.             Fib.fib$r_fid_overlay.fib$w_fid[i]=Nam.nam$w_fid[i];
  226.         for (i=0;i<3;i++)
  227.             Fib.fib$r_did_overlay.fib$w_did[i]=Nam.nam$w_did[i];
  228. #else
  229.         Fib.fib$l_acctl = FIB$M_NORECORD;
  230.         for (i=0;i<3;i++)
  231.             Fib.fib$w_fid[i]=Nam.nam$w_fid[i];
  232.         for (i=0;i<3;i++)
  233.             Fib.fib$w_did[i]=Nam.nam$w_did[i];
  234. #endif
  235.  
  236.         /* Use the IO$_MODIFY function to change info about the file */
  237.         /* Note, used this way, the file is not opened, however this would */
  238.         /* normally cause the expiration and revision dates to be modified. */
  239.         /* Using FIB$M_NORECORD prohibits this from happening. */
  240.         status = sys$qiow(0,DevChan,IO$_MODIFY,&iosb,0,0,
  241.                           &FibDesc,&FileName,0,0,&Atr,0);
  242.         if (!(status & 1)) return(status);
  243.  
  244.         status = iosb[0];
  245.         if (!(status & 1)) return(status);
  246.  
  247.         status = sys$dassgn(DevChan);
  248.         if (!(status & 1)) return(status);
  249.  
  250.         /* look for next file, if none, no big deal.. */
  251.         status = sys$search(&Fab);
  252.     }
  253. } /* end function change_zipfile_attributes() */
  254.  
  255.  
  256. #if 0   /* save for possible later use */ 
  257.  
  258. char *cvt_time(date)
  259.   long int date[2];
  260. {
  261.   static char str[27];
  262.   static struct dsc$descriptor date_str={26,DSC$K_DTYPE_T,DSC$K_CLASS_S,&str};
  263.  
  264.   if ((date[0]==0) && (date[1]==0))
  265.     return("none");
  266.  
  267.   sys$asctim(0,&date_str,date,0);
  268.   str[26]='\0';
  269.  
  270.   return(&str);
  271. }
  272.  
  273. bintim(time,binval)
  274.   char *time;
  275.   long int binval[2];
  276. {
  277.   static struct dsc$descriptor date_str={0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0};
  278.   date_str.dsc$w_length = strlen(time);
  279.   date_str.dsc$a_pointer = time;
  280.  
  281.   sys$bintim(&date_str,binval);
  282. }
  283. #endif /* 0 */ 
  284.