📄 unzip.c
字号:
xfilespecs = 0;
if (argc > 0) {
int in_files=FALSE, in_xfiles=FALSE;
char **pp = argv-1;
process_all_files = FALSE;
pfnames = argv;
while (*++pp) {
Trace((stderr, "pp - argv = %d\n", pp-argv));
if (!dflag && strncmp(*pp, "-d", 2) == 0) {
char *q = *pp;
int firstarg = (pp == argv);
dflag = TRUE;
if (in_files) { /* ... zipfile ... -d exdir ... */
*pp = 0; /* terminate pfnames */
filespecs = pp - pfnames;
in_files = FALSE;
} else if (in_xfiles) {
*pp = 0; /* terminate pxnames */
xfilespecs = pp - pxnames;
/* "... -x xlist -d exdir": nothing left */
}
/* first check for "-dpath", then for "-d path" */
if (q[2])
q += 2;
else if (*++pp)
q = *pp;
else {
FPRINTF(stderr, LoadFarString(MustGiveExdir));
RETURN(PK_PARAM); /* don't extract here by accident */
}
if (extract_flag) {
create_dirs = !fflag;
if ((error = checkdir(q, ROOT)) > 2)
RETURN(error); /* out of memory, or file in way */
} else
FPRINTF(stderr, LoadFarString(NotExtracting));
if (firstarg) /* ... zipfile -d exdir ... */
if (pp[1]) {
pfnames = pp + 1; /* argv+2 */
filespecs = argc - (pfnames-argv); /* for now... */
} else {
process_all_files = TRUE;
pfnames = fnames; /* GRR: necessary? */
filespecs = 0; /* GRR: necessary? */
break;
}
} else if (!in_xfiles) {
if (strcmp(*pp, "-x") == 0) {
in_xfiles = TRUE;
if (pp == argv || (pp == argv+2 && dflag)) {
pfnames = fnames; /* defaults */
filespecs = 0;
} else if (in_files) {
*pp = 0; /* terminate pfnames */
filespecs = pp - pfnames; /* adjust count */
in_files = FALSE;
}
pxnames = pp + 1; /* excluded-names ptr starts after -x */
xfilespecs = argc - (pxnames-argv); /* anything left... */
} else
in_files = TRUE;
}
}
} else
process_all_files = TRUE; /* for speed */
#endif /* ?(OLD_EXDIR || (SFX && !SFX_EXDIR)) */
/*---------------------------------------------------------------------------
Okey dokey, we have everything we need to get started. Let's roll.
---------------------------------------------------------------------------*/
inbuf = (uch *)malloc(INBUFSIZ + 4); /* 4 extra for hold[] (below) */
outbuf = (uch *)malloc(OUTBUFSIZ + 1); /* 1 extra for string termin. */
if ((inbuf == (uch *)NULL) || (outbuf == (uch *)NULL)) {
FPRINTF(stderr, LoadFarString(CantAllocateBuffers));
RETURN(PK_MEM);
}
hold = inbuf + INBUFSIZ; /* to check for boundary-spanning signatures */
#ifdef SMALL_MEM
outbuf2 = outbuf+RAWBUFSIZ; /* never changes */
#endif
RETURN(process_zipfiles()); /* keep passing errors back... */
} /* end main() */
/**********************/
/* Function uz_opts() */
/**********************/
int uz_opts(pargc, pargv)
int *pargc;
char ***pargv;
{
char **argv, *s;
int argc, c, error=FALSE, negative=0;
argc = *pargc;
argv = *pargv;
while (--argc > 0 && (*++argv)[0] == '-') {
s = argv[0] + 1;
while ((c = *s++) != 0) { /* "!= 0": prevent Turbo C warning */
switch (c) {
case ('-'):
++negative;
break;
case ('a'):
if (negative) {
aflag = MAX(aflag-negative,0);
negative = 0;
} else
++aflag;
break;
case ('b'):
if (negative)
negative = 0; /* do nothing: "-b" is default */
else
aflag = 0;
break;
case ('c'):
if (negative) {
cflag = FALSE, negative = 0;
#ifdef NATIVE
aflag = 0;
#endif
} else {
cflag = TRUE;
#ifdef NATIVE
aflag = 2; /* so you can read it on the screen */
#endif
}
break;
case ('C'): /* -C: match filenames case-insensitively */
if (negative)
C_flag = FALSE, negative = 0;
else
C_flag = TRUE;
break;
case ('d'): /* arg after zipfn is stored dir, not extract-to */
#ifdef OLD_EXDIR
if (negative)
dflag = FALSE, negative = 0;
else
dflag = TRUE;
#endif
break;
case ('e'): /* just ignore -e, -x options (extract) */
break;
case ('f'): /* "freshen" (extract only newer files) */
if (negative)
fflag = uflag = FALSE, negative = 0;
else
fflag = uflag = TRUE;
break;
case ('j'): /* junk pathnames/directory structure */
if (negative)
jflag = FALSE, negative = 0;
else
jflag = TRUE;
break;
#ifndef SFX
case ('l'):
if (negative) {
vflag = MAX(vflag-negative,0);
negative = 0;
} else
++vflag;
break;
#endif /* !SFX */
case ('L'): /* convert (some) filenames to lowercase */
if (negative)
L_flag = FALSE, negative = 0;
else
L_flag = TRUE;
break;
case ('n'): /* don't overwrite any files */
if (negative)
overwrite_none = FALSE, negative = 0;
else
overwrite_none = TRUE;
break;
case ('o'): /* OK to overwrite files without prompting */
if (negative) {
overwrite_all = MAX(overwrite_all-negative,0);
force_flag = MAX(force_flag-negative,0);
negative = 0;
} else {
++overwrite_all;
++force_flag; /* (share -o for now) force to cont. */
}
break;
case ('p'): /* pipes: extract to stdout, no messages */
if (negative) {
cflag = FALSE;
qflag = MAX(qflag-999,0);
negative = 0;
} else {
cflag = TRUE;
qflag += 999;
}
break;
case ('q'): /* quiet: fewer comments/messages */
if (negative) {
qflag = MAX(qflag-negative,0);
negative = 0;
} else
++qflag;
break;
#ifdef DOS_NT_OS2
case ('s'): /* spaces in filenames: allow by default */
if (negative)
sflag = FALSE, negative = 0;
else
sflag = TRUE;
break;
#endif
case ('t'):
if (negative)
tflag = FALSE, negative = 0;
else
tflag = TRUE;
break;
case ('u'): /* update (extract only new and newer files) */
if (negative)
uflag = FALSE, negative = 0;
else
uflag = TRUE;
break;
case ('U'): /* obsolete; to be removed in future release */
if (negative)
L_flag = TRUE, negative = 0;
else
L_flag = FALSE;
break;
#ifndef SFX
case ('v'): /* verbose */
if (negative) {
vflag = MAX(vflag-negative,0);
negative = 0;
} else if (vflag)
++vflag;
else
vflag = 2;
break;
#endif /* !SFX */
case ('V'): /* Version (retain VMS/DEC-20 file versions) */
if (negative)
V_flag = FALSE, negative = 0;
else
V_flag = TRUE;
break;
case ('x'): /* extract: default */
break;
#ifdef VMS
case ('X'): /* restore owner/protection info (need privs?) */
if (negative)
secinf = FALSE, negative = 0;
else
secinf = TRUE;
break;
#endif /* VMS */
case ('z'): /* display only the archive comment */
if (negative) {
zflag -= negative;
negative = 0;
} else
++zflag;
break;
#ifdef DOS_NT_OS2
case ('$'):
if (negative) {
volflag = MAX(volflag-negative,0);
negative = 0;
} else
++volflag;
break;
#endif /* DOS_NT_OS2 */
default:
error = TRUE;
break;
} /* end switch */
} /* end while (not end of argument string) */
} /* end while (not done with switches) */
/*---------------------------------------------------------------------------
Check for nonsensical combinations of options.
---------------------------------------------------------------------------*/
if ((cflag && tflag) || (cflag && uflag) || (tflag && uflag) ||
(fflag && overwrite_none)) {
FPRINTF(stderr, LoadFarString(InvalidOptionsMsg));
error = TRUE;
}
if (aflag > 2)
aflag = 2;
if (overwrite_all && overwrite_none) {
FPRINTF(stderr, LoadFarString(IgnoreOOptionMsg));
overwrite_all = FALSE;
}
#ifdef SFX
if (error)
#else
if ((argc-- == 0) || error)
#endif
{
*pargc = argc;
*pargv = argv;
#ifndef SFX
if (vflag >= 2 && argc == -1) {
if (qflag > 3)
PRINTF("%d\n", (UZ_MAJORVER*100 + UZ_MINORVER*10 + PATCHLEVEL));
else {
char *envptr, *getenv();
int numopts = 0;
PRINTF(LoadFarString(UnzipUsageLine1),
LoadFarStringSmall(UnzipVersion));
PRINTF(LoadFarString(UnzipUsageLine2a));
version();
PRINTF(LoadFarString(CompileOptions));
#ifdef NO_ZIPINFO
PRINTF(LoadFarString(CompileOptFormat),
LoadFarStringSmall(No_ZipInfo));
++numopts;
#endif
#ifdef CHECK_EOF
PRINTF(LoadFarString(CompileOptFormat),
LoadFarStringSmall(Check_EOF));
++numopts;
#endif
#ifdef DOSWILD
PRINTF(LoadFarString(CompileOptFormat),
LoadFarStringSmall(DosWild));
++numopts;
#endif
#ifdef VMSWILD
PRINTF(LoadFarString(CompileOptFormat),
LoadFarStringSmall(VmsWild));
++numopts;
#endif
#ifdef VMSCLI
PRINTF(LoadFarString(CompileOptFormat),
LoadFarStringSmall(VmsCLI));
++numopts;
#endif
#ifdef ASM_INFLATECODES
PRINTF(LoadFarString(CompileOptFormat),
LoadFarStringSmall(AsmInflateCodes));
++numopts;
#endif
#ifdef ASM_CRC
PRINTF(LoadFarString(CompileOptFormat),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -