home *** CD-ROM | disk | FTP | other *** search
- From: zip-bugs@wkuvx1.wku.edu (Info-ZIP group)
- Newsgroups: comp.sources.misc
- Subject: v44i073: unzip - Info-ZIP portable UnZip, version 5.12, Part08/20
- Date: 18 Sep 1994 23:15:22 -0500
- Organization: Sterling Software
- Sender: kent@sparky.sterling.com
- Approved: kent@sparky.sterling.com
- Message-ID: <35j38q$qo0@sparky.sterling.com>
- X-Md4-Signature: f330b237a5d9fd3100d029d904b846f7
-
- Submitted-by: zip-bugs@wkuvx1.wku.edu (Info-ZIP group)
- Posting-number: Volume 44, Issue 73
- Archive-name: unzip/part08
- 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/amiga/amiga.c unzip-5.12/nt/nt.c
- # Wrapped by kent@sparky on Sat Sep 17 23:33:40 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 8 (of 20)."'
- if test -f 'unzip-5.12/amiga/amiga.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'unzip-5.12/amiga/amiga.c'\"
- else
- echo shar: Extracting \"'unzip-5.12/amiga/amiga.c'\" \(25728 characters\)
- sed "s/^X//" >'unzip-5.12/amiga/amiga.c' <<'END_OF_FILE'
- X/*------------------------------------------------------------------------
- X
- X amiga.c
- X
- X Amiga-specific routines for use with Info-ZIP's UnZip 5.1 and later.
- X See History.5xx for revision history.
- X
- X Contents: mapattr()
- X mapname()
- X do_wild()
- X checkdir()
- X cmptime()
- X invlocal()
- X close_outfile()
- X _abort() (Aztec C only)
- X version()
- X
- X ------------------------------------------------------------------------*/
- X
- X
- X#include "unzip.h"
- X
- X/* Globular varibundus */
- X
- Xstatic int created_dir; /* used in mapname(), checkdir() */
- Xstatic int renamed_fullpath; /* ditto */
- X#define PERMS 0777
- X#define MKDIR(path,mode) mkdir(path)
- X
- X
- X#ifndef S_ISCRIPT /* not having one implies you have none */
- X# define S_IARCHIVE 0020 /* not modified since this bit was last set */
- X# define S_IREAD 0010 /* can be opened for reading */
- X# define S_IWRITE 0004 /* can be opened for writing */
- X# define S_IDELETE 0001 /* can be deleted */
- X#endif /* S_ISCRIPT */
- X
- X#ifndef S_IRWD
- X# define S_IRWD 0015 /* useful combo of Amiga privileges */
- X#endif /* !S_IRWD */
- X
- X#ifndef S_IHIDDEN
- X# define S_IHIDDEN 0200 /* hidden supported in future AmigaDOS (someday) */
- X#endif /* !S_HIDDEN */
- X
- X
- X
- X/**********************/
- X/* Function mapattr() */
- X/**********************/
- X
- Xint mapattr(void) /* Amiga version */
- X{
- X ulg tmp = crec.external_file_attributes;
- X
- X
- X /* Amiga attributes = hsparwed = hidden, script, pure, archive,
- X * read, write, execute, delete */
- X
- X switch (pInfo->hostnum) {
- X case AMIGA_:
- X if ((tmp & 1) == (tmp>>18 & 1))
- X tmp ^= 0x000F0000; /* PKAZip compatibility kluge */
- X /* turn off archive bit for restored Amiga files */
- X pInfo->file_attr = (unsigned)((tmp>>16) & (~S_IARCHIVE));
- X break;
- X
- X case UNIX_: /* preserve read, write, execute: use logical-OR of */
- X case VMS_: /* user, group, and other; if writable, set delete bit */
- X tmp >>= 16;
- X tmp = (( tmp>>6 | tmp>>3 | tmp) & 07) << 1;
- X pInfo->file_attr = (unsigned)(tmp&S_IWRITE? tmp|S_IDELETE : tmp);
- X break;
- X
- X /* all other platforms: assume read-only bit in DOS half of attribute
- X * word is set correctly ==> will become READ or READ+WRITE+DELETE */
- X case FS_FAT_:
- X case FS_HPFS_: /* can add S_IHIDDEN check to MSDOS/OS2/NT eventually */
- X case FS_NTFS_:
- X case MAC_:
- X case ATARI_:
- X case TOPS20_:
- X default:
- X pInfo->file_attr = (unsigned)(tmp&1? S_IREAD : S_IRWD);
- X break;
- X
- X } /* end switch (host-OS-created-by) */
- X
- X pInfo->file_attr &= 0xff; /* mask off all but lower eight bits */
- X return 0;
- X
- X} /* end function mapattr() */
- 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=NULL; /* character pointers */
- X char *lastsemi = NULL; /* pointer to last semi-colon in pathcomp */
- X int quote = FALSE; /* flags */
- 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
- X /* user gave full pathname: don't prepend rootpath */
- X renamed_fullpath = (renamed && strchr(filename, ':'));
- X
- X if (checkdir((char *)NULL, INIT) == 10)
- X return 10; /* initialize path buffer, unless no memory */
- X
- X *pathcomp = '\0'; /* initialize translation buffer */
- X pp = pathcomp; /* point to translation buffer */
- X if (jflag) /* junking directories */
- X cp = (char *)strrchr(filename, '/');
- X if (cp == 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 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 if ((error = checkdir(pathcomp, APPEND_DIR)) > 1)
- X return error;
- X pp = pathcomp; /* reset conversion buffer for next piece */
- X lastsemi = NULL; /* leave directory semi-colons alone */
- X break;
- X
- X case ';': /* VMS version (or DEC-20 attrib?) */
- X lastsemi = pp; /* keep for now; remove VMS ";##" */
- X *pp++ = (char)workch; /* later, if requested */
- X break;
- X
- X case '\026': /* control-V quote for special chars */
- X quote = TRUE; /* set flag for next character */
- X break;
- X
- X default:
- X /* allow European characters in filenames: */
- X if (isprint(workch) || (128 <= workch && workch <= 255))
- 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 with VMS version numbers (appended ";###") */
- X if (!V_flag && lastsemi) {
- X pp = lastsemi + 1;
- X while (isdigit((uch)(*pp)))
- X ++pp;
- X if (*pp == '\0') /* only digits between ';' and end: nuke */
- X *lastsemi = '\0';
- X }
- 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 if (checkdir(filename, GETPATH) == 1) {
- X fprintf(stderr, "pathname too long: truncat{ed/ing}\n");
- X return 1; /* GRR: NEEDS WORK! (do checking only when appending) */
- X }
- 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, "mapname: conversion of %s failed\n", filename);
- X return 3;
- X }
- X
- X if ((error = checkdir(pathcomp, APPEND_NAME)) == 1) {
- X /* GRR: OK if truncated here: warn and continue */
- X /* (warn in checkdir?) */
- X }
- X checkdir(filename, GETPATH);
- X
- X return error;
- X
- X} /* end function mapname() */
- X
- X
- Xstatic int ispattern(char *p)
- X{
- X register char c;
- X while (c = *p++)
- X if (c == '\\') {
- X if (!*++p)
- X return FALSE;
- X } else if (c == '?' || c == '*')
- X return TRUE;
- X else if (c == '[') {
- X for (;;) {
- X if (!(c = *p++))
- X return FALSE;
- X else if (c == '\\') {
- X if (!*++p)
- X return FALSE;
- X } else if (c == ']')
- X return TRUE;
- X }
- X }
- X return FALSE;
- X}
- X
- X/**********************/
- X/* Function do_wild() */ /* for porting: dir separator; match(ignore_case) */
- X/**********************/
- X
- Xchar *do_wild(wildspec)
- X char *wildspec; /* only used first time on a given dir */
- X{
- X static DIR *dir = NULL;
- X static char *dirname, *wildname, matchname[FILNAMSIZ];
- X static int firstcall=TRUE, have_dirname, dirnamelen;
- X struct dirent *file;
- X BPTR lok = 0;
- 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 /* avoid needless readdir() scans: */
- X if (!ispattern(wildspec) || (lok = Lock(wildspec, ACCESS_READ))) {
- X if (lok) UnLock(lok);
- X have_dirname = FALSE;
- X strcpy(matchname, wildspec);
- X return matchname;
- X }
- X
- X /* break the wildspec into a directory part and a wildcard filename */
- X if ((wildname = strrchr(wildspec, '/')) == NULL
- X && (wildname = strrchr(wildspec, ':')) == NULL) {
- X dirname = ""; /* current dir */
- 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)) == NULL) {
- X fprintf(stderr, "warning: can't allocate wildcard buffers\n");
- X strcpy(matchname, wildspec);
- X return matchname; /* but maybe filespec was not a wildcard */
- X }
- X strncpy(dirname, wildspec, dirnamelen);
- X dirname[dirnamelen] = 0;
- X have_dirname = TRUE;
- X }
- X
- X if ((dir = opendir(dirname)) != NULL) {
- X while ((file = readdir(dir)) != NULL) {
- X if (match(file->d_name, wildname, 1)) { /* case insensitive */
- 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 = NULL;
- X }
- 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 == 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)) != NULL)
- X if (match(file->d_name, wildname, 0)) { /* 0 == don't 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 = 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
- X
- X/***********************/
- X/* Function checkdir() */
- X/***********************/
- X
- Xint checkdir(pathcomp, flag)
- X char *pathcomp;
- X int flag;
- X/*
- X * returns: 1 - (on APPEND_xxx) truncated path component
- 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 * 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
- 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/* GRR: check path length after each segment: warn about truncation */
- X
- X if (FUNCTION == APPEND_DIR) {
- X Trace((stderr, "appending dir segment [%s]\n", pathcomp));
- X while ((*end = *pathcomp++))
- X ++end;
- X if (stat(buildpath, &statbuf)) { /* path doesn't exist */
- 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 (MKDIR(buildpath, 0777) == -1) { /* create the directory */
- X fprintf(stderr,
- X "checkdir: can't create %s\n unable to process %s.\n"
- X , buildpath, 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, "checkdir: %s exists but is not a directory\n\
- X unable to process %s.\n", buildpath, filename);
- X fflush(stderr);
- X free(buildpath);
- X return 3; /* path existed but wasn't dir */
- 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); /* DO ERROR CHECKING: TOO LONG? */
- X Trace((stderr, "getting and freeing path [%s]\n", pathcomp));
- X free(buildpath);
- X buildpath = end = 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) { /* DO ERROR CHECKING */
- X Trace((stderr, "appending filename [%s]\n", pathcomp));
- X while ((*end = *pathcomp++))
- X ++end;
- 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)) == NULL)
- X return 10;
- X if ((rootlen > 0) && !renamed_fullpath) {
- 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.
- 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 == NULL) {
- X rootlen = 0;
- X return 0;
- X }
- X if ((rootlen = strlen(pathcomp)) > 0) {
- X int had_trailing_pathsep=FALSE;
- X
- X if (pathcomp[rootlen-1] == '/') {
- X pathcomp[--rootlen] = '\0';
- X had_trailing_pathsep = TRUE;
- X }
- X if (rootlen > 0 && (stat(pathcomp, &statbuf) ||
- X !S_ISDIR(statbuf.st_mode))) /* path does not exist */
- X {
- X if (!create_dirs /* || iswild(pathcomp) */
- X#ifdef OLD_EXDIR
- X || !had_trailing_pathsep
- X#endif
- X ) {
- X rootlen = 0;
- X return 2; /* treat as stored file */
- X }
- X /* create the directory (could add loop here to scan pathcomp
- X * and create more than one level, but why really necessary?) */
- X if (MKDIR(pathcomp, 0777) == -1) {
- X fprintf(stderr,
- X "checkdir: can't create extraction directory: %s\n",
- X pathcomp);
- X fflush(stderr);
- X rootlen = 0; /* path didn't exist, tried to create, and */
- X return 3; /* failed: file exists, or 2+ levels required */
- X }
- X }
- X if ((rootpath = (char *)malloc(rootlen+2)) == NULL) {
- X rootlen = 0;
- X return 10;
- X }
- X strcpy(rootpath, pathcomp);
- X if (rootpath[rootlen - 1] != ':')
- 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/* Function cmptime() */
- X/**********************/
- X
- X/* cmptime() clone pinched from from Zip1.9h,
- X * by Mark Adler, Jean-loup Gailly, et al., circa 1991.
- X * Incorporated into UnZip 5.1d by John Bush
- X */
- X
- Xint cmptime(p, q)
- Xstruct tm *p, *q; /* times to compare */
- X/* Return negative if time p is before time q, positive if after, and
- X zero if the same */
- X{
- X int r; /* temporary variable */
- X
- X if (p == NULL)
- X return -1;
- X else if ((r = p->tm_year - q->tm_year) != 0)
- X return r;
- X else if ((r = p->tm_mon - q->tm_mon) != 0)
- X return r;
- X else if ((r = p->tm_mday - q->tm_mday) != 0)
- X return r;
- X else if ((r = p->tm_hour - q->tm_hour) != 0)
- X return r;
- X else if ((r = p->tm_min - q->tm_min) != 0)
- X return r;
- X else
- X return p->tm_sec - q->tm_sec;
- X}
- X
- X
- X/***********************/
- X/* Function invlocal() */
- X/***********************/
- X
- X/* mktime() clone pinched from from Zip1.9h,
- X * by Mark Adler and Jean-loup Gailly, et.al, circa 1991.
- X * Incorporated into UnZip 5.1d by John Bush
- X */
- Xtime_t invlocal(t)
- Xstruct tm *t; /* time to convert */
- X/* Find inverse of localtime() using bisection. This routine assumes that
- X time_t is an integer type, either signed or unsigned. The expectation
- X is that sometime before the year 2038, time_t will be made a 64-bit
- X integer, and this routine will still work. */
- X{
- X time_t i; /* midpoint of current root range */
- X time_t l; /* lower end of root range */
- X time_t u; /* upper end of root range */
- X
- X /* Bracket the root [0,largest time_t]. Note: if time_t is a 32-bit signed
- X integer, then the upper bound is GMT 1/19/2038 03:14:07, after which all
- X the Unix systems in the world come to a grinding halt. Either that, or
- X all those systems will suddenly find themselves transported to December
- X of 1901 ... */
- X l = 0;
- X u = 1;
- X while (u < (u << 1))
- X u = (u << 1) + 1;
- X
- X /* Find the root */
- X while (u - l > 1)
- X {
- X i = l + ((u - l) >> 1);
- X if (cmptime(localtime(&i), t) <= 0)
- X l = i;
- X else
- X u = i;
- X }
- X return l;
- X}
- X
- X
- X
- X/**************************************/
- X/* Function close_outfile() */
- X/**************************************/
- X/* this part differs slightly with Zip */
- X/*-------------------------------------*/
- X
- Xvoid close_outfile(void)
- X{
- X struct tm t; /* good ole time structure */
- X time_t u[2]; /* mean ole time stamp */
- X ulg dd,dt; /* DOS format time stamps */
- X LONG FileDate();
- X time_t invlocal();
- X
- X if (cflag) /* can't set time on stdout */
- X return;
- X
- X /* close the file *before* setting its time under AmigaDos */
- X
- X fclose(outfile);
- X
- X /* assign date and time to local variables */
- X
- X dd = lrec.last_mod_file_date;
- X dt = lrec.last_mod_file_time;
- X
- X /* Convert DOS time to time_t format in (time_t)u */
- X
- X t.tm_sec = (int) (dt << 1) & 0x3e;
- X t.tm_min = (int) (dt >> 5) & 0x3f;
- X t.tm_hour = (int) (dt >> 11) & 0x1f;
- X
- X t.tm_mday = (int) (dd & 0x1f);
- X t.tm_mon = ((int) (dd >> 5) & 0xf ) - 1;
- X t.tm_year = ((int) (dd >> 9) & 0x7f) + 80;
- X
- X /* invlocal() is equivalent to mktime() */
- X
- X u[0] = u[1] = invlocal(&t);
- X
- X#ifdef DEBUG
- X fprintf (stderr,"\nclose_outfile(): u=%s\n",ctime(&u[0]));
- X#endif
- X
- X if (!FileDate(filename, u))
- X fprintf(stderr, "warning: can't set the time for %s\n", filename);
- X
- X /* set file perms after closing (not done at creation)--see mapattr() */
- X
- X chmod(filename, pInfo->file_attr);
- X
- X} /* end function close_outfile() */
- X
- X
- X/********************************************************************/
- X/* Load filedate as a separate external file; it's used by Zip, too.*/
- X/* */
- X#include "amiga/filedate.c" /* */
- X/* */
- X/********************************************************************/
- X
- X/**************** for Aztec, do linewise with stat.c ****************/
- X
- X#ifdef AZTEC_C
- X# include "amiga/stat.c"
- X/* this is the exact same stat.c used for Aztec by Zip */
- X
- X# include <stdio.h>
- X# include "crypt.h"
- X
- Xvoid _abort(void) /* called when ^C is pressed */
- X{
- X echon();
- X close_leftover_open_dirs();
- X fflush(stdout);
- X fputs("\n^C\n", stderr);
- X exit(1);
- X}
- X#endif /* AZTEC_C */
- X
- X
- X#ifndef SFX
- X
- X/************************/
- X/* Function version() */
- X/************************/
- X
- X
- X/* NOTE: the following include depends upon the environment
- X * variable $Workbench to be set correctly. (Set by
- X * default, by kickstart during startup)
- X */
- Xint WBversion = (int)
- X#include "ENV:Workbench"
- X;
- X
- Xvoid version()
- X{
- X extern char Far CompiledWith[];
- X
- X/* Define buffers. */
- X
- X char buf1[16]; /* compiler name */
- X char buf2[16]; /* revstamp */
- X char buf3[16]; /* OS */
- X char buf4[16]; /* Date */
- X/* char buf5[16]; /* Time */
- X
- X/* format "with" name strings */
- X
- X#ifdef AMIGA
- X# ifdef __SASC
- X strcpy(buf1,"SAS/C ");
- X# else
- X# ifdef LATTICE
- X strcpy(buf1,"Lattice C ");
- X# else
- X# ifdef AZTEC_C
- X strcpy(buf1,"Manx Aztec C ");
- X# else
- X strcpy(buf1,"UNKNOWN ");
- X# endif
- X# endif
- X# endif
- X/* "under" */
- X sprintf(buf3,"AmigaDOS v%d",WBversion);
- X#else
- X strcpy(buf1,"Unknown compiler ");
- X strcpy(buf3,"Unknown OS");
- X#endif
- X
- X/* Define revision, date, and time strings.
- X * NOTE: Do not calculate run time, be sure to use time compiled.
- X * Pass these strings via your makefile if undefined.
- X */
- X
- X#if defined(__VERSION__) && defined(__REVISION__)
- X sprintf(buf2,"version %d.%d",__VERSION__,__REVISION__);
- X#else
- X# ifdef __VERSION__
- X sprintf(buf2,"version %d",__VERSION__);
- X# else
- X sprintf(buf2,"unknown version");
- X# endif
- X#endif
- X
- X#ifdef __DATE__
- X sprintf(buf4," on %s",__DATE__);
- X#else
- X strcpy(buf4," unknown date");
- X#endif
- X
- X/******
- X#ifdef __TIME__
- X sprintf(buf5," at %s",__TIME__);
- X#else
- X strcpy(buf5," unknown time");
- X#endif
- X******/
- X
- X/* Print strings using "CompiledWith" mask defined in unzip.c (used by all).
- X * ("Compiled with %s%s under %s%s%s%s.")
- X */
- X
- X printf(LoadFarString(CompiledWith),
- X buf1,
- X buf2,
- X buf3,
- X buf4,
- X /* buf5, */ "",
- X "" ); /* buf6 not used */
- X
- X} /* end function version() */
- X
- X#endif /* !SFX */
- END_OF_FILE
- if test 25728 -ne `wc -c <'unzip-5.12/amiga/amiga.c'`; then
- echo shar: \"'unzip-5.12/amiga/amiga.c'\" unpacked with wrong size!
- fi
- # end of 'unzip-5.12/amiga/amiga.c'
- fi
- if test -f 'unzip-5.12/nt/nt.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'unzip-5.12/nt/nt.c'\"
- else
- echo shar: Extracting \"'unzip-5.12/nt/nt.c'\" \(40790 characters\)
- sed "s/^X//" >'unzip-5.12/nt/nt.c' <<'END_OF_FILE'
- X/*---------------------------------------------------------------------------
- X
- X nt.c Last updated: 15 Aug 94
- X
- X WinNT-specific routines for use with Info-ZIP's UnZip 5.1 and later.
- X (Borrowed, pilfered and plundered code from OS/2 and MS-DOS versions and
- X from ZIP; modified as necessary.)
- X
- X Contains: GetLoadPath()
- X opendir()
- X readdir()
- X closedir()
- X mapattr()
- X getNTfiletime()
- X close_outfile()
- X isfloppy()
- X IsVolumeOldFAT()
- X IsFileNameValid()
- X map2fat()
- X checkdir()
- X do_wild()
- X mapname()
- X version()
- X
- X ---------------------------------------------------------------------------*/
- X
- X#include <windows.h>
- X#include "unzip.h"
- X
- X
- X#define MKDIR(path,mode) mkdir(path)
- X
- Xstruct direct
- X{
- X char reserved [21];
- X char ff_attrib;
- X short ff_ftime;
- X short ff_fdate;
- X long size;
- X char d_name[MAX_PATH];
- X int d_first;
- X HANDLE d_hFindFile;
- X};
- X
- X
- Xstatic int created_dir; /* used by mapname(), checkdir() */
- Xstatic int renamed_fullpath; /* ditto */
- Xstatic int fnlen; /* ditto */
- Xstatic unsigned nLabelDrive; /* ditto */
- X
- X
- X
- X#ifdef SFX
- X
- X/**************************/
- X/* Function GetLoadPath() */
- X/**************************/
- X
- Xchar *GetLoadPath(void)
- X{
- X#ifdef MSC
- X extern char *_pgmptr;
- X return _pgmptr;
- X
- X#else /* use generic API call */
- X GetModuleFileName(NULL, filename, FILNAMSIZ);
- X return filename;
- X#endif
- X
- X} /* end function GetLoadPath() */
- X
- X
- X
- X
- X
- X#else /* !SFX */
- X
- X/**********************/ /* Borrowed from ZIP 2.0 sources */
- X/* Function opendir() */ /* Difference: no special handling for */
- X/**********************/ /* hidden or system files. */
- X
- Xstatic struct direct *opendir(n)
- X const char *n; /* directory to open */
- X{
- X struct direct *d; /* malloc'd return value */
- X char *p; /* malloc'd temporary string */
- X WIN32_FIND_DATA fd;
- X int len = strlen(n);
- X
- X /* Start searching for files in the MSDOS directory n */
- X
- X if ((d = (struct direct *)malloc(sizeof(struct direct))) == NULL ||
- X (p = malloc(strlen(n) + 5)) == NULL)
- X {
- X if (d != (struct direct *)NULL)
- X free((void *)d);
- X return (struct direct *)NULL;
- X }
- X strcpy(p, n);
- X if (p[len-1] == ':')
- X p[len++] = '.'; /* x: => x:. */
- X else if (p[len-1] == '/' || p[len-1] == '\\')
- X --len; /* foo/ => foo */
- X strcpy(p+len, "/*");
- X
- X if (INVALID_HANDLE_VALUE == (d->d_hFindFile = FindFirstFile(p, &fd))) {
- X free((voidp *)d);
- X free((voidp *)p);
- X return NULL;
- X }
- X strcpy(d->d_name, fd.cFileName);
- X
- X free((voidp *)p);
- X d->d_first = 1;
- X return d;
- X
- X} /* end of function opendir() */
- X
- X
- X
- X
- X/**********************/ /* Borrowed from ZIP 2.0 sources */
- X/* Function readdir() */ /* Difference: no special handling for */
- X/**********************/ /* hidden or system files. */
- X
- Xstatic struct direct *readdir(d)
- X struct direct *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 {
- X WIN32_FIND_DATA fd;
- X
- X if ( !FindNextFile(d->d_hFindFile, &fd) )
- X return NULL;
- X
- X strcpy(d->d_name, fd.cFileName);
- X }
- X return (struct direct *)d;
- X
- X} /* end of function readdir() */
- X
- X
- X
- X
- X/***********************/
- X/* Function closedir() */ /* Borrowed from ZIP 2.0 sources */
- X/***********************/
- X
- Xstatic void closedir(d)
- X struct direct *d; /* directory stream to close */
- X{
- X FindClose(d->d_hFindFile);
- X free(d);
- X}
- X
- X#endif /* ?SFX */
- X
- X
- X
- X
- X/**********************/
- X/* Function mapattr() */
- X/**********************/
- X
- X/* Identical to MS-DOS, OS/2 versions. */
- X/* However, NT has a lot of extra permission stuff, so this function should */
- X/* probably be extended in the future. */
- 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/****************************/ /* Get the file time in a format that */
- X/* Function getNTfiletime() */ /* can be used by SetFileTime() in NT */
- X/****************************/
- X
- Xint getNTfiletime(FILETIME *ft)
- X{
- X FILETIME lft; /* 64-bit value made up of two 32 bit [low & high] */
- X WORD wDOSDate; /* for converting from DOS date to Windows NT */
- X WORD wDOSTime;
- X
- X /* Copy and/or convert time and date variables, if necessary; */
- X /* then set the file time/date. */
- X wDOSTime = (WORD)lrec.last_mod_file_time;
- X wDOSDate = (WORD)lrec.last_mod_file_date;
- X
- X /* The DosDateTimeToFileTime() function converts a DOS date/time */
- X /* into a 64 bit Windows NT file time */
- X if (!DosDateTimeToFileTime(wDOSDate, wDOSTime, &lft))
- X {
- X PRINTF("DosDateTime failed: %d\n", GetLastError());
- X return FALSE;
- X }
- X if (!LocalFileTimeToFileTime( &lft, ft))
- X {
- X PRINTF("LocalFileTime failed: %d\n", GetLastError());
- X *ft = lft;
- X }
- X return TRUE;
- X}
- X
- X
- X
- X
- X/****************************/
- X/* Function close_outfile() */
- X/****************************/
- X
- Xvoid close_outfile()
- X{
- X FILETIME ft; /* File time type defined in NT */
- X HANDLE hFile; /* File handle defined in NT */
- X int gotTime;
- X
- X /* don't set the time stamp on standard output */
- X if (cflag) {
- X fclose(outfile);
- X return;
- X }
- X
- X gotTime = getNTfiletime(&ft);
- X
- X /* Close the file and then re-open it using the Win32
- X * CreateFile call, so that the file can be created
- X * with GENERIC_WRITE access, otherwise the SetFileTime
- X * call will fail. */
- X fclose(outfile);
- X
- X hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
- X FILE_ATTRIBUTE_NORMAL, NULL);
- X if ( hFile == INVALID_HANDLE_VALUE ) {
- X FPRINTF(stderr, "\nCreateFile error %d when trying set file time\n",
- X GetLastError());
- X }
- X else {
- X if (gotTime)
- X if (!SetFileTime(hFile, NULL, NULL, &ft))
- X PRINTF("\nSetFileTime failed: %d\n", GetLastError());
- X CloseHandle(hFile);
- X }
- X
- X /* HG: I think this could be done in the CreateFile call above - just */
- X /* replace 'FILE_ATTRIBUTE_NORMAL' with 'pInfo->file_attr & 0x7F' */
- X if (!SetFileAttributes(filename, pInfo->file_attr & 0x7F))
- X FPRINTF(stderr, "\nwarning (%d): could not set file attributes\n",
- X GetLastError());
- X
- X return;
- X
- X} /* end function close_outfile() */
- X
- X
- X
- X/* ============================================================================
- X*/
- X
- X
- X
- X/***********************/
- X/* Function isfloppy() */ /* more precisely, is it removable? */
- X/***********************/
- X
- Xstatic int isfloppy(int nDrive) /* 1 == A:, 2 == B:, etc. */
- X{
- X char rootPathName[4];
- X
- X rootPathName[0] = 'A' + nDrive - 1; /* Build the root path name, */
- X rootPathName[1] = ':'; /* e.g. "A:/" */
- X rootPathName[2] = '/';
- X rootPathName[3] = '\0';
- X
- X return (GetDriveType(rootPathName) == DRIVE_REMOVABLE);
- X
- X} /* end function isfloppy() */
- X
- X
- X
- X
- X/*****************************/
- X/* Function IsVolumeOldFAT() */
- X/*****************************/
- X
- X/*
- X * Note: 8.3 limits on filenames apply only to old-style FAT filesystems.
- X * More recent versions of Windows (Windows NT 3.5 / Windows 4.0)
- X * can support long filenames (LFN) on FAT filesystems. Check the
- X * filesystem maximum component length field to detect LFN support.
- X * [GRR: this routine is only used to determine whether spaces in
- X * filenames are supported...]
- X */
- X
- Xstatic int IsVolumeOldFAT(char *name)
- X{
- X char *tmp0;
- X char rootPathName[4];
- X char tmp1[MAX_PATH], tmp2[MAX_PATH];
- X unsigned volSerNo, maxCompLen, fileSysFlags;
- X
- X if (isalpha(name[0]) && (name[1] == ':'))
- X tmp0 = name;
- X else
- X {
- X GetFullPathName(name, MAX_PATH, tmp1, &tmp0);
- X tmp0 = &tmp1[0];
- X }
- X strncpy(rootPathName, tmp0, 3); /* Build the root path name, */
- X rootPathName[3] = '\0'; /* e.g. "A:/" */
- X
- X GetVolumeInformation(rootPathName, tmp1, MAX_PATH, &volSerNo,
- X &maxCompLen, &fileSysFlags, tmp2, MAX_PATH);
- X
- X /* Long Filenames (LFNs) are available if the component length is > 12 */
- X return maxCompLen <= 12;
- X/* return !strncmp(strupr(tmp2), "FAT", 3); old version */
- X
- X}
- X
- X
- X
- X
- X/******************************/
- X/* Function IsFileNameValid() */
- X/******************************/
- X
- Xstatic int IsFileNameValid(char *name)
- X{
- X HFILE hf;
- X OFSTRUCT of;
- X
- X hf = OpenFile(name, &of, OF_READ | OF_SHARE_DENY_NONE);
- X if (hf == HFILE_ERROR)
- X switch (GetLastError())
- X {
- X case ERROR_INVALID_NAME:
- X case ERROR_FILENAME_EXCED_RANGE:
- X return FALSE;
- X default:
- X return TRUE;
- X }
- X else
- X _lclose(hf);
- X return TRUE;
- X}
- X
- X
- X
- X
- X/**********************/
- X/* Function map2fat() */ /* Identical to OS/2 version */
- X/**********************/
- X
- Xvoid map2fat(pathcomp, pEndFAT)
- X char *pathcomp, **pEndFAT;
- X{
- X char *ppc = pathcomp; /* variable pointer to pathcomp */
- X char *pEnd = *pEndFAT; /* variable pointer to buildpathFAT */
- X char *pBegin = *pEndFAT; /* constant pointer to start of this comp. */
- X char *last_dot = NULL; /* last dot not converted to underscore */
- X int dotname = FALSE; /* flag: path component begins with dot */
- X /* ("." and ".." don't count) */
- X register unsigned workch; /* hold the character being tested */
- X
- X
- X /* Only need check those characters which are legal in HPFS but not
- X * in FAT: to get here, must already have passed through mapname.
- X * (GRR: oops, small bug--if char was quoted, no longer have any
- X * knowledge of that.) Also must truncate path component to ensure
- X * 8.3 compliance...
- X */
- X while ((workch = (uch)*ppc++) != 0) {
- X switch (workch) {
- X case '[':
- X case ']':
- X *pEnd++ = '_'; /* convert brackets to underscores */
- X break;
- X
- X case '.':
- X if (pEnd == *pEndFAT) { /* nothing appended yet... */
- X if (*ppc == '\0') /* don't bother appending a */
- X break; /* "./" component to the path */
- X else if (*ppc == '.' && ppc[1] == '\0') { /* "../" */
- X *pEnd++ = '.'; /* add first dot, unchanged... */
- X ++ppc; /* skip second dot, since it will */
- X } else { /* be "added" at end of if-block */
- X *pEnd++ = '_'; /* 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 *pEnd = '\0'; /* remove it by shifting chars */
- X pEnd = *pEndFAT + 1; /* left one space (e.g., .p1.p2: */
- X while (pEnd[1]) { /* __p1 -> _p1_p2 -> _p1.p2 when */
- X *pEnd = pEnd[1]; /* finished) [opt.: since first */
- X ++pEnd; /* two chars are same, can start */
- X } /* shifting at second position] */
- X }
- X last_dot = pEnd; /* point at last dot so far... */
- X *pEnd++ = '_'; /* convert dot to underscore for now */
- X break;
- X
- X default:
- X *pEnd++ = (char)workch;
- X
- X } /* end switch */
- X } /* end while loop */
- X
- X *pEnd = '\0'; /* terminate buildpathFAT */
- X
- X /* NOTE: keep in mind that pEnd points to the end of the path
- X * component, and *pEndFAT still points to the *beginning* of it...
- X * Also note that the algorithm does not try to get too fancy:
- X * if there are no dots already, the name either gets truncated
- X * at 8 characters or the last underscore is converted to a dot
- X * (only if more characters are saved that way). In no case is
- X * a dot inserted between existing characters.
- X */
- X if (last_dot == NULL) { /* no dots: check for underscores... */
- X char *plu = strrchr(pBegin, '_'); /* pointer to last underscore */
- X
- X if (plu == NULL) { /* no dots, no underscores: truncate at 8 chars */
- X *pEndFAT += 8; /* (or could insert '.' and keep 11...?) */
- X if (*pEndFAT > pEnd)
- X *pEndFAT = pEnd; /* oops...didn't have 8 chars to truncate */
- X else
- X **pEndFAT = '\0';
- X } else if (MIN(plu - pBegin, 8) + MIN(pEnd - plu - 1, 3) > 8) {
- X last_dot = plu; /* be lazy: drop through to next if-blk */
- X } else if ((pEnd - *pEndFAT) > 8) {
- X *pEndFAT += 8; /* more fits into just basename than if */
- X **pEndFAT = '\0'; /* convert last underscore to dot */
- X } else
- X *pEndFAT = pEnd; /* whole thing fits into 8 chars or less */
- X }
- X
- X if (last_dot != NULL) { /* one dot (or two, in the case of */
- X *last_dot = '.'; /* "..") is OK: put it back in */
- X
- X if ((last_dot - pBegin) > 8) {
- X char *p=last_dot, *q=pBegin+8;
- X int i;
- X
- X for (i = 0; (i < 4) && *p; ++i) /* too many chars in basename: */
- X *q++ = *p++; /* shift .ext left and trun- */
- X *q = '\0'; /* cate/terminate it */
- X *pEndFAT = q;
- X } else if ((pEnd - last_dot) > 4) { /* too many chars in extension */
- X *pEndFAT = last_dot + 4;
- X **pEndFAT = '\0';
- X } else
- X *pEndFAT = pEnd; /* filename is fine; point at terminating zero */
- X }
- X} /* end function map2fat() */
- X
- X
- X
- X
- X/***********************/ /* Borrowed from os2.c for UnZip 5.1. */
- X/* Function checkdir() */ /* Difference: no EA stuff */
- X/***********************/ /* HPFS stuff works on NTFS too */
- 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 *buildpathHPFS; /* full path (so far) to extracted file, */
- X static char *buildpathFAT; /* both HPFS/EA (main) and FAT versions */
- X static char *endHPFS; /* corresponding pointers to end of */
- X static char *endFAT; /* buildpath ('\0') */
- 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 char *p = pathcomp;
- X int too_long=FALSE;
- X
- X Trace((stderr, "appending dir segment [%s]\n", pathcomp));
- X while ((*endHPFS = *p++) != '\0') /* copy to HPFS filename */
- X ++endHPFS;
- X if (IsFileNameValid(buildpathHPFS)) {
- X p = pathcomp;
- X while ((*endFAT = *p++) != '\0') /* copy to FAT filename, too */
- X ++endFAT;
- X } else {
- X/* GRR: check error return? */
- X map2fat(pathcomp, &endFAT); /* map, put in FAT fn, update endFAT */
- X }
- X
- X /* GRR: could do better check, see if overrunning buffer as we go:
- X * check endHPFS-buildpathHPFS after each append, set warning variable
- X * if within 20 of FILNAMSIZ; then if var set, do careful check when
- X * appending. Clear variable when begin new path. */
- X
- X /* next check: need to append '/', at least one-char name, '\0' */
- X if ((endHPFS-buildpathHPFS) > FILNAMSIZ-3)
- X too_long = TRUE; /* check if extracting dir? */
- X if (stat(buildpathFAT, &statbuf)) /* path doesn't exist */
- X {
- X if (!create_dirs) { /* told not to create (freshening) */
- X free(buildpathHPFS);
- X free(buildpathFAT);
- X return 2; /* path doesn't exist: nothing to do */
- X }
- X if (too_long) { /* GRR: should allow FAT extraction w/o EAs */
- X FPRINTF(stderr, "checkdir error: path too long: %s\n",
- X buildpathHPFS);
- X fflush(stderr);
- X free(buildpathHPFS);
- X free(buildpathFAT);
- X return 4; /* no room for filenames: fatal */
- X }
- X if (MKDIR(buildpathFAT, 0777) == -1) { /* create the directory */
- X FPRINTF(stderr, "checkdir error: can't create %s\n\
- X unable to process %s.\n", buildpathFAT, filename);
- X fflush(stderr);
- X free(buildpathHPFS);
- X free(buildpathFAT);
- 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, "checkdir error: %s exists but is not directory\n\
- X unable to process %s.\n", buildpathFAT, filename);
- X fflush(stderr);
- X free(buildpathHPFS);
- X free(buildpathFAT);
- X return 3; /* path existed but wasn't dir */
- X }
- X if (too_long) {
- X FPRINTF(stderr, "checkdir error: path too long: %s\n",
- X buildpathHPFS);
- X fflush(stderr);
- X free(buildpathHPFS);
- X free(buildpathFAT);
- X return 4; /* no room for filenames: fatal */
- X }
- X *endHPFS++ = '/';
- X *endFAT++ = '/';
- X *endHPFS = *endFAT = '\0';
- X Trace((stderr, "buildpathHPFS now = [%s]\n", buildpathHPFS));
- X Trace((stderr, "buildpathFAT now = [%s]\n", buildpathFAT));
- X return 0;
- X
- X } /* end if (FUNCTION == APPEND_DIR) */
- X
- X/*---------------------------------------------------------------------------
- X GETPATH: copy full FAT path to the string pointed at by pathcomp (want
- X filename to reflect name used on disk, not EAs; if full path is HPFS,
- X buildpathFAT and buildpathHPFS will be identical). Also free both paths.
- X ---------------------------------------------------------------------------*/
- X
- X if (FUNCTION == GETPATH) {
- X Trace((stderr, "getting and freeing FAT path [%s]\n", buildpathFAT));
- X Trace((stderr, "freeing HPFS path [%s]\n", buildpathHPFS));
- X strcpy(pathcomp, buildpathFAT);
- X free(buildpathFAT);
- X free(buildpathHPFS);
- X buildpathHPFS = buildpathFAT = endHPFS = endFAT = 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 char *p = pathcomp;
- X int error = 0;
- X
- X Trace((stderr, "appending filename [%s]\n", pathcomp));
- X while ((*endHPFS = *p++) != '\0') { /* copy to HPFS filename */
- X ++endHPFS;
- X if ((endHPFS-buildpathHPFS) >= FILNAMSIZ) {
- X *--endHPFS = '\0';
- X FPRINTF(stderr, "checkdir warning: path too long; truncating\n\
- X %s\n -> %s\n", filename, buildpathHPFS);
- X fflush(stderr);
- X error = 1; /* filename truncated */
- X }
- X }
- X
- X if ( pInfo->vollabel || IsFileNameValid(buildpathHPFS)) {
- X p = pathcomp;
- X while ((*endFAT = *p++) != '\0') /* copy to FAT filename, too */
- X ++endFAT;
- X } else {
- X map2fat(pathcomp, &endFAT); /* map, put in FAT fn, update endFAT */
- X }
- X Trace((stderr, "buildpathHPFS: %s\nbuildpathFAT: %s\n",
- X buildpathHPFS, buildpathFAT));
- X
- X return error; /* could check for existence, prompt for new name... */
- X
- X } /* end if (FUNCTION == APPEND_NAME) */
- 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
- X/* HG: variable not used here */
- X/* char *p; */
- X
- X Trace((stderr, "initializing buildpathHPFS and buildpathFAT to "));
- X if ((buildpathHPFS = (char *)malloc(fnlen+rootlen+1)) == NULL)
- X return 10;
- X if ((buildpathFAT = (char *)malloc(fnlen+rootlen+1)) == NULL) {
- X free(buildpathHPFS);
- X return 10;
- X }
- X if (pInfo->vollabel) { /* use root or renamed path, but don't store */
- X/* GRR: for network drives, do strchr() and return IZ_VOL_LABEL if not [1] */
- X if (renamed_fullpath && pathcomp[1] == ':')
- X *buildpathHPFS = ToLower(*pathcomp);
- X else if (!renamed_fullpath && rootpath && rootpath[1] == ':')
- X *buildpathHPFS = ToLower(*rootpath);
- X else {
- X char tmpN[MAX_PATH], *tmpP;
- X if (GetFullPathName(".", MAX_PATH, tmpN, &tmpP) > MAX_PATH)
- X { /* by definition of MAX_PATH we should never get here */
- X FPRINTF(stderr,
- X "checkdir warning: current dir path too long\n");
- X return 1; /* can't get drive letter */
- X }
- X nLabelDrive = *tmpN - 'a' + 1;
- X *buildpathHPFS = (char)(nLabelDrive - 1 + 'a');
- X }
- X nLabelDrive = *buildpathHPFS - 'a' + 1; /* save for mapname() */
- X if (volflag == 0 || *buildpathHPFS < 'a' || /* no labels/bogus? */
- X (volflag == 1 && !isfloppy(nLabelDrive))) { /* -$: no fixed */
- X free(buildpathHPFS);
- X free(buildpathFAT);
- X return IZ_VOL_LABEL; /* skipping with message */
- X }
- X *buildpathHPFS = '\0';
- X } else if (renamed_fullpath) /* pathcomp = valid data */
- X strcpy(buildpathHPFS, pathcomp);
- X else if (rootlen > 0)
- X strcpy(buildpathHPFS, rootpath);
- X else
- X *buildpathHPFS = '\0';
- X endHPFS = buildpathHPFS;
- X endFAT = buildpathFAT;
- X while ((*endFAT = *endHPFS) != '\0') {
- X ++endFAT;
- X ++endHPFS;
- X }
- X Trace((stderr, "[%s]\n", buildpathHPFS));
- 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 == 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 if (SSTAT(pathcomp, &statbuf) || !S_ISDIR(statbuf.st_mode)) {
- 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 /* 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,
- X "checkdir: can't create extraction directory: %s\n",
- 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)) == 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#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 struct direct *dir = NULL;
- X static char *dirname, *wildname, matchname[FILNAMSIZ];
- 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, '/')) == NULL &&
- X (wildname = strrchr(wildspec, ':')) == 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)) == NULL) {
- X FPRINTF(stderr, "warning: can't allocate wildcard buffers\n");
- X strcpy(matchname, wildspec);
- X return matchname; /* but maybe filespec was not a wildcard */
- X }
- 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)) != NULL) {
- X while ((file = readdir(dir)) != 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 = 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 == 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)) != 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 = 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/* Function mapname() */
- X/************************/
- X
- X/*
- X * There are presently two possibilities in OS/2: the output filesystem is
- X * FAT, or it is HPFS. If the former, we need to map to FAT, obviously, but
- X * we *also* must map to HPFS and store that version of the name in extended
- X * attributes. Either way, we need to map to HPFS, so the main mapname
- X * routine does that. In the case that the output file system is FAT, an
- X * extra filename-mapping routine is called in checkdir(). While it should
- X * be possible to determine the filesystem immediately upon entry to mapname(),
- X * it is conceivable that the DOS APPEND utility could be added to OS/2 some-
- X * day, allowing a FAT directory to be APPENDed to an HPFS drive/path. There-
- X * fore we simply check the filesystem at each path component.
- X *
- X * Note that when alternative IFS's become available/popular, everything will
- X * become immensely more complicated. For example, a Minix filesystem would
- X * have limited filename lengths like FAT but no extended attributes in which
- X * to store the longer versions of the names. A BSD Unix filesystem would
- X * support paths of length 1024 bytes or more, but it is not clear that FAT
- X * EAs would allow such long .LONGNAME fields or that OS/2 would properly
- X * restore such fields when moving files from FAT to the new filesystem.
- X *
- X * GRR: some or all of the following chars should be checked in either
- X * mapname (HPFS) or map2fat (FAT), depending: ,=^+'"[]<>|\t&
- 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 /* IZ_VOL_LABEL if can't do vol label, IZ_CREATED_DIR */
- X char pathcomp[FILNAMSIZ]; /* path-component buffer */
- X char *pp, *cp=NULL; /* character pointers */
- X char *lastsemi = NULL; /* pointer to last semi-colon in pathcomp */
- X int quote = FALSE; /* flag: next char is literal */
- 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 fnlen = strlen(filename);
- X
- 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 == 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 if ((error = checkdir(pathcomp, APPEND_DIR)) > 1)
- X return error;
- X pp = pathcomp; /* reset conversion buffer for next piece */
- X lastsemi = NULL; /* leave directory semi-colons alone */
- X break;
- X
- X case ':':
- X *pp++ = '_'; /* drive names not stored in zipfile, */
- X break; /* so no colons allowed */
- X
- X case ';': /* start of VMS version? */
- X lastsemi = pp; /* remove VMS version later... */
- X *pp++ = ';'; /* but keep semicolon for now */
- 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 ' ': /* keep spaces unless specifically */
- X /* NT cannot create filenames with spaces on FAT volumes */
- X if (sflag || IsVolumeOldFAT(filename))
- X *pp++ = '_';
- X else
- X *pp++ = ' ';
- 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 + 1; /* semi-colon was kept: expect #'s after */
- X while (isdigit((uch)(*pp)))
- X ++pp;
- X if (*pp == '\0') /* only digits between ';' and end: nuke */
- X *lastsemi = '\0';
- X }
- 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[fnlen-1] == '/') {
- X checkdir(filename, GETPATH);
- X if (created_dir && QCOND2) {
- X/* GRR: trailing '/'? need to strip or not? */
- X FPRINTF(stdout, " creating: %-22s\n", filename);
- X /* HG: are we setting the date&time on a newly created dir? */
- X /* Not quite sure how to do this. It does not seem to */
- X /* be done in the MS-DOS version of mapname(). */
- X return IZ_CREATED_DIR; /* dir time already set */
- X }
- X return 2; /* dir existed already; don't look for data to extract */
- X }
- X
- X if (*pathcomp == '\0') {
- X FPRINTF(stderr, "mapname: conversion of %s failed\n", filename);
- X return 3;
- X }
- X
- X checkdir(pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */
- X checkdir(filename, GETPATH);
- X Trace((stderr, "mapname returns with filename = [%s] (error = %d)\n\n",
- X filename, error));
- X
- X if (pInfo->vollabel) { /* set the volume label now */
- X char drive[3];
- X
- X /* Build a drive string, e.g. "b:" */
- X drive[0] = 'a' + nLabelDrive - 1;
- X drive[1] = ':';
- X drive[2] = '\0';
- X if (QCOND2)
- X FPRINTF(stdout, "labelling %s %-22s\n", drive, filename);
- X if (!SetVolumeLabel(drive, filename)) {
- X FPRINTF(stderr, "mapname: error setting volume label\n");
- 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#ifndef SFX
- X
- X/************************/
- X/* Function version() */
- X/************************/
- X
- Xvoid version()
- X{
- X extern char Far CompiledWith[];
- X#if defined(_MSC_VER)
- X char buf[80];
- X#endif
- X
- X PRINTF(LoadFarString(CompiledWith),
- X
- X#ifdef _MSC_VER /* MSC == VC++, but what about SDK compiler? */
- X (sprintf(buf, "Microsoft C %d.%02d ", _MSC_VER/100, _MSC_VER%100), buf),
- X# if (_MSC_VER >= 800)
- X "(Visual C++)",
- X# else
- X "(bad version)",
- X# endif
- X#else
- X "unknown compiler (SDK?)", "",
- X#endif
- X
- X "Windows NT", " (32-bit)",
- X
- X#ifdef __DATE__
- X " on ", __DATE__
- X#else
- X "", ""
- X#endif
- X );
- X
- X return;
- X
- X} /* end function version() */
- X
- X#endif /* !SFX */
- END_OF_FILE
- if test 40790 -ne `wc -c <'unzip-5.12/nt/nt.c'`; then
- echo shar: \"'unzip-5.12/nt/nt.c'\" unpacked with wrong size!
- fi
- # end of 'unzip-5.12/nt/nt.c'
- fi
- echo shar: End of archive 8 \(of 20\).
- cp /dev/null ark8isdone
- 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...
-