📄 amiga.c
字号:
}
created_dir = TRUE;
} else if (!S_ISDIR(statbuf.st_mode)) {
fprintf(stderr, "checkdir: %s exists but is not a directory\n\
unable to process %s.\n", buildpath, filename);
fflush(stderr);
free(buildpath);
return 3; /* path existed but wasn't dir */
}
*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); /* DO ERROR CHECKING: TOO LONG? */
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) { /* DO ERROR CHECKING */
Trace((stderr, "appending filename [%s]\n", pathcomp));
while ((*end = *pathcomp++))
++end;
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+1)) == 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, 0777) == -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);
if (rootpath[rootlen - 1] != ':')
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 cmptime() */
/**********************/
/* cmptime() clone pinched from from Zip1.9h,
* by Mark Adler, Jean-loup Gailly, et al., circa 1991.
* Incorporated into UnZip 5.1d by John Bush
*/
int cmptime(p, q)
struct tm *p, *q; /* times to compare */
/* Return negative if time p is before time q, positive if after, and
zero if the same */
{
int r; /* temporary variable */
if (p == NULL)
return -1;
else if ((r = p->tm_year - q->tm_year) != 0)
return r;
else if ((r = p->tm_mon - q->tm_mon) != 0)
return r;
else if ((r = p->tm_mday - q->tm_mday) != 0)
return r;
else if ((r = p->tm_hour - q->tm_hour) != 0)
return r;
else if ((r = p->tm_min - q->tm_min) != 0)
return r;
else
return p->tm_sec - q->tm_sec;
}
/***********************/
/* Function invlocal() */
/***********************/
/* mktime() clone pinched from from Zip1.9h,
* by Mark Adler and Jean-loup Gailly, et.al, circa 1991.
* Incorporated into UnZip 5.1d by John Bush
*/
time_t invlocal(t)
struct tm *t; /* time to convert */
/* Find inverse of localtime() using bisection. This routine assumes that
time_t is an integer type, either signed or unsigned. The expectation
is that sometime before the year 2038, time_t will be made a 64-bit
integer, and this routine will still work. */
{
time_t i; /* midpoint of current root range */
time_t l; /* lower end of root range */
time_t u; /* upper end of root range */
/* Bracket the root [0,largest time_t]. Note: if time_t is a 32-bit signed
integer, then the upper bound is GMT 1/19/2038 03:14:07, after which all
the Unix systems in the world come to a grinding halt. Either that, or
all those systems will suddenly find themselves transported to December
of 1901 ... */
l = 0;
u = 1;
while (u < (u << 1))
u = (u << 1) + 1;
/* Find the root */
while (u - l > 1)
{
i = l + ((u - l) >> 1);
if (cmptime(localtime(&i), t) <= 0)
l = i;
else
u = i;
}
return l;
}
/**************************************/
/* Function close_outfile() */
/**************************************/
/* this part differs slightly with Zip */
/*-------------------------------------*/
void close_outfile(void)
{
struct tm t; /* good ole time structure */
time_t u[2]; /* mean ole time stamp */
ulg dd,dt; /* DOS format time stamps */
LONG FileDate();
time_t invlocal();
if (cflag) /* can't set time on stdout */
return;
/* close the file *before* setting its time under AmigaDos */
fclose(outfile);
/* assign date and time to local variables */
dd = lrec.last_mod_file_date;
dt = lrec.last_mod_file_time;
/* Convert DOS time to time_t format in (time_t)u */
t.tm_sec = (int) (dt << 1) & 0x3e;
t.tm_min = (int) (dt >> 5) & 0x3f;
t.tm_hour = (int) (dt >> 11) & 0x1f;
t.tm_mday = (int) (dd & 0x1f);
t.tm_mon = ((int) (dd >> 5) & 0xf ) - 1;
t.tm_year = ((int) (dd >> 9) & 0x7f) + 80;
/* invlocal() is equivalent to mktime() */
u[0] = u[1] = invlocal(&t);
#ifdef DEBUG
fprintf (stderr,"\nclose_outfile(): u=%s\n",ctime(&u[0]));
#endif
if (!FileDate(filename, u))
fprintf(stderr, "warning: can't set the time for %s\n", filename);
/* set file perms after closing (not done at creation)--see mapattr() */
chmod(filename, pInfo->file_attr);
} /* end function close_outfile() */
/********************************************************************/
/* Load filedate as a separate external file; it's used by Zip, too.*/
/* */
#include "amiga/filedate.c" /* */
/* */
/********************************************************************/
/**************** for Aztec, do linewise with stat.c ****************/
#ifdef AZTEC_C
# include "amiga/stat.c"
/* this is the exact same stat.c used for Aztec by Zip */
# include <stdio.h>
# include "crypt.h"
void _abort(void) /* called when ^C is pressed */
{
echon();
close_leftover_open_dirs();
fflush(stdout);
fputs("\n^C\n", stderr);
exit(1);
}
#endif /* AZTEC_C */
#ifndef SFX
/************************/
/* Function version() */
/************************/
/* NOTE: the following include depends upon the environment
* variable $Workbench to be set correctly. (Set by
* default, by kickstart during startup)
*/
int WBversion = (int)
#include "ENV:Workbench"
;
void version()
{
extern char Far CompiledWith[];
/* Define buffers. */
char buf1[16]; /* compiler name */
char buf2[16]; /* revstamp */
char buf3[16]; /* OS */
char buf4[16]; /* Date */
/* char buf5[16]; /* Time */
/* format "with" name strings */
#ifdef AMIGA
# ifdef __SASC
strcpy(buf1,"SAS/C ");
# else
# ifdef LATTICE
strcpy(buf1,"Lattice C ");
# else
# ifdef AZTEC_C
strcpy(buf1,"Manx Aztec C ");
# else
strcpy(buf1,"UNKNOWN ");
# endif
# endif
# endif
/* "under" */
sprintf(buf3,"AmigaDOS v%d",WBversion);
#else
strcpy(buf1,"Unknown compiler ");
strcpy(buf3,"Unknown OS");
#endif
/* Define revision, date, and time strings.
* NOTE: Do not calculate run time, be sure to use time compiled.
* Pass these strings via your makefile if undefined.
*/
#if defined(__VERSION__) && defined(__REVISION__)
sprintf(buf2,"version %d.%d",__VERSION__,__REVISION__);
#else
# ifdef __VERSION__
sprintf(buf2,"version %d",__VERSION__);
# else
sprintf(buf2,"unknown version");
# endif
#endif
#ifdef __DATE__
sprintf(buf4," on %s",__DATE__);
#else
strcpy(buf4," unknown date");
#endif
/******
#ifdef __TIME__
sprintf(buf5," at %s",__TIME__);
#else
strcpy(buf5," unknown time");
#endif
******/
/* Print strings using "CompiledWith" mask defined in unzip.c (used by all).
* ("Compiled with %s%s under %s%s%s%s.")
*/
printf(LoadFarString(CompiledWith),
buf1,
buf2,
buf3,
buf4,
/* buf5, */ "",
"" ); /* buf6 not used */
} /* end function version() */
#endif /* !SFX */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -