home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume44
/
unzip
/
part07
< prev
next >
Wrap
Internet Message Format
|
1994-09-19
|
72KB
From: zip-bugs@wkuvx1.wku.edu (Info-ZIP group)
Newsgroups: comp.sources.misc
Subject: v44i072: unzip - Info-ZIP portable UnZip, version 5.12, Part07/20
Date: 18 Sep 1994 23:15:13 -0500
Organization: Sterling Software
Sender: kent@sparky.sterling.com
Approved: kent@sparky.sterling.com
Message-ID: <35j38h$qnk@sparky.sterling.com>
X-Md4-Signature: bd4ea122fc1e2897017a5d25d9d70cc8
Submitted-by: zip-bugs@wkuvx1.wku.edu (Info-ZIP group)
Posting-number: Volume 44, Issue 72
Archive-name: unzip/part07
Environment: UNIX, VMS, OS/2, MS-DOS, MACINTOSH, WIN-NT, LINUX, MINIX, COHERENT, AMIGA?, ATARI TOS, SGI, DEC, Cray, Convex, Amdahl, Sun
Supersedes: unzip50: Volume 31, Issue 104-117
#! /bin/sh
# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".
# Contents: unzip-5.12/msdos/msdos.c unzip-5.12/zipinfo.doc
# Wrapped by kent@sparky on Sat Sep 17 23:33:39 1994
PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:
echo ' "shar: End of archive 7 (of 20)."'
if test -f 'unzip-5.12/msdos/msdos.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'unzip-5.12/msdos/msdos.c'\"
else
echo shar: Extracting \"'unzip-5.12/msdos/msdos.c'\" \(46263 characters\)
sed "s/^X//" >'unzip-5.12/msdos/msdos.c' <<'END_OF_FILE'
X/*---------------------------------------------------------------------------
X
X msdos.c
X
X MSDOS-specific routines for use with Info-ZIP's UnZip 5.1 and later.
X
X Contains: Opendir() (from zip)
X Readdir() (from zip)
X do_wild()
X mapattr()
X mapname()
X checkdir()
X isfloppy()
X volumelabel() (non-djgpp, non-emx)
X close_outfile()
X dateformat()
X version()
X _dos_getcountryinfo() (djgpp, emx)
X _dos_setftime() (djgpp, emx)
X _dos_setfileattr() (djgpp, emx)
X _dos_getdrive() (djgpp, emx)
X _dos_creat() (djgpp, emx)
X _dos_close() (djgpp, emx)
X volumelabel() (djgpp, emx)
X
X ---------------------------------------------------------------------------*/
X
X
X
X#include "unzip.h"
X#undef FILENAME /* BC++ 3.1 and djgpp 1.11 define FILENAME in <dir.h> */
X
Xstatic int isfloppy OF((int nDrive));
Xstatic int volumelabel OF((char *newlabel));
X
Xstatic int created_dir; /* used by mapname(), checkdir() */
Xstatic int renamed_fullpath; /* ditto */
Xstatic unsigned nLabelDrive; /* ditto, plus volumelabel() */
X
X#if (defined(__GO32__) || defined(__EMX__))
X# define MKDIR(path,mode) mkdir(path,mode)
X# include <dirent.h> /* use readdir() */
X# define direct dirent
X# define Opendir opendir
X# define Readdir readdir
X# ifdef __EMX__
X# include <dos.h>
X# define GETDRIVE(d) d = _getdrive()
X# define FA_LABEL A_LABEL
X# else
X# define GETDRIVE(d) _dos_getdrive(&d)
X# endif
X#else /* !(__GO32__ || __EMX__) */
X# define MKDIR(path,mode) mkdir(path)
X# ifdef __TURBOC__
X# define FATTR FA_HIDDEN+FA_SYSTEM+FA_DIREC
X# define FVOLID FA_VOLID
X# define FFIRST(n,d,a) findfirst(n,(struct ffblk *)d,a)
X# define FNEXT(d) findnext((struct ffblk *)d)
X# define GETDRIVE(d) d=getdisk()+1
X# include <dir.h>
X# else /* !__TURBOC__ */
X# define FATTR _A_HIDDEN+_A_SYSTEM+_A_SUBDIR
X# define FVOLID _A_VOLID
X# define FFIRST(n,d,a) _dos_findfirst(n,a,(struct find_t *)d)
X# define FNEXT(d) _dos_findnext((struct find_t *)d)
X# define GETDRIVE(d) _dos_getdrive(&d)
X# include <direct.h>
X# endif /* ?__TURBOC__ */
X typedef struct direct {
X char d_reserved[30];
X char d_name[13];
X int d_first;
X } DIR;
X# define closedir free
X DIR *Opendir OF((const char *));
X struct direct *Readdir OF((DIR *));
X
X
X
X
X#ifndef SFX
X
X/**********************/ /* Borland C++ 3.x has its own opendir/readdir */
X/* Function Opendir() */ /* library routines, but earlier versions don't, */
X/**********************/ /* so use ours regardless */
X
XDIR *Opendir(name)
X const char *name; /* name of directory to open */
X{
X DIR *dirp; /* malloc'd return value */
X char *nbuf; /* malloc'd temporary string */
X int len = strlen(name); /* path length to avoid strlens and strcats */
X
X
X if ((dirp = (DIR *)malloc(sizeof(DIR))) == (DIR *)NULL)
X return (DIR *)NULL;
X if ((nbuf = malloc(len + 5)) == (char *)NULL) {
X free(dirp);
X return (DIR *)NULL;
X }
X strcpy(nbuf, name);
X if (nbuf[len-1] == ':') {
X nbuf[len++] = '.';
X } else if (nbuf[len-1] == '/' || nbuf[len-1] == '\\')
X --len;
X strcpy(nbuf+len, "/*.*");
X Trace((stderr, "opendir: nbuf = [%s]\n", nbuf));
X
X if (FFIRST(nbuf, dirp, FATTR)) {
X free((voidp *)nbuf);
X return (DIR *)NULL;
X }
X free((voidp *)nbuf);
X dirp->d_first = 1;
X return dirp;
X}
X
X
X
X
X
X/**********************/
X/* Function Readdir() */
X/**********************/
X
Xstruct direct *Readdir(d)
X DIR *d; /* directory stream from which to read */
X{
X /* Return pointer to first or next directory entry, or NULL if end. */
X
X if (d->d_first)
X d->d_first = 0;
X else
X if (FNEXT(d))
X return (struct direct *)NULL;
X return (struct direct *)d;
X}
X
X#endif /* !SFX */
X#endif /* ?(__GO32__ || __EMX__) */
X
X
X
X
X
X#ifndef SFX
X
X/************************/
X/* Function do_wild() */ /* identical to OS/2 version */
X/************************/
X
Xchar *do_wild(wildspec)
X char *wildspec; /* only used first time on a given dir */
X{
X static DIR *dir = (DIR *)NULL;
X static char *dirname, *wildname, matchname[FILNAMSIZ];
X static char Far CantAllocateWildcard[] =
X "warning: can't allocate wildcard buffers\n";
X static int firstcall=TRUE, have_dirname, dirnamelen;
X struct direct *file;
X
X
X /* Even when we're just returning wildspec, we *always* do so in
X * matchname[]--calling routine is allowed to append four characters
X * to the returned string, and wildspec may be a pointer to argv[].
X */
X if (firstcall) { /* first call: must initialize everything */
X firstcall = FALSE;
X
X /* break the wildspec into a directory part and a wildcard filename */
X if ((wildname = strrchr(wildspec, '/')) == (char *)NULL &&
X (wildname = strrchr(wildspec, ':')) == (char *)NULL) {
X dirname = ".";
X dirnamelen = 1;
X have_dirname = FALSE;
X wildname = wildspec;
X } else {
X ++wildname; /* point at character after '/' or ':' */
X dirnamelen = wildname - wildspec;
X if ((dirname = (char *)malloc(dirnamelen+1)) == (char *)NULL) {
X FPRINTF(stderr, LoadFarString(CantAllocateWildcard));
X strcpy(matchname, wildspec);
X return matchname; /* but maybe filespec was not a wildcard */
X }
X/* GRR: can't strip trailing char for opendir since might be "d:/" or "d:"
X * (would have to check for "./" at end--let opendir handle it instead) */
X strncpy(dirname, wildspec, dirnamelen);
X dirname[dirnamelen] = '\0'; /* terminate for strcpy below */
X have_dirname = TRUE;
X }
X Trace((stderr, "do_wild: dirname = [%s]\n", dirname));
X
X if ((dir = Opendir(dirname)) != (DIR *)NULL) {
X while ((file = Readdir(dir)) != (struct direct *)NULL) {
X Trace((stderr, "do_wild: readdir returns %s\n", file->d_name));
X if (match(file->d_name, wildname, 1)) { /* 1 == ignore case */
X Trace((stderr, "do_wild: match() succeeds\n"));
X if (have_dirname) {
X strcpy(matchname, dirname);
X strcpy(matchname+dirnamelen, file->d_name);
X } else
X strcpy(matchname, file->d_name);
X return matchname;
X }
X }
X /* if we get to here directory is exhausted, so close it */
X closedir(dir);
X dir = (DIR *)NULL;
X }
X Trace((stderr, "do_wild: opendir(%s) returns NULL\n", dirname));
X
X /* return the raw wildspec in case that works (e.g., directory not
X * searchable, but filespec was not wild and file is readable) */
X strcpy(matchname, wildspec);
X return matchname;
X }
X
X /* last time through, might have failed opendir but returned raw wildspec */
X if (dir == (DIR *)NULL) {
X firstcall = TRUE; /* nothing left to try--reset for new wildspec */
X if (have_dirname)
X free(dirname);
X return (char *)NULL;
X }
X
X /* If we've gotten this far, we've read and matched at least one entry
X * successfully (in a previous call), so dirname has been copied into
X * matchname already.
X */
X while ((file = Readdir(dir)) != (struct direct *)NULL)
X if (match(file->d_name, wildname, 1)) { /* 1 == ignore case */
X if (have_dirname) {
X /* strcpy(matchname, dirname); */
X strcpy(matchname+dirnamelen, file->d_name);
X } else
X strcpy(matchname, file->d_name);
X return matchname;
X }
X
X closedir(dir); /* have read at least one dir entry; nothing left */
X dir = (DIR *)NULL;
X firstcall = TRUE; /* reset for new wildspec */
X if (have_dirname)
X free(dirname);
X return (char *)NULL;
X
X} /* end function do_wild() */
X
X#endif /* !SFX */
X
X
X
X
X
X/**********************/
X/* Function mapattr() */
X/**********************/
X
Xint mapattr()
X{
X /* set archive bit (file is not backed up): */
X pInfo->file_attr = (unsigned)(crec.external_file_attributes | 32) & 0xff;
X return 0;
X
X} /* end function mapattr() */
X
X
X
X
X
X/*****************************/
X/* Strings used in msdos.c */
X/*****************************/
X
Xstatic char Far ConversionFailed[] = "mapname: conversion of %s failed\n";
Xstatic char Far ErrSetVolLabel[] = "mapname: error setting volume label\n";
Xstatic char Far PathTooLong[] = "checkdir error: path too long: %s\n";
Xstatic char Far CantCreateDir[] = "checkdir error: can't create %s\n\
X unable to process %s.\n";
Xstatic char Far DirIsntDirectory[] =
X "checkdir error: %s exists but is not directory\n\
X unable to process %s.\n";
Xstatic char Far PathTooLongTrunc[] =
X "checkdir warning: path too long; truncating\n %s\n\
X -> %s\n";
X#if (!defined(SFX) || defined(SFX_EXDIR))
X static char Far CantCreateExtractDir[] =
X "checkdir: can't create extraction directory: %s\n";
X#endif
X
X
X
X
X
X/************************/
X/* Function mapname() */
X/************************/
X
Xint mapname(renamed) /* return 0 if no error, 1 if caution (filename trunc), */
X int renamed; /* 2 if warning (skip file because dir doesn't exist), */
X{ /* 3 if error (skip file), 10 if no memory (skip file) */
X char pathcomp[FILNAMSIZ]; /* path-component buffer */
X char *pp, *cp=(char *)NULL; /* character pointers */
X char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */
X char *last_dot=(char *)NULL; /* last dot not converted to underscore */
X int quote = FALSE; /* flag: next char is literal */
X int dotname = FALSE; /* flag: path component begins with dot */
X int error = 0;
X register unsigned workch; /* hold the character being tested */
X
X
X/*---------------------------------------------------------------------------
X Initialize various pointers and counters and stuff.
X ---------------------------------------------------------------------------*/
X
X /* can create path as long as not just freshening, or if user told us */
X create_dirs = (!fflag || renamed);
X
X created_dir = FALSE; /* not yet */
X renamed_fullpath = FALSE;
X
X/* GRR: for VMS, convert to internal format now or later? or never? */
X if (renamed) {
X cp = filename - 1; /* point to beginning of renamed name... */
X while (*++cp)
X if (*cp == '\\') /* convert backslashes to forward */
X *cp = '/';
X cp = filename;
X /* use temporary rootpath if user gave full pathname */
X if (filename[0] == '/') {
X renamed_fullpath = TRUE;
X pathcomp[0] = '/'; /* copy the '/' and terminate */
X pathcomp[1] = '\0';
X ++cp;
X } else if (isalpha(filename[0]) && filename[1] == ':') {
X renamed_fullpath = TRUE;
X pp = pathcomp;
X *pp++ = *cp++; /* copy the "d:" (+ '/', possibly) */
X *pp++ = *cp++;
X if (*cp == '/')
X *pp++ = *cp++; /* otherwise add "./"? */
X *pp = '\0';
X }
X }
X
X /* pathcomp is ignored unless renamed_fullpath is TRUE: */
X if ((error = checkdir(pathcomp, INIT)) != 0) /* initialize path buffer */
X return error; /* ...unless no mem or vol label on hard disk */
X
X *pathcomp = '\0'; /* initialize translation buffer */
X pp = pathcomp; /* point to translation buffer */
X if (!renamed) { /* cp already set if renamed */
X if (jflag) /* junking directories */
X cp = (char *)strrchr(filename, '/');
X if (cp == (char *)NULL) /* no '/' or not junking dirs */
X cp = filename; /* point to internal zipfile-member pathname */
X else
X ++cp; /* point to start of last component of path */
X }
X
X/*---------------------------------------------------------------------------
X Begin main loop through characters in filename.
X ---------------------------------------------------------------------------*/
X
X while ((workch = (uch)*cp++) != 0) {
X
X if (quote) { /* if character quoted, */
X *pp++ = (char)workch; /* include it literally */
X quote = FALSE;
X } else
X switch (workch) {
X case '/': /* can assume -j flag not given */
X *pp = '\0';
X/* GRR: can add 8.3 truncation here */
X if (last_dot) { /* one dot in directory name is legal */
X *last_dot = '.';
X last_dot = (char *)NULL;
X }
X if ((error = checkdir(pathcomp, APPEND_DIR)) > 1)
X return error;
X pp = pathcomp; /* reset conversion buffer for next piece */
X lastsemi = (char *)NULL; /* leave directory semi-colons alone */
X break;
X
X case ':': /* drive names not stored in zipfile, */
X case '[': /* so no colons allowed; no brackets, */
X case ']': /* either */
X *pp++ = '_';
X break;
X
X case '.':
X if (pp == pathcomp) { /* nothing appended yet... */
X if (*cp == '/') { /* don't bother appending a "./" */
X ++cp; /* component to the path: skip */
X break; /* to next char after the '/' */
X } else if (*cp == '.' && cp[1] == '/') { /* "../" */
X *pp++ = '.'; /* add first dot, unchanged... */
X ++cp; /* skip second dot, since it will */
X } else { /* be "added" at end of if-block */
X *pp++ = '_'; /* FAT doesn't allow null filename */
X dotname = TRUE; /* bodies, so map .exrc -> _.exrc */
X } /* (extra '_' now, "dot" below) */
X } else if (dotname) { /* found a second dot, but still */
X dotname = FALSE; /* have extra leading underscore: */
X *pp = '\0'; /* remove it by shifting chars */
X pp = pathcomp + 1; /* left one space (e.g., .p1.p2: */
X while (pp[1]) { /* __p1 -> _p1_p2 -> _p1.p2 when */
X *pp = pp[1]; /* finished) [opt.: since first */
X ++pp; /* two chars are same, can start */
X } /* shifting at second position] */
X }
X last_dot = pp; /* point at last dot so far... */
X *pp++ = '_'; /* convert dot to underscore for now */
X break;
X
X case ';': /* start of VMS version? */
X lastsemi = pp; /* omit for now; remove VMS vers. later */
X break;
X
X case '\026': /* control-V quote for special chars */
X quote = TRUE; /* set flag for next character */
X break;
X
X case ' ': /* change spaces to underscore only */
X if (sflag) /* if specifically requested */
X *pp++ = '_';
X else
X *pp++ = (char)workch;
X break;
X
X default:
X /* allow European characters in filenames: */
X if (isprint(workch) || (128 <= workch && workch <= 254))
X *pp++ = (char)workch;
X } /* end switch */
X
X } /* end while loop */
X
X *pp = '\0'; /* done with pathcomp: terminate it */
X
X /* if not saving them, remove VMS version numbers (appended "###") */
X if (!V_flag && lastsemi) {
X pp = lastsemi; /* semi-colon was omitted: expect all #'s */
X while (isdigit((uch)(*pp)))
X ++pp;
X if (*pp == '\0') /* only digits between ';' and end: nuke */
X *lastsemi = '\0';
X }
X
X/* GRR: can add 8.3 truncation here */
X if (last_dot != (char *)NULL) /* one dot is OK: put it back in */
X *last_dot = '.'; /* (already done for directories) */
X
X/*---------------------------------------------------------------------------
X Report if directory was created (and no file to create: filename ended
X in '/'), check name to be sure it exists, and combine path and name be-
X fore exiting.
X ---------------------------------------------------------------------------*/
X
X if (filename[strlen(filename) - 1] == '/') {
X checkdir(filename, GETPATH);
X if (created_dir && QCOND2) {
X FPRINTF(stdout, " creating: %s\n", filename);
X return IZ_CREATED_DIR; /* set dir time (note trailing '/') */
X }
X return 2; /* dir existed already; don't look for data to extract */
X }
X
X if (*pathcomp == '\0') {
X FPRINTF(stderr, LoadFarString(ConversionFailed), filename);
X return 3;
X }
X
X checkdir(pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */
X checkdir(filename, GETPATH);
X
X if (pInfo->vollabel) { /* set the volume label now */
X if (QCOND2)
X FPRINTF(stdout, "labelling %c: %-22s\n", (nLabelDrive + 'a' - 1),
X filename);
X if (volumelabel(filename)) {
X FPRINTF(stderr, LoadFarString(ErrSetVolLabel));
X return 3;
X }
X return 2; /* success: skip the "extraction" quietly */
X }
X
X return error;
X
X} /* end function mapname() */
X
X
X
X
X
X/***********************/
X/* Function checkdir() */
X/***********************/
X
Xint checkdir(pathcomp, flag)
X char *pathcomp;
X int flag;
X/*
X * returns: 1 - (on APPEND_NAME) truncated filename
X * 2 - path doesn't exist, not allowed to create
X * 3 - path doesn't exist, tried to create and failed; or
X * path exists and is not a directory, but is supposed to be
X * 4 - path is too long
X * 10 - can't allocate memory for filename buffers
X */
X{
X static int rootlen = 0; /* length of rootpath */
X static char *rootpath; /* user's "extract-to" directory */
X static char *buildpath; /* full path (so far) to extracted file */
X static char *end; /* pointer to end of buildpath ('\0') */
X#ifdef MSC
X int attrs; /* work around MSC stat() bug */
X#endif
X
X# define FN_MASK 7
X# define FUNCTION (flag & FN_MASK)
X
X
X
X/*---------------------------------------------------------------------------
X APPEND_DIR: append the path component to the path being built and check
X for its existence. If doesn't exist and we are creating directories, do
X so for this one; else signal success or error as appropriate.
X ---------------------------------------------------------------------------*/
X
X if (FUNCTION == APPEND_DIR) {
X int too_long = FALSE;
X
X Trace((stderr, "appending dir segment [%s]\n", pathcomp));
X while ((*end = *pathcomp++) != '\0')
X ++end;
X
X /* GRR: could do better check, see if overrunning buffer as we go:
X * check end-buildpath after each append, set warning variable if
X * within 20 of FILNAMSIZ; then if var set, do careful check when
X * appending. Clear variable when begin new path. */
X
X if ((end-buildpath) > FILNAMSIZ-3) /* need '/', one-char name, '\0' */
X too_long = TRUE; /* check if extracting directory? */
X#ifdef MSC /* MSC 6.00 bug: stat(non-existent-dir) == 0 [exists!] */
X if (_dos_getfileattr(buildpath, &attrs) || stat(buildpath, &statbuf))
X#else
X if (stat(buildpath, &statbuf)) /* path doesn't exist */
X#endif
X {
X if (!create_dirs) { /* told not to create (freshening) */
X free(buildpath);
X return 2; /* path doesn't exist: nothing to do */
X }
X if (too_long) {
X FPRINTF(stderr, LoadFarString(PathTooLong), buildpath);
X fflush(stderr);
X free(buildpath);
X return 4; /* no room for filenames: fatal */
X }
X if (MKDIR(buildpath, 0777) == -1) { /* create the directory */
X FPRINTF(stderr, LoadFarString(CantCreateDir), buildpath,
X filename);
X fflush(stderr);
X free(buildpath);
X return 3; /* path didn't exist, tried to create, failed */
X }
X created_dir = TRUE;
X } else if (!S_ISDIR(statbuf.st_mode)) {
X FPRINTF(stderr, LoadFarString(DirIsntDirectory), buildpath,
X filename);
X fflush(stderr);
X free(buildpath);
X return 3; /* path existed but wasn't dir */
X }
X if (too_long) {
X FPRINTF(stderr, LoadFarString(PathTooLong), buildpath);
X fflush(stderr);
X free(buildpath);
X return 4; /* no room for filenames: fatal */
X }
X *end++ = '/';
X *end = '\0';
X Trace((stderr, "buildpath now = [%s]\n", buildpath));
X return 0;
X
X } /* end if (FUNCTION == APPEND_DIR) */
X
X/*---------------------------------------------------------------------------
X GETPATH: copy full path to the string pointed at by pathcomp, and free
X buildpath.
X ---------------------------------------------------------------------------*/
X
X if (FUNCTION == GETPATH) {
X strcpy(pathcomp, buildpath);
X Trace((stderr, "getting and freeing path [%s]\n", pathcomp));
X free(buildpath);
X buildpath = end = (char *)NULL;
X return 0;
X }
X
X/*---------------------------------------------------------------------------
X APPEND_NAME: assume the path component is the filename; append it and
X return without checking for existence.
X ---------------------------------------------------------------------------*/
X
X if (FUNCTION == APPEND_NAME) {
X Trace((stderr, "appending filename [%s]\n", pathcomp));
X while ((*end = *pathcomp++) != '\0') {
X ++end;
X if ((end-buildpath) >= FILNAMSIZ) {
X *--end = '\0';
X FPRINTF(stderr, LoadFarString(PathTooLongTrunc),
X filename, buildpath);
X fflush(stderr);
X return 1; /* filename truncated */
X }
X }
X Trace((stderr, "buildpath now = [%s]\n", buildpath));
X return 0; /* could check for existence here, prompt for new name... */
X }
X
X/*---------------------------------------------------------------------------
X INIT: allocate and initialize buffer space for the file currently being
X extracted. If file was renamed with an absolute path, don't prepend the
X extract-to path.
X ---------------------------------------------------------------------------*/
X
X if (FUNCTION == INIT) {
X Trace((stderr, "initializing buildpath to "));
X if ((buildpath = (char *)malloc(strlen(filename)+rootlen+1)) ==
X (char *)NULL)
X return 10;
X if (pInfo->vollabel) {
X/* GRR: for network drives, do strchr() and return IZ_VOL_LABEL if not [1] */
X if (renamed_fullpath && pathcomp[1] == ':')
X *buildpath = ToLower(*pathcomp);
X else if (!renamed_fullpath && rootpath && rootpath[1] == ':')
X *buildpath = ToLower(*rootpath);
X else {
X GETDRIVE(nLabelDrive); /* assumed that a == 1, b == 2, etc. */
X *buildpath = (char)(nLabelDrive - 1 + 'a');
X }
X nLabelDrive = *buildpath - 'a' + 1; /* save for mapname() */
X if (volflag == 0 || *buildpath < 'a' || /* no labels/bogus disk */
X (volflag == 1 && !isfloppy(nLabelDrive))) { /* -$: no fixed */
X free(buildpath);
X return IZ_VOL_LABEL; /* skipping with message */
X }
X *buildpath = '\0';
X end = buildpath;
X } else if (renamed_fullpath) { /* pathcomp = valid data */
X end = buildpath;
X while ((*end = *pathcomp++) != '\0')
X ++end;
X } else if (rootlen > 0) {
X strcpy(buildpath, rootpath);
X end = buildpath + rootlen;
X } else {
X *buildpath = '\0';
X end = buildpath;
X }
X Trace((stderr, "[%s]\n", buildpath));
X return 0;
X }
X
X/*---------------------------------------------------------------------------
X ROOT: if appropriate, store the path in rootpath and create it if neces-
X sary; else assume it's a zipfile member and return. This path segment
X gets used in extracting all members from every zipfile specified on the
X command line. Note that under OS/2 and MS-DOS, if a candidate extract-to
X directory specification includes a drive letter (leading "x:"), it is
X treated just as if it had a trailing '/'--that is, one directory level
X will be created if the path doesn't exist, unless this is otherwise pro-
X hibited (e.g., freshening).
X ---------------------------------------------------------------------------*/
X
X#if (!defined(SFX) || defined(SFX_EXDIR))
X if (FUNCTION == ROOT) {
X Trace((stderr, "initializing root path to [%s]\n", pathcomp));
X if (pathcomp == (char *)NULL) {
X rootlen = 0;
X return 0;
X }
X if ((rootlen = strlen(pathcomp)) > 0) {
X int had_trailing_pathsep=FALSE, has_drive=FALSE, xtra=2;
X
X if (isalpha(pathcomp[0]) && pathcomp[1] == ':')
X has_drive = TRUE; /* drive designator */
X if (pathcomp[rootlen-1] == '/') {
X pathcomp[--rootlen] = '\0';
X had_trailing_pathsep = TRUE;
X }
X if (has_drive && (rootlen == 2)) {
X if (!had_trailing_pathsep) /* i.e., original wasn't "x:/" */
X xtra = 3; /* room for '.' + '/' + 0 at end of "x:" */
X } else if (rootlen > 0) { /* need not check "x:." and "x:/" */
X#ifdef MSC
X /* MSC 6.00 bug: stat(non-existent-dir) == 0 [exists!] */
X if (_dos_getfileattr(pathcomp, &attrs) ||
X SSTAT(pathcomp, &statbuf) || !S_ISDIR(statbuf.st_mode))
X#else
X if (SSTAT(pathcomp, &statbuf) || !S_ISDIR(statbuf.st_mode))
X#endif
X {
X /* path does not exist */
X if (!create_dirs /* || iswild(pathcomp) */
X#ifdef OLD_EXDIR
X || (!has_drive && !had_trailing_pathsep)
X#endif
X ) {
X rootlen = 0;
X return 2; /* treat as stored file */
X }
X/* GRR: scan for wildcard characters? OS-dependent... if find any, return 2:
X * treat as stored file(s) */
X /* create directory (could add loop here to scan pathcomp
X * and create more than one level, but really necessary?) */
X if (MKDIR(pathcomp, 0777) == -1) {
X FPRINTF(stderr, LoadFarString(CantCreateExtractDir),
X pathcomp);
X fflush(stderr);
X rootlen = 0; /* path didn't exist, tried to create, */
X return 3; /* failed: file exists, or need 2+ levels */
X }
X }
X }
X if ((rootpath = (char *)malloc(rootlen+xtra)) == (char *)NULL) {
X rootlen = 0;
X return 10;
X }
X strcpy(rootpath, pathcomp);
X if (xtra == 3) /* had just "x:", make "x:." */
X rootpath[rootlen++] = '.';
X rootpath[rootlen++] = '/';
X rootpath[rootlen] = '\0';
X }
X Trace((stderr, "rootpath now = [%s]\n", rootpath));
X return 0;
X }
X#endif /* !SFX || SFX_EXDIR */
X
X/*---------------------------------------------------------------------------
X END: free rootpath, immediately prior to program exit.
X ---------------------------------------------------------------------------*/
X
X if (FUNCTION == END) {
X Trace((stderr, "freeing rootpath\n"));
X if (rootlen > 0)
X free(rootpath);
X return 0;
X }
X
X return 99; /* should never reach */
X
X} /* end function checkdir() */
X
X
X
X
X
X
X/***********************/
X/* Function isfloppy() */
X/***********************/
X
Xstatic int isfloppy(nDrive) /* more precisely, is it removable? */
X int nDrive;
X{
X union REGS regs;
X
X regs.h.ah = 0x44;
X regs.h.al = 0x08;
X regs.h.bl = (uch)nDrive;
X#ifdef __EMX__
X _int86(0x21, ®s, ®s);
X if (regs.x.flags & 1)
X#else
X intdos(®s, ®s);
X if (regs.x.cflag) /* error: do default a/b check instead */
X#endif
X {
X Trace((stderr,
X "error in DOS function 0x44 (AX = 0x%04x): guessing instead...\n",
X regs.x.ax));
X return (nDrive == 1 || nDrive == 2)? TRUE : FALSE;
X } else
X return regs.x.ax? FALSE : TRUE;
X}
X
X
X
X
X#if (!defined(__GO32__) && !defined(__EMX__))
X
Xtypedef struct dosfcb {
X uch flag; /* ff to indicate extended FCB */
X char res[5]; /* reserved */
X uch vattr; /* attribute */
X uch drive; /* drive (1=A, 2=B, ...) */
X uch vn[11]; /* file or volume name */
X char dmmy[5];
X uch nn[11]; /* holds new name if renaming (else reserved) */
X char dmmy2[9];
X} dos_fcb;
X
X/**************************/
X/* Function volumelabel() */
X/**************************/
X
Xstatic int volumelabel(newlabel)
X char *newlabel;
X{
X#ifdef DEBUG
X char *p;
X#endif
X int len = strlen(newlabel);
X dos_fcb fcb, dta, far *pfcb=&fcb, far *pdta=&dta;
X struct SREGS sregs;
X union REGS regs;
X
X
X/*---------------------------------------------------------------------------
X Label the diskette specified by nLabelDrive using FCB calls. (Old ver-
X sions of MS-DOS and OS/2 DOS boxes can't use DOS function 3Ch to create
X labels.) Must use far pointers for MSC FP_* macros to work; must pad
X FCB filenames with spaces; and cannot include dot in 8th position. May
X or may not need to zero out FCBs before using; do so just in case.
X ---------------------------------------------------------------------------*/
X
X memset((char *)&dta, 0, sizeof(dos_fcb));
X memset((char *)&fcb, 0, sizeof(dos_fcb));
X
X#ifdef DEBUG
X for (p = (char *)&dta; (p - (char *)&dta) < sizeof(dos_fcb); ++p)
X if (*p)
X fprintf(stderr, "error: dta[%d] = %x\n", (p - (char *)&dta), *p);
X for (p = (char *)&fcb; (p - (char *)&fcb) < sizeof(dos_fcb); ++p)
X if (*p)
X fprintf(stderr, "error: fcb[%d] = %x\n", (p - (char *)&fcb), *p);
X printf("testing pointer macros:\n");
X segread(&sregs);
X printf("cs = %x, ds = %x, es = %x, ss = %x\n", sregs.cs, sregs.ds, sregs.es,
X sregs.ss);
X#endif /* DEBUG */
X
X#if 0
X#ifdef __TURBOC__
X bdosptr(0x1a, dta, DO_NOT_CARE);
X#else
X (intdosx method below)
X#endif
X#endif /* 0 */
X
X /* set the disk transfer address for subsequent FCB calls */
X sregs.ds = FP_SEG(pdta);
X regs.x.dx = FP_OFF(pdta);
X Trace((stderr, "segment:offset of pdta = %x:%x\n", sregs.ds, regs.x.dx));
X Trace((stderr, "&dta = %lx, pdta = %lx\n", (ulg)&dta, (ulg)pdta));
X regs.h.ah = 0x1a;
X intdosx(®s, ®s, &sregs);
X
X /* fill in the FCB */
X sregs.ds = FP_SEG(pfcb);
X regs.x.dx = FP_OFF(pfcb);
X pfcb->flag = 0xff; /* extended FCB */
X pfcb->vattr = 0x08; /* attribute: disk volume label */
X pfcb->drive = (uch)nLabelDrive;
X
X#ifdef DEBUG
X Trace((stderr, "segment:offset of pfcb = %x:%x\n", sregs.ds, regs.x.dx));
X Trace((stderr, "&fcb = %lx, pfcb = %lx\n", (ulg)&fcb, (ulg)pfcb));
X Trace((stderr, "(2nd check: labelling drive %c:)\n", pfcb->drive-1+'A'));
X if (pfcb->flag != fcb.flag)
X fprintf(stderr, "error: pfcb->flag = %d, fcb.flag = %d\n",
X pfcb->flag, fcb.flag);
X if (pfcb->drive != fcb.drive)
X fprintf(stderr, "error: pfcb->drive = %d, fcb.drive = %d\n",
X pfcb->drive, fcb.drive);
X if (pfcb->vattr != fcb.vattr)
X fprintf(stderr, "error: pfcb->vattr = %d, fcb.vattr = %d\n",
X pfcb->vattr, fcb.vattr);
X#endif /* DEBUG */
X
X /* check for existing label */
X Trace((stderr, "searching for existing label via FCBs\n"));
X regs.h.ah = 0x11; /* FCB find first */
X#if 0 /* THIS STRNCPY FAILS (MSC bug?): */
X strncpy(pfcb->vn, "???????????", 11); /* i.e., "*.*" */
X Trace((stderr, "pfcb->vn = %lx\n", (ulg)pfcb->vn));
X Trace((stderr, "flag = %x, drive = %d, vattr = %x, vn = %s = %s.\n",
X fcb.flag, fcb.drive, fcb.vattr, fcb.vn, pfcb->vn));
X#endif
X strncpy((char *)fcb.vn, "???????????", 11); /* i.e., "*.*" */
X Trace((stderr, "fcb.vn = %lx\n", (ulg)fcb.vn));
X Trace((stderr, "regs.h.ah = %x, regs.x.dx = %04x, sregs.ds = %04x\n",
X regs.h.ah, regs.x.dx, sregs.ds));
X Trace((stderr, "flag = %x, drive = %d, vattr = %x, vn = %s = %s.\n",
X fcb.flag, fcb.drive, fcb.vattr, fcb.vn, pfcb->vn));
X intdosx(®s, ®s, &sregs);
X
X/*---------------------------------------------------------------------------
X If not previously labelled, write a new label. Otherwise just rename,
X since MS-DOS 2.x has a bug which damages the FAT when the old label is
X deleted.
X ---------------------------------------------------------------------------*/
X
X if (regs.h.al) {
X Trace((stderr, "no label found\n\n"));
X regs.h.ah = 0x16; /* FCB create file */
X strncpy((char *)fcb.vn, newlabel, len);
X if (len < 11) /* fill with spaces */
X strncpy((char *)(fcb.vn+len), " ", 11-len);
X Trace((stderr, "fcb.vn = %lx pfcb->vn = %lx\n", (ulg)fcb.vn,
X (ulg)pfcb->vn));
X Trace((stderr, "flag = %x, drive = %d, vattr = %x\n", fcb.flag,
X fcb.drive, fcb.vattr));
X Trace((stderr, "vn = %s = %s.\n", fcb.vn, pfcb->vn));
X intdosx(®s, ®s, &sregs);
X regs.h.ah = 0x10; /* FCB close file */
X if (regs.h.al) {
X Trace((stderr, "unable to write volume name (AL = %x)\n",
X regs.h.al));
X intdosx(®s, ®s, &sregs);
X return 1;
X } else {
X intdosx(®s, ®s, &sregs);
X Trace((stderr, "new volume label [%s] written\n", newlabel));
X return 0;
X }
X } else {
X Trace((stderr, "found old label [%s]\n\n", dta.vn)); /* not term. */
X regs.h.ah = 0x17; /* FCB rename */
X strncpy((char *)fcb.vn, (char *)dta.vn, 11);
X strncpy((char *)fcb.nn, newlabel, len);
X if (len < 11) /* fill with spaces */
X strncpy((char *)(fcb.nn+len), " ", 11-len);
X Trace((stderr, "fcb.vn = %lx pfcb->vn = %lx\n", (ulg)fcb.vn,
X (ulg)pfcb->vn));
X Trace((stderr, "fcb.nn = %lx pfcb->nn = %lx\n", (ulg)fcb.nn,
X (ulg)pfcb->nn));
X Trace((stderr, "flag = %x, drive = %d, vattr = %x\n", fcb.flag,
X fcb.drive, fcb.vattr));
X Trace((stderr, "vn = %s = %s.\n", fcb.vn, pfcb->vn));
X Trace((stderr, "nn = %s = %s.\n", fcb.nn, pfcb->nn));
X intdosx(®s, ®s, &sregs);
X if (regs.h.al) {
X Trace((stderr, "Unable to change volume name (AL = %x)\n",
X regs.h.al));
X return 1;
X } else {
X Trace((stderr, "volume label changed to [%s]\n", newlabel));
X return 0;
X }
X }
X} /* end function volumelabel() */
X
X#endif /* !__GO32__ && !__EMX__ */
X
X
X
X
X
X/****************************/
X/* Function close_outfile() */
X/****************************/
X
Xvoid close_outfile()
X /*
X * MS-DOS VERSION
X *
X * Set the output file date/time stamp according to information from the
X * zipfile directory record for this member, then close the file and set
X * its permissions (archive, hidden, read-only, system). Aside from closing
X * the file, this routine is optional (but most compilers support it).
X */
X{
X#ifdef __TURBOC__
X union {
X struct ftime ft; /* system file time record */
X struct {
X ush ztime; /* date and time words */
X ush zdate; /* .. same format as in .ZIP file */
X } zt;
X } td;
X#endif
X
X
X/*---------------------------------------------------------------------------
X Copy and/or convert time and date variables, if necessary; then set the
X file time/date. WEIRD BORLAND "BUG": if output is buffered, and if run
X under at least some versions of DOS (e.g., 6.0), and if files are smaller
X than DOS physical block size (i.e., 512 bytes) (?), then files MAY NOT
X get timestamped correctly--apparently setftime() occurs before any data
X are written to the file, and when file is closed and buffers are flushed,
X timestamp is overwritten with current time. Even with a 32K buffer, this
X does not seem to occur with larger files. UnZip output is now unbuffered,
X but if it were not, could still avoid problem by adding "fflush(outfile)"
X just before setftime() call. Weird, huh?
X ---------------------------------------------------------------------------*/
X
X#ifdef __TURBOC__
X td.zt.ztime = lrec.last_mod_file_time;
X td.zt.zdate = lrec.last_mod_file_date;
X setftime(fileno(outfile), &td.ft);
X#else
X _dos_setftime(fileno(outfile), lrec.last_mod_file_date,
X lrec.last_mod_file_time);
X#endif
X
X/*---------------------------------------------------------------------------
X And finally we can close the file...at least everybody agrees on how to
X do *this*. I think... Also change the mode according to the stored file
X attributes, since we didn't do that when we opened the dude.
X ---------------------------------------------------------------------------*/
X
X fclose(outfile);
X
X#ifdef __TURBOC__
X# if (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0452))
X# define Chmod _rtl_chmod
X# else
X# define Chmod _chmod
X# endif
X if (Chmod(filename, 1, pInfo->file_attr) != pInfo->file_attr)
X FPRINTF(stderr, "\nwarning: file attributes may not be correct\n");
X#else /* !__TURBOC__ */
X _dos_setfileattr(filename, pInfo->file_attr);
X#endif /* ?__TURBOC__ */
X
X} /* end function close_outfile() */
X
X
X
X
X
X#ifndef SFX
X
X/*************************/
X/* Function dateformat() */
X/*************************/
X
Xint dateformat()
X{
X
X/*---------------------------------------------------------------------------
X For those operating systems which support it, this function returns a
X value which tells how national convention says that numeric dates are
X displayed. Return values are DF_YMD, DF_DMY and DF_MDY (the meanings
X should be fairly obvious).
X ---------------------------------------------------------------------------*/
X
X#ifndef MSWIN
X#if (!defined(__GO32__) && !defined(__EMX__))
X unsigned short _CountryInfo[18];
X unsigned short far *CountryInfo = _CountryInfo;
X struct SREGS sregs;
X union REGS regs;
X
X sregs.ds = FP_SEG(CountryInfo);
X regs.x.dx = FP_OFF(CountryInfo);
X regs.x.ax = 0x3800;
X int86x(0x21, ®s, ®s, &sregs);
X
X#else /* __GO32__ || __EMX__ */
X unsigned short CountryInfo[18];
X
X _dos_getcountryinfo(CountryInfo);
X#endif
X
X switch(CountryInfo[0]) {
X case 0:
X return DF_MDY;
X case 1:
X return DF_DMY;
X case 2:
X return DF_YMD;
X }
X#endif /* !MSWIN */
X
X return DF_MDY; /* default for systems without locale info */
X
X} /* end function dateformat() */
X
X
X
X
X
X/************************/
X/* Function version() */
X/************************/
X
Xvoid version()
X{
X extern char Far CompiledWith[];
X#if defined(__WATCOMC__) || defined(__TURBOC__) || defined(_MSC_VER)
X char buf[80];
X#endif
X
X PRINTF(LoadFarString(CompiledWith),
X
X#ifdef __GNUC__
X# ifdef __EMX__ /* __EMX__ is defined as "1" only (sigh) */
X "emx+gcc ",
X# else
X# ifdef __GO32__ /* ...so is __GO32__ (double sigh) */
X "djgpp gcc ",
X# else
X "gcc ",
X# endif
X# endif
X __VERSION__,
X#else
X#ifdef __WATCOMC__
X "Watcom C", (sprintf(buf, " (__WATCOMC__ = %d)", __WATCOMC__), buf),
X#else
X#ifdef __TURBOC__
X# ifdef __BORLANDC__
X "Borland C++",
X# if (__BORLANDC__ < 0x0200)
X " 1.0",
X# else
X# if (__BORLANDC__ == 0x0200) /* James: __TURBOC__ = 0x0297 */
X " 2.0",
X# else
X# if (__BORLANDC__ == 0x0400)
X " 3.0",
X# else
X# if (__BORLANDC__ == 0x0410) /* __BCPLUSPLUS__ = 0x0310 */
X " 3.1",
X# else
X# if (__BORLANDC__ == 0x0452) /* __BCPLUSPLUS__ = 0x0320 */
X " 4.0 or 4.02",
X# else
X " later than 4.1",
X# endif
X# endif
X# endif
X# endif
X# endif
X# else
X "Turbo C",
X# if (__TURBOC__ >= 0x0400) /* Kevin: 3.0 -> 0x0401 */
X "++ 3.0 or later",
X# else
X# if (__TURBOC__ == 0x0295) /* [661] vfy'd by Kevin */
X "++ 1.0",
X# else
X# if ((__TURBOC__ >= 0x018d) && (__TURBOC__ <= 0x0200)) /* James: 0x0200 */
X " 2.0",
X# else
X# if (__TURBOC__ > 0x0100)
X " 1.5", /* James: 0x0105? */
X# else
X " 1.0", /* James: 0x0100 */
X# endif
X# endif
X# endif
X# endif
X# endif
X#else
X#ifdef MSC
X "Microsoft C ",
X# ifdef _MSC_VER
X# if (_MSC_VER == 800)
X "8.0/8.0c (Visual C++ 1.0/1.5)",
X# else
X (sprintf(buf, "%d.%02d", _MSC_VER/100, _MSC_VER%100), buf),
X# endif
X# else
X "5.1 or earlier",
X# endif
X#else
X "unknown compiler", "",
X#endif /* MSC */
X#endif /* __TURBOC__ */
X#endif /* __WATCOMC__ */
X#endif /* __GNUC__ */
X
X "MS-DOS",
X
X#if (defined(__GNUC__) || (defined(__WATCOMC__) && defined(__386__)))
X " (32-bit)",
X#else
X# if defined(M_I86HM) || defined(__HUGE__)
X " (16-bit, huge)",
X# else
X# if defined(M_I86LM) || defined(__LARGE__)
X " (16-bit, large)",
X# else
X# if defined(M_I86MM) || defined(__MEDIUM__)
X " (16-bit, medium)",
X# else
X# if defined(M_I86CM) || defined(__COMPACT__)
X " (16-bit, compact)",
X# else
X# if defined(M_I86SM) || defined(__SMALL__)
X " (16-bit, small)",
X# else
X# if defined(M_I86TM) || defined(__TINY__)
X " (16-bit, tiny)",
X# else
X " (16-bit)",
X# endif
X# endif
X# endif
X# endif
X# endif
X# endif
X#endif
X
X#ifdef __DATE__
X " on ", __DATE__
X#else
X "", ""
X#endif
X );
X
X /* temporary debugging code for Borland compilers only */
X#ifdef __TURBOC__
X PRINTF("\tdebug(__TURBOC__ = 0x%04x = %d)\n", __TURBOC__, __TURBOC__);
X#ifdef __BORLANDC__
X PRINTF("\tdebug(__BORLANDC__ = 0x%04x)\n", __BORLANDC__);
X#else
X PRINTF("\tdebug(__BORLANDC__ not defined)\n");
X#endif
X#ifdef __TCPLUSPLUS__
X PRINTF("\tdebug(__TCPLUSPLUS__ = 0x%04x)\n", __TCPLUSPLUS__);
X#else
X PRINTF("\tdebug(__TCPLUSPLUS__ not defined)\n");
X#endif
X#ifdef __BCPLUSPLUS__
X PRINTF("\tdebug(__BCPLUSPLUS__ = 0x%04x)\n\n", __BCPLUSPLUS__);
X#else
X PRINTF("\tdebug(__BCPLUSPLUS__ not defined)\n\n");
X#endif
X#endif
X
X} /* end function version() */
X
X#endif /* !SFX */
X
X
X
X
X
X#if (defined(__GO32__) || defined(__EMX__))
X
Xint volatile _doserrno;
X
Xunsigned _dos_getcountryinfo(void *countrybuffer)
X{
X asm("movl %0, %%edx": : "g" (countrybuffer));
X asm("movl $0x3800, %eax");
X asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
X _doserrno = 0;
X asm("jnc 1f");
X asm("movl %%eax, %0": "=m" (_doserrno));
X asm("1:");
X return _doserrno;
X}
X
Xvoid _dos_setftime(int fd, ush dosdate, ush dostime)
X{
X asm("movl %0, %%ebx": : "g" (fd));
X asm("movl %0, %%ecx": : "g" (dostime));
X asm("movl %0, %%edx": : "g" (dosdate));
X asm("movl $0x5701, %eax");
X asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
X}
X
Xvoid _dos_setfileattr(char *name, int attr)
X{
X asm("movl %0, %%edx": : "g" (name));
X asm("movl %0, %%ecx": : "g" (attr));
X asm("movl $0x4301, %eax");
X asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
X}
X
Xvoid _dos_getdrive(unsigned *d)
X{
X asm("movl $0x1900, %eax");
X asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
X asm("xorb %ah, %ah");
X asm("incb %al");
X asm("movl %%eax, %0": "=a" (*d));
X}
X
Xunsigned _dos_creat(char *path, unsigned attr, int *fd)
X{
X asm("movl $0x3c00, %eax");
X asm("movl %0, %%edx": :"g" (path));
X asm("movl %0, %%ecx": :"g" (attr));
X asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
X asm("movl %%eax, %0": "=a" (*fd));
X _doserrno = 0;
X asm("jnc 1f");
X _doserrno = *fd;
X switch (_doserrno) {
X case 3:
X errno = ENOENT;
X break;
X case 4:
X errno = EMFILE;
X break;
X case 5:
X errno = EACCES;
X break;
X }
X asm("1:");
X return _doserrno;
X}
X
Xunsigned _dos_close(int fd)
X{
X asm("movl %0, %%ebx": : "g" (fd));
X asm("movl $0x3e00, %eax");
X asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
X _doserrno = 0;
X asm("jnc 1f");
X asm ("movl %%eax, %0": "=m" (_doserrno));
X if (_doserrno == 6) {
X errno = EBADF;
X }
X asm("1:");
X return _doserrno;
X}
X
Xstatic int volumelabel(char *name)
X{
X int fd;
X
X return _dos_creat(name, FA_LABEL, &fd) ? fd : _dos_close(fd);
X}
X
X#endif /* __GO32__ || __EMX__ */
END_OF_FILE
if test 46263 -ne `wc -c <'unzip-5.12/msdos/msdos.c'`; then
echo shar: \"'unzip-5.12/msdos/msdos.c'\" unpacked with wrong size!
fi
# end of 'unzip-5.12/msdos/msdos.c'
fi
if test -f 'unzip-5.12/zipinfo.doc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'unzip-5.12/zipinfo.doc'\"
else
echo shar: Extracting \"'unzip-5.12/zipinfo.doc'\" \(21079 characters\)
sed "s/^X//" >'unzip-5.12/zipinfo.doc' <<'END_OF_FILE'
X
XZIPINFO(1L) MISC. REFERENCE MANUAL PAGES ZIPINFO(1L)
X
XNAME
X zipinfo - list detailed information about a ZIP archive
X
XSYNOPSIS
X zipinfo [-12smlvhtTz] file[.zip] [file(s) ...]
X [-x xfile(s) ...]
X
X unzip -Z [-12smlvhtTz] file[.zip] [file(s) ...]
X [-x xfile(s) ...]
X
XDESCRIPTION
X zipinfo lists technical information about files in a ZIP
X archive, most commonly found on MS-DOS systems. Such infor-
X mation includes file access permissions, encryption status,
X type of compression, version and operating system or file
X system of compressing program, and the like. The default
X behavior (with no options) is to list single-line entries
X for each file in the archive, with header and trailer lines
X providing summary information for the entire archive. The
X format is a cross between Unix ``ls -l'' and ``unzip -v''
X output. See DETAILED DESCRIPTION below. Note that zipinfo
X is the same program as unzip (under Unix, a link to it); on
X some systems, however, zipinfo support may have been omitted
X when unzip was compiled.
X
XARGUMENTS
X file[.zip]
X Path of the ZIP archive(s). If the file specification
X is a wildcard, each matching file is processed in an
X order determined by the operating system (or file sys-
X tem). Only the filename can be a wildcard; the path
X itself cannot. Wildcard expressions are similar to
X Unix egrep(1) (regular) expressions and may contain:
X
X * matches a sequence of 0 or more characters
X
X ? matches exactly 1 character
X
X [...]
X matches any single character found inside the
X brackets; ranges are specified by a beginning
X character, a hyphen, and an ending character. If
X an exclamation point or a caret (`!' or `^') fol-
X lows the left bracket, then the range of charac-
X ters within the brackets is complemented (that is,
X anything except the characters inside the brackets
X is considered a match).
X
X (Be sure to quote any character which might otherwise
X be interpreted or modified by the operating system,
X particularly under Unix and VMS.) If no matches are
X found, the specification is assumed to be a literal
X
XInfo-ZIP Last change: 28 Aug 94 (v2.02) 1
X
XZIPINFO(1L) MISC. REFERENCE MANUAL PAGES ZIPINFO(1L)
X
X filename; and if that also fails, the suffix .zip is
X appended. Note that self-extracting ZIP files are sup-
X ported; just specify the .exe suffix (if any) expli-
X citly.
X
X [file(s)]
X An optional list of archive members to be processed.
X Regular expressions (wildcards) may be used to match
X multiple members; see above. Again, be sure to quote
X expressions that would otherwise be expanded or modi-
X fied by the operating system.
X
X [-x xfile(s)]
X An optional list of archive members to be excluded from
X processing.
X
XOPTIONS
X -1 list filenames only, one per line. This option
X excludes all others; headers, trailers and zipfile com-
X ments are never printed. It is intended for use in
X Unix shell scripts.
X
X -2 list filenames only, one per line, but allow headers
X (-h), trailers (-t) and zipfile comments (-z), as well.
X This option may be useful in cases where the stored
X filenames are particularly long.
X
X -s list zipfile info in short Unix ``ls -l'' format. This
X is the default behavior; see below.
X
X -m list zipfile info in medium Unix ``ls -l'' format.
X Identical to the -s output, except that the compression
X factor, expressed as a percentage, is also listed.
X
X -l list zipfile info in long Unix ``ls -l'' format. As
X with -m except that the compressed size (in bytes) is
X printed instead of the compression ratio.
X
X -v list zipfile information in verbose, multi-page format.
X
X -h list header line. The archive name, actual size (in
X bytes) and total number of files is printed.
X
X -t list totals for files listed or for all files. The
X number of files listed, their uncompressed and
X compressed total sizes, and their overall compression
X factor is printed; or, if only the totals line is being
X printed, the values for the entire archive are given.
X Note that the total compressed (data) size will never
X match the actual zipfile size, since the latter
X includes all of the internal zipfile headers in addi-
X tion to the compressed data.
X
XInfo-ZIP Last change: 28 Aug 94 (v2.02) 2
X
XZIPINFO(1L) MISC. REFERENCE MANUAL PAGES ZIPINFO(1L)
X
X -T print the file dates and times in a sortable decimal
X format (yymmdd.hhmmss). The default date format is a
X more standard, human-readable version with abbreviated
X month names (see examples below).
X
X -z include the archive comment (if any) in the listing.
X
XDETAILED DESCRIPTION
X zipinfo has a number of modes, and its behavior can be
X rather difficult to fathom if one isn't familiar with Unix
X ls(1) (or even if one is). The default behavior is to list
X files in the following format:
X
X-rw-rws--- 1.9 unx 2802 t- defX 11-Aug-91 13:48 perms.2660
X
X The last three fields are the modification date and time of
X the file, and its name. The case of the filename is
X respected; thus files which come from MS-DOS PKZIP are
X always capitalized. If the file was zipped with a stored
X directory name, that is also displayed as part of the
X filename.
X
X The second and third fields indicate that the file was
X zipped under Unix with version 1.9 of zip. Since it comes
X from Unix, the file permissions at the beginning of the line
X are printed in Unix format. The uncompressed file-size
X (2802 in this example) is the fourth field.
X
X The fifth field consists of two characters, either of which
X may take on several values. The first character may be
X either `t' or `b', indicating that zip believes the file to
X be text or binary, respectively; but if the file is
X encrypted, zipinfo notes this fact by capitalizing the char-
X acter (`T' or `B'). The second character may also take on
X four values, depending on whether there is an extended local
X header and/or an ``extra field'' associated with the file
X (fully explained in PKWare's APPNOTE.TXT, but basically
X analogous to pragmas in ANSI C--i.e., they provide a stan-
X dard way to include non-standard information in the
X archive). If neither exists, the character will be a hyphen
X (`-'); if there is an extended local header but no extra
X field, `l'; if the reverse, `x'; and if both exist, `X'.
X Thus the file in this example is (probably) a text file, is
X not encrypted, and has neither an extra field nor an
X extended local header associated with it. The example
X below, on the other hand, is an encrypted binary file with
X an extra field:
X
XRWD,R,R 0.9 vms 168 Bx shrk 9-Aug-91 19:15 perms.0644
X
X Extra fields are used for various purposes (see discussion
X of the -v option below) including the storage of VMS file
X
XInfo-ZIP Last change: 28 Aug 94 (v2.02) 3
X
XZIPINFO(1L) MISC. REFERENCE MANUAL PAGES ZIPINFO(1L)
X
X attributes, which is presumably the case here. Note that
X the file attributes are listed in VMS format. Some other
X possibilities for the host operating system (which is actu-
X ally a misnomer--host file system is more correct) include
X OS/2 or NT with High Performance File System (HPFS), MS-DOS,
X OS/2 or NT with File Allocation Table (FAT) file system, and
X Macintosh. These are denoted as follows:
X
X-rw-a-- 1.0 hpf 5358 Tl i4:3 4-Dec-91 11:33 longfilename.hpfs
X-r--ahs 1.1 fat 4096 b- i4:2 14-Jul-91 12:58 EA DATA. SF
X--w------- 1.0 mac 17357 bx i8:2 4-May-92 04:02 unzip.macr
X
X File attributes in the first two cases are indicated in a
X Unix-like format, where the seven subfields indicate whether
X the file: (1) is a directory, (2) is readable (always
X true), (3) is writable, (4) is executable (guessed on the
X basis of the extension--.exe, .com, .bat, .cmd and .btm
X files are assumed to be so), (5) has its archive bit set,
X (6) is hidden, and (7) is a system file. Interpretation of
X Macintosh file attributes is unreliable because some Macin-
X tosh archivers don't store any attributes in the archive.
X
X Finally, the sixth field indicates the compression method
X and possible sub-method used. There are six methods known
X at present: storing (no compression), reducing, shrinking,
X imploding, tokenizing (never publicly released), and deflat-
X ing. In addition, there are four levels of reducing (1
X through 4); four types of imploding (4K or 8K sliding dic-
X tionary, and 2 or 3 Shannon-Fano trees); and four levels of
X deflating (superfast, fast, normal, maximum compression).
X zipinfo represents these methods and their sub-methods as
X follows: stor; re:1, re:2, etc.; shrk; i4:2, i8:3, etc.;
X tokn; and defS, defF, defN, and defX.
X
X The medium and long listings are almost identical to the
X short format except that they add information on the file's
X compression. The medium format lists the file's compression
X factor as a percentage indicating the amount of space which
X has been ``removed'':
X
X-rw-rws--- 1.5 unx 2802 t- 81% defX 11-Aug-91 13:48 perms.2660
X
X In this example, the file has been compressed by more than a
X factor of five; the compressed data are only 19% of the ori-
X ginal size. The long format gives the compressed file's
X size in bytes, instead:
X
X-rw-rws--- 1.5 unx 2802 t- 538 defX 11-Aug-91 13:48 perms.2660
X
X Adding the -T option changes the file date and time to
X decimal format:
X
XInfo-ZIP Last change: 28 Aug 94 (v2.02) 4
X
XZIPINFO(1L) MISC. REFERENCE MANUAL PAGES ZIPINFO(1L)
X
X-rw-rws--- 1.5 unx 2802 t- 538 defX 910811.134804 perms.2660
X
X Note that because of limitations in the MS-DOS format used
X to store file times, the seconds field is always rounded to
X the nearest even second. For Unix files this is expected to
X change in the next major releases of zip(1L) and unzip.
X
X In addition to individual file information, a default zip-
X file listing also includes header and trailer lines:
X
XArchive: OS2.zip 5453 bytes 5 files
X,,rw, 1.0 hpf 730 b- i4:3 26-Jun-92 23:40 Contents
X,,rw, 1.0 hpf 3710 b- i4:3 26-Jun-92 23:33 makefile.os2
X,,rw, 1.0 hpf 8753 b- i8:3 26-Jun-92 15:29 os2unzip.c
X,,rw, 1.0 hpf 98 b- stor 21-Aug-91 15:34 unzip.def
X,,rw, 1.0 hpf 95 b- stor 21-Aug-91 17:51 zipinfo.def
X5 files, 13386 bytes uncompressed, 4951 bytes compressed: 63.0%
X
X The header line gives the name of the archive, its total
X size, and the total number of files; the trailer gives the
X number of files listed, their total uncompressed size, and
X their total compressed size (not including any of zip's
X internal overhead). If, however, one or more file(s) are
X provided, the header and trailer lines are not listed. This
X behavior is also similar to that of Unix's ``ls -l''; it may
X be overridden by specifying the -h and -t options expli-
X citly. In such a case the listing format must also be
X specified explicitly, since -h or -t (or both) in the
X absence of other options implies that ONLY the header or
X trailer line (or both) is listed. See the EXAMPLES section
X below for a semi-intelligible translation of this nonsense.
X
X The verbose listing is mostly self-explanatory. It also
X lists file comments and the zipfile comment, if any, and the
X type and number of bytes in any stored extra fields.
X Currently known types of extra fields include PKWARE's
X authentication (``AV'') info; OS/2 extended attributes; VMS
X filesystem info, both PKWARE and Info-ZIP versions; Macin-
X tosh resource forks; Acorn/Archimedes SparkFS info; and so
X on. (Note that in the case of OS/2 extended attributes--
X perhaps the most common use of zipfile extra fields--the
X size of the stored EAs as reported by zipinfo may not match
X the number given by OS/2's dir command: OS/2 always reports
X the number of bytes required in 16-bit format, whereas
X zipinfo always reports the 32-bit storage.)
X
XENVIRONMENT OPTIONS
X Modifying zipinfo's default behavior via options placed in
X an environment variable can be a bit complicated to explain,
X due to zipinfo's attempts to handle various defaults in an
X intuitive, yet Unix-like, manner. (Try not to laugh.)
X Nevertheless, there is some underlying logic. In brief,
X
XInfo-ZIP Last change: 28 Aug 94 (v2.02) 5
X
XZIPINFO(1L) MISC. REFERENCE MANUAL PAGES ZIPINFO(1L)
X
X there are three ``priority levels'' of options: the default
X options; environment options, which can override or add to
X the defaults; and explicit options given by the user, which
X can override or add to either of the above.
X
X The default listing format, as noted above, corresponds
X roughly to the "zipinfo -hst" command (except when indivi-
X dual zipfile members are specified). A user who prefers the
X long-listing format (-l) can make use of the zipinfo's
X environment variable to change this default:
X
X ZIPINFO=-l; export ZIPINFO Unix Bourne shell
X setenv ZIPINFO -l Unix C shell
X set ZIPINFO=-l OS/2 or MS-DOS
X define ZIPINFO_OPTS "-l" VMS (quotes for lowercase)
X
X If, in addition, the user dislikes the trailer line,
X zipinfo's concept of ``negative options'' may be used to
X override the default inclusion of the line. This is accom-
X plished by preceding the undesired option with one or more
X minuses: e.g., ``-l-t'' or ``--tl'', in this example. The
X first hyphen is the regular switch character, but the one
X before the `t' is a minus sign. The dual use of hyphens may
X seem a little awkward, but it's reasonably intuitive
X nonetheless: simply ignore the first hyphen and go from
X there. It is also consistent with the behavior of the Unix
X command nice(1).
X
X As suggested above, the default variable names are
X ZIPINFO_OPTS for VMS (where the symbol used to install
X zipinfo as a foreign command would otherwise be confused
X with the environment variable), and ZIPINFO for all other
X operating systems. For compatibility with zip(1L), ZIPIN-
X FOOPT is also accepted (don't ask). If both ZIPINFO and
X ZIPINFOOPT are defined, however, ZIPINFO takes precedence.
X unzip's diagnostic option (-v with no zipfile name) can be
X used to check the values of all four possible unzip and
X zipinfo environment variables.
X
XEXAMPLES
X To get a basic, short-format listing of the complete con-
X tents of a ZIP archive storage.zip, with both header and
X totals lines, use only the archive name as an argument to
X zipinfo:
X
X zipinfo storage
X
X To produce a basic, long-format listing (not verbose),
X including header and totals lines, use -l:
X
X zipinfo -l storage
X
XInfo-ZIP Last change: 28 Aug 94 (v2.02) 6
X
XZIPINFO(1L) MISC. REFERENCE MANUAL PAGES ZIPINFO(1L)
X
X To list the complete contents of the archive without header
X and totals lines, either negate the -h and -t options or
X else specify the contents explicitly:
X
X zipinfo --h-t storage
X zipinfo storage \*
X
X (where the backslash is required only if the shell would
X otherwise expand the `*' wildcard, as in Unix when globbing
X is turned on--double quotes around the asterisk would have
X worked as well). To turn off the totals line by default,
X use the environment variable (C shell is assumed here):
X
X setenv ZIPINFO --t
X zipinfo storage
X
X To get the full, short-format listing of the first example
X again, given that the environment variable is set as in the
X previous example, it is necessary to specify the -s option
X explicitly, since the -t option by itself implies that ONLY
X the footer line is to be printed:
X
X setenv ZIPINFO --t
X zipinfo -t storage [only totals line]
X zipinfo -st storage [full listing]
X
X The -s option, like -m and -l, includes headers and footers
X by default, unless otherwise specified. Since the environ-
X ment variable specified no footers and that has a higher
X precedence than the default behavior of -s, an explicit -t
X option was necessary to produce the full listing. Nothing
X was indicated about the header, however, so the -s option
X was sufficient. Note that both the -h and -t options, when
X used by themselves or with each other, override any default
X listing of member files; only the header and/or footer are
X printed. This behavior is useful when zipinfo is used with
X a wildcard zipfile specification; the contents of all zip-
X files are then summarized with a single command.
X
X To list information on a single file within the archive, in
X medium format, specify the filename explicitly:
X
X zipinfo -m storage unshrink.c
X
X The specification of any member file, as in this example,
X will override the default header and totals lines; only the
X single line of information about the requested file will be
X printed. This is intuitively what one would expect when
X requesting information about a single file. For multiple
X files, it is often useful to know the total compressed and
X uncompressed size; in such cases -t may be specified expli-
X citly:
X
XInfo-ZIP Last change: 28 Aug 94 (v2.02) 7
X
XZIPINFO(1L) MISC. REFERENCE MANUAL PAGES ZIPINFO(1L)
X
X zipinfo -mt storage "*.[ch]" Mak\*
X
X To get maximal information about the ZIP archive, use the
X verbose option. It is usually wise to pipe the output into
X a filter such as Unix more(1) if the operating system allows
X it:
X
X zipinfo -v storage | more
X
X Finally, to see the most recently modified files in the
X archive, use the -T option in conjunction with an external
X sorting utility such as Unix sort(1) (and tail(1) as well,
X in this example):
X
X zipinfo -T storage | sort -n +6 | tail -15
X
X The -n option to sort(1) tells it to sort numerically rather
X than in ASCII order, and the +6 option tells it to sort on
X the sixth field after the first one (i.e., the seventh
X field). This assumes the default short-listing format; if
X -m or -l is used, the proper sort(1) option would be +7.
X The tail(1) command filters out all but the last 15 lines of
X the listing. Future releases of zipinfo may incorporate
X date/time and filename sorting as built-in options.
X
XTIPS
X The author finds it convenient to define an alias ii for
X zipinfo on systems which allow aliases (or, on other sys-
X tems, copy/rename the executable, create a link or create a
X command file with the name ii). The ii usage parallels the
X common ll alias for long listings in Unix, and the similar-
X ity between the outputs of the two commands was intentional.
X
XBUGS
X None known at this time, but we're always delighted to find
X a good one.
X
XSEE ALSO
X ls(1), funzip(1L), unzip(1L), unzipsfx(1L), zip(1L),
X zipcloak(1L), zipnote(1L), zipsplit(1L)
X
XAUTHOR
X Greg Roelofs (a.k.a. Cave Newt). ZipInfo contains pattern-
X matching code by Mark Adler and fixes/improvements by many
X others. Please refer to the CONTRIBS file in the UnZip
X source distribution for a more complete list.
X
XInfo-ZIP Last change: 28 Aug 94 (v2.02) 8
X
END_OF_FILE
if test 21079 -ne `wc -c <'unzip-5.12/zipinfo.doc'`; then
echo shar: \"'unzip-5.12/zipinfo.doc'\" unpacked with wrong size!
fi
# end of 'unzip-5.12/zipinfo.doc'
fi
echo shar: End of archive 7 \(of 20\).
cp /dev/null ark7isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 20 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still must unpack the following archives:
echo " " ${MISSING}
fi
exit 0
exit 0 # Just in case...