home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
SOFTWARE
/
SOURCES
/
UNZIP52.ZIP
/
msdos
/
msdos.c
(
.txt
)
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-23
|
54KB
|
1,559 lines
/*---------------------------------------------------------------------------
msdos.c
MSDOS-specific routines for use with Info-ZIP's UnZip 5.2 and later.
Contains: Opendir() (from zip)
Readdir() (from zip)
do_wild()
mapattr()
mapname()
map2fat()
checkdir()
isfloppy()
volumelabel() (non-djgpp, non-emx)
close_outfile()
dateformat()
version()
_dos_getcountryinfo() (djgpp, emx)
[_dos_getftime() (djgpp, emx) to be added]
_dos_setftime() (djgpp, emx)
_dos_setfileattr() (djgpp, emx)
_dos_getdrive() (djgpp, emx)
_dos_creat() (djgpp, emx)
_dos_close() (djgpp, emx)
volumelabel() (djgpp, emx)
__crt0_glob_function() (djgpp 2.x)
__crt_load_environment_file() (djgpp 2.x)
---------------------------------------------------------------------------*/
#define UNZIP_INTERNAL
#include "unzip.h"
#ifndef USE_VFAT
static void map2fat OF((char *pathcomp, char *last_dot));
#endif
static int isfloppy OF((int nDrive));
static int volumelabel OF((char *newlabel));
static int created_dir; /* used by mapname(), checkdir() */
static int renamed_fullpath; /* ditto */
static unsigned nLabelDrive; /* ditto, plus volumelabel() */
/*****************************/
/* Strings used in msdos.c */
/*****************************/
#ifndef SFX
static char Far CantAllocateWildcard[] =
"warning: can't allocate wildcard buffers\n";
#endif
static char Far Creating[] = " creating: %s\n";
static char Far ConversionFailed[] = "mapname: conversion of %s failed\n";
static char Far Labelling[] = "labelling %c: %-22s\n";
static char Far ErrSetVolLabel[] = "mapname: error setting volume label\n";
static char Far PathTooLong[] = "checkdir error: path too long: %s\n";
static char Far CantCreateDir[] = "checkdir error: can't create %s\n\
unable to process %s.\n";
static char Far DirIsntDirectory[] =
"checkdir error: %s exists but is not directory\n\
unable to process %s.\n";
static char Far PathTooLongTrunc[] =
"checkdir warning: path too long; truncating\n %s\n\
-> %s\n";
#if (!defined(SFX) || defined(SFX_EXDIR))
static char Far CantCreateExtractDir[] =
"checkdir: can't create extraction directory: %s\n";
#endif
#ifdef __TURBOC__
static char Far AttribsMayBeWrong[] =
"\nwarning: file attributes may not be correct\n";
#endif
#ifdef WATCOMC_386
# define WREGS(v,r) (v##.w.##r)
# define int86x int386x
#else
# define WREGS(v,r) (v##.x.##r)
#endif
#if (defined(__GO32__) || defined(__EMX__))
# include <dirent.h> /* use readdir() */
# define MKDIR(path,mode) mkdir(path,mode)
# define Opendir opendir
# define Readdir readdir
# define Closedir closedir
# define zdirent dirent
# define zDIR DIR
# ifdef __EMX__
# include <dos.h>
# define GETDRIVE(d) d = _getdrive()
# define FA_LABEL A_LABEL
# else
# define GETDRIVE(d) _dos_getdrive(&d)
# endif
#else /* !(__GO32__ || __EMX__) */
# define MKDIR(path,mode) mkdir(path)
# ifdef __TURBOC__
# define FATTR FA_HIDDEN+FA_SYSTEM+FA_DIREC
# define FVOLID FA_VOLID
# define FFIRST(n,d,a) findfirst(n,(struct ffblk *)d,a)
# define FNEXT(d) findnext((struct ffblk *)d)
# define GETDRIVE(d) d=getdisk()+1
# include <dir.h>
# else /* !__TURBOC__ */
# define FATTR _A_HIDDEN+_A_SYSTEM+_A_SUBDIR
# define FVOLID _A_VOLID
# define FFIRST(n,d,a) _dos_findfirst(n,a,(struct find_t *)d)
# define FNEXT(d) _dos_findnext((struct find_t *)d)
# define GETDRIVE(d) _dos_getdrive(&d)
# include <direct.h>
# endif /* ?__TURBOC__ */
typedef struct zdirent {
char d_reserved[30];
char d_name[13];
int d_first;
} zDIR;
zDIR *Opendir OF((const char *));
struct zdirent *Readdir OF((zDIR *));
# define Closedir free
#ifndef SFX
/**********************/ /* Borland C++ 3.x has its own opendir/readdir */
/* Function Opendir() */ /* library routines, but earlier versions don't, */
/**********************/ /* so use ours regardless */
zDIR *Opendir(name)
const char *name; /* name of directory to open */
{
zDIR *dirp; /* malloc'd return value */
char *nbuf; /* malloc'd temporary string */
int len = strlen(name); /* path length to avoid strlens and strcats */
if ((dirp = (zDIR *)malloc(sizeof(zDIR))) == (zDIR *)NULL)
return (zDIR *)NULL;
if ((nbuf = malloc(len + 5)) == (char *)NULL) {
free(dirp);
return (zDIR *)NULL;
}
strcpy(nbuf, name);
if (nbuf[len-1] == ':') {
nbuf[len++] = '.';
} else if (nbuf[len-1] == '/' || nbuf[len-1] == '\\')
--len;
strcpy(nbuf+len, "/*.*");
Trace((stderr, "Opendir: nbuf = [%s]\n", nbuf));
if (FFIRST(nbuf, dirp, FATTR)) {
free((zvoid *)nbuf);
return (zDIR *)NULL;
}
free((zvoid *)nbuf);
dirp->d_first = 1;
return dirp;
}
/**********************/
/* Function Readdir() */
/**********************/
struct zdirent *Readdir(d)
zDIR *d; /* directory stream from which to read */
{
/* Return pointer to first or next directory entry, or NULL if end. */
if (d->d_first)
d->d_first = 0;
else
if (FNEXT(d))
return (struct zdirent *)NULL;
return (struct zdirent *)d;
}
#endif /* !SFX */
#endif /* ?(__GO32__ || __EMX__) */
#ifndef SFX
/************************/
/* Function do_wild() */ /* identical to OS/2 version */
/************************/
char *do_wild(__G__ wildspec)
__GDEF
char *wildspec; /* only used first time on a given dir */
{
static zDIR *dir = (zDIR *)NULL;
static char *dirname, *wildname, matchname[FILNAMSIZ];
static int firstcall=TRUE, have_dirname, dirnamelen;
struct zdirent *file;
/* Even when we're just returning wildspec, we *always* do so in
* matchname[]--calling routine is allowed to append four characters
* to the returned string, and wildspec may be a pointer to argv[].
*/
if (firstcall) { /* first call: must initialize everything */
firstcall = FALSE;
if (!iswild(wildspec)) {
strcpy(matchname, wildspec);
have_dirname = FALSE;
dir = NULL;
return matchname;
}
/* break the wildspec into a directory part and a wildcard filename */
if ((wildname = strrchr(wildspec, '/')) == (char *)NULL &&
(wildname = strrchr(wildspec, ':')) == (char *)NULL) {
dirname = ".";
dirnamelen = 1;
have_dirname = FALSE;
wildname = wildspec;
} else {
++wildname; /* point at character after '/' or ':' */
dirnamelen = (int)(wildname - wildspec);
if ((dirname = (char *)malloc(dirnamelen+1)) == (char *)NULL) {
Info(slide, 1, ((char *)slide,
LoadFarString(CantAllocateWildcard)));
strcpy(matchname, wildspec);
return matchname; /* but maybe filespec was not a wildcard */
}
/* GRR: can't strip trailing char for opendir since might be "d:/" or "d:"
* (would have to check for "./" at end--let opendir handle it instead) */
strncpy(dirname, wildspec, dirnamelen);
dirname[dirnamelen] = '\0'; /* terminate for strcpy below */
have_dirname = TRUE;
}
Trace((stderr, "do_wild: dirname = [%s]\n", dirname));
if ((dir = Opendir(dirname)) != (zDIR *)NULL) {
while ((file = Readdir(dir)) != (struct zdirent *)NULL) {
Trace((stderr, "do_wild: readdir retu