Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6724 → Rev 6725

/programs/fs/unzip60/theos/Contents
0,0 → 1,20
Contents of the "theos" subdirectory for UnZip 5.41 and later:
 
Contents this file
makefile makefile for UnZip for THEOS architectures
theos.c Theos-specific support routines
thscfg.h
charconv.h
oldstat.h
stat.h
_fprintf.c
_isatty.c
_opendir.c
_setargv.c
_sprintf.c
_stat.c
 
Type "make" or "make help" to get general compile instructions (beyond
those in the INSTALL file), or "make list" for a list of makefile targets.
Note that there are some MS-DOS and cross-compilation targets thrown in
just to make things more exciting.
/programs/fs/unzip60/theos/_fprintf.c
0,0 → 1,26
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
#include <stdio.h>
#include <stdarg.h>
 
/* for Info and similar macroes. fprintf is already a macro and fprintf x
* fools the preprocessor
*/
 
int _fprintf(FILE* fp, const char* fmt, ...)
{
va_list ap;
long n;
 
va_start(ap, fmt);
n = vfprintf(fp, fmt, (long*) ap);
va_end(ap);
return n;
}
 
/programs/fs/unzip60/theos/_isatty.c
0,0 → 1,26
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/* replace standard library function who needs a FILE* */
 
#pragma library
 
#include <stdio.h>
#include <fcntl.h>
#include <sc.h>
#include <lub.h>
 
short _isatty(int fd)
{
register short lub;
 
lub = (int) _fcntl(&stdin[fd], 5, (size_t) 0);
return (lub >= CONIN && lub <= CONOUT)
|| (lub >= COM1 && lub <= COM4)
|| (lub >= COM5 && lub <= COM16);
}
/programs/fs/unzip60/theos/_setargv.c
0,0 → 1,165
/*
Copyright (c) 1990-2001 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*
* _setargv.c - derived from an command argument expander
*
* Author : Jean-Michel Dubois
* Date : 13-Dec-98
*
* Function: Looks for member names (fn.ft.mb) and add the libraries names
* (fn.ft) to the list of files to zip to force inclusion of
* libraries if necessary.
* Strings beginning by a dash are considered as options and left
* unchanged.
*
* Syntax : void _setargv(int *argc, char ***argv);
*
* Returns : new argc. Caller's argc and argv are updated.
* If a insufficient memory condition occurs, return 0 and errno
* is set to ENOMEM.
*
* Example :
* main(int argc, char **argv)
* {
* if (_setargv(&argc, &argv)) {
* ...
*/
#pragma library
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <errno.h>
#include <scr.h>
#include <peek.h>
 
/* Allocate argv array in 16 entries chunks */
 
static int allocarg(int n, int asize, char ***nargv, char *s)
{
if ((n+1) > asize) { /* If array full */
asize += 16; /* increase size and reallocate */
if (!(*nargv = (char **) realloc(*nargv, asize * sizeof (void *)))) {
errno = _errnum = ENOMEM; /* Not enough memory */
return 0;
}
}
(*nargv)[n] = strdup(s); /* Save argument */
return asize; /* Return new maxsize */
}
 
/* check if file is a member of a library */
 
static int ismember(char* path)
{
char* p;
 
if ((p = strrchr(path, '/')) == NULL)
p = path;
return ((p = strchr(p, '.')) && (p = strchr(p + 1, '.')));
}
 
/* extract library name from a file name */
 
static char* libname(char* path)
{
char* p;
static char lib[256];
char disk[3];
 
strcpy(lib, path);
if (p = strrchr(lib, ':')) {
strncpy(disk, p, 2);
disk[2] = '\0';
*p = '\0' ;
} else
disk[0] = '\0';
 
if ((p = strrchr(lib, '/')) == NULL)
p = lib;
 
p = strchr(p, '.');
p = strchr(p + 1, '.');
*p = 0;
strcat(lib, disk);
return lib;
}
 
/* Main body of the function */
 
int _setargv(int *argc, char ***argv)
{
register int nargc; /* New arguments counter */
char **nargv; /* New arguments pointers */
register int i, j;
int asize; /* argv array size */
char *arg;
char lib[256];
 
_errnum = 0;
nargc = 0; /* Initialise counter, size counter */
asize = *argc; /* and new argument vector to the */
/* current argv array size */
 
if ((nargv = (char **) calloc((size_t) *argc, sizeof (void *))) != NULL) {
/* For each initial argument */
for (i = 0; i < *argc; i++) {
arg = (*argv)[i];
#ifdef DEBUG
fprintf(stderr, "checking arg: %s", arg);
#endif
if (i == 0 || *arg == '-' || ! ismember(arg)) {
/* if it begins with a dash or doesn't include
* a library name simply add it to the new array */
if (! (asize = allocarg(nargc, asize, &nargv, arg)))
return 0; /* Not enough memory */
nargc++;
} else {
short insert;
strcpy(lib, libname(arg));
/* add library name if necessary */
for (j = 2, insert = 1; i < nargc; i++) {
if (ismember(nargv[i])
&& ! strcmp(lib, libname(nargv[i]))) {
insert = 0;
break;
}
}
if (insert) {
#ifdef DEBUG
fprintf(stderr, "inserting lib %s ", lib);
#endif
if (! (asize = allocarg(nargc, asize, &nargv, lib)))
return 0; /* Not enough memory */
nargc++;
}
/* add file name */
#ifdef DEBUG
fprintf(stderr, "inserting file %s", arg);
#endif
if (! (asize = allocarg(nargc, asize, &nargv, arg)))
return 0; /* Not enough memory */
nargc++;
}
#ifdef DEBUG
fprintf(stderr, "\n");
#endif
}
/* Update caller's parameters */
*argc = nargc;
*argv = nargv;
/* and sign on success */
return nargc;
}
 
/* If it is not possible to allocate initial array, sign on error */
_errnum = ENOMEM;
return 0;
}
/programs/fs/unzip60/theos/_sprintf.c
0,0 → 1,26
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
#include <stdio.h>
#include <stdarg.h>
 
/* for Info and similar macroes. fprintf is already a macro and fprintf x
* fools the preprocessor
*/
 
int _sprintf(char *s, const char *fmt, ...)
{
va_list ap;
long n;
 
va_start(ap, fmt);
n = vsprintf(s, fmt, (long*) ap);
va_end(ap);
return n;
}
 
/programs/fs/unzip60/theos/_stat.c
0,0 → 1,353
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
#pragma library
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sc.h>
#include <peek.h>
#include <lub.h>
#include <fdb.h>
#include <fsa.h>
#include "theos/stat.h"
 
/* replacement for standard library functions stat and fstat */
 
int _stat_(struct stat* st, struct fdb* fdb);
int _dstat_(struct stat* st);
 
#define peekucb() peeknuc()
 
/* map THEOS protection code to Unix modes */
 
unsigned short _tm2um_(char protect)
{
unsigned short umask = 0;
 
if (!(protect & _FDB_READ_PROTECT))
umask = S_IRUSR|S_IRGRP;
 
if (!(protect & _FDB_WRITE_PROTECT))
umask |= S_IWUSR|S_IWGRP;
 
if (!(protect & _FDB_EXECUTE_PROTECT))
umask |= S_IXUSR|S_IXGRP;
 
if (!(protect & _FDB_ERASE_PROTECT))
umask |= S_IEUSR|S_IEGRP;
 
if (!(protect & _FDB_SHARED_READ_PROTECT)) {
if (_osmajor > 3)
umask |= S_IROTH|S_IXOTH;
else
umask |= S_IROTH;
}
 
if (!(protect & _FDB_SHARED_WRITE_PROTECT))
umask |= S_IWOTH;
 
if (!(protect & _FDB_MODIFIED)) {
if (_osmajor > 3)
umask |= S_IMODF;
else
umask |= S_IXOTH;
}
 
if (protect & _FDB_NOT_HIDDEN)
umask |= S_INHID;
 
return umask;
}
 
/* map Unix modes to THEOS protections */
 
char _um2tm_(unsigned short mask)
{
char protect = 0;
 
if (!(mask & (S_IRUSR|S_IRGRP)))
protect |= _FDB_READ_PROTECT;
 
if (!(mask & (S_IWUSR|S_IWGRP)))
protect |= _FDB_WRITE_PROTECT;
 
if (!(mask & (S_IXUSR|S_IXGRP)))
protect |= _FDB_EXECUTE_PROTECT;
 
if (!(mask & (S_IEUSR|S_IEGRP)))
protect |= _FDB_ERASE_PROTECT;
 
if (_osmajor < 4) {
if (!(mask & S_IROTH))
protect |= _FDB_SHARED_READ_PROTECT;
} else {
if (!(mask & (S_IROTH|S_IXOTH)))
protect |= _FDB_SHARED_READ_PROTECT;
}
 
if (!(mask & S_IWOTH))
protect |= _FDB_SHARED_WRITE_PROTECT;
 
if (mask & S_IMODF && _osmajor > 3)
protect |= _FDB_MODIFIED;
 
if (mask & S_INHID && _osmajor > 3)
protect |= _FDB_NOT_HIDDEN;
 
return protect;
}
 
/* root directory stat */
 
static int rdirstat(char* fn, struct stat *st)
{
register char* p = strchr(fn, ':');
char drive;
 
drive = p ? p[1] : 'S';
 
if (drive >= 'a' && drive <= 'Z')
drive -= 0x40;
 
memset(st, 0, sizeof(struct stat));
 
if (getlub(drive - 'A') != 255) {
st->st_org = _FDB_STAT_DIRECTORY;
st->st_mode = S_IFDIR|S_IRUSR|S_IWUSR|S_IROTH|S_IWOTH;
st->st_nlink = 1;
st->st_dev = st->st_rdev = drive - 'A';
st->st_uid = st->st_gid = getuid();
st->st_protect = _FDB_ERASE_PROTECT;
return 0;
}
errno = _errnum = ENOENT;
_errarg = fn;
return -1;
}
 
/* file stat */
 
int _stat(const char *fn, struct stat *st)
{
char buf[256], buf2[256];
char *ifn;
register struct fdb *fdb;
register char *p;
 
if ((ifn = (char *)malloc(strlen(fn)+1)) == NULL) {
errno = _errnum = ENOMEM;
return -1;
}
 
if (p = strrchr(ifn, ':'))
*p = 0;
 
/* on current drive ./:d and .:m point to current dir
* on another drive to root directory */
 
if (! strcmp(ifn, "/") || ! strcmp(ifn, ".") || ! strcmp(ifn, "./")) {
if (p == NULL) {
free(ifn);
/* current dir on current drive */
ifn = getcwd(buf2, 256);
/* getcwd returns NULL on root dir on drive S */
if (ifn == NULL)
strcpy(ifn = buf2, "/:S");
/* getcwd returns /:d on root dir on any other drive */
if (ifn[1] == ':')
return rdirstat(ifn, st);
} else {
int rstat;
*p = ':';
rstat = rdirstat(ifn, st);
free(ifn);
return rstat;
}
}
 
if (p)
*p = ':';
 
strcpy(buf2, ifn);
/* remove trailing slash before optional disk name */
if (p = strrchr(buf2, '/')) {
if (p[1] == ':') {
*p = p[1];
p[1] = p[2];
p[2] = p[3];
} else if (p[1] == '\0')
*p = '\0';
}
/* if ifn is a file get file directory block structure and device */
if (fdb = _locate(buf2, buf, &st->st_dev)) {
/* is it a file from another user... */
if (strchr(buf2, '\\')
/* a public system file */
|| fdb->fileowner == 0
/* or a file from the current user account ? */
|| fdb->fileowner == getuid()) {
/* yes, return stat */
return _stat_(st, fdb);
} else {
/* no, say file doesn't exist */
errno = _errnum = ENOENT;
_errarg = fn;
return -1;
}
}
/* else should be a device */
st->st_rdev = st->st_dev = _lub_name(*ifn == ':' ? ifn+1 : ifn);
 
free(ifn);
if (st->st_dev != -1 && getlub(st->st_dev) != 255)
return _dstat_(st);
 
errno = _errnum = ENOENT;
_errarg = fn;
return -1;
}
 
int _fstat(int fd, struct stat *st)
{
unsigned short fsanum;
struct fsa fsa;
register FILE *fp;
int status;
register int i;
register char *p;
 
if (fd < FOPEN_MAX) {
fp = &stdin[fd];
if (_fcntl(fp,1,0) & 0x80) {
fsanum = (unsigned short) _fcntl(fp,83,0);
st->st_dev = (unsigned short) _fcntl(fp,5,0);
 
if (st->st_dev >= A_DISK && st->st_dev <= Z_DISK) {
for (i = 0, fsanum *= sizeof(fsa), p = (char *) &fsa;
i < (sizeof(fsa));
i++, fsanum++, p++)
*p = _peekfsa((char *) fsanum);
status = _stat_(st, (struct fdb*) &fsa);
if ((st->st_blksize = _fcntl(fp,817,0)) == 0)
st->st_blksize = BUFSIZ;
return status;
}
return _dstat_(st);
}
}
errno = _errnum = EBADF;
return -1;
}
 
static int _isprt(int dev)
{
return IS_PRT_LUB(dev);
}
 
/* device stat */
 
int _dstat_(st)
register struct stat* st;
{
register struct ucb* ucb;
 
ucb = getucb(st->st_dev);
st->st_ino = 0;
if (st->st_dev <= Z_DISK
|| (st->st_dev >= TAPE1 && st->st_dev <= TAPE4)) {
st->st_mode = S_IFBLK | S_IWUSR | S_IRUSR;
if (peekucb(&ucb->devowner) == 255)
st->st_mode |= S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH;
} else {
st->st_mode = S_IFCHR | S_IWUSR;
if (_isprt(st->st_dev))
st->st_mode |= S_IRUSR;
if (peekucb(&ucb->devowner) == 255) {
st->st_mode |= S_IWGRP | S_IWOTH;
if (_isprt(st->st_dev))
st->st_mode |= S_IRGRP | S_IROTH;
}
}
st->st_nlink = 1;
st->st_uid = st->st_gid = getuid();
st->st_size = 0;
st->st_atime = st->st_mtime = st->st_ctime = 0;
st->st_rlen = 0;
st->st_klen = 0;
st->st_grow = 0;
st->st_blksize = 0;
return 0;
}
 
/* regular file stat */
 
int _stat_(st, fdb)
register struct stat* st;
register struct fdb* fdb;
{
st->st_rdev = st->st_dev;
st->st_ino = 0;
st->st_org = fdb->filestat;
 
switch (fdb->filestat) {
case _FDB_STAT_LIBRARY: st->st_mode = S_IFLIB; break;
case _FDB_STAT_DIRECTORY: st->st_mode = S_IFDIR; break;
case _FDB_STAT_STREAM: st->st_mode = S_IFREG; break;
case _FDB_STAT_RELATIVE: st->st_mode = S_IFREL; break;
case _FDB_STAT_KEYED: st->st_mode = S_IFKEY; break;
case _FDB_STAT_INDEXED: st->st_mode = S_IFIND; break;
case _FDB_STAT_RANDOM: st->st_mode = S_IFRND; break;
case _FDB_STAT_PROGRAM: st->st_mode = S_IFR16; break;
case _FDB_STAT_16_BIT_PROGRAM: st->st_mode = S_IFP16; break;
case _FDB_STAT_32_BIT_PROGRAM: st->st_mode = S_IFP32; break;
}
 
st->st_mode |= _tm2um_(st->st_protect = fdb->protect);
st->st_nlink = 1;
st->st_uid = st->st_gid = fdb->fileowner;
st->st_size = fdb->filesize;
st->st_atime = st->st_mtime = st->st_ctime = getfiledate(fdb);
st->st_rlen = fdb->reclen;
st->st_klen = fdb->keylen;
st->st_grow = fdb->filegrow;
st->st_blksize = 0;
return 0;
}
 
#include <direct.h>
 
struct dirent* _opendir(const char* dirpath)
{
int l;
char *p;
struct dirent* dir;
char *mypath = NULL;
 
if (dirpath != NULL &&
(mypath = (char *)malloc(strlen(dirpath)+1)) == NULL) {
errno = _errnum = ENOMEM;
return NULL;
}
 
if (mypath) {
l = strlen(mypath);
if (l) {
p = dirpath + l - 1;
if (*p == '/') {
*p = '\0';
dir = opendir(dirpath);
*p = '/';
return dir;
}
}
 
}
return opendir(mypath);
}
/programs/fs/unzip60/theos/charconv.h
0,0 → 1,93
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
 
#ifdef IZ_THS2ISO_ARRAY
ZCONST uch Far ths2iso[] = {
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, /* 80 - 87 */
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, /* 88 - 8F */
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, /* 90 - 97 */
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, /* 98 - 9F */
0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, /* A0 - A7 */
0x2B, 0x2D, 0x7C, 0x2B, 0x2B, 0x2B, 0x2B, 0x23, /* A8 - AF */
0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, /* B0 - B7 */
0x3D, 0x23, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, /* B8 - BF */
0xC4, 0xE4, 0xE2, 0xE0, 0xE1, 0xC9, 0xEB, 0xEA, /* C0 - C7 */
0xE8, 0xE9, 0xEF, 0xEE, 0xEC, 0xED, 0xD6, 0xF6, /* C8 - CF */
0xF4, 0xF2, 0xF3, 0xDC, 0xFC, 0xFB, 0xF9, 0xFA, /* D0 - D7 */
0xC7, 0xE7, 0xD1, 0xF1, 0xC6, 0xE6, 0xC5, 0xE5, /* D8 - DF */
0xDF, 0xBF, 0xA1, 0xA2, 0xA3, 0xA5, 0xB5, 0xA4, /* E0 - E7 */
0xBC, 0xBD, 0xFF, 0xA7, 0xB0, 0xB2, 0x20, 0x20, /* E8 - EF */
0x20, 0xB1, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, /* F0 - F7 */
0x20, 0x20, 0xB7, 0x20, 0x20, 0x20, 0x20, 0x20 /* F8 - FF */
};
#endif /* IZ_THS2ISO_ARRAY */
 
#ifdef IZ_THS2OEM_ARRAY
ZCONST uch Far ths2oem[] = {
254,254,254,254, 254,254,134,135, /* 80 - 87 */
136,137,138,139, 140,141,142,143, /* 88 - 8F */
144,145,146,147, 148,149,150,151, /* 90 - 97 */
152,153,154,155, 156,157,158,159, /* 98 - 9F */
218,191,217,192, 197,195,180,194, /* A0 - A7 */
193,196,179,218, 191,217,192,201, /* A8 - AF */
183,188,200,206, 199,182,203,202, /* B0 - B7 */
205,186,186,187, 188,189,190,191, /* B8 - BF */
142,132,131,133, 160,144,137,136, /* C0 - C7 */
138,130,139,140, 141,161,153,148, /* C8 - CF */
147,149,162,154, 129,150,151,163, /* D0 - D7 */
128,135,165,164, 146,145,143,134, /* D8 - DF */
225,168,173,155, 156,157,158, 31, /* E0 - E7 */
172,171,152, 21, 248,253,238,239, /* E8 - EF */
240,241,242,243, 244,245,246,247, /* F0 - F7 */
248,249,250,251, 252,253,254,255 /* F8 - FF */
};
#endif /* IZ_THS2OEM_ARRAY */
 
