📄 mac.c
字号:
unable to process %s.\n", buildpath, filename);
fflush(stderr);
free(buildpath);
return 3; /* path didn't exist, tried to create, failed */
}
created_dir = TRUE;
} else if (!S_ISDIR(statbuf.st_mode)) {
fprintf(stderr, "checkdir error: %s exists but is not directory\n\
unable to process %s.\n", buildpath, filename);
fflush(stderr);
free(buildpath);
return 3; /* path existed but wasn't dir */
}
if (too_long) {
fprintf(stderr, "checkdir error: path too long: %s\n", buildpath);
fflush(stderr);
free(buildpath);
return 4; /* no room for filenames: fatal */
}
*end++ = ':';
*end = '\0';
Trace((stderr, "buildpath now = [%s]\n", buildpath));
return 0;
} /* 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", pathcomp));
free(buildpath);
buildpath = end = NULL;
return 0;
}
/*---------------------------------------------------------------------------
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", 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';
fprintf(stderr, "checkdir warning: path too long; truncating\n\
checkdir warning: path too long; truncating\n\
%s\n -> %s\n", filename, buildpath);
fflush(stderr);
return 1; /* filename truncated */
}
}
Trace((stderr, "buildpath now = [%s]\n", buildpath));
return 0; /* could check for existence here, prompt for new name... */
}
/*---------------------------------------------------------------------------
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.
---------------------------------------------------------------------------*/
if (FUNCTION == INIT) {
Trace((stderr, "initializing buildpath to "));
if ((buildpath = (char *)malloc(strlen(filename)+rootlen+2)) == NULL)
return 10;
if ((rootlen > 0) && !renamed_fullpath) {
strcpy(buildpath, rootpath);
end = buildpath + rootlen;
} else {
*buildpath = '\0';
end = buildpath;
}
Trace((stderr, "[%s]\n", buildpath));
return 0;
}
/*---------------------------------------------------------------------------
ROOT: if appropriate, store the path in rootpath and create it if neces-
sary; 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) {
Trace((stderr, "initializing root path to [%s]\n", pathcomp));
if (pathcomp == NULL) {
rootlen = 0;
return 0;
}
if ((rootlen = strlen(pathcomp)) > 0) {
int had_trailing_pathsep=FALSE;
if (pathcomp[rootlen-1] == ':') {
pathcomp[--rootlen] = '\0';
had_trailing_pathsep = TRUE;
}
if (rootlen > 0 && (stat(pathcomp, &statbuf) ||
!S_ISDIR(statbuf.st_mode))) /* path does not exist */
{
if (!create_dirs /* || iswild(pathcomp) */
#ifdef OLD_EXDIR
|| !had_trailing_pathsep
#endif
) {
rootlen = 0;
return 2; /* treat as stored file */
}
/* create the directory (could add loop here to scan pathcomp
* and create more than one level, but why really necessary?) */
if (MKDIR(pathcomp) == -1) {
fprintf(stderr,
"checkdir: can't create extraction directory: %s\n",
pathcomp);
fflush(stderr);
rootlen = 0; /* path didn't exist, tried to create, and */
return 3; /* failed: file exists, or 2+ levels required */
}
}
if ((rootpath = (char *)malloc(rootlen+2)) == NULL) {
rootlen = 0;
return 10;
}
strcpy(rootpath, pathcomp);
rootpath[rootlen++] = ':';
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() */
/****************************/
/* Function close_outfile() */
/****************************/
void close_outfile()
{
long m_time;
DateTimeRec dtr;
ParamBlockRec pbr;
HParamBlockRec hpbr;
OSErr err;
if (fileno(outfile) == 1) /* don't attempt to close or set time on stdout */
return;
fclose(outfile);
/*
* Macintosh bases all file modification times on the number of seconds
* elapsed since Jan 1, 1904, 00:00:00. Therefore, to maintain
* compatibility with MS-DOS archives, which date from Jan 1, 1980,
* with NO relation to GMT, the following conversions must be made:
* the Year (yr) must be incremented by 1980;
* and converted to seconds using the Mac routine Date2Secs(),
* almost similar in complexity to the Unix version :-)
* J. Lee
*/
dtr.year = (((lrec.last_mod_file_date >> 9) & 0x7f) + 1980);
dtr.month = ((lrec.last_mod_file_date >> 5) & 0x0f);
dtr.day = (lrec.last_mod_file_date & 0x1f);
dtr.hour = ((lrec.last_mod_file_time >> 11) & 0x1f);
dtr.minute = ((lrec.last_mod_file_time >> 5) & 0x3f);
dtr.second = ((lrec.last_mod_file_time & 0x1f) * 2);
Date2Secs(&dtr, (unsigned long *)&m_time);
c2pstr(filename);
if (HFSFlag) {
hpbr.fileParam.ioNamePtr = (StringPtr)filename;
hpbr.fileParam.ioVRefNum = gnVRefNum;
hpbr.fileParam.ioDirID = glDirID;
hpbr.fileParam.ioFDirIndex = 0;
err = PBHGetFInfo(&hpbr, 0L);
hpbr.fileParam.ioFlMdDat = m_time;
if ( !fMacZipped )
hpbr.fileParam.ioFlCrDat = m_time;
hpbr.fileParam.ioDirID = glDirID;
if (err == noErr)
err = PBHSetFInfo(&hpbr, 0L);
if (err != noErr)
printf("error: can't set the time for %s\n", filename);
} else {
pbr.fileParam.ioNamePtr = (StringPtr)filename;
pbr.fileParam.ioVRefNum = pbr.fileParam.ioFVersNum =
pbr.fileParam.ioFDirIndex = 0;
err = PBGetFInfo(&pbr, 0L);
pbr.fileParam.ioFlMdDat = pbr.fileParam.ioFlCrDat = m_time;
if (err == noErr)
err = PBSetFInfo(&pbr, 0L);
if (err != noErr)
printf("error: can't set the time for %s\n", filename);
}
/* set read-only perms if needed */
if ((err == noErr) && pInfo->read_only) {
if (HFSFlag) {
hpbr.fileParam.ioNamePtr = (StringPtr)filename;
hpbr.fileParam.ioVRefNum = gnVRefNum;
hpbr.fileParam.ioDirID = glDirID;
err = PBHSetFLock(&hpbr, 0);
} else
err = SetFLock((ConstStr255Param)filename, 0);
}
p2cstr(filename);
} /* end function close_outfile() */
#ifndef SFX
/************************/
/* Function version() */
/************************/
void version()
{
extern char Far CompiledWith[];
#if 0
char buf[40];
#endif
printf(LoadFarString(CompiledWith),
#ifdef __GNUC__
"gcc ", __VERSION__,
#else
# if 0
"cc ", (sprintf(buf, " version %d", _RELEASE), buf),
# else
# ifdef THINK_C
"Think C", "",
# else
# ifdef MPW
"MPW C", "",
# else
"unknown compiler", "",
# endif
# endif
# endif
#endif
"MacOS",
#if defined(foobar) || defined(FOOBAR)
" (Foo BAR)", /* hardware or OS version */
#else
"",
#endif /* Foo BAR */
#ifdef __DATE__
" on ", __DATE__
#else
"", ""
#endif
);
} /* end function version() */
#endif /* !SFX */
/************************/
/* Function IsHFSDisk() */
/************************/
static int IsHFSDisk(short wRefNum)
{
/* get info about the specified volume */
if (HFSFlag == true) {
HParamBlockRec hpbr;
Str255 temp;
short wErr;
hpbr.volumeParam.ioCompletion = 0;
hpbr.volumeParam.ioNamePtr = temp;
hpbr.volumeParam.ioVRefNum = wRefNum;
hpbr.volumeParam.ioVolIndex = 0;
wErr = PBHGetVInfo(&hpbr, 0);
if (wErr == noErr && hpbr.volumeParam.ioVFSID == 0
&& hpbr.volumeParam.ioVSigWord == 0x4244) {
return true;
}
}
return false;
} /* IsHFSDisk */
/************************/
/* Function MacFSTest() */
/************************/
void MacFSTest(int vRefNum)
{
Str255 st;
/* is this machine running HFS file system? */
if (FSFCBLen <= 0) {
HFSFlag = false;
}
else
{
HFSFlag = true;
}
/* get the file's volume reference number and directory ID */
if (HFSFlag == true) {
WDPBRec wdpb;
OSErr err = noErr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -