/****************************************************************************
Funzioni catturate da SPY
by Federico Giannici
-----------------------------------------------------------------------------
This source is provided for you to see the techniques I used to write SPY.
You can, obviously, use it to make your experiments and you can take some
routines to insert in your programs. But you CANNOT modify, recompile and
distribute the modified version to anyone without my permission.
Be a programmer not a copier.
-----------------------------------------------------------------------------
****************************************************************************/
#include "SPY.h"
#define TEMPLEN 60 /* Lunghezza stringhe temporanee per i nomi */
#define COPYTEMP( to, from ) strncpy( to, from, TEMPLEN )
extern struct MenuItem itemverbose;
extern struct MenuItem itemeverytime;
/***** Le proto di SPY *****/
extern void goin( void );
extern void goout( void );
extern BOOL canoutput( void );
extern void initout( UBYTE *funname );
extern void endout( void );
extern void status( UBYTE *text );
extern void setvect( WORD v );
extern void resetvect( WORD v );
extern void fsetvect( WORD v );
extern void fresetvect( WORD v );
extern void newline( void );
extern void prints( UBYTE *testo );
extern void printname( UBYTE *name );
extern void printpname( UBYTE *name );
extern void printbuffer( UBYTE *buffer, LONG len );
extern void printlock( BPTR lock );
extern void printfh( BPTR fh );
extern void printd( LONG numero );
extern void printpd( LONG numero );
extern void printh( ULONG numero );
extern void addfh( BPTR fh, UBYTE *name );
extern void remfh( BPTR fh );
extern struct fhnode *findfh( BPTR fh );
extern void clearfh( void );
extern BOOL cannotwait;
extern struct Window *window;
UBYTE returntext[]="Return: ";
UBYTE unknow[]="Unknow!!";
UBYTE *openmodetext[]=
{
unknow,
"MODE_READWRITE",
"MODE_OLDFILE",
"MODE_NEWFILE"
};
UBYTE *lockmodetext[]=
{
unknow,
"EXCLUSIVE_LOCK",
"SHARED_LOCK"
};
UBYTE *seekmodetext[]=
{
unknow,
"OFFSET_BEGINNING",
"OFFSET_CURRENT",
"OFFSET_END"
};
/***** Nuova routine Open *****/
BPTR __saveds __asm newopen( register __d1 char *name, register __d2 long accessmode )
{
BPTR ret;
goin();
fresetvect( OPENV );
ret=Open( name, accessmode );
fsetvect( OPENV );
addfh( ret, name );
if( canoutput() && (EVERYTIME || ret==NULL) )
{
initout( "Open");
if( VERBOSE )
prints( "FileName: " );
printname( name );
if( VERBOSE )
{
newline();
prints( "AccessMode: " );
prints( openmodetext[accessmode<1004 && accessmode>1006 ? 0 : accessmode-1003] );
printpd( accessmode );
newline();
prints( returntext );
printh( (ULONG)ret );
}
endout();
}
goout();
return( ret );
}
/***** Nuova routine Close *****/
void __saveds __asm newclose( register __d1 BPTR file )
{
goin();
fresetvect( CLOSEV );
Close( file );
fsetvect( CLOSEV );
if( canoutput() && (EVERYTIME) )
{
initout( "Close");
if( VERBOSE )
prints( "FileHandle: " );
printfh( file );
endout();
}
remfh( file );
goout();
return;
}
/***** Nuova routine Read *****/
long __saveds __asm newread( register __d1 BPTR file, register __d2 char *buffer, register __d3 long length )
{
long ret;
goin();
fresetvect( READV );
ret=Read( file, buffer, length );
fsetvect( READV );
if( canoutput() && (EVERYTIME || ret==-1) )
{
initout( "Read");
if( VERBOSE )
prints( "FileHandle: " );
printfh( file );
if( VERBOSE )
{
newline();
prints( "Buffer: " );
printbuffer( buffer, length );
newline();
prints( "Length: " );
printd( length );
newline();
prints( returntext );
printd( (ULONG)ret );
}
endout();
}
goout();
return( ret );
}
/***** Nuova routine Write *****/
long __saveds __asm newwrite( register __d1 BPTR file, register __d2 char *buffer, register __d3 long length )
{
long ret;
goin();
fresetvect( WRITEV );
ret=Write( file, buffer, length );
fsetvect( WRITEV );
if( canoutput() && (EVERYTIME || ret==-1) )
{
initout( "Write");
if( VERBOSE )
prints( "FileHandle: " );
printfh( file );
if( VERBOSE )
{
newline();
prints( "Buffer: " );
printbuffer( buffer, length );
newline();
prints( "Length: " );
printd( length );
newline();
prints( returntext );
printd( (ULONG)ret );
}
endout();
}
goout();
return( ret );
}
/***** Nuova routine Input *****/
BPTR __saveds __asm newinput( void )
{
BPTR ret;
goin();
fresetvect( INPUTV );
ret=Input();
fsetvect( INPUTV );
addfh( ret, "" );
if( canoutput() && (EVERYTIME || ret==NULL) )
{
initout( "Input");
if( VERBOSE )
prints( returntext );
printh( (ULONG)ret );
endout();
}
goout();
return( ret );
}
/***** Nuova routine Output *****/
BPTR __saveds __asm newoutput( void )
{
BPTR ret;
goin();
fresetvect( OUTPUTV );
ret=Input();
fsetvect( OUTPUTV );
addfh( ret, "