home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 10
/
aminetcdnumber101996.iso
/
Aminet
/
util
/
misc
/
chunker.lha
/
Chunker
/
source
/
machine.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-11-10
|
4KB
|
194 lines
/*************************************************************************
*
* Chunker/DeChunk
*
* Copyright ©1995 Lee Kindness and Evan Tuer
* cs2lk@scms.rgu.ac.uk
*
* machine.c
* Initilisation code plus any other machine dependant code.
*/
#include "machine.h"
#ifdef AMIGA
/*************************************************************************
* msprintf() - Equivalent to sprintf(). Implemented using the exec RawDoFmt
* command. Note that "\x16\xC0\x4E\x75" represents:
*
* move.b d0,(a3)+
* rts
*/
void msprintf(char *buffer, char *format, ...)
{
RawDoFmt(format, (APTR)(&format+1), (void (*))"\x16\xC0\x4E\x75", buffer);
}
#endif /* AMIGA */
/*************************************************************************
* InitSystem() - Called from main() to initilise and check any system
* options or dependancies.
*/
int InitSystem( void )
{
#ifdef AMIGA
if( (((struct Library *)DOSBase)->lib_Version >= 36) &&
(((struct Library *)SysBase)->lib_Version >= 36) )
return( 1 );
else
return( 0 );
#else
return( 1 );
#endif
}
/*************************************************************************
* FreeSystem() - Called from main() to delalocate anything allocated
* by InitSystem.
*/
void FreeSystem( void )
{
}
/*************************************************************************
* GetChunkerArgs() - Parse command line arguments for Chunker
*/
#define ARG_CSOURCE argv[1]
#define ARG_CDEST argv[2]
#define ARG_CSIZE argv[3]
#define NUM_CARGS 4
struct Args *GetChunkerArgs(int argc, char **argv)
{
struct Args *args = NULL;
#ifdef AMIGA
#define CHUNKER_TEMP "SOURCE/A,DESTBASENAME/A,SIZE/N/A"
#define OPT_CSOURCE 0
#define OPT_CDEST 1
#define OPT_CSIZE 2
#define OPT_CMAX 3
if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
{
STRPTR argsa[OPT_CMAX] = {0, 0, 0};
if( args->arg_RAHandle = ReadArgs(CHUNKER_TEMP, (LONG *)&argsa, NULL) )
{
args->arg_Filename = argsa[OPT_CSOURCE];
args->arg_Basename = argsa[OPT_CDEST];
args->arg_Size = *((unsigned long *)argsa[OPT_CSIZE]);
} else
{
mfree((char *)args);
args = NULL;
PrintFault(IoErr(), "Chunker");
}
}
#else
if( argc == NUM_CARGS )
{
if( atol(ARG_CSIZE) )
{
if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
{
args->arg_Filename = ARG_CSOURCE;
args->arg_Basename = ARG_CDEST;
args->arg_Size = atol(ARG_CSIZE);
}
} else
mprintf("3rd argument must be an integer\n");
} else
mprintf("Usage:\n chunker <file> <basename> <size>\n");
#endif
return( args );
}
/*************************************************************************
* FreeChunkerArgs() - Free Arguments for chunker
*/
void FreeChunkerArgs(struct Args *args)
{
if( args )
{
#ifdef AMIGA
if( args->arg_RAHandle )
FreeArgs(args->arg_RAHandle);
#endif
mfree((char *)args);
}
}
/*************************************************************************
* GetDeChunkArgs() - Parse command line arguments for dechunk
*/
#define ARG_DDEST argv[1]
#define ARG_DSOURCE argv[2]
#define NUM_DARGS 3
struct Args *GetDeChunkArgs(int argc, char **argv)
{
struct Args *args = NULL;
#ifdef AMIGA
#define DECHUNK_TEMP "DESTINATION/A,BASENAME/A"
#define OPT_DDEST 0
#define OPT_DBASE 1
#define OPT_DMAX 2
if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
{
STRPTR argsa[OPT_DMAX] = {0, 0};
if( args->arg_RAHandle = ReadArgs(DECHUNK_TEMP, (LONG *)&argsa, NULL) )
{
args->arg_Filename = argsa[OPT_DDEST];
args->arg_Basename = argsa[OPT_DBASE];
} else
{
mfree((char *)args);
args = NULL;
PrintFault(IoErr(), "DeChunk");
}
}
#else
if( argc == NUM_DARGS )
{
if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
{
args->arg_Filename = ARG_DDEST;
args->arg_Basename = ARG_DSOURCE;
}
} else
mprintf("Usage:\n dechunk <outputfile> <basename>");
#endif
return( args );
}
/*************************************************************************
* FreeDeChunkArgs() - Free Arguments for chunker
*/
void FreeDeChunkArgs(struct Args *args)
{
if( args )
{
#ifdef AMIGA
if( args->arg_RAHandle )
FreeArgs(args->arg_RAHandle);
#endif
mfree((char *)args);
}
}