📄 nt.c
字号:
rootpath[rootlen] = '\0';
}
Trace((stderr, "rootpath now = [%s]\n", rootpath));
return 0;
}
#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);
return 0;
}
return 99; /* should never reach */
} /* end function checkdir() */
#ifndef SFX
/************************/
/* Function do_wild() */ /* identical to OS/2 version */
/************************/
char *do_wild(wildspec)
char *wildspec; /* only used first time on a given dir */
{
static struct direct *dir = NULL;
static char *dirname, *wildname, matchname[FILNAMSIZ];
static int firstcall=TRUE, have_dirname, dirnamelen;
struct direct *file;
/* Even when we're just returning wildspec, we *always* do so in
* matchname[]--calling routine is allowed to append four characters
* to the returned string, and wildspec may be a pointer to argv[].
*/
if (firstcall) { /* first call: must initialize everything */
firstcall = FALSE;
/* break the wildspec into a directory part and a wildcard filename */
if ((wildname = strrchr(wildspec, '/')) == NULL &&
(wildname = strrchr(wildspec, ':')) == NULL) {
dirname = ".";
dirnamelen = 1;
have_dirname = FALSE;
wildname = wildspec;
} else {
++wildname; /* point at character after '/' or ':' */
dirnamelen = wildname - wildspec;
if ((dirname = (char *)malloc(dirnamelen+1)) == NULL) {
FPRINTF(stderr, "warning: can't allocate wildcard buffers\n");
strcpy(matchname, wildspec);
return matchname; /* but maybe filespec was not a wildcard */
}
strncpy(dirname, wildspec, dirnamelen);
dirname[dirnamelen] = '\0'; /* terminate for strcpy below */
have_dirname = TRUE;
}
Trace((stderr, "do_wild: dirname = [%s]\n", dirname));
if ((dir = opendir(dirname)) != NULL) {
while ((file = readdir(dir)) != NULL) {
Trace((stderr, "do_wild: readdir returns %s\n", file->d_name));
if (match(file->d_name, wildname, 1)) { /* 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(dir);
dir = NULL;
}
Trace((stderr, "do_wild: opendir(%s) returns NULL\n", dirname));
/* return the raw wildspec in case that works (e.g., directory not
* searchable, but filespec was not wild and file is readable) */
strcpy(matchname, wildspec);
return matchname;
}
/* last time through, might have failed opendir but returned raw wildspec */
if (dir == NULL) {
firstcall = TRUE; /* 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(dir)) != NULL)
if (match(file->d_name, wildname, 1)) { /* 1 == ignore case */
if (have_dirname) {
/* strcpy(matchname, dirname); */
strcpy(matchname+dirnamelen, file->d_name);
} else
strcpy(matchname, file->d_name);
return matchname;
}
closedir(dir); /* have read at least one dir entry; nothing left */
dir = NULL;
firstcall = TRUE; /* reset for new wildspec */
if (have_dirname)
free(dirname);
return (char *)NULL;
} /* end function do_wild() */
#endif /* !SFX */
/************************/
/* Function mapname() */
/************************/
/*
* There are presently two possibilities in OS/2: the output filesystem is
* FAT, or it is HPFS. If the former, we need to map to FAT, obviously, but
* we *also* must map to HPFS and store that version of the name in extended
* attributes. Either way, we need to map to HPFS, so the main mapname
* routine does that. In the case that the output file system is FAT, an
* extra filename-mapping routine is called in checkdir(). While it should
* be possible to determine the filesystem immediately upon entry to mapname(),
* it is conceivable that the DOS APPEND utility could be added to OS/2 some-
* day, allowing a FAT directory to be APPENDed to an HPFS drive/path. There-
* fore we simply check the filesystem at each path component.
*
* Note that when alternative IFS's become available/popular, everything will
* become immensely more complicated. For example, a Minix filesystem would
* have limited filename lengths like FAT but no extended attributes in which
* to store the longer versions of the names. A BSD Unix filesystem would
* support paths of length 1024 bytes or more, but it is not clear that FAT
* EAs would allow such long .LONGNAME fields or that OS/2 would properly
* restore such fields when moving files from FAT to the new filesystem.
*
* GRR: some or all of the following chars should be checked in either
* mapname (HPFS) or map2fat (FAT), depending: ,=^+'"[]<>|\t&
*/
int mapname(renamed) /* return 0 if no error, 1 if caution (filename trunc), */
int renamed; /* 2 if warning (skip file because dir doesn't exist), */
{ /* 3 if error (skip file), 10 if no memory (skip file), */
/* IZ_VOL_LABEL if can't do vol label, IZ_CREATED_DIR */
char pathcomp[FILNAMSIZ]; /* path-component buffer */
char *pp, *cp=NULL; /* character pointers */
char *lastsemi = NULL; /* pointer to last semi-colon in pathcomp */
int quote = FALSE; /* flag: next char is literal */
int error = 0;
register unsigned workch; /* hold the character being tested */
/*---------------------------------------------------------------------------
Initialize various pointers and counters and stuff.
---------------------------------------------------------------------------*/
/* can create path as long as not just freshening, or if user told us */
create_dirs = (!fflag || renamed);
created_dir = FALSE; /* not yet */
renamed_fullpath = FALSE;
fnlen = strlen(filename);
if (renamed) {
cp = filename - 1; /* point to beginning of renamed name... */
while (*++cp)
if (*cp == '\\') /* convert backslashes to forward */
*cp = '/';
cp = filename;
/* use temporary rootpath if user gave full pathname */
if (filename[0] == '/') {
renamed_fullpath = TRUE;
pathcomp[0] = '/'; /* copy the '/' and terminate */
pathcomp[1] = '\0';
++cp;
} else if (isalpha(filename[0]) && filename[1] == ':') {
renamed_fullpath = TRUE;
pp = pathcomp;
*pp++ = *cp++; /* copy the "d:" (+ '/', possibly) */
*pp++ = *cp++;
if (*cp == '/')
*pp++ = *cp++; /* otherwise add "./"? */
*pp = '\0';
}
}
/* pathcomp is ignored unless renamed_fullpath is TRUE: */
if ((error = checkdir(pathcomp, INIT)) != 0) /* initialize path buffer */
return error; /* ...unless no mem or vol label on hard disk */
*pathcomp = '\0'; /* initialize translation buffer */
pp = pathcomp; /* point to translation buffer */
if (!renamed) { /* cp already set if renamed */
if (jflag) /* junking directories */
cp = (char *)strrchr(filename, '/');
if (cp == NULL) /* no '/' or not junking dirs */
cp = 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) {
if (quote) { /* if character quoted, */
*pp++ = (char)workch; /* include it literally */
quote = FALSE;
} else
switch (workch) {
case '/': /* can assume -j flag not given */
*pp = '\0';
if ((error = checkdir(pathcomp, APPEND_DIR)) > 1)
return error;
pp = pathcomp; /* reset conversion buffer for next piece */
lastsemi = NULL; /* leave directory semi-colons alone */
break;
case ':':
*pp++ = '_'; /* drive names not stored in zipfile, */
break; /* so no colons allowed */
case ';': /* start of VMS version? */
lastsemi = pp; /* remove VMS version later... */
*pp++ = ';'; /* but keep semicolon for now */
break;
case '\026': /* control-V quote for special chars */
quote = TRUE; /* set flag for next character */
break;
case ' ': /* keep spaces unless specifically */
/* NT cannot create filenames with spaces on FAT volumes */
if (sflag || IsVolumeOldFAT(filename))
*pp++ = '_';
else
*pp++ = ' ';
break;
default:
/* allow European characters in filenames: */
if (isprint(workch) || (128 <= workch && workch <= 254))
*pp++ = (char)workch;
} /* end switch */
} /* end while loop */
*pp = '\0'; /* done with pathcomp: terminate it */
/* if not saving them, remove VMS version numbers (appended "###") */
if (!V_flag && lastsemi) {
pp = lastsemi + 1; /* semi-colon was kept: expect #'s after */
while (isdigit((uch)(*pp)))
++pp;
if (*pp == '\0') /* only digits between ';' and end: nuke */
*lastsemi = '\0';
}
/*---------------------------------------------------------------------------
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 (filename[fnlen-1] == '/') {
checkdir(filename, GETPATH);
if (created_dir && QCOND2) {
/* GRR: trailing '/'? need to strip or not? */
FPRINTF(stdout, " creating: %-22s\n", filename);
/* HG: are we setting the date&time on a newly created dir? */
/* Not quite sure how to do this. It does not seem to */
/* be done in the MS-DOS version of mapname(). */
return IZ_CREATED_DIR; /* dir time already set */
}
return 2; /* dir existed already; don't look for data to extract */
}
if (*pathcomp == '\0') {
FPRINTF(stderr, "mapname: conversion of %s failed\n", filename);
return 3;
}
checkdir(pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */
checkdir(filename, GETPATH);
Trace((stderr, "mapname returns with filename = [%s] (error = %d)\n\n",
filename, error));
if (pInfo->vollabel) { /* set the volume label now */
char drive[3];
/* Build a drive string, e.g. "b:" */
drive[0] = 'a' + nLabelDrive - 1;
drive[1] = ':';
drive[2] = '\0';
if (QCOND2)
FPRINTF(stdout, "labelling %s %-22s\n", drive, filename);
if (!SetVolumeLabel(drive, filename)) {
FPRINTF(stderr, "mapname: error setting volume label\n");
return 3;
}
return 2; /* success: skip the "extraction" quietly */
}
return error;
} /* end function mapname() */
#ifndef SFX
/************************/
/* Function version() */
/************************/
void version()
{
extern char Far CompiledWith[];
#if defined(_MSC_VER)
char buf[80];
#endif
PRINTF(LoadFarString(CompiledWith),
#ifdef _MSC_VER /* MSC == VC++, but what about SDK compiler? */
(sprintf(buf, "Microsoft C %d.%02d ", _MSC_VER/100, _MSC_VER%100), buf),
# if (_MSC_VER >= 800)
"(Visual C++)",
# else
"(bad version)",
# endif
#else
"unknown compiler (SDK?)", "",
#endif
"Windows NT", " (32-bit)",
#ifdef __DATE__
" on ", __DATE__
#else
"", ""
#endif
);
return;
} /* end function version() */
#endif /* !SFX */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -