#define __FILEIO_C
#define UNZIP_INTERNAL
#include "unzip.h"
#ifdef WINDLL
# include "windll/windll.h"
# include <setjmp.h>
#endif
#include "crypt.h"
#include "ttyio.h"
#if CRYPT
# if (defined(CRYP_USES_ISO2OEM) && !defined(IZ_ISO2OEM_ARRAY))
# define IZ_ISO2OEM_ARRAY
# endif
# if (defined(CRYP_USES_OEM2ISO) && !defined(IZ_OEM2ISO_ARRAY))
# define IZ_OEM2ISO_ARRAY
# endif
#endif
#include "ebcdic.h"
#ifdef WINDLL
# define WriteError(buf,len,strm) \
(win_fprintf(pG, strm, (extent)len, (char far *)buf) != (int)(len))
#else
# ifdef USE_FWRITE
# define WriteError(buf,len,strm) \
((extent)fwrite((char *)(buf),1,(extent)(len),strm) != (extent)(len))
# else
# define WriteError(buf,len,strm) \
((extent)write(fileno(strm),(char *)(buf),(extent)(len)) != (extent)(len))
# endif
#endif
#if (defined(USE_DEFLATE64) && defined(__16BIT__))
static int partflush OF((__GPRO__ uch *rawbuf, ulg size, int unshrink));
#endif
#ifdef VMS_TEXT_CONV
static int is_vms_varlen_txt OF((__GPRO__ uch *ef_buf, unsigned ef_len));
#endif
static int disk_error OF((__GPRO));
static ZCONST char Far CannotOpenZipfile[] =
"error: cannot open zipfile [ %s ]\n";
#if (!defined(VMS) && !defined(AOS_VS) && !defined(CMS_MVS) && !defined(MACOS))
#if (!defined(TANDEM))
#if (defined(BEO_THS_UNX) || defined(DOS_FLX_NLM_OS2_W32))
static ZCONST char Far CannotDeleteOldFile[] =
"error: cannot delete old %s\n";
#ifdef UNIXBACKUP
static ZCONST char Far CannotRenameOldFile[] =
"error: cannot rename old %s\n";
static ZCONST char Far BackupSuffix[] = "~";
#endif
#endif
#ifdef NOVELL_BUG_FAILSAFE
static ZCONST char Far NovellBug[] =
"error: %s: stat() says does not exist, but fopen() found anyway\n";
#endif
static ZCONST char Far CannotCreateFile[] = "error: cannot create %s\n";
#endif
#endif
static ZCONST char Far ReadError[] = "error: zipfile read error\n";
static ZCONST char Far FilenameTooLongTrunc[] =
"warning: filename too long--truncating.\n";
static ZCONST char Far ExtraFieldTooLong[] =
"warning: extra field too long (%d). Ignoring...\n";
#ifdef WINDLL
static ZCONST char Far DiskFullQuery[] =
"%s: write error (disk full?).\n";
#else
static ZCONST char Far DiskFullQuery[] =
"%s: write error (disk full?). Continue? (y/n/^C) ";
static ZCONST char Far ZipfileCorrupt[] =
"error: zipfile probably corrupt (%s)\n";
# ifdef SYMLINKS
static ZCONST char Far FileIsSymLink[] =
"%s exists and is a symbolic link%s.\n";
# endif
# ifdef MORE
static ZCONST char Far MorePrompt[] = "--More--(%lu)";
# endif
static ZCONST char Far QuitPrompt[] =
"--- Press `Q' to quit, or any other key to continue ---";
static ZCONST char Far HidePrompt[] =
"\r \r";
# if CRYPT
# ifdef MACOS
static ZCONST char Far PasswPrompt[] = "[%s]\n %s password: ";
# else
static ZCONST char Far PasswPrompt[] = "[%s] %s password: ";
# endif
static ZCONST char Far PasswPrompt2[] = "Enter password: ";
static ZCONST char Far PasswRetry[] = "password incorrect--reenter: ";
# endif
#endif
int open_input_file(__G)
__GDEF
{
#ifdef VMS
G.zipfd = open(G.zipfn, O_RDONLY, 0, "ctx=stm");
#else
#ifdef MACOS
G.zipfd = open(G.zipfn, 0);
#else
#ifdef CMS_MVS
G.zipfd = vmmvs_open_infile(__G);
#else
#ifdef USE_STRM_INPUT
G.zipfd = fopen(G.zipfn, FOPR);
#else
# ifdef O_BINARY
G.zipfd = open(G.zipfn, O_RDONLY | O_BINARY);
# else
G.zipfd = open(G.zipfn, O_RDONLY);
# endif
#endif
#endif
#endif
#endif
#ifdef USE_STRM_INPUT
if (G.zipfd == NULL)
#else
if (G.zipfd == -1)
#endif
{
Info(slide, 0x401, ((char *)slide, LoadFarString(CannotOpenZipfile),
G.zipfn));
return 1;
}
return 0;
}
#if (!defined(VMS) && !defined(AOS_VS) && !defined(CMS_MVS) && !defined(MACOS))
#if (!defined(TANDEM))
int open_outfile(__G)
__GDEF
{
#ifdef DLL
if (G.redirect_data)
return (redirect_outfile(__G) == FALSE);
#endif
#ifdef QDOS
QFilename(__G__ G.filename);
#endif
#if (defined(DOS_FLX_NLM_OS2_W32) || defined(BEO_THS_UNX))
#ifdef BORLAND_STAT_BUG
if (access(G.filename, 0) == -1) {
FILE *tmp = fopen(G.filename, "wb+");
fputc('0', tmp);
fclose(tmp);
}
#endif
#ifdef SYMLINKS
if (SSTAT(G.filename, &G.statbuf) == 0 || lstat(G.filename,&G.statbuf) == 0)
#else
if (SSTAT(G.filename, &G.statbuf) == 0)
#endif
{
Trace((stderr, "open_outfile: stat(%s) returns 0: file exists\n",
FnFilter1(G.filename)));
#ifdef UNIXBACKUP
if (uO.B_flag) {
char *tname;
struct stat tmpstat;
int blen, flen, tlen;
blen = strlen(BackupSuffix);
flen = strlen(G.filename);
tlen = flen + blen + 6;
if (tlen >= FILNAMSIZ) {
tname = (char *)malloc(FILNAMSIZ);
if (tname == NULL)
return 1;
tlen = FILNAMSIZ - 1 - blen;
strcpy(tname, G.filename);
tname[tlen] = '\0';
if (flen > tlen) flen = tlen;
tlen = FILNAMSIZ;
} else {
tname = (char *)malloc(tlen);
if (tname == NULL)
return 1;
strcpy(tname, G.filename);
}
strcpy(tname+flen, BackupSuffix);
if (IS_OVERWRT_ALL) {
if (SSTAT(tname, &tmpstat) == 0)
unlink(tname);
} else {
unsigned maxtail, i;
char *numtail = tname + flen + blen;
maxtail = 65535;
switch (tlen - flen - blen - 1) {
case 4: maxtail = 9999; break;
case 3: maxtail = 999; break;
case 2: maxtail = 99; break;
case 1: maxtail = 9; break;
case 0: maxtail = 0; break;
}
for (i = 0; (i <= maxtail) && (SSTAT(tname, &tmpstat) == 0);)
sprintf(numtail,"%u", ++i);
}
if (rename(G.filename, tname) != 0) {
Info(slide, 0x401, ((char *)slide,
LoadFarString(CannotRenameOldFile), FnFilter1(G.filename)));
free(tname);
return 1;
}
Trace((stderr, "open_outfile: %s now renamed into %s\n",
FnFilter1(G.filename), FnFilter2(tname)));
free(tname);
} else
#endif
{
#ifdef DOS_FLX_OS2_W32
if (!(G.statbuf.st_mode & S_IWRITE)) {
Trace((stderr,
"open_outfile: existing file %s is read-only\n",
FnFilter1(G.filename)));
chmod(G.filename, S_IREAD | S_IWRITE);
Trace((stderr, "open_outfile: %s now writable\n",
FnFilter1(G.filename)));
}
#endif
#ifdef NLM
chmod(G.filename, 0);
#endif
if (unlink(G.filename) != 0) {
Info(slide, 0x401, ((char *)slide,
LoadFarString(CannotDeleteOldFile), FnFilter1(G.filename)));
return 1;
}
Trace((stderr, "open_outfile: %s now deleted\n",
FnFilter1(G.filename)));
}
}
#endif
#ifdef RISCOS
if (SWI_OS_File_7(G.filename,0xDEADDEAD,0xDEADDEAD,G.lrec.ucsize)!=NULL) {
Info(slide, 1, ((char *)slide, LoadFarString(CannotCreateFile),
FnFilter1(G.filename)));
return 1;
}
#endif
#ifdef TOPS20
char *tfilnam;
if ((tfilnam = (char *)malloc(2*strlen(G.filename)+1)) == (char *)NULL)
return 1;
strcpy(tfilnam, G.filename);
upper(tfilnam);
enquote(tfilnam);
if ((G.outfile = fopen(tfilnam, FOPW)) == (FILE *)NULL) {
Info(slide, 1, ((char *)slide, LoadFarString(CannotCreateFile),
tfilnam));
free(tfilnam);
return 1;
}
free(tfilnam);
#else
#ifdef MTS
if (uO.aflag)
G.outfile = fopen(G.filename, FOPWT);
else
G.outfile = fopen(G.filename, FOPW);
if (G.outfile == (FILE *)NULL) {
Info(slide, 1, ((char *)slide, LoadFarString(CannotCreateFile),
FnFilter1(G.filename)));
return 1;
}
#else
#ifdef DEBUG
Info(slide, 1, ((char *)slide,
"open_outfile: doing fopen(%s) for reading\n", FnFilter1(G.filename)));
if ((G.outfile = fopen(G.filename, FOPR)) == (FILE *)NULL)
Info(slide, 1, ((char *)slide,
"open_outfile: fopen(%s) for reading failed: does not exist\n",
FnFilter1(G.filename)));
else {
Info(slide, 1, ((char *)slide,
"open_outfile: fopen(%s) for reading succeeded: file exists\n",
FnFilter1(G.filename)));
fclose(G.outfile);
}
#endif
#ifdef NOVELL_BUG_FAILSAFE
if (G.dne && ((G.outfile = fopen(G.filename, FOPR)) != (FILE *)NULL)) {
Info(slide, 0x401, ((char *)slide, LoadFarString(NovellBug),
FnFilter1(G.filename)));
fclose(G.outfile);
return 1;
}
#endif
Trace((stderr, "open_outfile: doing fopen(%s) for writing\n",
FnFilter1(G.filename)));
if ((G.outfile = fopen(G.filename, FOPW)) == (FILE *)NULL) {
Info(slide, 0x401, ((char *)slide, LoadFarString(CannotCreateFile),
FnFilter1(G.filename)));
return 1;
}
Trace((stderr, "open_outfile: fopen(%s) for writing succeeded\n",
FnFilter1(G.filename)));
#endif
#endif
#ifdef USE_FWRITE
#ifdef DOS_NLM_OS2_W32
setbuf(G.outfile, (char *)NULL);
#else
#ifndef RISCOS
#ifdef _IOFBF
setvbuf(G.outfile, (char *)slide, _IOFBF, WSIZE);
#else
setbuf(G.outfile, (char *)slide);
#endif
#endif
#endif
#endif
#ifdef OS2_W32
SetFileSize(G.outfile, G.pInfo->uncompr_size);
#endif
return 0;
}
#endif
#endif
void undefer_input(__G)
__GDEF
{
if (G.incnt > 0)
G.csize += G.incnt;
if (G.incnt_leftover > 0) {
G.incnt = G.incnt_leftover + (int)G.csize;
G.inptr = G.inptr_leftover - (int)G.csize;
G.incnt_leftover = 0;
} else if (G.incnt < 0)
G.incnt = 0;
}
void defer_leftover_input(__G)
__GDEF
{
if ((long)G.incnt > G.csize) {
if (G.csize < 0L)
G.csize = 0L;
G.inptr_leftover = G.inptr + (int)G.csize;
G.incnt_leftover = G.incnt - (int)G.csize;
G.incnt = (int)G.csize;
} else
G.incnt_leftover = 0;
G.csize -= G.incnt;
}
unsigned readbuf(__G__ buf, size)
__GDEF
char *buf;
register unsigned size;
{
register unsigned count;
unsigned n;
n = size;
while (size) {
if (G.incnt <= 0) {
if ((G.incnt = read(G.zipfd, (char *)G.inbuf, INBUFSIZ)) == 0)
return (n-size);
else if (G.incnt < 0) {
(*G.message)((zvoid *)&G,
(uch *)LoadFarString(ReadError),
(ulg)strlen(LoadFarString(ReadError)), 0x401);
return 0;
}
G.cur_zipfile_bufstart += INBUFSIZ;
G.inptr = G.inbuf;
}
count = MIN(size, (unsigned)G.incnt);
memcpy(buf, G.inptr, count);
buf += count;
G.inptr += count;
G.incnt -= count;
size -= count;
}
return n;
}
int readbyte(__G)
__GDEF
{
if (G.mem_mode)
return EOF;
if (G.csize <= 0) {
G.csize--;
G.incnt = 0;
return EOF;
}
if (G.incnt <= 0) {
if ((G.incnt = read(G.zipfd, (char *)G.inbuf, INBUFSIZ)) == 0) {
G.incnt = 0;
return EOF;
} else if (G.incnt < 0) {
(*G.message)((zvoid *)&G,
(uch *)LoadFarString(ReadError),
(ulg)strlen(LoadFarString(ReadError)), 0x401);
echon();
#ifdef WINDLL
longjmp(dll_error_return, 1);
#else
DESTROYGLOBALS();
EXIT(PK_BADERR);
#endif
}
G.cur_zipfile_bufstart += INBUFSIZ;
G.inptr = G.inbuf;
defer_leftover_input(__G);
}
#if CRYPT
if (G.pInfo->encrypted) {
uch *p;
int n;
for (n = G.incnt, p = G.inptr; n--; p++)
zdecode(*p);
}
#endif
--G.incnt;
return *G.inptr++;
}
#ifdef USE_ZLIB
int fillinbuf(__G)
__GDEF
{
if (G.mem_mode ||
(G.incnt = read(G.zipfd, (char *)G.inbuf, INBUFSIZ)) <= 0)
return 0;
G.cur_zipfile_bufstart += INBUFSIZ;
G.inptr = G.inbuf;
defer_leftover_input(__G);
#if CRYPT
if (G.pInfo->encrypted) {
uch *p;
int n;
for (n = G.incnt, p = G.inptr; n--; p++)
zdecode(*p);
}
#endif
return G.incnt;
}
#endif
int seek_zipf(__G__ abs_offset)
__GDEF
LONGINT abs_offset;
{
LONGINT request = abs_offset + G.extra_bytes;
LONGINT inbuf_offset = request % INBUFSIZ;
LONGINT bufstart = request - inbuf_offset;
if (request < 0) {
Info(slide, 1, ((char *)slide, LoadFarStringSmall(SeekMsg),
G.zipfn, LoadFarString(ReportMsg)));
return(PK_BADERR);
} else if (bufstart != G.cur_zipfile_bufstart) {
Trace((stderr,
"fpos_zip: abs_offset = %ld, G.extra_bytes = %ld\n",
abs_offset, G.extra_bytes));
#ifdef USE_STRM_INPUT
fseek(G.zipfd, (LONGINT)bufstart, SEEK_SET);
G.cur_zipfile_bufstart = ftell(G.zipfd);
#else
G.cur_zipfile_bufstart = lseek(G.zipfd, (LONGINT)bufstart, SEEK_SET);
#endif
Trace((stderr,
" request = %ld, (abs+extra) = %ld, inbuf_offset = %ld\n",
request, (abs_offset+G.extra_bytes), inbuf_offset));
Trace((stderr, " bufstart = %ld, cur_zipfile_bufstart = %ld\n",
bufstart, G.cur_zipfile_bufstart));
if ((G.incnt = read(G.zipfd, (char *)G.inbuf, INBUFSIZ)) <= 0)
return(PK_EOF);
G.incnt -= (int)inbuf_offset;
G.inptr = G.inbuf + (int)inbuf_offset;
} else {
G.incnt += (G.inptr-G.inbuf) - (int)inbuf_offset;
G.inptr = G.inbuf + (int)inbuf_offset;
}
return(PK_OK);
}
#ifndef VMS
int flush(__G__ rawbuf, size, unshrink)
__GDEF
uch *rawbuf;
ulg size;
int unshrink;
#if (defined(USE_DEFLATE64) && defined(__16BIT__))
{
int ret;
while (size > 0x8000L) {
ret = partflush(__G__ rawbuf, 0x8000L, unshrink);
if (ret != PK_OK)
return ret;
size -= 0x8000L;
rawbuf += (unsigned)0x8000;
}
return partflush(__G__ rawbuf, size, unshrink);
}
static int partflush(__G__ rawbuf, size, unshrink)
__GDEF
uch *rawbuf;
ulg size;
int unshrink;
#endif
{
register uch *p;
register uch *q;
uch *transbuf;
#if (defined(SMALL_MEM) || defined(MED_MEM) || defined(VMS_TEXT_CONV))
ulg transbufsiz;
#endif
G.crc32val = crc32(G.crc32val, rawbuf, (extent)size);
#ifdef DLL
if ((G.statreportcb != NULL) &&
(*G.statreportcb)(__G__ UZ_ST_IN_PROGRESS, G.zipfn, G.filename, NULL))
return IZ_CTRLC;
#endif
if (uO.tflag || size == 0L)
return PK_OK;
if (G.disk_full)
return PK_DISK;
if (!G.pInfo->textmode) {
#ifdef DLL
if (G.redirect_data)
writeToMemory(__G__ rawbuf, (extent)size);
else
#endif
if (!uO.cflag && WriteError(rawbuf, size, G.outfile))
return disk_error(__G);
else if (uO.cflag && (*G.message)((zvoid *)&G, rawbuf, size, 0))
return PK_OK;
} else {
if (unshrink) {
transbuf = G.outbuf2;
#if (defined(SMALL_MEM) || defined(MED_MEM) || defined(VMS_TEXT_CONV))
transbufsiz = TRANSBUFSIZ;
#endif
} else {
transbuf = G.outbuf;
#if (defined(SMALL_MEM) || defined(MED_MEM) || defined(VMS_TEXT_CONV))
transbufsiz = OUTBUFSIZ;
Trace((stderr, "\ntransbufsiz = OUTBUFSIZ = %u\n",
(unsigned)OUTBUFSIZ));
#endif
}
if (G.newfile) {
#ifdef VMS_TEXT_CONV
if (G.pInfo->hostnum == VMS_ && G.extra_field &&
is_vms_varlen_txt(__G__ G.extra_field,
G.lrec.extra_field_length))
G.VMS_line_state = 0;
else
G.VMS_line_state = -1;
#endif
G.didCRlast = FALSE;
G.newfile = FALSE;
}
#ifdef VMS_TEXT_CONV
if (G.VMS_line_state >= 0)
{
p = rawbuf;
q = transbuf;
while (p < rawbuf+(unsigned)size) {
switch (G.VMS_line_state) {
case 0:
G.VMS_line_length = 0;
if (p == rawbuf+(unsigned)size-1) {
G.VMS_line_length = (unsigned)(*p++);
G.VMS_line_state = 1;
} else {
G.VMS_line_length = makeword(p);
p += 2;
G.VMS_line_state = 2;
}
G.VMS_line_pad =
((G.VMS_line_length & 1) != 0);
break;
case 1:
G.VMS_line_length += ((unsigned)(*p++) << 8);
G.VMS_line_state = 2;
break;
case 2:
{
extent remaining = rawbuf+(unsigned)size-p;
extent outroom;
if (G.VMS_line_length < remaining) {
remaining = G.VMS_line_length;
G.VMS_line_state = 3;
}
outroom = transbuf+(unsigned)transbufsiz-q;
if (remaining >= outroom) {
remaining -= outroom;
for (;outroom > 0; p++, outroom--)
*q++ = native(*p);
#ifdef DLL
if (G.redirect_data)
writeToMemory(__G__ transbuf,
(extent)(q-transbuf));
else
#endif
if (!uO.cflag && WriteError(transbuf,
(extent)(q-transbuf), G.outfile))
return disk_error(__G);
else if (uO.cflag && (*G.message)((zvoid *)&G,
transbuf, (ulg)(q-transbuf), 0))
return PK_OK;
q = transbuf;
}
G.VMS_line_length -= remaining;
for (;remaining > 0; p++, remaining--)
*q++ = native(*p);
}
break;
case 3:
if (q > transbuf+(unsigned)transbufsiz-lenEOL) {
#ifdef DLL
if (G.redirect_data)
writeToMemory(__G__ transbuf,
(extent)(q-transbuf));
else
#endif
if (!uO.cflag &&
WriteError(transbuf, (extent)(q-transbuf),
G.outfile))
return disk_error(__G);
else if (uO.cflag && (*G.message)((zvoid *)&G,
transbuf, (ulg)(q-transbuf), 0))
return PK_OK;
q = transbuf;
}
PutNativeEOL
G.VMS_line_state = G.VMS_line_pad ? 4 : 0;
break;
case 4:
++p;
G.VMS_line_state = 0;
break;
}
}
} else
#endif
{
p = rawbuf;
if (*p == LF && G.didCRlast)
++p;
G.didCRlast = FALSE;
for (q = transbuf; p < rawbuf+(unsigned)size; ++p) {
if (*p == CR) {
PutNativeEOL
if (p == rawbuf+(unsigned)size-1)
G.didCRlast = TRUE;
else if (p[1] == LF)
++p;
} else if (*p == LF)
PutNativeEOL
else
#ifndef DOS_FLX_OS2_W32
if (*p != CTRLZ)
#endif
*q++ = native(*p);
#if (defined(SMALL_MEM) || defined(MED_MEM))
# if (lenEOL == 1)
if (!unshrink)
# endif
if (q > transbuf+(unsigned)transbufsiz-lenEOL) {
Trace((stderr,
"p - rawbuf = %u q-transbuf = %u size = %lu\n",
(unsigned)(p-rawbuf), (unsigned)(q-transbuf), size));
if (!uO.cflag && WriteError(transbuf,
(extent)(q-transbuf), G.outfile))
return disk_error(__G);
else if (uO.cflag && (*G.message)((zvoid *)&G,
transbuf, (ulg)(q-transbuf), 0))
return PK_OK;
q = transbuf;
continue;
}
#endif
}
}
Trace((stderr, "p - rawbuf = %u q-transbuf = %u size = %lu\n",
(unsigned)(p-rawbuf), (unsigned)(q-transbuf), size));
if (q > transbuf) {
#ifdef DLL
if (G.redirect_data)
writeToMemory(__G__ transbuf, (extent)(q-transbuf));
else
#endif
if (!uO.cflag && WriteError(transbuf, (extent)(q-transbuf),
G.outfile))
return disk_error(__G);
else if (uO.cflag && (*G.message)((zvoid *)&G, transbuf,
(ulg)(q-transbuf), 0))
return PK_OK;
}
}
return PK_OK;
}
#ifdef VMS_TEXT_CONV
static int is_vms_varlen_txt(__G__ ef_buf, ef_len)
__GDEF
uch *ef_buf;
unsigned ef_len;
{
unsigned eb_id;
unsigned eb_len;
uch *eb_data;
unsigned eb_datlen;
#define VMSREC_C_UNDEF 0
#define VMSREC_C_VAR 2
uch vms_rectype = VMSREC_C_UNDEF;
uch vms_fileorg = 0;
#define VMSPK_ITEMID 0
#define VMSPK_ITEMLEN 2
#define VMSPK_ITEMHEADSZ 4
#define VMSATR_C_RECATTR 4
#define VMS_FABSIG 0x42414656
#define VMSFAB_B_RFM 31
#define VMSFAB_B_ORG 29
if (ef_len == 0 || ef_buf == NULL)
return FALSE;
while (ef_len >= EB_HEADSIZE) {
eb_id = makeword(EB_ID + ef_buf);
eb_len = makeword(EB_LEN + ef_buf);
if (eb_len > (ef_len - EB_HEADSIZE)) {
Trace((stderr,
"is_vms_varlen_txt: block length %u > rest ef_size %u\n", eb_len,
ef_len - EB_HEADSIZE));
break;
}
switch (eb_id) {
case EF_PKVMS:
eb_data = ef_buf+(EB_HEADSIZE+4);
eb_datlen = eb_len-4;
if (makelong(ef_buf+EB_HEADSIZE) !=
crc32(CRCVAL_INITIAL, eb_data, (extent)eb_datlen))
{
Info(slide, 1, ((char *)slide,
"[Warning: CRC error, discarding PKWARE extra field]\n"));
break;
}
while (eb_datlen > 4)
{
unsigned fldsize = makeword(&eb_data[VMSPK_ITEMLEN]);
switch (makeword(&eb_data[VMSPK_ITEMID])) {
case VMSATR_C_RECATTR:
if (fldsize >= 1) {
vms_rectype = eb_data[VMSPK_ITEMHEADSZ] & 15;
vms_fileorg = eb_data[VMSPK_ITEMHEADSZ] >> 4;
}
break;
default:
break;
}
eb_datlen -= fldsize + VMSPK_ITEMHEADSZ;
eb_data += fldsize + VMSPK_ITEMHEADSZ;
}
break;
case EF_IZVMS:
if (makelong(ef_buf+EB_HEADSIZE) == VMS_FABSIG) {
if ((eb_data = extract_izvms_block(__G__
ef_buf+EB_HEADSIZE, eb_len,
&eb_datlen, NULL, 0))
!= NULL)
{
if (eb_datlen >= VMSFAB_B_RFM+1) {
vms_rectype = eb_data[VMSFAB_B_RFM] & 15;
vms_fileorg = eb_data[VMSFAB_B_ORG] >> 4;
}
free(eb_data);
}
}
break;
default:
break;
}
ef_buf += (eb_len + EB_HEADSIZE);
ef_len -= (eb_len + EB_HEADSIZE);
}
return (vms_rectype == VMSREC_C_VAR);
}
#endif
static int disk_error(__G)
__GDEF
{
Info(slide, 0x4a1, ((char *)slide, LoadFarString(DiskFullQuery),
FnFilter1(G.filename)));
#ifndef WINDLL
fgets(G.answerbuf, 9, stdin);
if (*G.answerbuf == 'y')
G.disk_full = 1;
else
#endif
G.disk_full = 2;
return PK_DISK;
}
#endif
int UZ_EXP UzpMessagePrnt(pG, buf, size, flag)
zvoid *pG;
uch *buf;
ulg size;
int flag;
{
int error;
uch *q=buf, *endbuf=buf+(unsigned)size;
#ifdef MORE
uch *p=buf;
#if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
int islinefeed = FALSE;
#endif
#endif
FILE *outfp;
#if (defined(OS2) && defined(DLL))
if (MSG_NO_DLL2(flag))
return 0;
#endif
#ifdef WINDLL
if (MSG_NO_WDLL(flag))
return 0;
#endif
#ifdef WINDLL
if (MSG_NO_WGUI(flag))
return 0;
#endif
#ifdef DLL
if (((Uz_Globs *)pG)->redirect_data &&
!((Uz_Globs *)pG)->redirect_text)
return 0;
#endif
if (MSG_STDERR(flag) && !((Uz_Globs *)pG)->UzO.tflag)
outfp = (FILE *)stderr;
else
outfp = (FILE *)stdout;
#ifdef QUERY_TRNEWLN
if (MSG_MNEWLN(flag)) {
*endbuf++ = '\n';
++size;
}
#endif
if (MSG_TNEWLN(flag)) {
if ((!size && !((Uz_Globs *)pG)->sol) ||
(size && (endbuf[-1] != '\n')))
{
*endbuf++ = '\n';
++size;
}
}
#ifdef MORE
# ifdef SCREENSIZE
# if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
SCREENSIZE(&((Uz_Globs *)pG)->height, &((Uz_Globs *)pG)->width);
# else
SCREENSIZE(&((Uz_Globs *)pG)->height, (int *)NULL);
# endif
((Uz_Globs *)pG)->height -= 2;
# else
((Uz_Globs *)pG)->height = SCREENLINES - 2;
# if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
((Uz_Globs *)pG)->width = SCREENWIDTH;
# endif
# endif
#endif
if (MSG_LNEWLN(flag) && !((Uz_Globs *)pG)->sol) {
#ifdef OS2DLL
if (!((Uz_Globs *)pG)->redirect_text) {
#endif
putc('\n', outfp);
fflush(outfp);
#ifdef MORE
if (((Uz_Globs *)pG)->M_flag)
{
#if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
((Uz_Globs *)pG)->chars = 0;
#endif
++((Uz_Globs *)pG)->numlines;
++((Uz_Globs *)pG)->lines;
if (((Uz_Globs *)pG)->lines >= ((Uz_Globs *)pG)->height)
(*((Uz_Globs *)pG)->mpause)((zvoid *)pG,
LoadFarString(MorePrompt), 1);
}
#endif
if (MSG_STDERR(flag) && ((Uz_Globs *)pG)->UzO.tflag &&
!isatty(1) && isatty(2))
{
putc('\n', stderr);
fflush(stderr);
}
#ifdef OS2DLL
} else
REDIRECTC('\n');
#endif
((Uz_Globs *)pG)->sol = TRUE;
}
#ifdef MORE
if (((Uz_Globs *)pG)->M_flag
#ifdef OS2DLL
&& !((Uz_Globs *)pG)->redirect_text
#endif
)
{
while (p < endbuf) {
if (*p == '\n') {
#if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
islinefeed = TRUE;
} else if (SCREENLWRAP) {
if (*p == '\r') {
((Uz_Globs *)pG)->chars = 0;
} else {
# ifdef TABSIZE
if (*p == '\t')
((Uz_Globs *)pG)->chars +=
(TABSIZE - (((Uz_Globs *)pG)->chars % TABSIZE));
else
# endif
++((Uz_Globs *)pG)->chars;
if (((Uz_Globs *)pG)->chars >= ((Uz_Globs *)pG)->width)
islinefeed = TRUE;
}
}
if (islinefeed) {
islinefeed = FALSE;
((Uz_Globs *)pG)->chars = 0;
#endif
++((Uz_Globs *)pG)->numlines;
++((Uz_Globs *)pG)->lines;
if (((Uz_Globs *)pG)->lines >= ((Uz_Globs *)pG)->height)
{
if ((error = WriteError(q, p-q+1, outfp)) != 0)
return error;
fflush(outfp);
((Uz_Globs *)pG)->sol = TRUE;
q = p + 1;
(*((Uz_Globs *)pG)->mpause)((zvoid *)pG,
LoadFarString(MorePrompt), 1);
}
}
INCSTR(p);
}
size = (ulg)(p - q);
}
#endif
if (size) {
#ifdef OS2DLL
if (!((Uz_Globs *)pG)->redirect_text) {
#endif
if ((error = WriteError(q, size, outfp)) != 0)
return error;
fflush(outfp);
if (MSG_STDERR(flag) && ((Uz_Globs *)pG)->UzO.tflag &&
!isatty(1) && isatty(2))
{
if ((error = WriteError(q, size, stderr)) != 0)
return error;
fflush(stderr);
}
#ifdef OS2DLL
} else {
if ((error = REDIRECTPRINT(q, size)) != 0)
return error;
}
#endif
((Uz_Globs *)pG)->sol = (endbuf[-1] == '\n');
}
return 0;
}
#ifdef DLL
int UZ_EXP UzpMessageNull(pG, buf, size, flag)
zvoid *pG;
uch *buf;
ulg size;
int flag;
{
return 0;
}
#endif
int UZ_EXP UzpInput(pG, buf, size, flag)
zvoid *pG;
uch *buf;
int *size;
int flag;
{
pG = pG; buf = buf; flag = flag;
*size = 0;
return 0;
}
#if (!defined(WINDLL) && !defined(MACOS))
void UZ_EXP UzpMorePause(pG, prompt, flag)
zvoid *pG;
ZCONST char *prompt;
int flag;
{
uch c;
if (!((Uz_Globs *)pG)->sol)
fprintf(stderr, "\n");
fprintf(stderr, prompt, ((Uz_Globs *)pG)->numlines);
fflush(stderr);
if (flag & 1) {
do {
c = (uch)FGETCH(0);
} while (
#ifdef THEOS
c != 17 &&
#endif
c != '\r' && c != '\n' && c != ' ' && c != 'q' && c != 'Q');
} else
c = (uch)FGETCH(0);
fprintf(stderr, LoadFarString(HidePrompt));
fflush(stderr);
if (
#ifdef THEOS
(c == 17) ||
#endif
(ToLower(c) == 'q')) {
DESTROYGLOBALS();
EXIT(PK_COOL);
}
((Uz_Globs *)pG)->sol = TRUE;
#ifdef MORE
if ((flag & 1) && c == ' ')
((Uz_Globs *)pG)->lines = 0;
#endif
}
#endif
#ifndef WINDLL
int UZ_EXP UzpPassword (pG, rcnt, pwbuf, size, zfn, efn)
zvoid *pG;
int *rcnt;
char *pwbuf;
int size;
ZCONST char *zfn;
ZCONST char *efn;
{
#if CRYPT
int r = IZ_PW_ENTERED;
char *m;
char *prompt;
#ifndef REENTRANT
pG = pG;
#endif
if (*rcnt == 0) {
*rcnt = 2;
if ((prompt = (char *)malloc(2*FILNAMSIZ + 15)) != (char *)NULL) {
sprintf(prompt, LoadFarString(PasswPrompt),
FnFilter1(zfn), FnFilter2(efn));
m = prompt;
} else
m = (char *)LoadFarString(PasswPrompt2);
} else {
(*rcnt)--;
prompt = NULL;
m = (char *)LoadFarString(PasswRetry);
}
m = getp(__G__ m, pwbuf, size);
if (prompt != (char *)NULL) {
free(prompt);
}
if (m == (char *)NULL) {
r = IZ_PW_ERROR;
}
else if (*pwbuf == '\0') {
r = IZ_PW_CANCELALL;
}
return r;
#else
pG = pG; rcnt = rcnt; pwbuf = pwbuf; size = size; zfn = zfn; efn = efn;
return IZ_PW_ERROR;
#endif
}
void handler(signal)
int signal;
{
GETGLOBALS();
#if !(defined(SIGBUS) || defined(SIGSEGV))
(*G.message)((zvoid *)&G, slide, 0L, 0x41);
#endif
echon();
#ifdef SIGBUS
if (signal == SIGBUS) {
Info(slide, 0x421, ((char *)slide, LoadFarString(ZipfileCorrupt),
"bus error"));
DESTROYGLOBALS();
EXIT(PK_BADERR);
}
#endif
#ifdef SIGSEGV
if (signal == SIGSEGV) {
Info(slide, 0x421, ((char *)slide, LoadFarString(ZipfileCorrupt),
"segmentation violation"));
DESTROYGLOBALS();
EXIT(PK_BADERR);
}
#endif
DESTROYGLOBALS();
#if defined(AMIGA) && defined(__SASC)
_abort();
#endif
EXIT(IZ_CTRLC);
}
#endif
#if (!defined(VMS) && !defined(CMS_MVS))
#if (!defined(OS2) || defined(TIMESTAMP))
#if (!defined(HAVE_MKTIME) || defined(WIN32))
ZCONST ush ydays[] =
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
#endif
time_t dos_to_unix_time(dosdatetime)
ulg dosdatetime;
{
time_t m_time;
#ifdef HAVE_MKTIME
ZCONST time_t now = time(NULL);
struct tm *tm;
# define YRBASE 1900
tm = localtime(&now);
tm->tm_isdst = -1;
tm->tm_year = ((int)(dosdatetime >> 25) & 0x7f) + (1980 - YRBASE);
tm->tm_mon = ((int)(dosdatetime >> 21) & 0x0f) - 1;
tm->tm_mday = ((int)(dosdatetime >> 16) & 0x1f);
tm->tm_hour = (int)((unsigned)dosdatetime >> 11) & 0x1f;
tm->tm_min = (int)((unsigned)dosdatetime >> 5) & 0x3f;
tm->tm_sec = (int)((unsigned)dosdatetime << 1) & 0x3e;
m_time = mktime(tm);
NATIVE_TO_TIMET(m_time)
TTrace((stderr, " final m_time = %lu\n", (ulg)m_time));
#else
int yr, mo, dy, hh, mm, ss;
#ifdef TOPS20
# define YRBASE 1900
struct tmx *tmx;
char temp[20];
#else
# define YRBASE 1970
int leap;
unsigned days;
struct tm *tm;
#if (!defined(MACOS) && !defined(RISCOS) && !defined(QDOS) && !defined(TANDEM))
#ifdef WIN32
TIME_ZONE_INFORMATION tzinfo;
DWORD res;
#else
#ifndef BSD4_4
#if (defined(BSD) || defined(MTS) || defined(__GO32__))
struct timeb tbp;
#else
#ifdef DECLARE_TIMEZONE
extern time_t timezone;
#endif
#endif
#endif
#endif
#endif
#endif
yr = ((int)(dosdatetime >> 25) & 0x7f) + (1980 - YRBASE);
mo = ((int)(dosdatetime >> 21) & 0x0f) - 1;
dy = ((int)(dosdatetime >> 16) & 0x1f) - 1;
hh = (int)((unsigned)dosdatetime >> 11) & 0x1f;
mm = (int)((unsigned)dosdatetime >> 5) & 0x3f;
ss = (int)((unsigned)dosdatetime & 0x1f) * 2;
#ifdef TOPS20
tmx = (struct tmx *)malloc(sizeof(struct tmx));
sprintf (temp, "%02d/%02d/%02d %02d:%02d:%02d", mo+1, dy+1, yr, hh, mm, ss);
time_parse(temp, tmx, (char *)0);
m_time = time_make(tmx);
free(tmx);
#else
leap = ((yr + YRBASE - 1) / 4);
days = (yr * 365) + (leap - 492) + ydays[mo];
if ((mo > 1) && ((yr+YRBASE)%4 == 0) && ((yr+YRBASE) != 2100))
++days;
m_time = (time_t)(((unsigned long)days + dy) * 86400L +
(unsigned long)hh * 3600L +
(unsigned long)(mm * 60 + ss));
TTrace((stderr, "dos_to_unix_time:\n"));
TTrace((stderr, " m_time before timezone = %lu\n", (ulg)m_time));
#if (!defined(MACOS) && !defined(RISCOS) && !defined(QDOS) && !defined(TANDEM))
#ifdef WIN32
res = GetTimeZoneInformation(&tzinfo);
if (res != TIME_ZONE_ID_INVALID)
{
m_time += 60*(tzinfo.Bias);
#else
#if (defined(BSD) || defined(MTS) || defined(__GO32__))
#ifdef BSD4_4
if ( (dosdatetime >= DOSTIME_2038_01_18) &&
(m_time < (time_t)0x70000000L) )
m_time = U_TIME_T_MAX;
if (m_time < (time_t)0L)
m_time = S_TIME_T_MAX;
if ((tm = localtime(&m_time)) != (struct tm *)NULL)
m_time -= tm->tm_gmtoff;
#else
ftime(&tbp);
m_time += tbp.timezone * 60L;
#endif
#else
#if (!defined(__BEOS__) && !defined(__HAIKU__))
m_time += timezone;
#endif
#endif
#endif
TTrace((stderr, " m_time after timezone = %lu\n", (ulg)m_time));
#ifndef BSD4_4
if ( (dosdatetime >= DOSTIME_2038_01_18) &&
(m_time < (time_t)0x70000000L) )
m_time = U_TIME_T_MAX;
if (m_time < (time_t)0L)
m_time = S_TIME_T_MAX;
TIMET_TO_NATIVE(m_time)
if (((tm = localtime((time_t *)&m_time)) != NULL) && tm->tm_isdst)
#ifdef WIN32
m_time += 60L * tzinfo.DaylightBias;
else
m_time += 60L * tzinfo.StandardBias;
#else
m_time -= 60L * 60L;
#endif
NATIVE_TO_TIMET(m_time)
TTrace((stderr, " m_time after DST = %lu\n", (ulg)m_time));
#endif
#ifdef WIN32
}
#endif
#endif
#endif
#endif
if ( (dosdatetime >= DOSTIME_2038_01_18) &&
(m_time < (time_t)0x70000000L) )
m_time = U_TIME_T_MAX;
if (m_time < (time_t)0L)
m_time = S_TIME_T_MAX;
return m_time;
}
#endif
#endif
#if (!defined(VMS) && !defined(OS2) && !defined(CMS_MVS))
int check_for_newer(__G__ filename)
__GDEF
char *filename;
{
time_t existing, archive;
#ifdef USE_EF_UT_TIME
iztimes z_utime;
#endif
#ifdef AOS_VS
long dyy, dmm, ddd, dhh, dmin, dss;
dyy = (lrec.last_mod_dos_datetime >> 25) + 1980;
dmm = (lrec.last_mod_dos_datetime >> 21) & 0x0f;
ddd = (lrec.last_mod_dos_datetime >> 16) & 0x1f;
dhh = (lrec.last_mod_dos_datetime >> 11) & 0x1f;
dmin = (lrec.last_mod_dos_datetime >> 5) & 0x3f;
dss = (lrec.last_mod_dos_datetime & 0x1f) * 2;
if (!zvs_create(filename, (((ulg)dgdate(dmm, ddd, dyy)) << 16) |
(dhh*1800L + dmin*30L + dss/2L), -1L, -1L, (char *) -1, -1, -1, -1))
return DOES_NOT_EXIST;
#endif
Trace((stderr, "check_for_newer: doing stat(%s)\n", FnFilter1(filename)));
if (SSTAT(filename, &G.statbuf)) {
Trace((stderr,
"check_for_newer: stat(%s) returns %d: file does not exist\n",
FnFilter1(filename), SSTAT(filename, &G.statbuf)));
#ifdef SYMLINKS
Trace((stderr, "check_for_newer: doing lstat(%s)\n",
FnFilter1(filename)));
if (lstat(filename, &G.statbuf) == 0) {
Trace((stderr,
"check_for_newer: lstat(%s) returns 0: symlink does exist\n",
FnFilter1(filename)));
if (QCOND2 && !IS_OVERWRT_ALL)
Info(slide, 0, ((char *)slide, LoadFarString(FileIsSymLink),
FnFilter1(filename), " with no real file"));
return EXISTS_AND_OLDER;
}
#endif
return DOES_NOT_EXIST;
}
Trace((stderr, "check_for_newer: stat(%s) returns 0: file exists\n",
FnFilter1(filename)));
#ifdef SYMLINKS
if (lstat(filename, &G.statbuf) == 0 && S_ISLNK(G.statbuf.st_mode)) {
Trace((stderr, "check_for_newer: %s is a symbolic link\n",
FnFilter1(filename)));
if (QCOND2 && !IS_OVERWRT_ALL)
Info(slide, 0, ((char *)slide, LoadFarString(FileIsSymLink),
FnFilter1(filename), ""));
return EXISTS_AND_OLDER;
}
#endif
NATIVE_TO_TIMET(G.statbuf.st_mtime)
#ifdef USE_EF_UT_TIME
if (G.extra_field &&
#ifdef IZ_CHECK_TZ
G.tz_is_valid &&
#endif
(ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0,
G.lrec.last_mod_dos_datetime, &z_utime, NULL)
& EB_UT_FL_MTIME))
{
TTrace((stderr, "check_for_newer: using Unix extra field mtime\n"));
existing = G.statbuf.st_mtime;
archive = z_utime.mtime;
} else {
existing = ((G.statbuf.st_mtime & 1) &&
(G.statbuf.st_mtime + 1 > G.statbuf.st_mtime)) ?
G.statbuf.st_mtime + 1 : G.statbuf.st_mtime;
archive = dos_to_unix_time(G.lrec.last_mod_dos_datetime);
}
#else
existing = ((G.statbuf.st_mtime & 1) &&
(G.statbuf.st_mtime + 1 > G.statbuf.st_mtime)) ?
G.statbuf.st_mtime + 1 : G.statbuf.st_mtime;
archive = dos_to_unix_time(G.lrec.last_mod_dos_datetime);
#endif
TTrace((stderr, "check_for_newer: existing %lu, archive %lu, e-a %ld\n",
(ulg)existing, (ulg)archive, (long)(existing-archive)));
return (existing >= archive);
}
#endif
int do_string(__G__ length, option)
__GDEF
unsigned int length;
int option;
{
unsigned comment_bytes_left;
unsigned int block_len;
int error=PK_OK;
#ifdef AMIGA
char tmp_fnote[2 * AMIGA_FILENOTELEN];
#endif
if (!length)
return PK_COOL;
switch (option) {
#if (defined(SFX) && defined(CHEAP_SFX_AUTORUN))
case CHECK_AUTORUN:
case CHECK_AUTORUN_Q:
comment_bytes_left = length;
if (length >= 10)
{
block_len = readbuf(__G__ (char *)G.outbuf, 10);
if (block_len == 0)
return PK_EOF;
comment_bytes_left -= block_len;
G.outbuf[block_len] = '\0';
if (!strcmp((char *)G.outbuf, "$AUTORUN$>")) {
char *eol;
length -= 10;
block_len = readbuf(__G__ G.autorun_command,
MIN(length, sizeof(G.autorun_command)-1));
if (block_len == 0)
return PK_EOF;
comment_bytes_left -= block_len;
G.autorun_command[block_len] = '\0';
A_TO_N(G.autorun_command);
eol = strchr(G.autorun_command, '\n');
if (!eol)
eol = G.autorun_command + strlen(G.autorun_command) - 1;
length -= eol + 1 - G.autorun_command;
while (eol >= G.autorun_command && isspace(*eol))
*eol-- = '\0';
#ifdef WIN32
INTERN_TO_OEM(G.autorun_command, G.autorun_command);
#endif
}
}
if (option == CHECK_AUTORUN_Q)
length = 0;
seek_zipf(__G__ G.cur_zipfile_bufstart - G.extra_bytes +
(G.inptr - G.inbuf) + comment_bytes_left - length);
if (!length)
break;
#endif
case DISPLAY:
case DISPL_8:
comment_bytes_left = length;
block_len = OUTBUFSIZ;
while (comment_bytes_left > 0 && block_len > 0) {
register uch *p = G.outbuf;
register uch *q = G.outbuf;
if ((block_len = readbuf(__G__ (char *)G.outbuf,
MIN((unsigned)OUTBUFSIZ, comment_bytes_left))) == 0)
return PK_EOF;
comment_bytes_left -= block_len;
G.outbuf[block_len] = '\0';
while (*p) {
while (*p == CR)
++p;
*q++ = *p++;
}
*q = '\0';
if (option == DISPL_8) {
Ext_ASCII_TO_Native((char *)G.outbuf, G.pInfo->hostnum,
G.pInfo->hostver, G.pInfo->HasUxAtt,
FALSE);
#ifdef WINDLL
INTERN_TO_ISO((char *)G.outbuf, (char *)G.outbuf);
#else
#ifdef WIN32
INTERN_TO_OEM((char *)G.outbuf, (char *)G.outbuf);
#endif
#endif
} else {
A_TO_N(G.outbuf);
}
#ifdef WINDLL
win_fprintf((zvoid *)&G, stdout, length, (char *)G.outbuf);
win_fprintf((zvoid *)&G, stdout, 2, (char *)"\n\n");
#else
#ifdef NOANSIFILT
(*G.message)((zvoid *)&G, G.outbuf, (ulg)(q-G.outbuf), 0);
#else
p = G.outbuf - 1;
q = slide;
while (*++p) {
int pause = FALSE;
if (*p == 0x1B) {
*q++ = '^';
*q++ = '[';
} else if (*p == 0x13) {
pause = TRUE;
if (p[1] == LF)
*q++ = *++p;
else if (p[1] == CR && p[2] == LF) {
*q++ = *++p;
*q++ = *++p;
}
} else
*q++ = *p;
if ((unsigned)(q-slide) > WSIZE-3 || pause) {
(*G.message)((zvoid *)&G, slide, (ulg)(q-slide), 0);
q = slide;
if (pause && G.extract_flag)
(*G.mpause)((zvoid *)&G, LoadFarString(QuitPrompt), 0);
}
}
(*G.message)((zvoid *)&G, slide, (ulg)(q-slide), 0);
#endif
#endif
}
(*G.message)((zvoid *)&G, slide, 0L, 0x40);
break;
case DS_FN:
case DS_FN_L:
if (length >= FILNAMSIZ) {
Info(slide, 0x401, ((char *)slide,
LoadFarString(FilenameTooLongTrunc)));
error = PK_WARN;
block_len = length - (FILNAMSIZ - 1);
length = FILNAMSIZ - 1;
} else
block_len = 0;
if (readbuf(__G__ G.filename, length) == 0)
return PK_EOF;
G.filename[length] = '\0';
Ext_ASCII_TO_Native(G.filename, G.pInfo->hostnum, G.pInfo->hostver,
G.pInfo->HasUxAtt, (option == DS_FN_L));
if (G.pInfo->lcflag)
STRLOWER(G.filename, G.filename);
if (G.pInfo->vollabel && length > 8 && G.filename[8] == '.') {
char *p = G.filename+8;
while (*p++)
p[-1] = *p;
}
if (!block_len)
break;
Info(slide, 0x401, ((char *)slide, "[ %s ]\n", FnFilter1(G.filename)));
length = block_len;
case SKIP:
seek_zipf(__G__ G.cur_zipfile_bufstart - G.extra_bytes +
(G.inptr-G.inbuf) + length);
break;
case EXTRA_FIELD:
if (G.extra_field != (uch *)NULL)
free(G.extra_field);
if ((G.extra_field = (uch *)malloc(length)) == (uch *)NULL) {
Info(slide, 0x401, ((char *)slide, LoadFarString(ExtraFieldTooLong),
length));
seek_zipf(__G__ G.cur_zipfile_bufstart - G.extra_bytes +
(G.inptr-G.inbuf) + length);
} else
if (readbuf(__G__ (char *)G.extra_field, length) == 0)
return PK_EOF;
break;
#ifdef AMIGA
case FILENOTE:
if ((block_len = readbuf(__G__ tmp_fnote, (unsigned)
MIN(length, 2 * AMIGA_FILENOTELEN - 1))) == 0)
return PK_EOF;
if ((length -= block_len) > 0)
seek_zipf(__G__ G.cur_zipfile_bufstart - G.extra_bytes
+ (G.inptr - G.inbuf) + length);
tmp_fnote[block_len] = '\0';
while ((short int) --block_len >= 0)
if ((unsigned) tmp_fnote[block_len] < ' ')
if (tmp_fnote[block_len+1] == ' ')
strcpy(tmp_fnote+block_len, tmp_fnote+block_len+1);
else
tmp_fnote[block_len] = ' ';
tmp_fnote[AMIGA_FILENOTELEN - 1] = '\0';
if (G.filenotes[G.filenote_slot])
free(G.filenotes[G.filenote_slot]);
G.filenotes[G.filenote_slot] = NULL;
if (tmp_fnote[0]) {
if (!(G.filenotes[G.filenote_slot] = malloc(strlen(tmp_fnote)+1)))
return PK_MEM;
strcpy(G.filenotes[G.filenote_slot], tmp_fnote);
}
break;
#endif
}
return error;
}
ush makeword(b)
ZCONST uch *b;
{
return (ush)((b[1] << 8) | b[0]);
}
ulg makelong(sig)
ZCONST uch *sig;
{
return (((ulg)sig[3]) << 24)
+ (((ulg)sig[2]) << 16)
+ (((ulg)sig[1]) << 8)
+ ((ulg)sig[0]);
}
#if CRYPT
#ifdef NEED_STR2ISO
char *str2iso(dst, src)
char *dst;
register ZCONST char *src;
{
#ifdef INTERN_TO_ISO
INTERN_TO_ISO(src, dst);
#else
register uch c;
register char *dstp = dst;
do {
c = (uch)foreign(*src++);
*dstp++ = (char)ASCII2ISO(c);
} while (c != '\0');
#endif
return dst;
}
#endif
#ifdef NEED_STR2OEM
char *str2oem(dst, src)
char *dst;
register ZCONST char *src;
{
#ifdef INTERN_TO_OEM
INTERN_TO_OEM(src, dst);
#else
register uch c;
register char *dstp = dst;
do {
c = (uch)foreign(*src++);
*dstp++ = (char)ASCII2OEM(c);
} while (c != '\0');
#endif
return dst;
}
#endif
#endif
#ifdef ZMEM
zvoid *memset(buf, init, len)
register zvoid *buf;
register int init;
register unsigned int len;
{
zvoid *start;
start = buf;
while (len--)
*((char *)buf++) = (char)init;
return start;
}
int memcmp(b1, b2, len)
register ZCONST zvoid *b1;
register ZCONST zvoid *b2;
register unsigned int len;
{
register int c;
if (len > 0) do {
if ((c = (int)(*((ZCONST unsigned char *)b1)++) -
(int)(*((ZCONST unsigned char *)b2)++)) != 0)
return c;
} while (--len > 0)
return 0;
}
zvoid *memcpy(dst, src, len)
register zvoid *dst;
register ZCONST zvoid *src;
register unsigned int len;
{
zvoid *start;
start = dst;
while (len-- > 0)
*((char *)dst)++ = *((ZCONST char *)src)++;
return start;
}
#endif
#ifdef NO_STRNICMP
int zstrnicmp(s1, s2, n)
register ZCONST char *s1, *s2;
register unsigned n;
{
for (; n > 0; --n, ++s1, ++s2) {
if (ToLower(*s1) != ToLower(*s2))
return (ToLower(*s1) < ToLower(*s2))? -1 : 1;
if (*s1 == '\0')
return 0;
}
return 0;
}
#endif
#ifdef REGULUS
# undef stat
int zstat(p, s)
ZCONST char *p;
struct stat *s;
{
return (stat((char *)p,s) >= 0? 0 : (-1));
}
#endif
#ifdef _MBCS
char *plastchar(ptr, len)
ZCONST char *ptr;
extent len;
{
unsigned clen;
ZCONST char *oldptr = ptr;
while(*ptr != '\0' && len > 0){
oldptr = ptr;
clen = CLEN(ptr);
ptr += clen;
len -= clen;
}
return (char *)oldptr;
}
#ifdef NEED_UZMBSCHR
unsigned char *uzmbschr(str, c)
ZCONST unsigned char *str;
unsigned int c;
{
while(*str != '\0'){
if (*str == c) {return (unsigned char *)str;}
INCSTR(str);
}
return NULL;
}
#endif
#ifdef NEED_UZMBSRCHR
unsigned char *uzmbsrchr(str, c)
ZCONST unsigned char *str;
unsigned int c;
{
unsigned char *match = NULL;
while(*str != '\0'){
if (*str == c) {match = (unsigned char *)str;}
INCSTR(str);
}
return match;
}
#endif
#endif
#ifdef SMALL_MEM
char *fLoadFarString(__GPRO__ const char Far *sz)
{
(void)zfstrcpy(G.rgchBigBuffer, sz);
return G.rgchBigBuffer;
}
char *fLoadFarStringSmall(__GPRO__ const char Far *sz)
{
(void)zfstrcpy(G.rgchSmallBuffer, sz);
return G.rgchSmallBuffer;
}
char *fLoadFarStringSmall2(__GPRO__ const char Far *sz)
{
(void)zfstrcpy(G.rgchSmallBuffer2, sz);
return G.rgchSmallBuffer2;
}
#if (!defined(_MSC_VER) || (_MSC_VER < 600))
char Far * Far zfstrcpy(char Far *s1, const char Far *s2)
{
char Far *p = s1;
while ((*s1++ = *s2++) != '\0');
return p;
}
#endif
#endif