home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 9
/
FreshFishVol9-CD2.bin
/
bbs
/
util
/
zoo-2.1.lha
/
zoo
/
amiga.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-02
|
16KB
|
732 lines
#ifndef LINT
static char amigaid[] = "@(#) amiga.c 1.1 91/08/03 23:21:00";
#endif /* LINT */
/*
* machine.c for Amiga.
*
* This file is (C) Copyright 1991 by Olaf Seibert. All rights reserved. May
* be used and distributed under the same conditions as the other
* non-public-domain files that are part of Zoo.
*/
#undef TEXT /* typedef in exec/types.h */
#include <assert.h>
#include <exec/types.h>
#include <libraries/dos.h>
#include <signal.h>
#ifdef __STDC__
#define __args
#include <functions.h>
#else
BPTR Lock(), CreateDir(), ParentDir();
long Examine(), ExNext();
void *AllocMem();
struct MsgPort *DeviceProc();
long SetSignal();
#endif
int iswild PARMS((char *));
void endfile PARMS((int));
void fcbpath PARMS((char *, char *));
void ToDateStamp PARMS((struct DateStamp * datestamp, unsigned date, unsigned time));
void ToMSDate PARMS((unsigned *date, unsigned *time, struct DateStamp * datestamp));
void _abort PARMS((void));
long Chk_Abort PARMS((void));
/*
* WARNING: This file assumes that ZOOFILE is a standard buffered file.
* It will have to be modified if ZOOFILE is changed to be an unbuffered
* file descriptor or to any other kind of file.
*/
#ifdef UNBUF_IO
/*
* Function tell() returns the current seek position for a file
* descriptor. 4.3BSD on VAX-11/785 has an undocumented tell() function
* but it may not exist on all implementations, so we code one here to be
* on the safe side. It is needed for unbuffered I/O only.
*/
long lseek PARMS((int, long, int));
long
tell(fd)
int fd;
{
return lseek(fd, 0L, 1);
}
#endif
/*
* Function zootrunc() truncates a file.
*/
int
zootrunc(f)
ZOOFILE f;
{
fflush(f); /* just in case it matters */
/* Cannot truncate on AmigaOS < 2.0 */
}
/*
* Function fixfname() converts the supplied filename to a syntax legal
* for the host system. It is used during extraction.
*/
char *
fixfname(fname)
char *fname;
{
return fname; /* default is no-op */
}
/*
* Function isuadir() returns 1 if the supplied name is a directory, else
* it returns 0.
*/
int
isuadir(path)
char *path;
{
struct FileInfoBlock *fib;
int its_a_dir;
its_a_dir = 0;
if (fib = malloc(sizeof (*fib))) {
BPTR lock;
if (lock = Lock(path, ACCESS_READ)) {
Examine(lock, fib);
its_a_dir = (fib->fib_DirEntryType > 0);
UnLock(lock);
}
free(fib);
}
return its_a_dir;
}
/* No standard UNIX-compatible time routines */
/*
* Function getutime() gets the date and time of the file name supplied.
* Date and time is in MSDOS format.
*/
int
getutime(path, date, time)
char *path;
unsigned *date,
*time;
{
struct FileInfoBlock *fib;
*date = 0;
*time = 0;
if (fib = malloc(sizeof (*fib))) {
BPTR lock;
if (lock = Lock(path, ACCESS_READ)) {
Examine(lock, fib);
ToMSDate(date, time, &fib->fib_Date);
UnLock(lock);
}
free(fib);
}
return 0;
}
/*
* Function setutime() sets the date and time of the filename supplied.
* Date and time is in MSDOS format.
*/
int
setutime(path, date, time)
char *path;
unsigned int date,
time;
{
struct DateStamp DateStamp;
extern int SetFileDate PARMS((char *file, struct DateStamp * date));
ToDateStamp(&DateStamp, date, time);
return !SetFileDate(path, &DateStamp);
}
#ifdef AZTEC_C
# ifndef EXEC_MEMORY_H
# include <exec/memory.h>
# endif
# ifndef ACTION_SET_DATE
# define ACTION_SET_DATE 34L
# endif
int
SetFileDate(path, date)
char *path;
struct DateStamp *date;
{
struct MsgPort *task;
BPTR lock,
plock;
UBYTE *bcplstring;
int result;
if (!(bcplstring = (UBYTE *) AllocMem(64L, (long) MEMF_PUBLIC)))
return 0;
result = 0;
if (!(task = DeviceProc(path))) {
goto abort;
}
if (!(lock = Lock(path, SHARED_LOCK))) {
goto abort;
}
plock = ParentDir(lock);
UnLock(lock);
/* Strip pathnames first */
strcpy((char *) (bcplstring + 1), nameptr(path));
*bcplstring = strlen((char *) (bcplstring + 1));
result = dos_packet(task, ACTION_SET_DATE, NULL, plock,
(ULONG) bcplstring >> 2, (ULONG) date, 0L, 0L, 0L);
UnLock(plock);
abort:
FreeMem((void *) bcplstring, 64L);
return result;
}
#endif
/* No standard UNIX-specific file attribute routines */
/*
* Get file attributes. Currently only the lowest nine of the *IX mode
* bits are used. Also we return bit 23=0 and bit 22=1, which means use
* portable attribute format, and use attribute value instead of using
* default at extraction time.
*/
unsigned long
getfattr(f)
ZOOFILE f;
{
return NO_FATTR; /* inaccessible -- no attributes */
}
/*
* Set file attributes. Only the lowest nine bits are used.
*/
int
setfattr(f, a)
char *f; /* filename */
unsigned long a; /* atributes to set */
{
return 0; /* cannot do */
}
int
iswild(name)
char *name;
{
return (strchr(name, '*') != NULL) || (strchr(name, '?') != NULL);
}
#define FMAX 3 /* Number of different filename patterns */
/* #include "various.h" */
/* #include "zoo.h" *//* solely to define PATHSIZE */
#ifdef SPECNEXT
/*-
nextfile() returns the name of the next source file matching a filespec.
INPUT
what: A flag specifying what to do. If "what" is 0, nextfile()
initializes itself. If "what" is 1, nextfile() returns the next
matching filename.
filespec: The filespec, usually containing wildcard characters, that
specifies which files are needed. If "what" is 0, filespec must be
the filespec for which matching filenames are needed. If "what" is 1,
nextfile() does not use "filespec" and "filespec" should be NULL to
avoid an assertion error during debugging.
fileset: nextfile() can keep track of more than one set of filespecs.
The fileset specifies which filespec is being matched and therefore
which set of files is being considered. "fileset" can be in the
range 0:FMAX. Initialization of one fileset does not affect the
other filesets.
OUTPUT
IF what == 0 THEN
return value is NULL
ELSE IF what == 1 THEN
IF a matching filename is found THEN
return value is pointer to matching filename including supplied path
ELSE
IF at least one file matched previously but no more match THEN
return value is NULL
ELSE IF supplied filespec never matched any filename THEN
IF this is the first call with what == 1 THEN
return value is pointer to original filespec
ELSE
return value is NULL
END IF
END IF
END IF
END IF
NOTE
Initialization done when "what"=0 is not dependent on the correctness
of the supplied filespec but simply initializes internal variables
and makes a local copy of the supplied filespec. If the supplied
filespec was illegal, the only effect is that the first time that
nextfile() is called with "what"=1, it will return the original
filespec instead of a matching filename. That the filespec was
illegal will become obvious when the caller attempts to open the
returned filename for input/output and the open attempt fails.
USAGE HINTS
nextfile() can be used in the following manner:
char *filespec; -- will point to filespec
char *this_file; -- will point to matching filename
filespec = parse_command_line(); -- may contain wildcards
FILE *stream;
nextfile (0, filespec, 0); -- initialize fileset 0
while ((this_file = nextfile(1, (char *) NULL, 0)) != NULL) {
stream = fopen (this_file, "whatever");
if (stream == NULL)
printf ("could not open %s\n", this_file);
else
perform_operations (stream);
}
*/
static int first_time[FMAX + 1];
static BPTR filelock[FMAX + 1];
static struct FileInfoBlock *fib[FMAX + 1];
char *
nextfile(what, filespec, fileset)
int what; /* whether to initialize or match */
register char *filespec; /* filespec to match if initializing */
register int fileset; /* which set of files */
{
static char pathholder[FMAX + 1][PATHSIZE]; /* holds a pathname to
* return */