home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip532.zip / aosvs / aosvs.c next >
C/C++ Source or Header  |  1997-10-21  |  45KB  |  1,327 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   aosvs.c
  4.  
  5.   AOS/VS-specific routines for use with Info-ZIP's UnZip 5.2 and later.
  6. [GRR:  copied from unix.c -> undoubtedly has unnecessary stuff: delete at will]
  7.  
  8.   Contains:  readdir()
  9.              do_wild()
  10.              open_outfile()
  11.              mapattr()
  12.              mapname()
  13.              checkdir()
  14.              screenlines()
  15.              close_outfile()
  16.              version()             <-- GRR:  needs work!  (Unix, not AOS/VS)
  17.              zvs_create()
  18.              zvs_credir()
  19.              ux_to_vs_name()
  20.              dgdate()
  21.  
  22.   ---------------------------------------------------------------------------*/
  23.  
  24.  
  25. #define UNZIP_INTERNAL
  26. #include "unzip.h"
  27. #include "aosvs/aosvs.h"
  28. #include <packets/create.h>
  29. #include <sys_calls.h>
  30. #include <paru.h>
  31.  
  32. #define symlink(resname,linkname) \
  33.   zvs_create(linkname,-1L,-1L,-1L,ux_to_vs_name(vs_resname,resname),$FLNK,-1,-1)
  34.                                              *  file type */
  35.  
  36. #ifdef DIRENT
  37. #  include <dirent.h>
  38. #else
  39. #  ifdef SYSV
  40. #    ifdef SYSNDIR
  41. #      include <sys/ndir.h>
  42. #    else
  43. #      include <ndir.h>
  44. #    endif
  45. #  else /* !SYSV */
  46. #    ifndef NO_SYSDIR
  47. #      include <sys/dir.h>
  48. #    endif
  49. #  endif /* ?SYSV */
  50. #  ifndef dirent
  51. #    define dirent direct
  52. #  endif
  53. #endif /* ?DIRENT */
  54.  
  55. static int            created_dir;          /* used in mapname(), checkdir() */
  56. static int            renamed_fullpath;     /* ditto */
  57.  
  58. static ZEXTRAFLD      zzextrafld;           /* buffer for extra field containing
  59.                                              *  ?FSTAT packet & ACL buffer */
  60. static char           vs_resname[2*$MXPL];
  61. static char           vs_path[2*$MXPL];     /* buf for AOS/VS pathname */
  62. static char           Vs_path[512];         /* should be big enough [GRR: ?] */
  63. static P_CTIM         zztimeblock;          /* time block for file creation */
  64. static ZVSCREATE_STRU zzcreatepacket;       /* packet for sys_create(), any
  65.  
  66.  
  67. #ifndef SFX
  68. #ifdef NO_DIR                  /* for AT&T 3B1 */
  69.  
  70. #define opendir(path) fopen(path,"r")
  71. #define closedir(dir) fclose(dir)
  72. typedef FILE DIR;
  73.  
  74. /*
  75.  *  Apparently originally by Rich Salz.
  76.  *  Cleaned up and modified by James W. Birdsall.
  77.  */
  78. struct dirent *readdir(dirp)
  79.     DIR *dirp;
  80. {
  81.     static struct dirent entry;
  82.  
  83.     if (dirp == NULL)
  84.         return NULL;
  85.  
  86.     for (;;)
  87.         if (fread(&entry, sizeof (struct dirent), 1, dirp) == 0)
  88.             return (struct dirent *)NULL;
  89.         else if (entry.d_ino)
  90.             return &entry;
  91.  
  92. } /* end function readdir() */
  93.  
  94. #endif /* NO_DIR */
  95.  
  96.  
  97. /**********************/
  98. /* Function do_wild() */   /* for porting:  dir separator; match(ignore_case) */
  99. /**********************/
  100.  
  101. char *do_wild(__G__ wildspec)
  102.     __GDEF
  103.     char *wildspec;         /* only used first time on a given dir */
  104. {
  105.     static DIR *dir = (DIR *)NULL;
  106.     static char *dirname, *wildname, matchname[FILNAMSIZ];
  107.     static int firstcall=TRUE, have_dirname, dirnamelen;
  108.     struct dirent *file;
  109.  
  110.  
  111.     /* Even when we're just returning wildspec, we *always* do so in
  112.      * matchname[]--calling routine is allowed to append four characters
  113.      * to the returned string, and wildspec may be a pointer to argv[].
  114.      */
  115.     if (firstcall) {        /* first call:  must initialize everything */
  116.         firstcall = FALSE;
  117.  
  118.         /* break the wildspec into a directory part and a wildcard filename */
  119.         if ((wildname = strrchr(wildspec, '/')) == (char *)NULL) {
  120.             dirname = ".";
  121.             dirnamelen = 1;
  122.             have_dirname = FALSE;
  123.             wildname = wildspec;
  124.         } else {
  125.             ++wildname;     /* point at character after '/' */
  126.             dirnamelen = wildname - wildspec;
  127.             if ((dirname = (char *)malloc(dirnamelen+1)) == (char *)NULL) {
  128.                 Info(slide, 1, ((char *)slide,
  129.                   "warning:  cannot allocate wildcard buffers\n"));
  130.                 strcpy(matchname, wildspec);
  131.                 return matchname;   /* but maybe filespec was not a wildcard */
  132.             }
  133.             strncpy(dirname, wildspec, dirnamelen);
  134.             dirname[dirnamelen] = '\0';   /* terminate for strcpy below */
  135.             have_dirname = TRUE;
  136.         }
  137.  
  138.         if ((dir = opendir(dirname)) != (DIR *)NULL) {
  139.             while ((file = readdir(dir)) != (struct dirent *)NULL) {
  140.                 if (file->d_name[0] == '.' && wildname[0] != '.')
  141.                     continue;  /* Unix:  '*' and '?' do not match leading dot */
  142.                 if (match(file->d_name, wildname, 0)) {  /* 0 == case sens. */
  143.                     if (have_dirname) {
  144.                         strcpy(matchname, dirname);
  145.                         strcpy(matchname+dirnamelen, file->d_name);
  146.                     } else
  147.                         strcpy(matchname, file->d_name);
  148.                     return matchname;
  149.                 }
  150.             }
  151.             /* if we get to here directory is exhausted, so close it */
  152.             closedir(dir);
  153.             dir = (DIR *)NULL;
  154.         }
  155.  
  156.         /* return the raw wildspec in case that works (e.g., directory not
  157.          * searchable, but filespec was not wild and file is readable) */
  158.         strcpy(matchname, wildspec);
  159.         return matchname;
  160.     }
  161.  
  162.     /* last time through, might have failed opendir but returned raw wildspec */
  163.     if (dir == (DIR *)NULL) {
  164.         firstcall = TRUE;  /* nothing left to try--reset for new wildspec */
  165.         if (have_dirname)
  166.             free(dirname);
  167.         return (char *)NULL;
  168.     }
  169.  
  170.     /* If we've gotten this far, we've read and matched at least one entry
  171.      * successfully (in a previous call), so dirname has been copied into
  172.      * matchname already.
  173.      */
  174.     while ((file = readdir(dir)) != (struct dirent *)NULL)
  175.         if (match(file->d_name, wildname, 0)) {   /* 0 == don't ignore case */
  176.             if (have_dirname) {
  177.                 /* strcpy(matchname, dirname); */
  178.                 strcpy(matchname+dirnamelen, file->d_name);
  179.             } else
  180.                 strcpy(matchname, file->d_name);
  181.             return matchname;
  182.         }
  183.  
  184.     closedir(dir);     /* have read at least one dir entry; nothing left */
  185.     dir = (DIR *)NULL;
  186.     firstcall = TRUE;  /* reset for new wildspec */
  187.     if (have_dirname)
  188.         free(dirname);
  189.     return (char *)NULL;
  190.  
  191. } /* end function do_wild() */
  192.  
  193. #endif /* !SFX */
  194.  
  195.  
  196.  
  197.  
  198.  
  199. /***************************/
  200. /* Function open_outfile() */
  201. /***************************/
  202.  
  203. int open_outfile(__G)         /* return 1 if fail */
  204.     __GDEF
  205. {
  206.     int errc = 1;    /* init to show no success with AOS/VS info */
  207.     long dmm, ddd, dyy, dhh, dmin, dss;
  208.  
  209.  
  210. #ifdef DLL
  211.     if (G.redirect_data)
  212.         return redirect_outfile(__G)==FALSE;
  213. #endif
  214.  
  215.     if (stat(G.filename, &G.statbuf) == 0 && unlink(G.filename) < 0) {
  216.         Info(slide, 0x401, ((char *)slide, LoadFarString(CannotDeleteOldFile),
  217.           G.filename));
  218.         return 1;
  219.     }
  220.  
  221. /*---------------------------------------------------------------------------
  222.     If the file didn't already exist, we created it earlier.  But we just
  223.     deleted it, which we still had to do in case we are overwriting an exis-
  224.     ting file.  So we must create it now, again, to set the creation time
  225.     properly.  (The creation time is the best functional approximation of
  226.     the Unix mtime.  Really!)
  227.  
  228.     If we stored this with an AOS/VS Zip that set the extra field to contain
  229.     the ?FSTAT packet and the ACL, we should use info from the ?FSTAT call
  230.     now.  Otherwise (or if that fails), we should create anyway as best we
  231.     can from the normal Zip info.
  232.  
  233.     In theory, we should look through an entire series of extra fields that
  234.     might exist for the same file, but we're not going to bother.  If we set
  235.     up other types of extra fields, or if other environments we run into may
  236.     add their own stuff to existing entries in Zip files, we'll have to.
  237.  
  238.     Note that all the packet types for sys_fstat() are the same size & mostly
  239.     have the same structure, with some fields being unused, etc.  Ditto for
  240.     sys_create().  Thus, we assume a normal one here, not a dir/cpd or device
  241.     or IPC file, & make little adjustments as necessary.  We will set ACLs
  242.     later (to reduce the chance of lacking access to what we create now); note
  243.     that for links the resolution name should be stored in the ACL field (once
  244.     we get Zip recognizing links OK).
  245.   ---------------------------------------------------------------------------*/
  246.  
  247.     if (G.extra_field != NULL) {
  248.         memcpy((char *) &zzextrafld, G.extra_field, sizeof(zzextrafld));
  249.         if (!memcmp(ZEXTRA_HEADID, zzextrafld.extra_header_id,
  250.                     sizeof(zzextrafld.extra_header_id))  &&
  251.             !memcmp(ZEXTRA_SENTINEL, zzextrafld.extra_sentinel),
  252.                     sizeof(zzextrafld.extra_sentinel))
  253.         {
  254.             zzcreatepacket.norm_create_packet.cftyp_format =
  255.               zzextrafld.fstat_packet.norm_fstat_packet.styp_format;
  256.             zzcreatepacket.norm_create_packet.cftyp_entry =
  257.               zzextrafld.fstat_packet.norm_fstat_packet.styp_type;
  258.  
  259.             /* for DIRS/CPDs, the next one will give the hash frame size; for
  260.              * IPCs it will give the port number */
  261.             zzcreatepacket.norm_create_packet.ccps =
  262.               zzextrafld.fstat_packet.norm_fstat_packet.scps;
  263.  
  264.             zzcreatepacket.norm_create_packet.ctim = &zztimeblock;
  265.             zztimeblock.tcth = zzextrafld.fstat_packet.norm_fstat_packet.stch;
  266.  
  267.             /* access & modification times default to current */
  268.             zztimeblock.tath.long_time = zztimeblock.tmth.long_time = -1;
  269.  
  270.             /* give it current process's ACL unless link; then give it
  271.              * resolution name */
  272.             zzcreatepacket.norm_create_packet.cacp = (char *)(-1);
  273.  
  274.             if (zzcreatepacket.norm_create_packet.cftyp_entry == $FLNK)
  275.                 zzcreatepacket.norm_create_packet.cacp = zzextrafld.aclbuf;
  276.  
  277.             zzcreatepacket.dir_create_packet.cmsh =
  278.               zzextrafld.fstat_packet.dir_fstat_packet.scsh;
  279.             if (zzcreatepacket.norm_create_packet.cftyp_entry != $FCPD) {
  280.                 /* element size for normal files */
  281.                 zzcreatepacket.norm_create_packet.cdel =
  282.                   zzextrafld.fstat_packet.norm_fstat_packet.sdeh;
  283.             }
  284.             zzcreatepacket.norm_create_packet.cmil =
  285.               zzextrafld.fstat_packet.norm_fstat_packet.smil;
  286.  
  287.             if ((errc = sys_create(ux_to_vs_name(vs_path, G.filename),
  288.                  &zzcreatepacket)) != 0)
  289.                 Info(slide, 0x201, ((char *)slide,
  290.                   "error creating %s with AOS/VS info -\n\
  291.                   will try again with ordinary Zip info\n", G.filename));
  292.         }
  293.     }
  294.  
  295.     /* do it the hard way if no AOS/VS info was stored or if we had problems */
  296.     if (errc) {
  297.         dmm = (G.lrec.last_mod_file_date >> 5) & 0x0f;
  298.         ddd = G.lrec.last_mod_file_date & 0x1f;
  299.         dyy = (G.lrec.last_mod_file_date >> 9) + 1980;
  300.         dhh = (G.lrec.last_mod_file_time >> 11) & 0x1f;
  301.         dmin = (G.lrec.last_mod_file_time >> 5) & 0x3f;
  302.         dss = (G.lrec.last_mod_file_time & 0x1f) * 2;
  303.  
  304.         if (zvs_create(G.filename, (((ulg)dgdate(dmm, ddd, dyy)) << 16) |
  305.             (dhh*1800L + dmin*30L + dss/2L), -1L, -1L, (char *) -1, -1, -1, -1))
  306.         {
  307.             Info(slide, 0x201, ((char *)slide, "error: %s: cannot create\n",
  308.               G.filename));
  309.             return 1;
  310.         }
  311.     }
  312.  
  313.     Trace((stderr, "open_outfile:  doing fopen(%s) for writing\n", G.filename));
  314.     if ((G.outfile = fopen(G.filename, FOPW)) == (FILE *)NULL) {
  315.         Info(slide, 0x401, ((char *)slide, LoadFarString(CannotCreateFile),
  316.           G.filename));
  317.         return 1;
  318.     }
  319.     Trace((stderr, "open_outfile:  fopen(%s) for writing succeeded\n",
  320.       G.filename));
  321.  
  322. #ifdef USE_FWRITE
  323. #ifdef _IOFBF  /* make output fully buffered (works just about like write()) */
  324.     setvbuf(G.outfile, (char *)slide, _IOFBF, WSIZE);
  325. #else
  326.     setbuf(G.outfile, (char *)slide);
  327. #endif
  328. #endif /* USE_FWRITE */
  329.     return 0;
  330.  
  331. } /* end function open_outfile() */
  332.  
  333.  
  334.  
  335.  
  336.  
  337. /**********************/
  338. /* Function mapattr() */
  339. /**********************/
  340.  
  341. int mapattr(__G)
  342.     __GDEF
  343. {
  344.     ulg tmp = G.crec.external_file_attributes;
  345.  
  346.     switch (G.pInfo->hostnum) {
  347.         case UNIX_:
  348.         case VMS_:
  349.         case ACORN_:
  350.         case ATARI_:
  351.         case BEOS_:
  352.         case QDOS_:
  353.             G.pInfo->file_attr = (unsigned)(tmp >> 16);
  354.             return 0;
  355.         case AMIGA_:
  356.             tmp = (unsigned)(tmp>>17 & 7);   /* Amiga RWE bits */
  357.             G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
  358.             break;
  359.         /* all remaining cases:  expand MSDOS read-only bit into write perms */
  360.         case FS_FAT_:
  361.         case FS_HPFS_:
  362.         case FS_NTFS_:
  363.         case MAC_:
  364.         case TOPS20_:
  365.         default:
  366.             tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */
  367.             G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
  368.             break;
  369.     } /* end switch (host-OS-created-by) */
  370.  
  371.     /* for originating systems with no concept of "group," "other," "system": */
  372.     umask( (int)(tmp=umask(0)) );    /* apply mask to expanded r/w(/x) perms */
  373.     G.pInfo->file_attr &= ~tmp;
  374.  
  375.     return 0;
  376.  
  377. } /* end function mapattr() */
  378.  
  379.  
  380.  
  381.  
  382.  
  383. /************************/
  384. /*  Function mapname()  */
  385. /************************/
  386.                              /* return 0 if no error, 1 if caution (filename */
  387. int mapname(__G__ renamed)   /*  truncated), 2 if warning (skip file because */
  388.     __GDEF                   /*  dir doesn't exist), 3 if error (skip file), */
  389.     int renamed;             /*  or 10 if out of memory (skip file) */
  390. {                            /*  [also IZ_VOL_LABEL, IZ_CREATED_DIR] */
  391.     char pathcomp[FILNAMSIZ];    /* path-component buffer */
  392.     char *pp, *cp=(char *)NULL;  /* character pointers */
  393.     char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */
  394.     int quote = FALSE;           /* flags */
  395.     int error = 0;
  396.     register unsigned workch;    /* hold the character being tested */
  397.  
  398.  
  399. /*---------------------------------------------------------------------------
  400.     Initialize various pointers and counters and stuff.
  401.   ---------------------------------------------------------------------------*/
  402.  
  403.     if (G.pInfo->vollabel)
  404.         return IZ_VOL_LABEL;    /* can't set disk volume labels in Unix */
  405.  
  406.     /* can create path as long as not just freshening, or if user told us */
  407.     G.create_dirs = (!G.fflag || renamed);
  408.  
  409.     created_dir = FALSE;        /* not yet */
  410.  
  411.     /* user gave full pathname:  don't prepend rootpath */
  412.     renamed_fullpath = (renamed && (*G.filename == '/'));
  413.  
  414.     if (checkdir(__G__ (char *)NULL, INIT) == 10)
  415.         return 10;              /* initialize path buffer, unless no memory */
  416.  
  417.     *pathcomp = '\0';           /* initialize translation buffer */
  418.     pp = pathcomp;              /* point to translation buffer */
  419.     if (G.jflag)                /* junking directories */
  420.         cp = (char *)strrchr(G.filename, '/');
  421.     if (cp == (char *)NULL)     /* no '/' or not junking dirs */
  422.         cp = G.filename;        /* point to internal zipfile-member pathname */
  423.     else
  424.         ++cp;                   /* point to start of last component of path */
  425.  
  426. /*---------------------------------------------------------------------------
  427.     Begin main loop through characters in filename.
  428.   ---------------------------------------------------------------------------*/
  429.  
  430.     while ((workch = (uch)*cp++) != 0) {
  431.  
  432.         if (quote) {                 /* if character quoted, */
  433.             *pp++ = (char)workch;    /*  include it literally */
  434.             quote = FALSE;
  435.         } else
  436.             switch (workch) {
  437.             case '/':             /* can assume -j flag not given */
  438.                 *pp = '\0';
  439.                 if ((error = checkdir(__G__ pathcomp, APPEND_DIR)) > 1)
  440.                     return error;
  441.                 pp = pathcomp;    /* reset conversion buffer for next piece */
  442.                 lastsemi = (char *)NULL; /* leave directory semi-colons alone */
  443.                 break;
  444.  
  445.             case ';':             /* VMS version (or DEC-20 attrib?) */
  446.                 lastsemi = pp;
  447.                 *pp++ = ';';      /* keep for now; remove VMS ";##" */
  448.                 break;            /*  later, if requested */
  449.  
  450.             case '\026':          /* control-V quote for special chars */
  451.                 quote = TRUE;     /* set flag for next character */
  452.                 break;
  453.  
  454. #ifdef MTS
  455.             case ' ':             /* change spaces to underscore under */
  456.                 *pp++ = '_';      /*  MTS; leave as spaces under Unix */
  457.                 break;
  458. #endif
  459.  
  460.             default:
  461.                 /* allow European characters in filenames: */
  462.                 if (isprint(workch) || (128 <= workch && workch <= 254))
  463.                     *pp++ = (char)workch;
  464.             } /* end switch */
  465.  
  466.     } /* end while loop */
  467.  
  468.     *pp = '\0';                   /* done with pathcomp:  terminate it */
  469.  
  470.     /* if not saving them, remove VMS version numbers (appended ";###") */
  471.     if (!G.V_flag && lastsemi) {
  472.         pp = lastsemi + 1;
  473.         while (isdigit((uch)(*pp)))
  474.             ++pp;
  475.         if (*pp == '\0')          /* only digits between ';' and end:  nuke */
  476.             *lastsemi = '\0';
  477.     }
  478.  
  479. /*---------------------------------------------------------------------------
  480.     Report if directory was created (and no file to create:  filename ended
  481.     in '/'), check name to be sure it exists, and combine path and name be-
  482.     fore exiting.
  483.   ---------------------------------------------------------------------------*/
  484.  
  485.     if (G.filename[strlen(G.filename) - 1] == '/') {
  486.         checkdir(__G__ G.filename, GETPATH);
  487.         if (created_dir) {
  488.             if (QCOND2) {
  489.                 Info(slide, 0, ((char *)slide, "   creating: %s\n",
  490.                   G.filename));
  491.             }
  492.             return IZ_CREATED_DIR;   /* set dir time (note trailing '/') */
  493.         }
  494.         return 2;   /* dir existed already; don't look for data to extract */
  495.     }
  496.  
  497.     if (*pathcomp == '\0') {
  498.         Info(slide, 1, ((char *)slide, "mapname:  conversion of %s failed\n",
  499.           G.filename));
  500.         return 3;
  501.     }
  502.  
  503.     checkdir(__G__ pathcomp, APPEND_NAME);  /* returns 1 if truncated: care? */
  504.     checkdir(__G__ G.filename, GETPATH);
  505.  
  506.     return error;
  507.  
  508. } /* end function mapname() */
  509.  
  510.  
  511.  
  512.  
  513. #if 0  /*========== NOTES ==========*/
  514.  
  515.   extract-to dir:      a:path/
  516.   buildpath:           path1/path2/ ...   (NULL-terminated)
  517.   pathcomp:                filename
  518.  
  519.   mapname():
  520.     loop over chars in zipfile member name
  521.       checkdir(path component, COMPONENT | CREATEDIR) --> map as required?
  522.         (d:/tmp/unzip/)                    (disk:[tmp.unzip.)
  523.         (d:/tmp/unzip/jj/)                 (disk:[tmp.unzip.jj.)
  524.         (d:/tmp/unzip/jj/temp/)            (disk:[tmp.unzip.jj.temp.)
  525.     finally add filename itself and check for existence? (could use with rename)
  526.         (d:/tmp/unzip/jj/temp/msg.outdir)  (disk:[tmp.unzip.jj.temp]msg.outdir)
  527.     checkdir(name, GETPATH)     -->  copy path to name and free space
  528.  
  529. #endif /* 0 */
  530.  
  531.  
  532.  
  533.  
  534. /***********************/
  535. /* Function checkdir() */
  536. /***********************/
  537.  
  538. int checkdir(__G__ pathcomp, flag)
  539.     __GDEF
  540.     char *pathcomp;
  541.     int flag;
  542. /*
  543.  * returns:  1 - (on APPEND_NAME) truncated filename
  544.  *           2 - path doesn't exist, not allowed to create
  545.  *           3 - path doesn't exist, tried to create and failed; or
  546.  *               path exists and is not a directory, but is supposed to be
  547.  *           4 - path is too long
  548.  *          10 - can't allocate memory for filename buffers
  549.  */
  550. {
  551.     static int rootlen = 0;   /* length of rootpath */
  552.     static char *rootpath;    /* user's "extract-to" directory */
  553.     static char *buildpath;   /* full path (so far) to extracted file */
  554.     static char *end;         /* pointer to end of buildpath ('\0') */
  555.  
  556. #   define FN_MASK   7
  557. #   define FUNCTION  (flag & FN_MASK)
  558.  
  559.  
  560.  
  561. /*---------------------------------------------------------------------------
  562.     APPEND_DIR:  append the path component to the path being built and check
  563.     for its existence.  If doesn't exist and we are creating directories, do
  564.     so for this one; else signal success or error as appropriate.
  565.   ---------------------------------------------------------------------------*/
  566.  
  567.     if (FUNCTION == APPEND_DIR) {
  568.         int too_long = FALSE;
  569. #ifdef SHORT_NAMES
  570.         char *old_end = end;
  571. #endif
  572.  
  573.         Trace((stderr, "appending dir segment [%s]\n", pathcomp));
  574.         while ((*end = *pathcomp++) != '\0')
  575.             ++end;
  576. #ifdef SHORT_NAMES   /* path components restricted to 14 chars, typically */
  577.         if ((end-old_end) > FILENAME_MAX)  /* GRR:  proper constant? */
  578.             *(end = old_end + FILENAME_MAX) = '\0';
  579. #endif
  580.  
  581.         /* GRR:  could do better check, see if overrunning buffer as we go:
  582.          * check end-buildpath after each append, set warning variable if
  583.          * within 20 of FILNAMSIZ; then if var set, do careful check when
  584.          * appending.  Clear variable when begin new path. */
  585.  
  586.         if ((end-buildpath) > FILNAMSIZ-3)  /* need '/', one-char name, '\0' */
  587.             too_long = TRUE;                /* check if extracting directory? */
  588.         /* for AOS/VS, try to create so as to not use searchlist: */
  589.         if ( /*stat(buildpath, &G.statbuf)*/ 1) {
  590.             if (!G.create_dirs) { /* told not to create (freshening) */
  591.                 free(buildpath);
  592.                 return 2;         /* path doesn't exist:  nothing to do */
  593.             }
  594.             if (too_long) {
  595.                 Info(slide, 1, ((char *)slide,
  596.                   "checkdir error:  path too long: %s\n", buildpath));
  597.                 free(buildpath);
  598.                 return 4;         /* no room for filenames:  fatal */
  599.             }
  600.             /* create the directory */
  601.             if (zvs_credir(buildpath,-1L,-1L,-1L,(char *) -1,-1,0L,-1,-1) == -1)
  602.             {
  603.                 Info(slide, 1, ((char *)slide,
  604.                   "checkdir error:  cannot create %s\n\
  605.                  unable to process %s.\n", buildpath, G.filename));
  606.                 free(buildpath);
  607.                 return 3;      /* path didn't exist, tried to create, failed */
  608.             }
  609.             created_dir = TRUE;
  610.         } else if (!S_ISDIR(G.statbuf.st_mode)) {
  611.             Info(slide, 1, ((char *)slide, "checkdir error:  %s exists but is not directory\n\
  612.                  unable to process %s.\n", buildpath, G.filename));
  613.             free(buildpath);
  614.             return 3;          /* path existed but wasn't dir */
  615.         }
  616.         if (too_long) {
  617.             Info(slide, 1, ((char *)slide,
  618.               "checkdir error:  path too long: %s\n", buildpath));
  619.             free(buildpath);
  620.             return 4;         /* no room for filenames:  fatal */
  621.         }
  622.         *end++ = '/';
  623.         *end = '\0';
  624.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  625.         return 0;
  626.  
  627.     } /* end if (FUNCTION == APPEND_DIR) */
  628.  
  629. /*---------------------------------------------------------------------------
  630.     GETPATH:  copy full path to the string pointed at by pathcomp, and free
  631.     buildpath.
  632.   ---------------------------------------------------------------------------*/
  633.  
  634.     if (FUNCTION == GETPATH) {
  635.         strcpy(pathcomp, buildpath);
  636.         Trace((stderr, "getting and freeing path [%s]\n", pathcomp));
  637.         free(buildpath);
  638.         buildpath = end = (char *)NULL;
  639.         return 0;
  640.     }
  641.  
  642. /*---------------------------------------------------------------------------
  643.     APPEND_NAME:  assume the path component is the filename; append it and
  644.     return without checking for existence.
  645.   ---------------------------------------------------------------------------*/
  646.  
  647.     if (FUNCTION == APPEND_NAME) {
  648. #ifdef SHORT_NAMES
  649.         char *old_end = end;
  650. #endif
  651.  
  652.         Trace((stderr, "appending filename [%s]\n", pathcomp));
  653.         while ((*end = *pathcomp++) != '\0') {
  654.             ++end;
  655. #ifdef SHORT_NAMES  /* truncate name at 14 characters, typically */
  656.             if ((end-old_end) > FILENAME_MAX)      /* GRR:  proper constant? */
  657.                 *(end = old_end + FILENAME_MAX) = '\0';
  658. #endif
  659.             if ((end-buildpath) >= FILNAMSIZ) {
  660.                 *--end = '\0';
  661.                 Info(slide, 1, ((char *)slide,
  662.                   "checkdir warning:  path too long; truncating\n\
  663.                    %s\n                -> %s\n", G.filename, buildpath));
  664.                 return 1;   /* filename truncated */
  665.             }
  666.         }
  667.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  668.         return 0;  /* could check for existence here, prompt for new name... */
  669.     }
  670.  
  671. /*---------------------------------------------------------------------------
  672.     INIT:  allocate and initialize buffer space for the file currently being
  673.     extracted.  If file was renamed with an absolute path, don't prepend the
  674.     extract-to path.
  675.   ---------------------------------------------------------------------------*/
  676.  
  677. /* GRR:  for VMS and TOPS-20, add up to 13 to strlen */
  678.  
  679.     if (FUNCTION == INIT) {
  680.         Trace((stderr, "initializing buildpath to "));
  681.         if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1)) ==
  682.             (char *)NULL)
  683.             return 10;
  684.         if ((rootlen > 0) && !renamed_fullpath) {
  685.             strcpy(buildpath, rootpath);
  686.             end = buildpath + rootlen;
  687.         } else {
  688.             *buildpath = '\0';
  689.             end = buildpath;
  690.         }
  691.         Trace((stderr, "[%s]\n", buildpath));
  692.         return 0;
  693.     }
  694.  
  695. /*---------------------------------------------------------------------------
  696.     ROOT:  if appropriate, store the path in rootpath and create it if neces-
  697.     sary; else assume it's a zipfile member and return.  This path segment
  698.     gets used in extracting all members from every zipfile specified on the
  699.     command line.
  700.   ---------------------------------------------------------------------------*/
  701.  
  702. #if (!defined(SFX) || defined(SFX_EXDIR))
  703.     if (FUNCTION == ROOT) {
  704.         Trace((stderr, "initializing root path to [%s]\n", pathcomp));
  705.         if (pathcomp == (char *)NULL) {
  706.             rootlen = 0;
  707.             return 0;
  708.         }
  709.         if ((rootlen = strlen(pathcomp)) > 0) {
  710.             if (pathcomp[rootlen-1] == '/') {
  711.                 pathcomp[--rootlen] = '\0';
  712.             }
  713.             if (rootlen > 0 && (stat(pathcomp, &G.statbuf) ||
  714.                 !S_ISDIR(G.statbuf.st_mode)))       /* path does not exist */
  715.             {
  716.                 if (!G.create_dirs /* || iswild(pathcomp) */ ) {
  717.                     rootlen = 0;
  718.                     return 2;   /* skip (or treat as stored file) */
  719.                 }
  720.                 /* create the directory (could add loop here to scan pathcomp
  721.                  * and create more than one level, but why really necessary?) */
  722.                 if (zvs_credir(pathcomp,-1L,-1L,-1L,(char *) -1,-1,0L,-1,-1)
  723.                     == -1)
  724.                 {
  725.                     Info(slide, 1, ((char *)slide,
  726.                       "checkdir:  cannot create extraction directory: %s\n",
  727.                       pathcomp));
  728.                     rootlen = 0;   /* path didn't exist, tried to create, and */
  729.                     return 3;  /* failed:  file exists, or 2+ levels required */
  730.                 }
  731.             }
  732.             if ((rootpath = (char *)malloc(rootlen+2)) == (char *)NULL) {
  733.                 rootlen = 0;
  734.                 return 10;
  735.             }
  736.             strcpy(rootpath, pathcomp);
  737.             rootpath[rootlen++] = '/';
  738.             rootpath[rootlen] = '\0';
  739.             Trace((stderr, "rootpath now = [%s]\n", rootpath));
  740.         }
  741.         return 0;
  742.     }
  743. #endif /* !SFX || SFX_EXDIR */
  744.  
  745. /*---------------------------------------------------------------------------
  746.     END:  free rootpath, immediately prior to program exit.
  747.   ---------------------------------------------------------------------------*/
  748.  
  749.     if (FUNCTION == END) {
  750.         Trace((stderr, "freeing rootpath\n"));
  751.         if (rootlen > 0) {
  752.             free(rootpath);
  753.             rootlen = 0;
  754.         }
  755.         return 0;
  756.     }
  757.  
  758.     return 99;  /* should never reach */
  759.  
  760. } /* end function checkdir() */
  761.  
  762.  
  763.  
  764.  
  765.  
  766. #ifdef MORE
  767.  
  768. /**************************/
  769. /* Function screenlines() */
  770. /**************************/
  771.  
  772. int screenlines()
  773. {
  774.     char *envptr, *getenv();
  775.     int n;
  776.  
  777.     /* GRR:  this is overly simplistic; should use winsize struct and
  778.      * appropriate TIOCGWINSZ ioctl(), assuming exists on enough systems
  779.      */
  780.     envptr = getenv("LINES");
  781.     if (envptr == (char *)NULL || (n = atoi(envptr)) < 5)
  782.         return 24;   /* VT-100 assumed to be minimal hardware */
  783.     else
  784.         return n;
  785. }
  786.  
  787. #endif /* MORE */
  788.  
  789.  
  790.  
  791.  
  792.  
  793. /****************************/
  794. /* Function close_outfile() */
  795. /****************************/
  796.  
  797. void close_outfile(__G)    /* GRR: change to return PK-style warning level */
  798.     __GDEF
  799. {
  800.  
  801. /*---------------------------------------------------------------------------
  802.     If symbolic links are supported, allocate a storage area, put the uncom-
  803.     pressed "data" in it, and create the link.  Since we know it's a symbolic
  804.     link to start with, we shouldn't have to worry about overflowing unsigned
  805.     ints with unsigned longs.
  806.   ---------------------------------------------------------------------------*/
  807.  
  808. #ifdef SYMLINKS
  809.     if (G.symlnk) {
  810.         unsigned ucsize = (unsigned)G.lrec.ucsize;
  811.         char *linktarget = (char *)malloc((unsigned)G.lrec.ucsize+1);
  812.  
  813.         fclose(G.outfile);                      /* close "data" file... */
  814.         G.outfile = fopen(G.filename, FOPR);    /* ...and reopen for reading */
  815.         if (!linktarget || fread(linktarget, 1, ucsize, G.outfile) !=
  816.                            (int)ucsize)
  817.         {
  818.             Info(slide, 0x201, ((char *)slide,
  819.               "warning:  symbolic link (%s) failed\n", G.filename));
  820.             if (linktarget)
  821.                 free(linktarget);
  822.             fclose(G.outfile);
  823.             return;
  824.         }
  825.         fclose(G.outfile);                  /* close "data" file for good... */
  826.         unlink(G.filename);                 /* ...and delete it */
  827.         linktarget[ucsize] = '\0';
  828.         if (QCOND2)
  829.             Info(slide, 0, ((char *)slide, "-> %s ", linktarget));
  830.         if (symlink(linktarget, G.filename))  /* create the real link */
  831.             perror("symlink error");
  832.         free(linktarget);
  833.         return;                             /* can't set time on symlinks */
  834.     }
  835. #endif /* SYMLINKS */
  836.  
  837.     fclose(G.outfile);
  838.  
  839. /*---------------------------------------------------------------------------
  840.     Change the file permissions from default ones to those stored in the
  841.     zipfile.
  842.   ---------------------------------------------------------------------------*/
  843.  
  844. #ifndef NO_CHMOD
  845.     if (chmod(G.filename, 0xffff & G.pInfo->file_attr))
  846.         perror("chmod (file attributes) error");
  847. #endif
  848.  
  849. /*---------------------------------------------------------------------------
  850.     AOS/VS only allows setting file times at creation but has its own permis-
  851.     sions scheme which is better invoked here if the necessary information
  852.     was in fact stored.  In theory, we should look through an entire series
  853.     of extra fields that might exist for the same file, but we're not going
  854.     to bother.  If we set up other types of extra fields, or if we run into
  855.     other environments that add their own stuff to existing entries in ZIP
  856.     files, we'll have to.  NOTE:  already copied extra-field stuff into
  857.     zzextrafld structure when file was created.
  858.   ---------------------------------------------------------------------------*/
  859.  
  860.     if (G.extra_field != NULL) {
  861.         if (!memcmp(ZEXTRA_HEADID, zzextrafld.extra_header_id,
  862.                     sizeof(zzextrafld.extra_header_id))  &&
  863.             !memcmp(ZEXTRA_SENTINEL, zzextrafld.extra_sentinel,
  864.                     sizeof(zzextrafld.extra_sentinel))  &&
  865.             zzextrafld.fstat_packet.norm_fstat_packet.styp_type != $FLNK)
  866.             /* (AOS/VS links don't have ACLs) */
  867.         {
  868.             /* vs_path was set (in this case) when we created the file */
  869.             if (sys_sacl(vs_path, zzextrafld.aclbuf)) {
  870.                 Info(slide, 0x201, ((char *)slide,
  871.                   "error: cannot set ACL for %s\n", G.filename));
  872.                 perror("sys_sacl()");
  873.             }
  874.         }
  875.     }
  876. } /* end function close_outfile() */
  877.  
  878.  
  879.  
  880.  
  881. #ifndef SFX
  882.  
  883. /************************/
  884. /*  Function version()  */
  885. /************************/
  886.  
  887. void version(__G)
  888.     __GDEF
  889. {
  890. #if defined(CRAY) || defined(NX_CURRENT_COMPILER_RELEASE) || defined(NetBSD)
  891.     char buf1[40];
  892. #if defined(CRAY) || defined(NX_CURRENT_COMPILER_RELEASE)
  893.     char buf2[40];
  894. #endif
  895. #endif
  896.  
  897.     /* Pyramid, NeXT have problems with huge macro expansion, too:  no Info() */
  898.     sprintf((char *)slide, LoadFarString(CompiledWith),
  899.  
  900. #ifdef __GNUC__
  901. #  ifdef NX_CURRENT_COMPILER_RELEASE
  902.       (sprintf(buf1, "NeXT DevKit %d.%02d ", NX_CURRENT_COMPILER_RELEASE/100,
  903.         NX_CURRENT_COMPILER_RELEASE%100), buf1),
  904.       (strlen(__VERSION__) > 8)? "(gcc)" :
  905.         (sprintf(buf2, "(gcc %s)", __VERSION__), buf2),
  906. #  else
  907.       "gcc ", __VERSION__,
  908. #  endif
  909. #else
  910. #  if defined(CRAY) && defined(_RELEASE)
  911.       "cc ", (sprintf(buf1, "version %d", _RELEASE), buf1),
  912. #  else
  913. #  ifdef __VERSION__
  914.       "cc ", __VERSION__,
  915. #  else
  916.       "cc", "",
  917. #  endif
  918. #  endif
  919. #endif
  920.  
  921.       "Unix",
  922.  
  923. #if defined(sgi) || defined(__sgi)
  924.       " (Silicon Graphics IRIX)",
  925. #else
  926. #ifdef sun
  927. #  ifdef sparc
  928. #    ifdef __SVR4
  929.       " (Sun Sparc/Solaris)",
  930. #    else /* may or may not be SunOS */
  931.       " (Sun Sparc)",
  932. #    endif
  933. #  else
  934. #  if defined(sun386) || defined(i386)
  935.       " (Sun 386i)",
  936. #  else
  937. #  if defined(mc68020) || defined(__mc68020__)
  938.       " (Sun 3)",
  939. #  else /* mc68010 or mc68000:  Sun 2 or earlier */
  940.       " (Sun 2)",
  941. #  endif
  942. #  endif
  943. #  endif
  944. #else
  945. #ifdef __hpux
  946.       " (HP/UX)",
  947. #else
  948. #ifdef __osf__
  949.       " (DEC OSF/1)",
  950. #else
  951. #ifdef _AIX
  952.       " (IBM AIX)",
  953. #else
  954. #ifdef aiws
  955.       " (IBM RT/AIX)",
  956. #else
  957. #if defined(CRAY) || defined(cray)
  958. #  ifdef _UNICOS
  959.       (sprintf(buf2, " (Cray UNICOS release %d)", _UNICOS), buf2),
  960. #  else
  961.       " (Cray UNICOS)",
  962. #  endif
  963. #else
  964. #if defined(uts) || defined(UTS)
  965.       " (Amdahl UTS)",
  966. #else
  967. #ifdef NeXT
  968. #  ifdef mc68000
  969.       " (NeXTStep/black)",
  970. #  else
  971.       " (NeXTStep for Intel)",
  972. #  endif
  973. #else              /* the next dozen or so are somewhat order-dependent */
  974. #ifdef LINUX
  975. #  ifdef __ELF__
  976.       " (Linux ELF)",
  977. #  else
  978.       " (Linux a.out)",
  979. #  endif
  980. #else
  981. #ifdef MINIX
  982.       " (Minix)",
  983. #else
  984. #ifdef M_UNIX
  985.       " (SCO Unix)",
  986. #else
  987. #ifdef M_XENIX
  988.       " (SCO Xenix)",
  989. #else
  990. #ifdef __NetBSD__
  991. #  ifdef NetBSD0_8
  992.       (sprintf(buf1, " (NetBSD 0.8%c)", (char)(NetBSD0_8 - 1 + 'A')), buf1),
  993. #  else
  994. #  ifdef NetBSD0_9
  995.       (sprintf(buf1, " (NetBSD 0.9%c)", (char)(NetBSD0_9 - 1 + 'A')), buf1),
  996. #  else
  997. #  ifdef NetBSD1_0
  998.       (sprintf(buf1, " (NetBSD 1.0%c)", (char)(NetBSD1_0 - 1 + 'A')), buf1),
  999. #  else
  1000.       (BSD4_4 == 0.5)? " (NetBSD before 0.9)" : " (NetBSD 1.1 or later)",
  1001. #  endif
  1002. #  endif
  1003. #  endif
  1004. #else
  1005. #ifdef __FreeBSD__
  1006.       (BSD4_4 == 0.5)? " (FreeBSD 1.x)" : " (FreeBSD 2.0 or later)",
  1007. #else
  1008. #ifdef __bsdi__
  1009.       (BSD4_4 == 0.5)? " (BSD/386 1.0)" : " (BSD/386 1.1 or later)",
  1010. #else
  1011. #ifdef __386BSD__
  1012.       (BSD4_4 == 1)? " (386BSD, post-4.4 release)" : " (386BSD)",
  1013. #else
  1014. #if defined(i486) || defined(__i486) || defined(__i486__)
  1015.       " (Intel 486)",
  1016. #else
  1017. #if defined(i386) || defined(__i386) || defined(__i386__)
  1018.       " (Intel 386)",
  1019. #else
  1020. #ifdef pyr
  1021.       " (Pyramid)",
  1022. #else
  1023. #ifdef ultrix
  1024. #  ifdef mips
  1025.       " (DEC/MIPS)",
  1026. #  else
  1027. #  ifdef vax
  1028.       " (DEC/VAX)",
  1029. #  else /* __alpha? */
  1030.       " (DEC/Alpha)",
  1031. #  endif
  1032. #  endif
  1033. #else
  1034. #ifdef gould
  1035.       " (Gould)",
  1036. #else
  1037. #ifdef MTS
  1038.       " (MTS)",
  1039. #else
  1040. #ifdef __convexc__
  1041.       " (Convex)",
  1042. #else
  1043.       "",
  1044. #endif /* Convex */
  1045. #endif /* MTS */
  1046. #endif /* Gould */
  1047. #endif /* DEC */
  1048. #endif /* Pyramid */
  1049. #endif /* 386 */
  1050. #endif /* 486 */
  1051. #endif /* 386BSD */
  1052. #endif /* BSDI BSD/386 */
  1053. #endif /* NetBSD */
  1054. #endif /* FreeBSD */
  1055. #endif /* SCO Xenix */
  1056. #endif /* SCO Unix */
  1057. #endif /* Minix */
  1058. #endif /* Linux */
  1059. #endif /* NeXT */
  1060. #endif /* Amdahl */
  1061. #endif /* Cray */
  1062. #endif /* RT/AIX */
  1063. #endif /* AIX */
  1064. #endif /* OSF/1 */
  1065. #endif /* HP/UX */
  1066. #endif /* Sun */
  1067. #endif /* SGI */
  1068.  
  1069. #ifdef __DATE__
  1070.       " on ", __DATE__
  1071. #else
  1072.       "", ""
  1073. #endif
  1074.     );
  1075.  
  1076.     (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
  1077.  
  1078. } /* end function version() */
  1079.  
  1080. #endif /* !SFX */
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086. /* ===================================================================
  1087.  * ZVS_CREATE()
  1088.  * Function to create a file with specified times.  The times should be sent
  1089.  * as long ints in DG time format; use -1 to set to the current times.  You
  1090.  * may also specify a pointer to the ACL, the file type (see PARU.H, and do
  1091.  * not specify dirs or links), the element size, and the max index level.
  1092.  * For all of these parameters you may use -1 to specify the default.
  1093.  *
  1094.  * Returns 0 if no error, or the error code returned by ?CREATE.
  1095.  *
  1096.  *    HISTORY:
  1097.  *        15-dec-93 dbl
  1098.  *        31-may-94 dbl: added call to convert pathname to AOS/VS
  1099.  *
  1100.  *
  1101.  */
  1102.  
  1103. int zvs_create(char *fname, long cretim, long modtim, long acctim, char *pacl,
  1104.                int ftyp, int eltsize, int maxindlev)
  1105. {
  1106.     P_CREATE    pcr_stru;
  1107.     P_CTIM      pct_stru;
  1108.  
  1109.     pcr_stru.cftyp_format = 0;           /* unspecified record format */
  1110.     if (ftyp == -1)                      /* default file type to UNX */
  1111.         pcr_stru.cftyp_entry = $FUNX;
  1112.     else
  1113.         pcr_stru.cftyp_entry = ftyp;
  1114.     pcr_stru.ctim = &pct_stru;
  1115.     pcr_stru.cacp = pacl;
  1116.     pcr_stru.cdel = eltsize;
  1117.     pcr_stru.cmil = maxindlev;
  1118.  
  1119.     pct_stru.tcth.long_time = cretim;
  1120.     pct_stru.tath.long_time = acctim;
  1121.     pct_stru.tmth.long_time = modtim;
  1122.  
  1123.     return (sys_create(ux_to_vs_name(Vs_path, fname), &pcr_stru));
  1124.  
  1125. } /* end zvs_create() */
  1126.  
  1127.  
  1128.  
  1129. /* ===================================================================
  1130.  * ZVS_CREDIR()
  1131.  * Function to create a dir as specified.  The times should be sent
  1132.  * as long ints in DG time format; use -1 to set to the current times.  You
  1133.  * may also specify a pointer to the ACL, the file type (either $FDIR or $FCPD; see PARU.H),
  1134.  * the max # blocks (if a CPD), the hash frame size, and the max index level.
  1135.  * For all of these parameters (except for the CPD's maximum blocks),
  1136.  * you may use -1 to specify the default.
  1137.  *
  1138.  * (The System Call Dictionary says both that you may specify a
  1139.  * maximum-index-level value up to the maximum, with 0 for a contiguous
  1140.  * directory, and that 3 is always used for this whatever you specify.)
  1141.  *
  1142.  * If you specify anything other than CPD for the file type, DIR will
  1143.  * be used.
  1144.  *
  1145.  * Returns 0 if no error, or the error code returned by ?CREATE.
  1146.  *
  1147.  *    HISTORY:
  1148.  *        1-jun-94 dbl
  1149.  *
  1150.  *
  1151.  */
  1152.  
  1153. int zvs_credir(char *dname, long cretim, long modtim, long acctim, char *pacl, int ftyp, long maxblocks, int hashfsize, int maxindlev)
  1154. {
  1155.     P_CREATE_DIR    pcr_stru;
  1156.     P_CTIM          pct_stru;
  1157.  
  1158.     if (ftyp != $FCPD)                      /* default file type to UNX */
  1159.         pcr_stru.cftyp_entry = $FDIR;
  1160.     else
  1161.     {
  1162.         pcr_stru.cftyp_entry = ftyp;
  1163.         pcr_stru.cmsh = maxblocks;
  1164.     }
  1165.  
  1166.     pcr_stru.ctim = &pct_stru;
  1167.     pcr_stru.cacp = pacl;
  1168.     pcr_stru.chfs = hashfsize;
  1169.     pcr_stru.cmil = maxindlev;
  1170.  
  1171.     pct_stru.tcth.long_time = cretim;
  1172.     pct_stru.tath.long_time = acctim;
  1173.     pct_stru.tmth.long_time = modtim;
  1174.  
  1175.     return (sys_create(ux_to_vs_name(Vs_path, dname), &pcr_stru));
  1176.  
  1177. } /* end zvs_credir() */
  1178.  
  1179.  
  1180.  
  1181. /* ===================================================================
  1182.  * UX_TO_VS_NAME() - makes a somewhat dumb pass at converting a Unix
  1183.  *           filename to an AOS/VS filename.  This should
  1184.  *           be just about adequate to handle the results
  1185.  *           of similarly-simple AOS/VS-to-Unix conversions
  1186.  *           in the ZIP program.  It does not guarantee a
  1187.  *           legal AOS/VS filename for every Unix filename;
  1188.  *           conspicuous examples would be names with
  1189.  *           embedded ./ and ../ (which will receive no
  1190.  *           special treatment).
  1191.  *
  1192.  *       RETURNS: pointer to the result (which is an input parameter)
  1193.  *
  1194.  *       NOTE: calling code is responsible for making sure
  1195.  *           the output buffer is big enough!
  1196.  *
  1197.  *       HISTORY:
  1198.  *           31-may-94 dbl
  1199.  *
  1200.  */
  1201. char *ux_to_vs_name(char *outname, char *inname)
  1202. {
  1203.     char *ip=inname, *op=outname;
  1204.  
  1205.  
  1206.     if (ip[0] == '.') {
  1207.         if (ip[1] == '/') {
  1208.             *(op++) = '=';
  1209.             ip += 2;
  1210.         } else if (ip[1] == '.'  &&  ip[2] == '/') {
  1211.             *(op++) = '^';
  1212.             ip += 3;
  1213.         }
  1214.     }
  1215.  
  1216.     do {
  1217.         if (*ip == '/')
  1218.             *(op++) = ':';
  1219.         else if (strchr(
  1220.            "0123456789_$?.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
  1221.            *ip) != NULL)
  1222.         {
  1223.             *(op++) = *ip;
  1224.         } else
  1225.             *(op++) = '?';
  1226.  
  1227.     } while (*(ip++) != '\0');
  1228.  
  1229.     return outname;
  1230.  
  1231. } /* end ux_to_vs_name() */
  1232.  
  1233.  
  1234.  
  1235. /* =================================================================== */
  1236.  
  1237. /* DGDATE
  1238.    Two functions do encode/decode dates in DG system format.
  1239.  
  1240.    Usage:
  1241.     long value,year,month,day;
  1242.  
  1243.     value=dgdate(month,day,year);
  1244.     undgdate(value,&month,&day,&year);   [GRR:  not used in UnZip: removed]
  1245.  
  1246.    Notes:
  1247.  
  1248.    1. DG date functions only work on dates within the range
  1249.       Jan 1, 1968 through Dec 31, 2099.  I have tested these
  1250.       functions through the same range with exact agreement.
  1251.       For dates outside of that range, the DG system calls
  1252.       may return different values than these functions.
  1253.  
  1254.    2. dgundate() accepts values between 0 and 48213 inclusive.
  1255.       These correspond to 12/31/1967 and 12/31/2099.
  1256.  
  1257.    3. Both functions assume the data is in the native OS byte
  1258.       order.  So if you're reading or writing these fields from
  1259.       a file that has been passed between AOS/VS and PC-DOS you
  1260.       will need to swap byte order.
  1261.  
  1262.    4. With reference to byte order, the entire range of values
  1263.       supported by these functions will fit into an unsigned
  1264.       short int.  In most cases the input or output will be
  1265.       in that variable type.  You are better off casting the
  1266.       value to/from unsigned short so you only need to concern
  1267.       yourself with swapping two bytes instead of four.
  1268.  
  1269.   Written by: Stanley J. Gula
  1270.               US&T, Inc.
  1271.               529 Main Street, Suite 1
  1272.               Indian Orchard, MA 01151
  1273.               (413)-543-3672
  1274.               Copyright (c) 1990 US&T, Inc.
  1275.               All rights reserved.
  1276.  
  1277.               I hereby release these functions into the public
  1278.               domain.  You may use these routines freely as long
  1279.               as the US&T copyright remains intact in the source
  1280.               code.
  1281.  
  1282.               Stanley J. Gula     July 24, 1990
  1283. */
  1284.  
  1285. long motable[13]={0,31,59,90,120,151,181,212,243,273,304,334,365};
  1286.  
  1287. long yrtable[132]={
  1288.       366,  731, 1096, 1461, 1827, 2192, 2557, 2922, 3288, 3653,
  1289.      4018, 4383, 4749, 5114, 5479, 5844, 6210, 6575, 6940, 7305,
  1290.      7671, 8036, 8401, 8766, 9132, 9497, 9862,10227,10593,10958,
  1291.     11323,11688,12054,12419,12784,13149,13515,13880,14245,14610,
  1292.     14976,15341,15706,16071,16437,16802,17167,17532,17898,18263,
  1293.     18628,18993,19359,19724,20089,20454,20820,21185,21550,21915,
  1294.     22281,22646,23011,23376,23742,24107,24472,24837,25203,25568,
  1295.     25933,26298,26664,27029,27394,27759,28125,28490,28855,29220,
  1296.     29586,29951,30316,30681,31047,31412,31777,32142,32508,32873,
  1297.     33238,33603,33969,34334,34699,35064,35430,35795,36160,36525,
  1298.     36891,37256,37621,37986,38352,38717,39082,39447,39813,40178,
  1299.     40543,40908,41274,41639,42004,42369,42735,43100,43465,43830,
  1300.     44196,44561,44926,45291,45657,46022,46387,46752,47118,47483,
  1301.     47848,48213};
  1302.  
  1303. /* Given y,m,d return # of days since 12/31/67 */
  1304. long int dgdate(short mm, short dd, short yy)
  1305. {
  1306.     long int temp;
  1307.     short ytmp;
  1308.  
  1309.     if (mm<1 || mm>12 || dd<1 || dd>31 || yy<1968 || yy>2099)
  1310.         return 0L;
  1311.  
  1312.     /* Figure in whole years since 1968 + whole months plus days */
  1313.     temp=365L*(long)(yy-1968) + motable[mm-1] + (long)dd;
  1314.  
  1315.     /* Adjust for leap years - note we don't account for skipped leap
  1316.        year in years divisible by 1000 but not by 4000.  We're correct
  1317.        through the year 2099 */
  1318.     temp+=(yy-1965)/4;
  1319.  
  1320.     /* Correct for this year */
  1321.     /* In leap years, if date is 3/1 or later, bump */
  1322.     if ((yy%4==0) && (mm>2))
  1323.         temp++;
  1324.  
  1325.     return temp;
  1326. }
  1327.