#ifdef IZ_ISO2THS_ARRAY
ZCONST uch Far iso2ths[] = {
0x3F, 0x3F, 0x27, 0x3F, 0x22, 0x2E, 0xA4, 0xB3, /* 80 - 87 */
0x5E, 0x25, 0x53, 0x3C, 0x4F, 0x3F, 0x3F, 0x3F, /* 88 - 8F */
0x3F, 0x27, 0x27, 0x22, 0x22, 0x07, 0x2D, 0x2D, /* 90 - 97 */
0x7E, 0x54, 0x73, 0x3E, 0x6F, 0x3F, 0x3F, 0x59, /* 98 - 9F */
0x20, 0xE2, 0xE3, 0xE4, 0xE7, 0xE5, 0x7C, 0xEB, /* A0 - A7 */
0x20, 0x20, 0x20, 0x22, 0x20, 0x2D, 0x20, 0x2D, /* A8 - AF */
0xEC, 0xF1, 0xED, 0x20, 0x20, 0xE6, 0x20, 0xFA, /* B0 - B7 */
0x20, 0x20, 0x20, 0x22, 0xE8, 0xE9, 0x20, 0xE1, /* B8 - BF */
0xC3, 0xC4, 0xC2, 0x41, 0xC0, 0xDE, 0xDC, 0xD8, /* C0 - C7 */
0xC8, 0xC5, 0xC7, 0xC6, 0xCC, 0xCD, 0xCB, 0xCA, /* C8 - CF */
0x44, 0xDA, 0xD1, 0xD2, 0xD0, 0x4F, 0xCE, 0x78, /* D0 - D7 */
0x4F, 0xD6, 0xD7, 0xD5, 0xD3, 0x59, 0x20, 0xE0, /* D8 - DF */
0xC3, 0xC4, 0xC2, 0x61, 0xC1, 0xDF, 0xDD, 0xD9, /* E0 - E7 */
0xC8, 0xC9, 0xC7, 0xC6, 0xCC, 0xCD, 0xCB, 0xCA, /* E8 - EF */
0x64, 0xDB, 0xD1, 0xD2, 0xD0, 0x4F, 0xCF, 0xF1, /* F0 - F7 */
0x6F, 0xD6, 0xD7, 0xD5, 0xD4, 0x79, 0x20, 0xEA /* F8 - FF */
};
#endif /* IZ_ISO2THS_ARRAY */
 
#ifdef IZ_OEM2THS_ARRAY
ZCONST uch Far oem2ths[] = {
216,212,201,194, 193,195,223,217, /* 80 - 87 */
199,198,200,202, 203,204,192,222, /* 88 - 8F */
197,221,220,208, 207,209,213,214, /* 90 - 97 */
234,206,211,227, 228,229,230,159, /* 98 - 9F */
196,205,210,215, 219,218,254,254, /* A0 - A7 */
225,254,254,233, 232,226, 34, 34, /* A8 - AF */
254,254,254,170, 166,166,181,176, /* B0 - B7 */
161,181,185,176, 177,177,162,161, /* B8 - BF */
163,168,167,165, 169,164,165,180, /* C0 - C7 */
178,175,183,182, 180,184,179,168, /* C8 - CF */
183,167,182,178, 163,160,175,179, /* D0 - D7 */
164,162,160,254, 254,254,254,254, /* D8 - DF */
254,224,254,254, 254,254,254, 31, /* E0 - E7 */
254,254,254, 21, 254,254,238,239, /* E8 - EF */
240,241,242,243, 244,245,246,247, /* F0 - F7 */
236,249,250,251, 252,237,254,255 /* F8 - FF */
};
#endif /* IZ_OEM2THS_ARRAY */
 
/programs/fs/unzip60/theos/makefile
0,0 → 1,192
#==============================================================================
# Makefile for UnZip, UnZipSFX and fUnZip: Unix and MS-DOS ("real" makes only)
# Version: 5.53 25 December 2006
#==============================================================================
 
 
# INSTRUCTIONS (such as they are):
#
# "make vax" -- makes UnZip on a generic Unix VAX in the current directory
# "make list" -- lists all supported systems (targets)
# "make help" -- provides pointers on what targets to try if problems occur
# "make wombat" -- chokes and dies if you haven't added the specifics for your
# Wombat 68000 (or whatever) to the systems list
#
# CF are flags for the C compiler. LF are flags for the loader. LF2 are more
# flags for the loader, if they need to be at the end of the line instead of at
# the beginning (for example, some libraries). FL and FL2 are the corre-
# sponding flags for fUnZip. LOCAL_UNZIP is an environment variable that can
# be used to add default C flags to your compile without editing the Makefile
# (e.g., -DDEBUG_STRUC, or -FPi87 on PCs using Microsoft C).
#
# Some versions of make do not define the macro "$(MAKE)"; this is rare, but
# if things don't work, try using "make" instead of "$(MAKE)" in your system's
# makerule. Or try adding the following line to your .login file:
# setenv MAKE "make"
# (That never works--makes which are too stupid to define MAKE are also too
# stupid to look in the environment--but try it anyway for kicks. :-) )
#
# Memcpy and memset are provided for those systems that don't have them; they
# are in file_io.c and will be used if -DZMEM is included in CF. These days
# almost all systems have them.
#
# Be sure to test your new UnZip (and UnZipSFX and fUnZip); successful compila-
# tion does not always imply a working program.
 
 
#####################
# MACRO DEFINITIONS #
#####################
 
# Defaults most systems use (use LOCAL_UNZIP in environment to add flags,
# such as -DDOSWILD).
 
# UnZip flags
CC = cl
LD = cl
LOC = $(LOCAL_UNZIP)
CF = -c -Zi -W2 -DCRYPT -DOLD_THEOS_EXTRA $(LOCAL_UNZIP)
LF = -Zi -o
LF2 = -m
 
# defaults for crc32 stuff and system dependent headers
CRCA_O =
OSDEP_H =
 
# general-purpose stuff
CP = copyfile
LN = copyfile
RM = erase
 
.c.o:
$(CC) $(CF) $*.c
 
# object files
OBJS1 = unzip.o crc32.o $(CRCA_O) crypt.o envargs.o explode.o
OBJS2 = extract.o fileio.o globals.o inflate.o list.o match.o
OBJS3 = process.o ttyio.o ubz2err.o unreduce.o unshrink.o zipinfo.o
OBJS4 = _sprintf.o _fprintf.o _isatty.o _stat.o _setargv.o
OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) theos.o
#LOBJS = $(OBJS)
LOBJS = $(OBJS1) $(OBJS2) $(OBJS3) theos.o
OBJX = unzipsfx.o crc32_.o $(CRCA_O) crypt_.o extract_.o fileio_.o \
globals_.o inflate_.o match_.o process_.o ttyio_.o obz2err_.o theos_.o
LOBJX = $(OBJX)
OBJF = funzip.o crc32f.o $(CRCA_O) cryptf.o globalsf.o inflatef.o ttyiof.o \
_sprintf.o _fprintf.o _isatty.o
UNZIP_H = unzip.h unzpriv.h globals.h $(OSDEP_H)
EBCDIC_H = ebcdic.h theos/charconv.h
 
UNZIPS = unzip.command funzip.command unzipsfx.command zipinfo.command
 
unzips: $(UNZIPS)
 
 
crc32.o: crc32.c $(UNZIP_H) zip.h crc32.h
crypt.o: crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
envargs.o: envargs.c $(UNZIP_H)
explode.o: explode.c $(UNZIP_H)
extract.o: extract.c $(UNZIP_H) crc32.h crypt.h
fileio.o: fileio.c $(UNZIP_H) crc32.h crypt.h ttyio.h EBCDIC_H
funzip.o: funzip.c $(UNZIP_H) crc32.h crypt.h ttyio.h
globals.o: globals.c $(UNZIP_H)
inflate.o: inflate.c inflate.h $(UNZIP_H)
list.o: list.c $(UNZIP_H)
match.o: match.c $(UNZIP_H)
process.o: process.c $(UNZIP_H) crc32.h
ttyio.o: ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
ubz2err.o: ubz2err.c $(UNZIP_H)
unreduce.o: unreduce.c $(UNZIP_H)
unshrink.o: unshrink.c $(UNZIP_H)
unzip.o: unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h
zipinfo.o: zipinfo.c $(UNZIP_H)
 
# unzipsfx only
crc32_.o: crc32.c $(UNZIP_H) zip.h crc32.h
$(CC) $(CF) -DSFX -Fo$@ crc32.c
 
crypt_.o: crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
$(CC) $(CF) -DSFX -Fo$@ crypt.c
 
extract_.o: extract.c $(UNZIP_H) crc32.h crypt.h
$(CC) $(CF) -DSFX -Fo$@ extract.c
 
fileio_.o: fileio.c $(UNZIP_H) crc32.h crypt.h ttyio.h EBCDIC_H
$(CC) $(CF) -DSFX -Fo$@ fileio.c
 
globals_.o: globals.c $(UNZIP_H)
$(CC) $(CF) -DSFX -Fo$@ globals.c
 
inflate_.o: inflate.c inflate.h $(UNZIP_H) crypt.h
$(CC) $(CF) -DSFX -Fo$@ inflate.c
 
match_.o: match.c $(UNZIP_H)
$(CC) $(CF) -DSFX -Fo$@ match.c
 
process_.o: process.c $(UNZIP_H) crc32.h
$(CC) $(CF) -DSFX -Fo$@ process.c
 
ttyio_.o: ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
$(CC) $(CF) -DSFX -Fo$@ ttyio.c
 
ubz2err_.o: ubz2err.c $(UNZIP_H)
$(CC) $(CF) -DSFX -Fo$@ ubz2err.c
 
unzipsfx.o: unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h
$(CC) $(CF) -DSFX -Fo$@ unzip.c
 
# funzip only
crc32f.o: crc32.c $(UNZIP_H) zip.h crc32.h
$(CC) $(CF) -DFUNZIP -Fo$@ crc32.c
 
cryptf.o: crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
$(CC) $(CF) -DFUNZIP -Fo$@ crypt.c
 
globalsf.o: globals.c $(UNZIP_H)
$(CC) $(CF) -DFUNZIP -Fo$@ globals.c
 
inflatef.o: inflate.c inflate.h $(UNZIP_H) crypt.h
$(CC) $(CF) -DFUNZIP -Fo$@ inflate.c
 
ttyiof.o: ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
$(CC) $(CF) -DFUNZIP -Fo$@ ttyio.c
 
theos.o: theos/theos.c $(UNZIP_H) unzvers.h # THEOS only
$(CC) $(CF) theos/theos.c
 
theos_.o: theos/theos.c $(UNZIP_H) # THEOS unzipsfx
$(CC) $(CF) -DSFX -Fo$@ theos/theos.c
 
_sprintf.o: theos/_sprintf.c $(UNZIP_H) # THEOS only
$(CC) $(CF) theos/_sprintf.c
 
_fprintf.o: theos/_fprintf.c $(UNZIP_H) # THEOS only
$(CC) $(CF) theos/_fprintf.c
 
_isatty.o: theos/_isatty.c $(UNZIP_H) # THEOS only
$(CC) $(CF) theos/_isatty.c
 
_stat.o: theos/_stat.c $(UNZIP_H) # THEOS only
$(CC) $(CF) theos/_stat.c
 
_setargv.o: theos/_setargv.c $(UNZIP_H) # THEOS only
$(CC) $(CF) theos/_setargv.c
 
unzip.command: $(OBJS)
$(LD) $(LF) $@ $(LOBJS) $(LF2)
 
unzipsfx.command: $(OBJX)
$(LD) $(LF) $@ $(LOBJX) $(LF2)
 
funzip.command: $(OBJF)
$(LD) $(LF) $@ $(OBJF) $(LF2)
 
zipinfo.command: unzip.command
$(LN) $? $@ ( rep not
 
install:
copy *.command /system.cmd32.=(rep noq
 
clean:
erase *.o(noq not
erase *.command(noq not
/programs/fs/unzip60/theos/oldstat.h
0,0 → 1,32
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
#define _THS_IFMT 0xff00 /* type of file */
#define _THS_IFLIB 0x8000 /* library */
#define _THS_IFDIR 0x4000 /* directory */
#define _THS_IFCHR 0x2000 /* character device */
#define _THS_IFREG 0x1000 /* regular file */
#define _THS_IODRC 0x0800 /* direct */
#define _THS_IOKEY 0x0400 /* keyed */
#define _THS_IOIND 0x0200 /* indexed */
#define _THS_IOPRG 0x0100 /* program */
#define _THS_IO286 0x2100 /* program */
#define _THS_IO386 0x4100 /* program */
#define _THS_IREAD 0x0001 /* read permission */
#define _THS_IWRITE 0x0002 /* write permission */
#define _THS_IEXEC 0x0004 /* execute permission */
#define _THS_IERASE 0x0008 /* erase permission */
#define _THS_IRWXU 0x000f /* read, write, execute, erase: owner */
#define _THS_IRUSR 0x0001 /* read permission: owner */
#define _THS_IWUSR 0x0002 /* write permission: owner */
#define _THS_IXUSR 0x0004 /* execute permission: owner */
#define _THS_IEUSR 0x0008 /* erase permission: owner */
#define _THS_IROTH 0x0010 /* read permission: other */
#define _THS_IWOTH 0x0020 /* write permission: other */
#define _THS_IXOTH 0x0040 /* execute permission: other */
#define _THS_HIDDN 0x0080 /* hidden, 0 = true */
/programs/fs/unzip60/theos/stat.h
0,0 → 1,107
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
 
#ifndef __theos_stat_h
#define __theos_stat_h
 
/* extended stat structure for stat, fstat, chmod */
/* Written by Jean-Michel Dubois */
 
#pragma field word
struct stat {
unsigned short st_mode; /* file attributes */
#define S_IFMT 0xf000 /* file type mask */
#define S_IFIFO 0x1000 /* pipe */
#define S_IFCHR 0x2000 /* char device */
#define S_IFSOCK 0x3000 /* socket */
#define S_IFDIR 0x4000 /* directory */
#define S_IFLIB 0x5000 /* library */
#define S_IFBLK 0x6000 /* block device */
#define S_IFREG 0x8000 /* regular file */
#define S_IFREL 0x9000 /* relative (direct) */
#define S_IFKEY 0xA000 /* keyed */
#define S_IFIND 0xB000 /* indexed */
#define S_IFRND 0xC000 /* ???? */
#define S_IFR16 0xD000 /* 16 bit real mode program */
#define S_IFP16 0xE000 /* 16 bit protected mode prog */
#define S_IFP32 0xF000 /* 32 bit protected mode prog */
 
#define S_ISUID 0x0800 /* meaningless */
#define S_ISGID 0x0400 /* meaningless */
#define S_ISVTX 0x0200 /* meaningless */
 
#define S_IMODF 0x0800 /* modified */
#define S_INHID 0x0400 /* not hidden */
 
#define S_IRWXU 0x03c0 /* read,write,execute: owner */
#define S_IEUSR 0x0200 /* erase permission: owner */
#define S_IRUSR 0x0100 /* read permission: owner */
#define S_IWUSR 0x0080 /* write permission: owner */
#define S_IXUSR 0x0040 /* execute permission: owner */
/* group permissions */
#define S_IRWXG 0x0238
#define S_IEGRP 0x0200
#define S_IRGRP 0x0020
#define S_IWGRP 0x0010
#define S_IXGRP 0x0008
/* other never has erase permission */
#define S_IRWXO 0x0207 /* read,write,execute: other */
#define S_IROTH 0x0004 /* read permission: other */
#define S_IWOTH 0x0002 /* write permission: other */
#define S_IXOTH 0x0001 /* execute permission: other */
 
#define S_IREAD 0x0100 /* read permission, owner */
#define S_IEXEC 0x0040 /* execute permission, owner */
#define S_IWRITE 0x0080 /* write permission, owner */
short st_ino; /* not used */
short st_dev; /* not used */
short st_rdev; /* not used */
short st_nlink; /* not used */
short st_uid; /* owner id */
short st_gid; /* not used */
unsigned long st_size; /* size of file */
unsigned long st_atime; /* not used */
unsigned long st_mtime; /* date & time last modified */
unsigned long st_ctime; /* not used */
unsigned long st_blksize; /* buffer size */
unsigned short st_org; /* organization */
unsigned short st_rlen; /* record size */
unsigned short st_klen; /* key size */
char st_grow; /* growing factor */
char st_protect; /* native protections */
};
#pragma field
 
#define S_ISREG(m) (((m) & S_IFMT) >= S_IFREG)
#define S_ISLIB(m) (((m) & S_IFMT) == S_IFLIB)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
 
#define S_ISSEQ(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISREL(m) (((m) & S_IFMT) == S_IFREL)
#define S_ISKEY(m) (((m) & S_IFMT) == S_IFKEY)
#define S_ISIND(m) (((m) & S_IFMT) == S_IFIND)
#define S_ISPRG(m) (((m) & S_IFMT) >= S_IFP16)
#define S_ISLNK(m) 0
 
/* avoid conflict with original THEOS functions */
 
#define stat(a,b) _stat(a,b)
#define fstat(a,b) _fstat(a,b)
#define chmod(a,b) _chmod(a,b)
 
extern int _stat(const char *file, struct stat *statptr);
extern int _fstat(int fd, struct stat *statptr);
extern int _chmod(const char *file, short mask);
 
#define _chstat(a,b) ((int) _sc_168(a,'p',(size_t)(b)))
extern unsigned short _sc_168(const char _far *fn, int cmd, size_t value);
 
#endif /* !__theos_stat_h */
/programs/fs/unzip60/theos/theos.c
0,0 → 1,1206
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*---------------------------------------------------------------------------
 
theos.c
 
Theos-specific routines for use with Info-ZIP's UnZip 5.41 and later.
 
Contains: do_wild() <-- generic enough to put in fileio.c?
mapattr()
mapname()
checkdir()
close_outfile()
defer_dir_attribs()
set_direc_attribs()
stamp_file()
version()
 
---------------------------------------------------------------------------*/
 
 
#define UNZIP_INTERNAL
#include "unzip.h"
#include <direct.h>
#include <sc.h>
#include <fdb.h>
#include <nuc.h>
#include <peek.h>
 
/* standard function doesn't work with a trailing / */
#define opendir(a) _opendir(a)
extern DIR* _opendir(const char* dirpath);
 
#ifdef SET_DIR_ATTRIB
typedef struct uxdirattr { /* struct for holding unix style directory */
struct uxdirattr *next; /* info until can be sorted and set at end */
char *fn; /* filename of directory */
union {
iztimes t3; /* mtime, atime, ctime */
ztimbuf t2; /* modtime, actime */
} u;
unsigned perms; /* same as min_info.file_attr */
char fnbuf[1]; /* buffer stub for directory name */
} uxdirattr;
#define UxAtt(d) ((uxdirattr *)d) /* typecast shortcut */
#endif /* SET_DIR_ATTRIB */
 
#ifdef ACORN_FTYPE_NFS
/* Acorn bits for NFS filetyping */
typedef struct {
uch ID[2];
uch size[2];
uch ID_2[4];
uch loadaddr[4];
uch execaddr[4];
uch attr[4];
} RO_extra_block;
 
#endif /* ACORN_FTYPE_NFS */
 
static int created_dir; /* used in mapname(), checkdir() */
static int renamed_fullpath; /* ditto */
 
#define _FDB_SHARED_EXECUTE_PROTECT _FDB_MODIFIED
 
uch _um2tm_(ush mask);
 
int chmodv2_3(const char *fname, short mask)
{
return _filechange(fname,'p',(size_t) _um2tm_(mask)|0x80);
}
 
int chlen(char *fname, unsigned short reclen, unsigned short keylen)
{
size_t a = reclen + ((size_t) keylen << 16);
return _filechange(fname,'ma',(size_t) &a);
}
 
#define chgrow(a,b) ((int) _filechange(a,'g',(size_t)(b)))
#define chorg(a,b) ((int) _filechange(a,'m',(size_t)(b)))
 
#ifndef SFX
 
/*************************/
/* Function dateformat() */
/*************************/
 
int dateformat()
{
/*---------------------------------------------------------------------------
For those operating systems that support it, this function returns a
value that tells how national convention says that numeric dates are
displayed. Return values are DF_YMD, DF_DMY and DF_MDY (the meanings
should be fairly obvious).
---------------------------------------------------------------------------*/
 
switch (peeknuc(&NUC->dateopt) & (aform|eform|iform)) {
case aform: return DF_MDY;
case eform: return DF_DMY;
}
return DF_YMD;
}
 
 
/* usual THEOS match function for filenames */
 
/* match from Phase One Systems */
 
/* Returns non-zero if string matches the literal mask */
int match(string, pattern, ignore_case __WDL)
ZCONST char *string;
ZCONST char *pattern;
int ignore_case; /* unused in this variant of match()! */
__WDLDEF
{
int matched, k;
 
if (!(*pattern))
return 1;
for(;;) {
if ( (!(*string)) && (!(*pattern)) )
return(1);
else if ( !(*pattern) )
return(0);
else if (*pattern == '*') {
if (!*(pattern+1))
return(1);
k=0;
do {
matched = match(string+k, pattern+1, ignore_case __WDL);
k++;
} while ( (!matched) && *(string+k));
return(matched);
} else if (*pattern == '@') {
if (!((*string >= 'a' && *string <= 'z')
||(*string >= 'A' && *string <= 'Z')))
return(0);
} else if (*pattern == '#') {
if (*string < '0' || *string > '9')
return(0);
} else if (*pattern != '?') {
if (toupper(*string) != toupper(*pattern))
return(0);
 
}
string++; pattern++;
}
} /* end function match() */
 
 
 
/**********************/
/* Function do_wild() */ /* for porting: dir separator; match(ignore_case) */
/**********************/
 
char *do_wild(__G__ wildspec)
__GDEF
ZCONST char *wildspec; /* only used first time on a given dir */
{
static DIR *wild_dir = (DIR *)NULL;
static ZCONST char *wildname;
static char *dirname, matchname[FILNAMSIZ];
static int notfirstcall=FALSE, have_dirname, dirnamelen;
struct dirent *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 (!notfirstcall) { /* first call: must initialize everything */
notfirstcall = TRUE;
 
if (!iswild(wildspec)) {
strcpy(matchname, wildspec);
have_dirname = FALSE;
wild_dir = NULL;
return matchname;
}
 
/* break the wildspec into a directory part and a wildcard filename */
if ((wildname = (ZCONST char *)strrchr(wildspec, '/')) ==
(ZCONST char *)NULL)
{
dirname = ".";
dirnamelen = 1;
have_dirname = FALSE;
wildname = wildspec;
} else {
++wildname; /* point at character after '/' */
dirnamelen = wildname - wildspec;
if ((dirname = (char *)malloc(dirnamelen+1)) == (char *)NULL) {
Info(slide, 0x201, ((char *)slide,
"warning: cannot allocate wildcard buffers\n"));
strncpy(matchname, wildspec, FILNAMSIZ);
matchname[FILNAMSIZ-1] = '\0';
return matchname; /* but maybe filespec was not a wildcard */
}
strncpy(dirname, wildspec, dirnamelen);
dirname[dirnamelen] = '\0'; /* terminate for strcpy below */
have_dirname = TRUE;
}
 
if ((wild_dir = opendir(dirname)) != (DIR *)NULL) {
while ((file = readdir(wild_dir)) != (struct dirent *)NULL) {
Trace((stderr, "do_wild: readdir returns %s\n",
FnFilter1(file->d_name)));
if (match(file->d_name, wildname, 1 WISEP)) { /*1=ignore case*/
Trace((stderr, "do_wild: match() succeeds\n"));
if (have_dirname) {
strcpy(matchname, dirname);
strcpy(matchname+dirnamelen, file->d_name);
} else
strcpy(matchname, file->d_name);
return matchname;
}
}
/* if we get to here directory is exhausted, so close it */
closedir(wild_dir);
wild_dir = (DIR *)NULL;
}
 
/* return the raw wildspec in case that works (e.g., directory not
* searchable, but filespec was not wild and file is readable) */
strncpy(matchname, wildspec, FILNAMSIZ);
matchname[FILNAMSIZ-1] = '\0';
return matchname;
}
 
/* last time through, might have failed opendir but returned raw wildspec */
if (wild_dir == (DIR *)NULL) {
notfirstcall = FALSE; /* nothing left to try--reset for new wildspec */
if (have_dirname)
free(dirname);
return (char *)NULL;
}
 
/* If we've gotten this far, we've read and matched at least one entry
* successfully (in a previous call), so dirname has been copied into
* matchname already.
*/
while ((file = readdir(wild_dir)) != (struct dirent *)NULL) {
Trace((stderr, "do_wild: readdir returns %s\n",
FnFilter1(file->d_name)));
if (file->d_name[0] == '.' && wildname[0] != '.')
continue; /* Unix: '*' and '?' do not match leading dot */
if (match(file->d_name, wildname, 1 WISEP)) { /* 1 == ignore case */
Trace((stderr, "do_wild: match() succeeds\n"));
if (have_dirname) {
/* strcpy(matchname, dirname); */
strcpy(matchname+dirnamelen, file->d_name);
} else
strcpy(matchname, file->d_name);
return matchname;
}
}
 
closedir(wild_dir); /* have read at least one entry; nothing left */
wild_dir = (DIR *)NULL;
notfirstcall = FALSE; /* reset for new wildspec */
if (have_dirname)
free(dirname);
return (char *)NULL;
 
} /* end function do_wild() */
 
#endif /* !SFX */
 
 
 
 
 
/**********************/
/* Function mapattr() */
/**********************/
 
int mapattr(__G)
__GDEF
{
ulg tmp = G.crec.external_file_attributes;
 
G.pInfo->file_attr = 0;
/* initialized to 0 for check in "default" branch below... */
 
switch (G.pInfo->hostnum) {
case AMIGA_:
tmp = (unsigned)(tmp>>17 & 7); /* Amiga RWE bits */
G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
break;
case UNIX_:
case VMS_:
case ACORN_:
case ATARI_:
case ATHEOS_:
case BEOS_:
case QDOS_:
case TANDEM_:
case THEOS_:
G.pInfo->file_attr = (unsigned)(tmp >> 16);
if (G.pInfo->file_attr != 0 || !G.extra_field) {
return 0;
} else {
/* Some (non-Info-ZIP) implementations of Zip for Unix and
* VMS (and probably others ??) leave 0 in the upper 16-bit
* part of the external_file_attributes field. Instead, they
* store file permission attributes in some extra field.
* As a work-around, we search for the presence of one of
* these extra fields and fall back to the MSDOS compatible
* part of external_file_attributes if one of the known
* e.f. types has been detected.
* Later, we might implement extraction of the permission
* bits from the VMS extra field. But for now, the work-around
* should be sufficient to provide "readable" extracted files.
* (For ASI Unix e.f., an experimental remap from the e.f.
* mode value IS already provided!)
*/
ush ebID;
unsigned ebLen;
uch *ef = G.extra_field;
unsigned ef_len = G.crec.extra_field_length;
int r = FALSE;
 
while (!r && ef_len >= EB_HEADSIZE) {
ebID = makeword(ef);
ebLen = (unsigned)makeword(ef+EB_LEN);
if (ebLen > (ef_len - EB_HEADSIZE))
/* discoverd some e.f. inconsistency! */
break;
switch (ebID) {
case EF_ASIUNIX:
if (ebLen >= (EB_ASI_MODE+2)) {
G.pInfo->file_attr =
(unsigned)makeword(ef+(EB_HEADSIZE+EB_ASI_MODE));
/* force stop of loop: */
ef_len = (ebLen + EB_HEADSIZE);
break;
}
/* else: fall through! */
case EF_PKVMS:
/* "found nondecypherable e.f. with perm. attr" */
r = TRUE;
default:
break;
}
ef_len -= (ebLen + EB_HEADSIZE);
ef += (ebLen + EB_HEADSIZE);
}
if (!r)
return 0;
}
/* fall through! */
/* all remaining cases: expand MSDOS read-only bit into write perms */
case FS_FAT_:
/* PKWARE's PKZip for Unix marks entries as FS_FAT_, but stores the
* Unix attributes in the upper 16 bits of the external attributes
* field, just like Info-ZIP's Zip for Unix. We try to use that
* value, after a check for consistency with the MSDOS attribute
* bits (see below).
*/
G.pInfo->file_attr = (unsigned)(tmp >> 16);
/* fall through! */
case FS_HPFS_:
case FS_NTFS_:
case MAC_:
case TOPS20_:
default:
/* Ensure that DOS subdir bit is set when the entry's name ends
* in a '/'. Some third-party Zip programs fail to set the subdir
* bit for directory entries.
*/
if ((tmp & 0x10) == 0) {
extent fnlen = strlen(G.filename);
if (fnlen > 0 && G.filename[fnlen-1] == '/')
tmp |= 0x10;
}
/* read-only bit --> write perms; subdir bit --> dir exec bit */
tmp = !(tmp & 1) << 1 | (tmp & 0x10) >> 4;
if ((G.pInfo->file_attr & 0700) == (unsigned)(0400 | tmp<<6))
/* keep previous G.pInfo->file_attr setting, when its "owner"
* part appears to be consistent with DOS attribute flags!
*/
return 0;
G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
break;
} /* end switch (host-OS-created-by) */
 
/* for originating systems with no concept of "group," "other," "system": */
G.pInfo->file_attr &= ~tmp;
 
return 0;
 
} /* end function mapattr() */
 
 
 
/* portabilibity functions to ensure access to port 2.0 and new ports */
 
int isv2_3()
{
return G.extra_field[0] == 'T' && G.extra_field[1] == 'h';
}
 
int isv2_3lib()
{
return isv2_3() && S_ISLIB((G.pInfo->file_attr >> 8) & 0xFF);
}
 
int isv2_3dir()
{
return isv2_3() && S_ISDIR((G.pInfo->file_attr >> 8) & 0xFF);
}
 
#ifdef OLD_THEOS_EXTRA
#define S_IFMT_ 0xf800 /* type of file */
#define S_IFLIB_ 0x8000 /* library */
#define S_IFDIR_ 0x4000 /* directory */
 
#define S_ISLIB_(a) (((a) & 0xff) == _FDB_STAT_LIBRARY)
#define S_ISDIR_(a) (((a) & 0xff) == _FDB_STAT_DIRECTORY)
 
struct extra_block
{
ush signature;
ush size;
ush flags;
ulg filesize;
ush reclen;
ush keylen;
uch filegrow;
uch reserved[3];
};
 
struct extra_block *v2_0extra()
{
return (struct extra_block *) G.extra_field;
}
 
int isv2_0()
{
return ((struct extra_block *) G.extra_field)->signature == 0x4854;
}
 
int isv2_0lib()
{
return isv2_0() && S_ISLIB_(G.pInfo->file_attr);
}
 
int isv2_0dir()
{
return isv2_0() && S_ISDIR_(G.pInfo->file_attr);
}
 
#define islib() (isv2_0lib() || isv2_3lib())
#define isdir() (isv2_0dir() || isv2_3dir())
#define chmodv2_0(a,b) ((int) _sc_168(a,'p',(size_t)(b)|0x80))
#undef chmod
#define chmod(a,b) (isv2_0() && chmodv2_0(a,b))||(isv2_3() && chmodv2_3(a,b))
#else
#define islib() isv2_3lib()
#define isdir() isv2_3dir()
#undef chmod
#define chmod(a,b) chmodv2_0(a,b)
#endif
 
/************************/
/* Function mapname() */
/************************/
 
int mapname(__G__ renamed)
__GDEF
int renamed;
/*
* returns:
* MPN_OK - no problem detected
* MPN_INF_TRUNC - caution (truncated filename)
* MPN_INF_SKIP - info "skip entry" (dir doesn't exist)
* MPN_ERR_SKIP - error -> skip entry
* MPN_ERR_TOOLONG - error -> path is too long
* MPN_NOMEM - error (memory allocation failed) -> skip entry
* [also MPN_VOL_LABEL, MPN_CREATED_DIR]
*/
{
char pathcomp[FILNAMSIZ]; /* path-component buffer */
char *pp, *cp=(char *)NULL; /* character pointers */
char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */
#ifdef ACORN_FTYPE_NFS
char *lastcomma=(char *)NULL; /* pointer to last comma in pathcomp */
RO_extra_block *ef_spark; /* pointer Acorn FTYPE ef block */
#endif
int killed_ddot = FALSE; /* is set when skipping "../" pathcomp */
int error = MPN_OK;
register unsigned workch; /* hold the character being tested */
 
 
/*---------------------------------------------------------------------------
Initialize various pointers and counters and stuff.
---------------------------------------------------------------------------*/
 
if (G.pInfo->vollabel)
return MPN_VOL_LABEL; /* can't set disk volume labels in Unix */
 
/* can create path as long as not just freshening, or if user told us */
G.create_dirs = (!uO.fflag || renamed);
 
created_dir = FALSE; /* not yet */
 
/* user gave full pathname: don't prepend rootpath */
renamed_fullpath = (renamed && (*G.filename == '/'));
 
if (checkdir(__G__ (char *)NULL, INIT) == MPN_NOMEM)
return MPN_NOMEM; /* initialize path buffer, unless no memory */
 
*pathcomp = '\0'; /* initialize translation buffer */
pp = pathcomp; /* point to translation buffer */
if (uO.jflag) /* junking directories */
cp = (char *)strrchr(G.filename, '/');
if (cp == (char *)NULL) /* no '/' or not junking dirs */
cp = G.filename; /* point to internal zipfile-member pathname */
else
++cp; /* point to start of last component of path */
 
/*---------------------------------------------------------------------------
Begin main loop through characters in filename.
---------------------------------------------------------------------------*/
 
while ((workch = (uch)*cp++) != 0) {
 
switch (workch) {
case '/': /* can assume -j flag not given */
*pp = '\0';
if (strcmp(pathcomp, ".") == 0) {
/* don't bother appending "./" to the path */
*pathcomp = '\0';
} else if (!uO.ddotflag && strcmp(pathcomp, "..") == 0) {
/* "../" dir traversal detected, skip over it */
*pathcomp = '\0';
killed_ddot = TRUE; /* set "show message" flag */
}
/* when path component is not empty, append it now */
if (*pathcomp != '\0' &&
((error = checkdir(__G__ pathcomp, APPEND_DIR))
& MPN_MASK) > MPN_INF_TRUNC)
return error;
pp = pathcomp; /* reset conversion buffer for next piece */
lastsemi = (char *)NULL; /* leave direct. semi-colons alone */
break;
 
#ifdef ACORN_FTYPE_NFS
case ',': /* NFS filetype extension */
lastcomma = pp;
*pp++ = ','; /* keep for now; may need to remove */
break; /* later, if requested */
#endif
 
default:
if (isfnsym(workch) || workch == '.')
*pp++ = (char)workch;
else
*pp++ = '_';
} /* end switch */
 
} /* end while loop */
 
/* Show warning when stripping insecure "parent dir" path components */
if (killed_ddot && QCOND2) {
Info(slide, 0, ((char *)slide,
"warning: skipped \"../\" path component(s) in %s\n",
FnFilter1(G.filename)));
if (!(error & ~MPN_MASK))
error = (error & MPN_MASK) | PK_WARN;
}
 
/*---------------------------------------------------------------------------
Report if directory was created (and no file to create: filename ended
in '/'), check name to be sure it exists, and combine path and name be-
fore exiting.
---------------------------------------------------------------------------*/
 
if (G.filename[strlen(G.filename) - 1] == '/') {
checkdir(__G__ G.filename, GETPATH);
if (islib() && G.filename[strlen(G.filename) - 1] == '/')
G.filename[strlen(G.filename) - 1] = '\0';
 
if (created_dir) {
if (QCOND2) {
Info(slide, 0, ((char *)slide, " creating: %s\n",
FnFilter1(G.filename)));
}
/* set dir time (note trailing '/') */
return (error & ~MPN_MASK) | MPN_CREATED_DIR;
}
/* dir existed already; don't look for data to extract */
return (error & ~MPN_MASK) | MPN_INF_SKIP;
}
 
*pp = '\0'; /* done with pathcomp: terminate it */
 
#ifdef ACORN_FTYPE_NFS
/* translate Acorn filetype information if asked to do so */
if (uO.acorn_nfs_ext &&
(ef_spark = (RO_extra_block *)
getRISCOSexfield(G.extra_field, G.lrec.extra_field_length))
!= (RO_extra_block *)NULL)
{
/* file *must* have a RISC OS extra field */
long ft = (long)makelong(ef_spark->loadaddr);
/*32-bit*/
if (lastcomma) {
pp = lastcomma + 1;
while (isxdigit((uch)(*pp))) ++pp;
if (pp == lastcomma+4 && *pp == '\0') *lastcomma='\0'; /* nuke */
}
if ((ft & 1<<31)==0) ft=0x000FFD00;
sprintf(pathcomp+strlen(pathcomp), ",%03x", (int)(ft>>8) & 0xFFF);
}
#endif /* ACORN_FTYPE_NFS */
 
if (*pathcomp == '\0') {
Info(slide, 1, ((char *)slide, "mapname: conversion of %s failed\n",
FnFilter1(G.filename)));
return (error & ~MPN_MASK) | MPN_ERR_SKIP;
}
 
checkdir(__G__ pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */
checkdir(__G__ G.filename, GETPATH);
 
return error;
 
} /* end function mapname() */
 
 
 
 
#if 0 /*========== NOTES ==========*/
 
extract-to dir: a:path/
buildpath: path1/path2/ ... (NULL-terminated)
pathcomp: filename
 
mapname():
loop over chars in zipfile member name
checkdir(path component, COMPONENT | CREATEDIR) --> map as required?
(d:/tmp/unzip/) (disk:[tmp.unzip.)
(d:/tmp/unzip/jj/) (disk:[tmp.unzip.jj.)
(d:/tmp/unzip/jj/temp/) (disk:[tmp.unzip.jj.temp.)
finally add filename itself and check for existence? (could use with rename)
(d:/tmp/unzip/jj/temp/msg.outdir) (disk:[tmp.unzip.jj.temp]msg.outdir)
checkdir(name, GETPATH) --> copy path to name and free space
 
#endif /* 0 */
 
 
 
 
/***********************/
/* Function checkdir() */
/***********************/
 
int checkdir(__G__ pathcomp, flag)
__GDEF
char *pathcomp;
int flag;
/*
* returns:
* MPN_OK - no problem detected
* MPN_INF_TRUNC - (on APPEND_NAME) truncated filename
* MPN_INF_SKIP - path doesn't exist, not allowed to create
* MPN_ERR_SKIP - path doesn't exist, tried to create and failed; or path
* exists and is not a directory, but is supposed to be
* MPN_ERR_TOOLONG - path is too long
* MPN_NOMEM - can't allocate memory for filename buffers
*/
{
static int rootlen = 0; /* length of rootpath */
static char *rootpath; /* user's "extract-to" directory */
static char rootdisk[3]; /* user's "extract-to" disk */
static char *buildpath; /* full path (so far) to extracted file */
static char *end; /* pointer to end of buildpath ('\0') */
 
# define FN_MASK 7
# define FUNCTION (flag & FN_MASK)
 
 
 
/*---------------------------------------------------------------------------
APPEND_DIR: append the path component to the path being built and check
for its existence. If doesn't exist and we are creating directories, do
so for this one; else signal success or error as appropriate.
---------------------------------------------------------------------------*/
 
if (FUNCTION == APPEND_DIR) {
int too_long = FALSE;
#ifdef SHORT_NAMES
char *old_end = end;
#endif
 
Trace((stderr, "appending dir segment [%s]\n", FnFilter1(pathcomp)));
while ((*end = *pathcomp++) != '\0')
++end;
#ifdef SHORT_NAMES /* path components restricted to 14 chars, typically */
if ((end-old_end) > FILENAME_MAX) /* GRR: proper constant? */
*(end = old_end + FILENAME_MAX) = '\0';
#endif
 
/* GRR: could do better check, see if overrunning buffer as we go:
* check end-buildpath after each append, set warning variable if
* within 20 of FILNAMSIZ; then if var set, do careful check when
* appending. Clear variable when begin new path. */
 
if ((end-buildpath) > FILNAMSIZ-3) /* need '/', one-char name, '\0' */
too_long = TRUE; /* check if extracting directory? */
Trace((stderr, "appending disk segment [%s]\n", FnFilter1(rootdisk)));
strcat(buildpath, rootdisk);
if (stat(buildpath, &G.statbuf)) { /* path doesn't exist */
if (!G.create_dirs) { /* told not to create (freshening) */
free(buildpath);
return MPN_INF_SKIP; /* path doesn't exist: nothing to do */
}
if (too_long) {
Info(slide, 1, ((char *)slide,
"checkdir error: path too long: %s\n",
FnFilter1(buildpath)));
free(buildpath);
/* no room for filenames: fatal */
return MPN_ERR_TOOLONG;
}
if (islib()) {
ulg size;
#ifdef OLD_THEOS_EXTRA
if (isv2_0lib())
size = v2_0extra()->filesize;
else
#endif
{
size = (ulg) G.extra_field[5] |
((ulg) G.extra_field[6] << 8) |
((ulg) G.extra_field[7] << 16) |
((ulg) G.extra_field[8] << 24);
}
if (makelib(buildpath, size / 64)) {
Info(slide, 1, ((char*)slide,
"checkdir error: can't create library %s\n\
unable to process %s.\n",
FnFilter2(buildpath), FnFilter1(G.filename));
free(buildpath);
/* path didn't exist, tried to create, failed */
return MPN_ERR_SKIP;
}
} else if (mkdir(buildpath) == -1) { /* create the directory */
Info(slide, 1, ((char *)slide,
"checkdir error: cannot create %s\n\
unable to process %s.\n",
FnFilter2(buildpath), FnFilter1(G.filename));
free(buildpath);
/* path didn't exist, tried to create, failed */
return MPN_ERR_SKIP;
}
created_dir = TRUE;
} else if (!S_ISDIR(G.statbuf.st_mode) && isdir()) {
Info(slide, 1, ((char *)slide,
"checkdir error: %s exists but is not directory\n\
unable to process %s.\n",
FnFilter2(buildpath), FnFilter1(G.filename));
free(buildpath);
/* path existed but wasn't dir */
return MPN_ERR_SKIP;
} else if (!S_ISLIB(G.statbuf.st_mode) && islib()) {
Info(slide, 1, ((char *)slide,
"checkdir error: %s exists but is not library\n\
unable to process %s.\n",
FnFilter2(buildpath), FnFilter1(G.filename));
free(buildpath);
/* path existed but wasn't lib */
return MPN_ERR_SKIP;
}
if (too_long) {
Info(slide, 1, ((char *)slide,
"checkdir error: path too long: %s\n", FnFilter1(buildpath)));
free(buildpath);
/* no room for filenames: fatal */
return MPN_ERR_TOOLONG;
}
*end++ = '/';
*end = '\0';
Trace((stderr, "buildpath now = [%s]\n", FnFilter1(buildpath)));
return MPN_OK;
 
} /* end if (FUNCTION == APPEND_DIR) */
 
/*---------------------------------------------------------------------------
GETPATH: copy full path to the string pointed at by pathcomp, and free
buildpath.
---------------------------------------------------------------------------*/
 
if (FUNCTION == GETPATH) {
strcpy(pathcomp, buildpath);
Trace((stderr, "getting and freeing path [%s]\n",
FnFilter1(pathcomp)));
free(buildpath);
buildpath = end = (char *)NULL;
return MPN_OK;
}
 
/*---------------------------------------------------------------------------
APPEND_NAME: assume the path component is the filename; append it and
return without checking for existence.
---------------------------------------------------------------------------*/
 
if (FUNCTION == APPEND_NAME) {
#ifdef SHORT_NAMES
char *old_end = end;
#endif
 
Trace((stderr, "appending filename [%s]\n", FnFilter1(pathcomp)));
while ((*end = *pathcomp++) != '\0') {
++end;
#ifdef SHORT_NAMES /* truncate name at 14 characters, typically */
if ((end-old_end) > FILENAME_MAX) /* GRR: proper constant? */
*(end = old_end + FILENAME_MAX) = '\0';
#endif
if ((end-buildpath) >= FILNAMSIZ) {
*--end = '\0';
Info(slide, 0x201, ((char *)slide,
"checkdir warning: path too long; truncating\n\
%s\n -> %s\n",
FnFilter1(G.filename), FnFilter2(buildpath)));
return MPN_INF_TRUNC; /* filename truncated */
}
}
strcat(buildpath, rootdisk);
Trace((stderr, "buildpath now = [%s]\n", FnFilter1(buildpath)));
/* could check for existence here, prompt for new name... */
return MPN_OK;
}
 
/*---------------------------------------------------------------------------
INIT: allocate and initialize buffer space for the file currently being
extracted. If file was renamed with an absolute path, don't prepend the
extract-to path.
---------------------------------------------------------------------------*/
 
/* GRR: for VMS and TOPS-20, add up to 13 to strlen */
 
if (FUNCTION == INIT) {
Trace((stderr, "initializing buildpath to "));
#ifdef ACORN_FTYPE_NFS
if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+
(uO.acorn_nfs_ext ? 5 : 1)))
#else
if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1))
#endif
== (char *)NULL)
return MPN_NOMEM;
if ((rootlen > 0) && !renamed_fullpath) {
strcpy(buildpath, rootpath);
end = buildpath + rootlen;
} else {
*buildpath = '\0';
end = buildpath;
}
Trace((stderr, "[%s]\n", FnFilter1(buildpath)));
return MPN_OK;
}
 
/*---------------------------------------------------------------------------
ROOT: if appropriate, store the path in rootpath and create it if
necessary; else assume it's a zipfile member and return. This path
segment gets used in extracting all members from every zipfile specified
on the command line.
---------------------------------------------------------------------------*/
 
#if (!defined(SFX) || defined(SFX_EXDIR))
if (FUNCTION == ROOT) {
if (pathcomp == (char *)NULL) {
rootlen = 0;
return MPN_OK;
}
if (rootlen > 0) /* rootpath was already set, nothing to do */
return MPN_OK;
if ((rootlen = strlen(pathcomp)) > 0) {
int prepend_slash = 0;
char *tmproot, *p;
 
if (*pathcomp == ':') {
preprend_slash = 1;
rootlen++;
}
if ((tmproot = (char *)malloc(rootlen+2)) == (char *)NULL) {
rootlen = 0;
return MPN_NOMEM;
}
if (prepend_slash)
strcpy(tmproot, "/");
else
*tmproot = '\0';
strcat(tmproot, pathcomp);
Trace((stderr, "initializing root path to [%s]\n",
FnFilter1(tmproot)));
if (tmproot[rootlen-1] == '/') {
tmproot[--rootlen] = '\0';
}
if (rootlen > 0 && (SSTAT(tmproot, &G.statbuf) ||
!S_ISDIR(G.statbuf.st_mode)))
{ /* path does not exist */
if (!G.create_dirs /* || iswild(tmproot) */ ) {
free(tmproot);
rootlen = 0;
/* skip (or treat as stored file) */
return MPN_INF_SKIP;
}
/* create the directory (could add loop here scanning tmproot
* to create more than one level, but why really necessary?) */
if (mkdir(tmproot) == -1) {
Info(slide, 1, ((char *)slide,
"checkdir: cannot create extraction directory: %s\n",
FnFilter1(tmproot)));
free(tmproot);
rootlen = 0;
/* path didn't exist, tried to create, and failed: */
/* file exists, or 2+ subdir levels required */
return MPN_ERR_SKIP;
}
}
/* split rootpath in path and disk */
if ((p = strchr(tmproot, ':')) != NULL) {
strncpy(rootdisk, p, 2);
rootdisk[2] = '\0';
*p = '\0';
rootlen = p - tmproot;
} else
rootdisk[0] = '\0';
if (rootpath[rootlen - 1] != '/') {
rootpath[rootlen++] = '/';
rootpath[rootlen] = '\0';
}
if ((rootpath = (char *)realloc(tmproot, rootlen+1)) == NULL) {
free(tmproot);
rootlen = 0;
return MPN_NOMEM;
}
Trace((stderr, "rootpath now = [%s], rootdisk now = [%s]\n",
FnFilter1(rootpath), FnFilter2(rootdisk)));
}
return MPN_OK;
}
#endif /* !SFX || SFX_EXDIR */
 
/*---------------------------------------------------------------------------
END: free rootpath, immediately prior to program exit.
---------------------------------------------------------------------------*/
 
if (FUNCTION == END) {
Trace((stderr, "freeing rootpath\n"));
if (rootlen > 0) {
free(rootpath);
rootlen = 0;
}
return MPN_OK;
}
 
return MPN_INVALID; /* should never reach */
 
} /* end function checkdir() */
 
 
 
 
#ifdef MORE
 
/**************************/
/* Function screenlines() */
/**************************/
 
int screenlines()
{
return getpl(27) + 1;
}
 
#endif /* MORE */
 
 
 
 
 
#if (!defined(MTS) || defined(SET_DIR_ATTRIB))
static void get_extattribs OF((__GPRO__ iztimes *pzt));
 
static int get_extattribs(__G__ pzt)
__GDEF
iztimes *pzt;
{
/*---------------------------------------------------------------------------
Convert from MSDOS-format local time and date to Unix-format 32-bit GMT
time: adjust base year from 1980 to 1970, do usual conversions from
yy/mm/dd hh:mm:ss to elapsed seconds, and account for timezone and day-
light savings time differences. If we have a Unix extra field, however,
we're laughing: both mtime and atime are ours.
---------------------------------------------------------------------------*/
#ifdef USE_EF_UT_TIME
unsigned eb_izux_flg;
 
eb_izux_flg = (G.extra_field ? ef_scan_for_izux(G.extra_field,
G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime,
#ifdef IZ_CHECK_TZ
(G.tz_is_valid ? pzt : NULL),
#else
pzt,
#endif
z_uidgid) : 0);
if (eb_izux_flg & EB_UT_FL_MTIME) {
TTrace((stderr, "\nget_extattribs: Unix e.f. modif. time = %ld\n",
pzt->mtime));
} else {
pzt->mtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);
}
if (eb_izux_flg & EB_UT_FL_ATIME) {
TTrace((stderr, "get_extattribs: Unix e.f. access time = %ld\n",
pzt->atime));
} else {
pzt->atime = pzt->mtime;
TTrace((stderr, "\nget_extattribs: modification/access times = %ld\n",
pzt->mtime));
}
#else
pzt->mtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);
pzt->atime = pzt->mtime;
#endif
}
#endif /* !MTS || SET_DIR_ATTRIB */
 
 
 
#ifndef MTS
 
/****************************/
/* Function close_outfile() */
/****************************/
 
void close_outfile(__G) /* GRR: change to return PK-style warning level */
__GDEF
{
union {
iztimes t3; /* mtime, atime, ctime */
ztimbuf t2; /* modtime, actime */
} zt;
 
/*---------------------------------------------------------------------------
If symbolic links are supported, allocate a storage area, put the uncom-
pressed "data" in it, and create the link. Since we know it's a symbolic
link to start with, we shouldn't have to worry about overflowing unsigned
ints with unsigned longs.
---------------------------------------------------------------------------*/
 
fclose(G.outfile);
 
get_extattribs(__G__ &(zt.t3));
 
/* set the file's access and modification times */
if (utime(G.filename, &(zt.t2))) {
if (uO.qflag)
Info(slide, 0x201, ((char *)slide,
"warning: cannot set times for %s\n", FnFilter1(G.filename)));
else
Info(slide, 0x201, ((char *)slide,
" (warning) cannot set times"));
}
 
/*---------------------------------------------------------------------------
Change the file permissions from default ones to those stored in the
zipfile.
---------------------------------------------------------------------------*/
 
if (chmod(G.filename, 0xffff & G.pInfo->file_attr))
perror("chmod (file attributes) error");
 
/*---------------------------------------------------------------------------
Change the file structure and set native .
---------------------------------------------------------------------------*/
 
if (isv2_3()) {
chorg(G.filename, G.extra_field[9]);
chlen(G.filename,
(ush) G.extra_field[10] | ((ush) G.extra_field[11] << 8),
(ush) G.extra_field[12] | ((ush) G.extra_field[13] << 8));
chgrow(G.filename, G.extra_field[14]);
}
#if OLD_THEOS_EXTRA
else if (isv2_0()) {
chorg(G.filename, G.pInfo->file_attr & 0xFF);
chlen(G.filename, v2_0extra()->reclen, v2_0extra()->keylen);
chgrow(G.filename, v2_0extra()->filegrow);
}
#endif
} /* end function close_outfile() */
 
#endif /* !MTS */
 
 
 
 
#ifdef SET_DIR_ATTRIB
/* messages of code for setting directory attributes */
static ZCONST char Far DirlistUidGidFailed[] =
"warning: cannot set UID %d and/or GID %d for %s\n";
static ZCONST char Far DirlistUtimeFailed[] =
"warning: cannot set modification, access times for %s\n";
# ifndef NO_CHMOD
static ZCONST char Far DirlistChmodFailed[] =
"warning: cannot set permissions for %s\n";
# endif
 
 
int defer_dir_attribs(__G__ pd)
__GDEF
direntry **pd;
{
uxdirattr *d_entry;
 
d_entry = (uxdirattr *)malloc(sizeof(uxdirattr) + strlen(G.filename));
*pd = (direntry *)d_entry;
if (d_entry == (uxdirattr *)NULL) {
return PK_MEM;
}
d_entry->fn = d_entry->fnbuf;
strcpy(d_entry->fn, G.filename);
 
d_entry->perms = G.pInfo->file_attr;
 
get_extattribs(__G__ &(d_entry->u.t3));
return PK_OK;
} /* end function defer_dir_attribs() */
 
 
int set_direc_attribs(__G__ d)
__GDEF
direntry *d;
{
int errval = PK_OK;
 
if (utime(d->fn, &UxAtt(d)->u.t2)) {
Info(slide, 0x201, ((char *)slide,
LoadFarString(DirlistUtimeFailed), FnFilter1(d->fn)));
if (!errval)
errval = PK_WARN;
}
if (chmod(d->fn, 0xffff & UxAtt(d)->perms)) {
Info(slide, 0x201, ((char *)slide,
LoadFarString(DirlistChmodFailed), FnFilter1(d->fn)));
/* perror("chmod (file attributes) error"); */
if (!errval)
errval = PK_WARN;
}
return errval;
} /* end function set_direc_attribs() */
 
#endif /* SET_DIR_ATTRIB */
 
 
 
 
#ifdef TIMESTAMP
 
/***************************/
/* Function stamp_file() */
/***************************/
 
int stamp_file(fname, modtime)
ZCONST char *fname;
time_t modtime;
{
ztimbuf tp;
 
tp.modtime = tp.actime = modtime;
return (utime(fname, &tp));
 
} /* end function stamp_file() */
 
#endif /* TIMESTAMP */
 
 
 
 
#ifndef SFX
 
/************************/
/* Function version() */
/************************/
 
void version(__G)
__GDEF
{
char buf1[40];
extern char Far CompiledWith[];
 
sprintf(slide, CompiledWith,
"THEOS C ","5.28", "THEOS ", "4.x", " on ", __DATE__);
(*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
 
} /* end function version() */
 
#endif /* !SFX */
/programs/fs/unzip60/theos/thscfg.h
0,0 → 1,62
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
#ifndef __theos_thscfg_h
#define __theos_thscfg_h
 
#include <unistd.h> /* dup proto & unix system calls live here */
#define _HANDLE_DEFINED
#include <fcntl.h> /* O_BINARY for open() w/o CR/LF translation */
#include <conio.h>
#include <time.h>
#include <sys/types.h> /* off_t, time_t, dev_t, ... */
#include "theos/stat.h"
#include <sys/utime.h>
#define GOT_UTIMBUF
#define DATE_FORMAT dateformat()
#define SCREENLINES screenlines()
#define USE_EF_UT_TIME
#define DIR_END '/'
#define INT_SPRINTF
#define lenEOL 1
#define PutNativeEOL *q++ = native(CR);
#define PIPE_ERROR (errno = 9999)
#define isatty(a) _isatty(a)
#undef match
int open(const char *name, int mode, ...);
size_t read(int fd, char *buf, size_t len);
size_t write(int fd, char *buf, size_t len);
unsigned long lseek(int fd, long offset, int base);
int close(int);
int _fprintf(FILE *fp, const char *fmt, ...);
int _isatty(int);
typedef unsigned char uid_t;
typedef unsigned char gid_t;
 
extern int _sprintf(char *s, const char *fmt, ...);
 
#ifndef NO_BOGUS_SPC
# include <stdio.h>
# undef fprintf
# undef sprintf
# define fprintf _fprintf
# define sprintf _sprintf
#else /* NO_BOGUS_SPC */
#ifndef Info /* may already have been defined for redirection */
# ifdef FUNZIP
# define Info(buf,flag,sprf_arg) \
fprintf((flag)&1? stderr : stdout, (char *)(_sprintf sprf_arg, (buf)))
# else
# define Info(buf,flag,sprf_arg) \
UzpMessagePrnt((zvoid *)&G, (uch *)(buf), (ulg)_sprintf sprf_arg, (flag))
# endif
#endif /* !Info */
#endif /* ?NO_BOGUS_SPC */
 
#endif /* !__theos_thscfg_h */