home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip52.zip / aosvs / aosvs.c next >
C/C++ Source or Header  |  1996-04-20  |  44KB  |  1,318 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:  can't 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 which 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.             G.pInfo->file_attr = (unsigned)(tmp >> 16);
  350.             return 0;
  351.         case AMIGA_:
  352.             tmp = (unsigned)(tmp>>17 & 7);   /* Amiga RWE bits */
  353.             G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
  354.             break;
  355.         /* all remaining cases:  expand MSDOS read-only bit into write perms */
  356.         case FS_FAT_:
  357.         case FS_HPFS_:
  358.         case FS_NTFS_:
  359.         case MAC_:
  360.         case ATARI_:             /* (used to set = 0666) */
  361.         case TOPS20_:
  362.         default:
  363.             tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */
  364.             G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
  365.             break;
  366.     } /* end switch (host-OS-created-by) */
  367.  
  368.     /* for originating systems with no concept of "group," "other," "system": */
  369.     umask( (int)(tmp=umask(0)) );    /* apply mask to expanded r/w(/x) perms */
  370.     G.pInfo->file_attr &= ~tmp;
  371.  
  372.     return 0;
  373.  
  374. } /* end function mapattr() */
  375.  
  376.  
  377.  
  378.  
  379.  
  380. /************************/
  381. /*  Function mapname()  */
  382. /************************/
  383.  
  384. int mapname(__G__ renamed)   /* return 0 if no error, 1 if caution (filename */
  385.     __GDEF                   /* truncated), 2 if warning (skip file because  */
  386.     int renamed;             /* dir doesn't exist), 3 if error (skip file),  */
  387. {                            /* 10 if no memory (skip file) */
  388.     char pathcomp[FILNAMSIZ];    /* path-component buffer */
  389.     char *pp, *cp=(char *)NULL;  /* character pointers */
  390.     char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */
  391.     int quote = FALSE;           /* flags */
  392.     int error = 0;
  393.     register unsigned workch;    /* hold the character being tested */
  394.  
  395.  
  396. /*---------------------------------------------------------------------------
  397.     Initialize various pointers and counters and stuff.
  398.   ---------------------------------------------------------------------------*/
  399.  
  400.     if (G.pInfo->vollabel)
  401.         return IZ_VOL_LABEL;    /* can't set disk volume labels in Unix */
  402.  
  403.     /* can create path as long as not just freshening, or if user told us */
  404.     G.create_dirs = (!G.fflag || renamed);
  405.  
  406.     created_dir = FALSE;        /* not yet */
  407.  
  408.     /* user gave full pathname:  don't prepend rootpath */
  409.     renamed_fullpath = (renamed && (*G.filename == '/'));
  410.  
  411.     if (checkdir(__G__ (char *)NULL, INIT) == 10)
  412.         return 10;              /* initialize path buffer, unless no memory */
  413.  
  414.     *pathcomp = '\0';           /* initialize translation buffer */
  415.     pp = pathcomp;              /* point to translation buffer */
  416.     if (G.jflag)                /* junking directories */
  417.         cp = (char *)strrchr(G.filename, '/');
  418.     if (cp == (char *)NULL)     /* no '/' or not junking dirs */
  419.         cp = G.filename;        /* point to internal zipfile-member pathname */
  420.     else
  421.         ++cp;                   /* point to start of last component of path */
  422.  
  423. /*---------------------------------------------------------------------------
  424.     Begin main loop through characters in filename.
  425.   ---------------------------------------------------------------------------*/
  426.  
  427.     while ((workch = (uch)*cp++) != 0) {
  428.  
  429.         if (quote) {                 /* if character quoted, */
  430.             *pp++ = (char)workch;    /*  include it literally */
  431.             quote = FALSE;
  432.         } else
  433.             switch (workch) {
  434.             case '/':             /* can assume -j flag not given */
  435.                 *pp = '\0';
  436.                 if ((error = checkdir(__G__ pathcomp, APPEND_DIR)) > 1)
  437.                     return error;
  438.                 pp = pathcomp;    /* reset conversion buffer for next piece */
  439.                 lastsemi = (char *)NULL; /* leave directory semi-colons alone */
  440.                 break;
  441.  
  442.             case ';':             /* VMS version (or DEC-20 attrib?) */
  443.                 lastsemi = pp;
  444.                 *pp++ = ';';      /* keep for now; remove VMS ";##" */
  445.                 break;            /*  later, if requested */
  446.  
  447.             case '\026':          /* control-V quote for special chars */
  448.                 quote = TRUE;     /* set flag for next character */
  449.                 break;
  450.  
  451. #ifdef MTS
  452.             case ' ':             /* change spaces to underscore under */
  453.                 *pp++ = '_';      /*  MTS; leave as spaces under Unix */
  454.                 break;
  455. #endif
  456.  
  457.             default:
  458.                 /* allow European characters in filenames: */
  459.                 if (isprint(workch) || (128 <= workch && workch <= 254))
  460.                     *pp++ = (char)workch;
  461.             } /* end switch */
  462.  
  463.     } /* end while loop */
  464.  
  465.     *pp = '\0';                   /* done with pathcomp:  terminate it */
  466.  
  467.     /* if not saving them, remove VMS version numbers (appended ";###") */
  468.     if (!G.V_flag && lastsemi) {
  469.         pp = lastsemi + 1;
  470.         while (isdigit((uch)(*pp)))
  471.             ++pp;
  472.         if (*pp == '\0')          /* only digits between ';' and end:  nuke */
  473.             *lastsemi = '\0';
  474.     }
  475.  
  476. /*---------------------------------------------------------------------------
  477.     Report if directory was created (and no file to create:  filename ended
  478.     in '/'), check name to be sure it exists, and combine path and name be-
  479.     fore exiting.
  480.   ---------------------------------------------------------------------------*/
  481.  
  482.     if (G.filename[strlen(G.filename) - 1] == '/') {
  483.         checkdir(__G__ G.filename, GETPATH);
  484.         if (created_dir && QCOND2) {
  485.             Info(slide, 0, ((char *)slide, "   creating: %s\n", G.filename));
  486.             return IZ_CREATED_DIR;   /* set dir time (note trailing '/') */
  487.         }
  488.         return 2;   /* dir existed already; don't look for data to extract */
  489.     }
  490.  
  491.     if (*pathcomp == '\0') {
  492.         Info(slide, 1, ((char *)slide, "mapname:  conversion of %s failed\n",
  493.           G.filename));
  494.         return 3;
  495.     }
  496.  
  497.     checkdir(__G__ pathcomp, APPEND_NAME);   /* returns 1 if truncated: care? */
  498.     checkdir(__G__ G.filename, GETPATH);
  499.  
  500.     return error;
  501.  
  502. } /* end function mapname() */
  503.  
  504.  
  505.  
  506.  
  507. #if 0  /*========== NOTES ==========*/
  508.  
  509.   extract-to dir:      a:path/
  510.   buildpath:           path1/path2/ ...   (NULL-terminated)
  511.   pathcomp:                filename
  512.  
  513.   mapname():
  514.     loop over chars in zipfile member name
  515.       checkdir(path component, COMPONENT | CREATEDIR) --> map as required?
  516.         (d:/tmp/unzip/)                    (disk:[tmp.unzip.)
  517.         (d:/tmp/unzip/jj/)                 (disk:[tmp.unzip.jj.)
  518.         (d:/tmp/unzip/jj/temp/)            (disk:[tmp.unzip.jj.temp.)
  519.     finally add filename itself and check for existence? (could use with rename)
  520.         (d:/tmp/unzip/jj/temp/msg.outdir)  (disk:[tmp.unzip.jj.temp]msg.outdir)
  521.     checkdir(name, COPYFREE)     -->  copy path to name and free space
  522.  
  523. #endif /* 0 */
  524.  
  525.  
  526.  
  527.  
  528. /***********************/
  529. /* Function checkdir() */
  530. /***********************/
  531.  
  532. int checkdir(__G__ pathcomp, flag)
  533.     __GDEF
  534.     char *pathcomp;
  535.     int flag;
  536. /*
  537.  * returns:  1 - (on APPEND_NAME) truncated filename
  538.  *           2 - path doesn't exist, not allowed to create
  539.  *           3 - path doesn't exist, tried to create and failed; or
  540.  *               path exists and is not a directory, but is supposed to be
  541.  *           4 - path is too long
  542.  *          10 - can't allocate memory for filename buffers
  543.  */
  544. {
  545.     static int rootlen = 0;   /* length of rootpath */
  546.     static char *rootpath;    /* user's "extract-to" directory */
  547.     static char *buildpath;   /* full path (so far) to extracted file */
  548.     static char *end;         /* pointer to end of buildpath ('\0') */
  549.  
  550. #   define FN_MASK   7
  551. #   define FUNCTION  (flag & FN_MASK)
  552.  
  553.  
  554.  
  555. /*---------------------------------------------------------------------------
  556.     APPEND_DIR:  append the path component to the path being built and check
  557.     for its existence.  If doesn't exist and we are creating directories, do
  558.     so for this one; else signal success or error as appropriate.
  559.   ---------------------------------------------------------------------------*/
  560.  
  561.     if (FUNCTION == APPEND_DIR) {
  562.         int too_long = FALSE;
  563. #ifdef SHORT_NAMES
  564.         char *old_end = end;
  565. #endif
  566.  
  567.         Trace((stderr, "appending dir segment [%s]\n", pathcomp));
  568.         while ((*end = *pathcomp++) != '\0')
  569.             ++end;
  570. #ifdef SHORT_NAMES   /* path components restricted to 14 chars, typically */
  571.         if ((end-old_end) > FILENAME_MAX)  /* GRR:  proper constant? */
  572.             *(end = old_end + FILENAME_MAX) = '\0';
  573. #endif
  574.  
  575.         /* GRR:  could do better check, see if overrunning buffer as we go:
  576.          * check end-buildpath after each append, set warning variable if
  577.          * within 20 of FILNAMSIZ; then if var set, do careful check when
  578.          * appending.  Clear variable when begin new path. */
  579.  
  580.         if ((end-buildpath) > FILNAMSIZ-3)  /* need '/', one-char name, '\0' */
  581.             too_long = TRUE;                /* check if extracting directory? */
  582.         /* for AOS/VS, try to create so as to not use searchlist: */
  583.         if ( /*stat(buildpath, &G.statbuf)*/ 1) {
  584.             if (!G.create_dirs) { /* told not to create (freshening) */
  585.                 free(buildpath);
  586.                 return 2;         /* path doesn't exist:  nothing to do */
  587.             }
  588.             if (too_long) {
  589.                 Info(slide, 1, ((char *)slide,
  590.                   "checkdir error:  path too long: %s\n", buildpath));
  591.                 free(buildpath);
  592.                 return 4;         /* no room for filenames:  fatal */
  593.             }
  594.             /* create the directory */
  595.             if (zvs_credir(buildpath,-1L,-1L,-1L,(char *) -1,-1,0L,-1,-1) == -1)
  596.             {
  597.                 Info(slide, 1, ((char *)slide,
  598.                   "checkdir error:  can't create %s\n\
  599.                  unable to process %s.\n", buildpath, G.filename));
  600.                 free(buildpath);
  601.                 return 3;      /* path didn't exist, tried to create, failed */
  602.             }
  603.             created_dir = TRUE;
  604.         } else if (!S_ISDIR(G.statbuf.st_mode)) {
  605.             Info(slide, 1, ((char *)slide, "checkdir error:  %s exists but is not directory\n\
  606.                  unable to process %s.\n", buildpath, G.filename));
  607.             free(buildpath);
  608.             return 3;          /* path existed but wasn't dir */
  609.         }
  610.         if (too_long) {
  611.             Info(slide, 1, ((char *)slide,
  612.               "checkdir error:  path too long: %s\n", buildpath));
  613.             free(buildpath);
  614.             return 4;         /* no room for filenames:  fatal */
  615.         }
  616.         *end++ = '/';
  617.         *end = '\0';
  618.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  619.         return 0;
  620.  
  621.     } /* end if (FUNCTION == APPEND_DIR) */
  622.  
  623. /*---------------------------------------------------------------------------
  624.     GETPATH:  copy full path to the string pointed at by pathcomp, and free
  625.     buildpath.
  626.   ---------------------------------------------------------------------------*/
  627.  
  628.     if (FUNCTION == GETPATH) {
  629.         strcpy(pathcomp, buildpath);
  630.         Trace((stderr, "getting and freeing path [%s]\n", pathcomp));
  631.         free(buildpath);
  632.         buildpath = end = (char *)NULL;
  633.         return 0;
  634.     }
  635.  
  636. /*---------------------------------------------------------------------------
  637.     APPEND_NAME:  assume the path component is the filename; append it and
  638.     return without checking for existence.
  639.   ---------------------------------------------------------------------------*/
  640.  
  641.     if (FUNCTION == APPEND_NAME) {
  642. #ifdef SHORT_NAMES
  643.         char *old_end = end;
  644. #endif
  645.  
  646.         Trace((stderr, "appending filename [%s]\n", pathcomp));
  647.         while ((*end = *pathcomp++) != '\0') {
  648.             ++end;
  649. #ifdef SHORT_NAMES  /* truncate name at 14 characters, typically */
  650.             if ((end-old_end) > FILENAME_MAX)      /* GRR:  proper constant? */
  651.                 *(end = old_end + FILENAME_MAX) = '\0';
  652. #endif
  653.             if ((end-buildpath) >= FILNAMSIZ) {
  654.                 *--end = '\0';
  655.                 Info(slide, 1, ((char *)slide,
  656.                   "checkdir warning:  path too long; truncating\n\
  657.                    %s\n                -> %s\n", G.filename, buildpath));
  658.                 return 1;   /* filename truncated */
  659.             }
  660.         }
  661.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  662.         return 0;  /* could check for existence here, prompt for new name... */
  663.     }
  664.  
  665. /*---------------------------------------------------------------------------
  666.     INIT:  allocate and initialize buffer space for the file currently being
  667.     extracted.  If file was renamed with an absolute path, don't prepend the
  668.     extract-to path.
  669.   ---------------------------------------------------------------------------*/
  670.  
  671. /* GRR:  for VMS and TOPS-20, add up to 13 to strlen */
  672.  
  673.     if (FUNCTION == INIT) {
  674.         Trace((stderr, "initializing buildpath to "));
  675.         if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1)) ==
  676.             (char *)NULL)
  677.             return 10;
  678.         if ((rootlen > 0) && !renamed_fullpath) {
  679.             strcpy(buildpath, rootpath);
  680.             end = buildpath + rootlen;
  681.         } else {
  682.             *buildpath = '\0';
  683.             end = buildpath;
  684.         }
  685.         Trace((stderr, "[%s]\n", buildpath));
  686.         return 0;
  687.     }
  688.  
  689. /*---------------------------------------------------------------------------
  690.     ROOT:  if appropriate, store the path in rootpath and create it if neces-
  691.     sary; else assume it's a zipfile member and return.  This path segment
  692.     gets used in extracting all members from every zipfile specified on the
  693.     command line.
  694.   ---------------------------------------------------------------------------*/
  695.  
  696. #if (!defined(SFX) || defined(SFX_EXDIR))
  697.     if (FUNCTION == ROOT) {
  698.         Trace((stderr, "initializing root path to [%s]\n", pathcomp));
  699.         if (pathcomp == (char *)NULL) {
  700.             rootlen = 0;
  701.             return 0;
  702.         }
  703.         if ((rootlen = strlen(pathcomp)) > 0) {
  704.             if (pathcomp[rootlen-1] == '/') {
  705.                 pathcomp[--rootlen] = '\0';
  706.             }
  707.             if (rootlen > 0 && (stat(pathcomp, &G.statbuf) ||
  708.                 !S_ISDIR(G.statbuf.st_mode)))       /* path does not exist */
  709.             {
  710.                 if (!G.create_dirs /* || iswild(pathcomp) */ ) {
  711.                     rootlen = 0;
  712.                     return 2;   /* skip (or treat as stored file) */
  713.                 }
  714.                 /* create the directory (could add loop here to scan pathcomp
  715.                  * and create more than one level, but why really necessary?) */
  716.                 if (zvs_credir(pathcomp,-1L,-1L,-1L,(char *) -1,-1,0L,-1,-1)
  717.                     == -1)
  718.                 {
  719.                     Info(slide, 1, ((char *)slide,
  720.                       "checkdir:  can't create extraction directory: %s\n",
  721.                       pathcomp));
  722.                     rootlen = 0;   /* path didn't exist, tried to create, and */
  723.                     return 3;  /* failed:  file exists, or 2+ levels required */
  724.                 }
  725.             }
  726.             if ((rootpath = (char *)malloc(rootlen+2)) == (char *)NULL) {
  727.                 rootlen = 0;
  728.                 return 10;
  729.             }
  730.             strcpy(rootpath, pathcomp);
  731.             rootpath[rootlen++] = '/';
  732.             rootpath[rootlen] = '\0';
  733.             Trace((stderr, "rootpath now = [%s]\n", rootpath));
  734.         }
  735.         return 0;
  736.     }
  737. #endif /* !SFX || SFX_EXDIR */
  738.  
  739. /*---------------------------------------------------------------------------
  740.     END:  free rootpath, immediately prior to program exit.
  741.   ---------------------------------------------------------------------------*/
  742.  
  743.     if (FUNCTION == END) {
  744.         Trace((stderr, "freeing rootpath\n"));
  745.         if (rootlen > 0)
  746.             free(rootpath);
  747.         return 0;
  748.     }
  749.  
  750.     return 99;  /* should never reach */
  751.  
  752. } /* end function checkdir() */
  753.  
  754.  
  755.  
  756.  
  757.  
  758. #ifdef MORE
  759.  
  760. /**************************/
  761. /* Function screenlines() */
  762. /**************************/
  763.  
  764. int screenlines()
  765. {
  766.     char *envptr, *getenv();
  767.     int n;
  768.  
  769.     /* GRR:  this is overly simplistic; should use winsize struct and
  770.      * appropriate TIOCGWINSZ ioctl(), assuming exists on enough systems
  771.      */
  772.     envptr = getenv("LINES");
  773.     if (envptr == (char *)NULL || (n = atoi(envptr)) < 5)
  774.         return 24;   /* VT-100 assumed to be minimal hardware */
  775.     else
  776.         return n;
  777. }
  778.  
  779. #endif /* MORE */
  780.  
  781.  
  782.  
  783.  
  784.  
  785. /****************************/
  786. /* Function close_outfile() */
  787. /****************************/
  788.  
  789. void close_outfile(__G)    /* GRR: change to return PK-style warning level */
  790.     __GDEF
  791. {
  792.  
  793. /*---------------------------------------------------------------------------
  794.     If symbolic links are supported, allocate a storage area, put the uncom-
  795.     pressed "data" in it, and create the link.  Since we know it's a symbolic
  796.     link to start with, we shouldn't have to worry about overflowing unsigned
  797.     ints with unsigned longs.
  798.   ---------------------------------------------------------------------------*/
  799.  
  800. #ifdef SYMLINKS
  801.     if (G.symlnk) {
  802.         unsigned ucsize = (unsigned)G.lrec.ucsize;
  803.         char *linktarget = (char *)malloc((unsigned)G.lrec.ucsize+1);
  804.  
  805.         fclose(G.outfile);                      /* close "data" file... */
  806.         G.outfile = fopen(G.filename, FOPR);    /* ...and reopen for reading */
  807.         if (!linktarget || fread(linktarget, 1, ucsize, G.outfile) !=
  808.                            (int)ucsize)
  809.         {
  810.             Info(slide, 0x201, ((char *)slide,
  811.               "warning:  symbolic link (%s) failed\n", G.filename));
  812.             if (linktarget)
  813.                 free(linktarget);
  814.             fclose(G.outfile);
  815.             return;
  816.         }
  817.         fclose(G.outfile);                  /* close "data" file for good... */
  818.         unlink(G.filename);                 /* ...and delete it */
  819.         linktarget[ucsize] = '\0';
  820.         Info(slide, 0, ((char *)slide, "-> %s ", linktarget));
  821.         if (symlink(linktarget, G.filename))  /* create the real link */
  822.             perror("symlink error");
  823.         free(linktarget);
  824.         return;                             /* can't set time on symlinks */
  825.     }
  826. #endif /* SYMLINKS */
  827.  
  828.     fclose(G.outfile);
  829.  
  830. /*---------------------------------------------------------------------------
  831.     Change the file permissions from default ones to those stored in the
  832.     zipfile.
  833.   ---------------------------------------------------------------------------*/
  834.  
  835. #ifndef NO_CHMOD
  836.     if (chmod(G.filename, 0xffff & G.pInfo->file_attr))
  837.         perror("chmod (file attributes) error");
  838. #endif
  839.  
  840. /*---------------------------------------------------------------------------
  841.     AOS/VS only allows setting file times at creation but has its own permis-
  842.     sions scheme which is better invoked here if the necessary information
  843.     was in fact stored.  In theory, we should look through an entire series
  844.     of extra fields that might exist for the same file, but we're not going
  845.     to bother.  If we set up other types of extra fields, or if we run into
  846.     other environments that add their own stuff to existing entries in ZIP
  847.     files, we'll have to.  NOTE:  already copied extra-field stuff into
  848.     zzextrafld structure when file was created.
  849.   ---------------------------------------------------------------------------*/
  850.  
  851.     if (G.extra_field != NULL) {
  852.         if (!memcmp(ZEXTRA_HEADID, zzextrafld.extra_header_id,
  853.                     sizeof(zzextrafld.extra_header_id))  &&
  854.             !memcmp(ZEXTRA_SENTINEL, zzextrafld.extra_sentinel,
  855.                     sizeof(zzextrafld.extra_sentinel))  &&
  856.             zzextrafld.fstat_packet.norm_fstat_packet.styp_type != $FLNK)
  857.             /* (AOS/VS links don't have ACLs) */
  858.         {
  859.             /* vs_path was set (in this case) when we created the file */
  860.             if (sys_sacl(vs_path, zzextrafld.aclbuf)) {
  861.                 Info(slide, 0x201, ((char *)slide,
  862.                   "error: can't set ACL for %s\n", G.filename));
  863.                 perror("sys_sacl()");
  864.             }
  865.         }
  866.     }
  867. } /* end function close_outfile() */
  868.  
  869.  
  870.  
  871.  
  872. #ifndef SFX
  873.  
  874. /************************/
  875. /*  Function version()  */
  876. /************************/
  877.  
  878. void version(__G)
  879.     __GDEF
  880. {
  881. #if defined(CRAY) || defined(NX_CURRENT_COMPILER_RELEASE) || defined(NetBSD)
  882.     char buf1[40];
  883. #if defined(CRAY) || defined(NX_CURRENT_COMPILER_RELEASE)
  884.     char buf2[40];
  885. #endif
  886. #endif
  887.  
  888.     /* Pyramid, NeXT have problems with huge macro expansion, too:  no Info() */
  889.     sprintf((char *)slide, LoadFarString(CompiledWith),
  890.  
  891. #ifdef __GNUC__
  892. #  ifdef NX_CURRENT_COMPILER_RELEASE
  893.       (sprintf(buf1, "NeXT DevKit %d.%02d ", NX_CURRENT_COMPILER_RELEASE/100,
  894.         NX_CURRENT_COMPILER_RELEASE%100), buf1),
  895.       (strlen(__VERSION__) > 8)? "(gcc)" :
  896.         (sprintf(buf2, "(gcc %s)", __VERSION__), buf2),
  897. #  else
  898.       "gcc ", __VERSION__,
  899. #  endif
  900. #else
  901. #  if defined(CRAY) && defined(_RELEASE)
  902.       "cc ", (sprintf(buf1, "version %d", _RELEASE), buf1),
  903. #  else
  904. #  ifdef __VERSION__
  905.       "cc ", __VERSION__,
  906. #  else
  907.       "cc", "",
  908. #  endif
  909. #  endif
  910. #endif
  911.  
  912.       "Unix",
  913.  
  914. #if defined(sgi) || defined(__sgi)
  915.       " (Silicon Graphics IRIX)",
  916. #else
  917. #ifdef sun
  918. #  ifdef sparc
  919. #    ifdef __SVR4
  920.       " (Sun Sparc/Solaris)",
  921. #    else /* may or may not be SunOS */
  922.       " (Sun Sparc)",
  923. #    endif
  924. #  else
  925. #  if defined(sun386) || defined(i386)
  926.       " (Sun 386i)",
  927. #  else
  928. #  if defined(mc68020) || defined(__mc68020__)
  929.       " (Sun 3)",
  930. #  else /* mc68010 or mc68000:  Sun 2 or earlier */
  931.       " (Sun 2)",
  932. #  endif
  933. #  endif
  934. #  endif
  935. #else
  936. #ifdef __hpux
  937.       " (HP/UX)",
  938. #else
  939. #ifdef __osf__
  940.       " (DEC OSF/1)",
  941. #else
  942. #ifdef _AIX
  943.       " (IBM AIX)",
  944. #else
  945. #ifdef aiws
  946.       " (IBM RT/AIX)",
  947. #else
  948. #if defined(CRAY) || defined(cray)
  949. #  ifdef _UNICOS
  950.       (sprintf(buf2, " (Cray UNICOS release %d)", _UNICOS), buf2),
  951. #  else
  952.       " (Cray UNICOS)",
  953. #  endif
  954. #else
  955. #if defined(uts) || defined(UTS)
  956.       " (Amdahl UTS)",
  957. #else
  958. #ifdef NeXT
  959. #  ifdef mc68000
  960.       " (NeXTStep/black)",
  961. #  else
  962.       " (NeXTStep for Intel)",
  963. #  endif
  964. #else              /* the next dozen or so are somewhat order-dependent */
  965. #ifdef LINUX
  966. #  ifdef __ELF__
  967.       " (Linux ELF)",
  968. #  else
  969.       " (Linux a.out)",
  970. #  endif
  971. #else
  972. #ifdef MINIX
  973.       " (Minix)",
  974. #else
  975. #ifdef M_UNIX
  976.       " (SCO Unix)",
  977. #else
  978. #ifdef M_XENIX
  979.       " (SCO Xenix)",
  980. #else
  981. #ifdef __NetBSD__
  982. #  ifdef NetBSD0_8
  983.       (sprintf(buf1, " (NetBSD 0.8%c)", (char)(NetBSD0_8 - 1 + 'A')), buf1),
  984. #  else
  985. #  ifdef NetBSD0_9
  986.       (sprintf(buf1, " (NetBSD 0.9%c)", (char)(NetBSD0_9 - 1 + 'A')), buf1),
  987. #  else
  988. #  ifdef NetBSD1_0
  989.       (sprintf(buf1, " (NetBSD 1.0%c)", (char)(NetBSD1_0 - 1 + 'A')), buf1),
  990. #  else
  991.       (BSD4_4 == 0.5)? " (NetBSD before 0.9)" : " (NetBSD 1.1 or later)",
  992. #  endif
  993. #  endif
  994. #  endif
  995. #else
  996. #ifdef __FreeBSD__
  997.       (BSD4_4 == 0.5)? " (FreeBSD 1.x)" : " (FreeBSD 2.0 or later)",
  998. #else
  999. #ifdef __bsdi__
  1000.       (BSD4_4 == 0.5)? " (BSD/386 1.0)" : " (BSD/386 1.1 or later)",
  1001. #else
  1002. #ifdef __386BSD__
  1003.       (BSD4_4 == 1)? " (386BSD, post-4.4 release)" : " (386BSD)",
  1004. #else
  1005. #if defined(i486) || defined(__i486) || defined(__i486__)
  1006.       " (Intel 486)",
  1007. #else
  1008. #if defined(i386) || defined(__i386) || defined(__i386__)
  1009.       " (Intel 386)",
  1010. #else
  1011. #ifdef pyr
  1012.       " (Pyramid)",
  1013. #else
  1014. #ifdef ultrix
  1015. #  ifdef mips
  1016.       " (DEC/MIPS)",
  1017. #  else
  1018. #  ifdef vax
  1019.       " (DEC/VAX)",
  1020. #  else /* __alpha? */
  1021.       " (DEC/Alpha)",
  1022. #  endif
  1023. #  endif
  1024. #else
  1025. #ifdef gould
  1026.       " (Gould)",
  1027. #else
  1028. #ifdef MTS
  1029.       " (MTS)",
  1030. #else
  1031. #ifdef __convexc__
  1032.       " (Convex)",
  1033. #else
  1034.       "",
  1035. #endif /* Convex */
  1036. #endif /* MTS */
  1037. #endif /* Gould */
  1038. #endif /* DEC */
  1039. #endif /* Pyramid */
  1040. #endif /* 386 */
  1041. #endif /* 486 */
  1042. #endif /* 386BSD */
  1043. #endif /* BSDI BSD/386 */
  1044. #endif /* NetBSD */
  1045. #endif /* FreeBSD */
  1046. #endif /* SCO Xenix */
  1047. #endif /* SCO Unix */
  1048. #endif /* Minix */
  1049. #endif /* Linux */
  1050. #endif /* NeXT */
  1051. #endif /* Amdahl */
  1052. #endif /* Cray */
  1053. #endif /* RT/AIX */
  1054. #endif /* AIX */
  1055. #endif /* OSF/1 */
  1056. #endif /* HP/UX */
  1057. #endif /* Sun */
  1058. #endif /* SGI */
  1059.  
  1060. #ifdef __DATE__
  1061.       " on ", __DATE__
  1062. #else
  1063.       "", ""
  1064. #endif
  1065.     );
  1066.  
  1067.     (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
  1068.  
  1069. } /* end function version() */
  1070.  
  1071. #endif /* !SFX */
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077. /* ===================================================================
  1078.  * ZVS_CREATE()
  1079.  * Function to create a file with specified times.  The times should be sent
  1080.  * as long ints in DG time format; use -1 to set to the current times.  You
  1081.  * may also specify a pointer to the ACL, the file type (see PARU.H, and do
  1082.  * not specify dirs or links), the element size, and the max index level.
  1083.  * For all of these parameters you may use -1 to specify the default.
  1084.  *
  1085.  * Returns 0 if no error, or the error code returned by ?CREATE.
  1086.  *
  1087.  *    HISTORY:
  1088.  *        15-dec-93 dbl
  1089.  *        31-may-94 dbl: added call to convert pathname to AOS/VS
  1090.  *
  1091.  *
  1092.  */
  1093.  
  1094. int zvs_create(char *fname, long cretim, long modtim, long acctim, char *pacl,
  1095.                int ftyp, int eltsize, int maxindlev)
  1096. {
  1097.     P_CREATE    pcr_stru;
  1098.     P_CTIM        pct_stru;
  1099.  
  1100.     pcr_stru.cftyp_format = 0;           /* unspecified record format */
  1101.     if (ftyp == -1)                      /* default file type to UNX */
  1102.         pcr_stru.cftyp_entry = $FUNX;
  1103.     else
  1104.         pcr_stru.cftyp_entry = ftyp;
  1105.     pcr_stru.ctim = &pct_stru;
  1106.     pcr_stru.cacp = pacl;
  1107.     pcr_stru.cdel = eltsize;
  1108.     pcr_stru.cmil = maxindlev;
  1109.  
  1110.     pct_stru.tcth.long_time = cretim;
  1111.     pct_stru.tath.long_time = acctim;
  1112.     pct_stru.tmth.long_time = modtim;
  1113.  
  1114.     return (sys_create(ux_to_vs_name(Vs_path, fname), &pcr_stru));
  1115.  
  1116. } /* end zvs_create() */
  1117.  
  1118.  
  1119.  
  1120. /* ===================================================================
  1121.  * ZVS_CREDIR()
  1122.  * Function to create a dir as specified.  The times should be sent
  1123.  * as long ints in DG time format; use -1 to set to the current times.  You
  1124.  * may also specify a pointer to the ACL, the file type (either $FDIR or $FCPD; see PARU.H),
  1125.  * the max # blocks (if a CPD), the hash frame size, and the max index level.
  1126.  * For all of these parameters (except for the CPD's maximum blocks),
  1127.  * you may use -1 to specify the default.
  1128.  *
  1129.  * (The System Call Dictionary says both that you may specify a
  1130.  * maximum-index-level value up to the maximum, with 0 for a contiguous
  1131.  * directory, and that 3 is always used for this whatever you specify.)
  1132.  *
  1133.  * If you specify anything other than CPD for the file type, DIR will
  1134.  * be used.
  1135.  *
  1136.  * Returns 0 if no error, or the error code returned by ?CREATE.
  1137.  *
  1138.  *    HISTORY:
  1139.  *         1-jun-94 dbl
  1140.  *
  1141.  *
  1142.  */
  1143.  
  1144. int zvs_credir(char *dname, long cretim, long modtim, long acctim, char *pacl, int ftyp, long maxblocks, int hashfsize, int maxindlev)
  1145. {
  1146.     P_CREATE_DIR    pcr_stru;
  1147.     P_CTIM        pct_stru;
  1148.  
  1149.     if (ftyp != $FCPD)                      /* default file type to UNX */
  1150.         pcr_stru.cftyp_entry = $FDIR;
  1151.     else
  1152.     {
  1153.         pcr_stru.cftyp_entry = ftyp;
  1154.         pcr_stru.cmsh = maxblocks;
  1155.     }
  1156.  
  1157.     pcr_stru.ctim = &pct_stru;
  1158.     pcr_stru.cacp = pacl;
  1159.     pcr_stru.chfs = hashfsize;
  1160.     pcr_stru.cmil = maxindlev;
  1161.  
  1162.     pct_stru.tcth.long_time = cretim;
  1163.     pct_stru.tath.long_time = acctim;
  1164.     pct_stru.tmth.long_time = modtim;
  1165.  
  1166.     return (sys_create(ux_to_vs_name(Vs_path, dname), &pcr_stru));
  1167.  
  1168. } /* end zvs_credir() */
  1169.  
  1170.  
  1171.  
  1172. /* ===================================================================
  1173.  * UX_TO_VS_NAME() - makes a somewhat dumb pass at converting a Unix
  1174.  *            filename to an AOS/VS filename.  This should
  1175.  *            be just about adequate to handle the results
  1176.  *            of similarly-simple AOS/VS-to-Unix conversions
  1177.  *            in the ZIP program.  It does not guarantee a
  1178.  *            legal AOS/VS filename for every Unix filename;
  1179.  *            conspicuous examples would be names with
  1180.  *            embedded ./ and ../ (which will receive no
  1181.  *            special treatment).
  1182.  *
  1183.  *        RETURNS: pointer to the result (which is an input parameter)
  1184.  *
  1185.  *        NOTE: calling code is responsible for making sure
  1186.  *            the output buffer is big enough!
  1187.  *
  1188.  *        HISTORY:
  1189.  *            31-may-94 dbl
  1190.  *
  1191.  */
  1192. char *ux_to_vs_name(char *outname, char *inname)
  1193. {
  1194.     char *ip=inname, *op=outname;
  1195.  
  1196.  
  1197.     if (ip[0] == '.') {
  1198.         if (ip[1] == '/') {
  1199.             *(op++) = '=';
  1200.             ip += 2;
  1201.         } else if (ip[1] == '.'  &&  ip[2] == '/') {
  1202.             *(op++) = '^';
  1203.             ip += 3;
  1204.         }
  1205.     }
  1206.  
  1207.     do {
  1208.         if (*ip == '/')
  1209.             *(op++) = ':';
  1210.         else if (strchr(
  1211.            "0123456789_$?.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
  1212.            *ip) != NULL)
  1213.         {
  1214.             *(op++) = *ip;
  1215.         } else
  1216.             *(op++) = '?';
  1217.  
  1218.     } while (*(ip++) != '\0');
  1219.  
  1220.     return outname;
  1221.  
  1222. } /* end ux_to_vs_name() */
  1223.  
  1224.  
  1225.  
  1226. /* =================================================================== */
  1227.  
  1228. /* DGDATE
  1229.    Two functions do encode/decode dates in DG system format.
  1230.  
  1231.    Usage:
  1232.     long value,year,month,day;
  1233.  
  1234.     value=dgdate(month,day,year);
  1235.     undgdate(value,&month,&day,&year);   [GRR:  not used in UnZip: removed]
  1236.  
  1237.    Notes:
  1238.  
  1239.    1. DG date functions only work on dates within the range
  1240.       Jan 1, 1968 through Dec 31, 2099.  I have tested these
  1241.       functions through the same range with exact agreement.
  1242.       For dates outside of that range, the DG system calls
  1243.       may return different values than these functions.
  1244.  
  1245.    2. dgundate() accepts values between 0 and 48213 inclusive.
  1246.       These correspond to 12/31/1967 and 12/31/2099.
  1247.  
  1248.    3. Both functions assume the data is in the native OS byte
  1249.       order.  So if you're reading or writing these fields from
  1250.       a file that has been passed between AOS/VS and PC-DOS you
  1251.       will need to swap byte order.
  1252.  
  1253.    4. With reference to byte order, the entire range of values
  1254.       supported by these functions will fit into an unsigned
  1255.       short int.  In most cases the input or output will be
  1256.       in that variable type.  You are better off casting the
  1257.       value to/from unsigned short so you only need to concern
  1258.       yourself with swapping two bytes instead of four.
  1259.  
  1260.   Written by: Stanley J. Gula
  1261.               US&T, Inc.
  1262.               529 Main Street, Suite 1
  1263.               Indian Orchard, MA 01151
  1264.               (413)-543-3672
  1265.               Copyright (c) 1990 US&T, Inc.
  1266.               All rights reserved.
  1267.  
  1268.               I hereby release these functions into the public
  1269.               domain.  You may use these routines freely as long
  1270.               as the US&T copyright remains intact in the source
  1271.               code.
  1272.  
  1273.               Stanley J. Gula     July 24, 1990
  1274. */
  1275.  
  1276. long motable[13]={0,31,59,90,120,151,181,212,243,273,304,334,365};
  1277.  
  1278. long yrtable[132]={
  1279.       366,  731, 1096, 1461, 1827, 2192, 2557, 2922, 3288, 3653,
  1280.      4018, 4383, 4749, 5114, 5479, 5844, 6210, 6575, 6940, 7305,
  1281.      7671, 8036, 8401, 8766, 9132, 9497, 9862,10227,10593,10958,
  1282.     11323,11688,12054,12419,12784,13149,13515,13880,14245,14610,
  1283.     14976,15341,15706,16071,16437,16802,17167,17532,17898,18263,
  1284.     18628,18993,19359,19724,20089,20454,20820,21185,21550,21915,
  1285.     22281,22646,23011,23376,23742,24107,24472,24837,25203,25568,
  1286.     25933,26298,26664,27029,27394,27759,28125,28490,28855,29220,
  1287.     29586,29951,30316,30681,31047,31412,31777,32142,32508,32873,
  1288.     33238,33603,33969,34334,34699,35064,35430,35795,36160,36525,
  1289.     36891,37256,37621,37986,38352,38717,39082,39447,39813,40178,
  1290.     40543,40908,41274,41639,42004,42369,42735,43100,43465,43830,
  1291.     44196,44561,44926,45291,45657,46022,46387,46752,47118,47483,
  1292.     47848,48213};
  1293.  
  1294. /* Given y,m,d return # of days since 12/31/67 */
  1295. long int dgdate(short mm, short dd, short yy)
  1296. {
  1297.     long int temp;
  1298.     short ytmp;
  1299.  
  1300.     if (mm<1 || mm>12 || dd<1 || dd>31 || yy<1968 || yy>2099)
  1301.         return 0L;
  1302.  
  1303.     /* Figure in whole years since 1968 + whole months plus days */
  1304.     temp=365L*(long)(yy-1968) + motable[mm-1] + (long)dd;
  1305.  
  1306.     /* Adjust for leap years - note we don't account for skipped leap
  1307.        year in years divisible by 1000 but not by 4000.  We're correct
  1308.        through the year 2099 */
  1309.     temp+=(yy-1965)/4;
  1310.  
  1311.     /* Correct for this year */
  1312.     /* In leap years, if date is 3/1 or later, bump */
  1313.     if ((yy%4==0) && (mm>2))
  1314.         temp++;
  1315.  
  1316.     return temp;
  1317. }
  1318.