home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
dirs
/
fileio_393.lzh
/
FileIO
/
C_Example
/
Main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-28
|
9KB
|
346 lines
#include <functions.h>
#include <exec/types.h>
#include <exec/io.h>
#include <stdio.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <graphics/gfxbase.h>
#include "FileIO.h"
/* extern long GetMsg(), OpenWindow(), IoErr(), OpenLibrary(); */
/* === System Global Variables ========================================== */
struct IntuitionBase *IntuitionBase = 0L;
struct GfxBase *GfxBase = 0L;
struct DosLibrary *DosBase = 0L;
struct RequesterBase *RequesterBase = 0L;
struct FileIO *myFileIO = 0L;
struct FileIO *myFileIO2 = 0L;
struct Window *myWindow = 0L;
struct Screen *myScreen = 0L;
ULONG argcount; /* Saves argc from main(). argcount==0, then run from WB. */
struct TextAttr topaz80_font;
BOOL TestFileIO();
struct NewScreen NewFileIOScreen =
{
0, 0, /* LeftEdge, TopEdge */
640, 400, /* Width, Height */
2, /* Depth */
0, 1, /* Detail/BlockPens */
HIRES | LACE, /* ViewPort Modes (must set/clear HIRES as needed) */
CUSTOMSCREEN,
&topaz80_font, /* Font */
(UBYTE *)"Example FileIO Program's Screen",
0L, /* Gadgets */
0L, /* CustomBitMap */
};
struct NewWindow NewFileIOWindow =
{
168, 30, /* LeftEdge, TopEdge */
303, 145, /* Width, Height */
-1, -1, /* Detail/BlockPens */
MENUPICK | MOUSEBUTTONS | CLOSEWINDOW | RAWKEY | DISKINSERTED,
/* IDCMP Flags */
WINDOWDRAG | WINDOWDEPTH | SIZEBRIGHT | SMART_REFRESH |
WINDOWCLOSE | ACTIVATE | NOCAREREFRESH,
/* Window Specification Flags */
0L, /* FirstGadget */
0L, /* Checkmark */
(UBYTE *)"FileIO Requester Window", /* WindowTitle */
0L, /* Screen */
0L, /* SuperBitMap */
303, 145, /* MinWidth, MinHeight */
600, 200, /* MaxWidth, MaxHeight */
WBENCHSCREEN,
};
struct IntuiText itxt[] = {
{0,1,JAM1,19,1,NULL,(UBYTE *)"Multiple"},
{0,1,JAM1,19,1,NULL,(UBYTE *)"Handler"}, };
struct MenuItem mi[] = {
{&mi[1],0, 0,91,10,CHECKIT | MENUTOGGLE | ITEMTEXT | ITEMENABLED | HIGHCOMP,\
NULL,(APTR)&itxt[0],NULL,NULL},
{NULL,0, 10,91,10,CHECKIT | MENUTOGGLE | ITEMTEXT | ITEMENABLED | HIGHCOMP,\
NULL,(APTR)&itxt[1],NULL,NULL},};
struct Menu myMenu = {NULL,0,0,72,0,MENUENABLED, "Project",&mi[0]};
BOOL myFunc();
struct HandlerBlock hblock = {
/* APTR StartUpCode; */ (APTR)myFunc,
/* APTR DiskInsertedCode; */ 0,
/* APTR GadgetCode; */ 0,
/* APTR KeyCode; */ 0,
/* APTR MouseMoveCode; */ 0 };
/************************ MAIN ROUTINE *****************************/
VOID main(argc, argv)
LONG argc;
char **argv;
{
LONG class;
USHORT code;
struct IntuiMessage *message;
BOOL end;
argcount = argc;
if (!(IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", 0L)))
exit_program("FileIO Demo: No intuition library. \n", 1L);
if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0L)))
exit_program("FileIO Demo: No graphics library. \n", 2L);
/* NOW OPEN THE REQUESTER LIBRARY */
if (!(RequesterBase = (struct RequesterBase *)OpenLibrary("requester.library", 1L)))
exit_program("FileIO Demo: No requester.library. \n", 4L);
if (argv)
{
/* OK, we started from CLI */
if (argc > 1)
{
/*
Note: if we expected to receive a path name from the user as one of the
argv arguments, we should call requester lib's ParseString() now, passing
that arg. For example, assume that the user typed at the CLI:
TestProgram df0:mydir/blort
where df0:mydir/blort is some data file that TestProgram should load. We
would now call:
ParseString(myFileIO, argv[1]);
This will not only copy "df0:" to the FileIO's Diskname[], "mydir" to the
Drawername[], and "blort" to the Filename[], it will also set the FREEBYTES
and FILESIZE fields so that you know how much room is on the disk and whether
the file exists (FileIO->FileSize != 0). So, you can use the same load
routine that you would use for loading a data file after calling DoFileIO().
In fact, ParseString() is the routine to use if you want to set the FileIO
to some specific path without calling DoFileIO and presenting the req to the
user.
*/
if (myScreen = OpenScreen(&NewFileIOScreen))
{
NewFileIOWindow.Screen = myScreen;
NewFileIOWindow.Type = CUSTOMSCREEN;
}
}
}
if (!(myWindow = (struct Window *) OpenWindow( &NewFileIOWindow ) ))
exit_program("FileIO Demo: Null Window.\n", 5L);
SetMenuStrip( myWindow, &myMenu );
/* GET 2 FileIO STRUCTURES */
if (!(myFileIO = GetFileIO() ))
exit_program("FileIO Demo: No FileIO 1.\n", 6L);
if (!(myFileIO2 = GetFileIO() ))
exit_program("FileIO Demo: No FileIO 2.\n", 7L);
/* Set up the XY co-ordinates where the requester should open */
myFileIO->X = 6;
myFileIO->Y = 11;
myFileIO2->X = 6;
myFileIO2->Y = 11;
/* Set default colors and DrawMode */
myFileIO->DrawMode = JAM2;
myFileIO->PenA = 1;
myFileIO->PenB = 0;
myFileIO2->DrawMode = JAM2;
myFileIO2->PenA = 1;
myFileIO2->PenB = 0;
/* pretty easy to set up, eh? */
end = FALSE;
SetFlag(myFileIO2->Flags, WBENCH_MATCH | MATCH_OBJECTTYPE);
myFileIO2->MatchType = WBTOOL;
SetFlag(myFileIO2->Flags, USE_DEVICE_NAMES);
myFileIO->Custom = &hblock;
SetFileIOHandlers( &hblock );
while (end == FALSE)
{
WaitPort(myWindow->UserPort);
while (message = ( struct IntuiMessage *)GetMsg(myWindow->UserPort))
{
code = message->Code;
class = message->Class;
ReplyMsg(message);
switch (class)
{
case CLOSEWINDOW:
end = TRUE;
break;
case DISKINSERTED:
/* You should clear the NO_CARE_REDRAW flag whenever you
* detect that a new disk was inserted (if using this feature).
We aren't using it, so comment it out.
ClearFlag(myFileIO->Flags, NO_CARE_REDRAW);
ClearFlag(myFileIO2->Flags, NO_CARE_REDRAW);
*/
break;
case MENUPICK:
switch( ITEMNUM( code ) )
{
case 0:
ToggleFlag( myFileIO->Flags, MULTIPLE_FILES );
if (TestFileIO(myFileIO, myWindow))
{
/*
ClearFlag(myFileIO->Flags, NO_CARE_REDRAW);
ClearFlag(myFileIO2->Flags, NO_CARE_REDRAW);
*/
}
break;
case 1:
ToggleFlag( myFileIO->Flags, CUSTOM_HANDLERS );
if (TestFileIO(myFileIO, myWindow))
{
/*
ClearFlag(myFileIO->Flags, NO_CARE_REDRAW);
ClearFlag(myFileIO2->Flags, NO_CARE_REDRAW);
*/
}
break;
}
break;
case MOUSEBUTTONS:
if (TestFileIO(myFileIO, myWindow))
{
/*
ClearFlag(myFileIO->Flags, NO_CARE_REDRAW);
ClearFlag(myFileIO2->Flags, NO_CARE_REDRAW);
*/
}
break;
case RAWKEY:
if (TestFileIO(myFileIO2, myWindow))
{
/*
ClearFlag(myFileIO->Flags, NO_CARE_REDRAW);
ClearFlag(myFileIO2->Flags, NO_CARE_REDRAW);
*/
}
break;
default:
break;
}
}
}
exit_program( 0L, 0L);
}
exit_program( error_words, error_code ) /* All exits through here. */
char error_words;
ULONG error_code;
{
if( argcount && error_words ) puts( error_words );
if (myFileIO) ReleaseFileIO(myFileIO);
if (myFileIO2) ReleaseFileIO(myFileIO2);
if (myWindow) CloseWindow(myWindow);
if (myScreen) CloseScreen(myScreen);
if (IntuitionBase) CloseLibrary(IntuitionBase);
if (GfxBase) CloseLibrary(GfxBase);
if (DosBase) CloseLibrary(DosBase);
if (RequesterBase) CloseLibrary(RequesterBase);
exit( error_code );
}
BOOL TestFileIO(fileio, wind)
struct FileIO *fileio;
struct Window *wind;
{
UBYTE *address;
struct FileEntry *fentry1 = 0, *fentry2 = 0;
/* This guy calls DoFileIO(), displays the file name selected by the
* user, and returns TRUE if the user swapped disks during DoFileIO()
* (else returns FALSE) if an error, CANCEL, or no disk swap.
*/
UBYTE buffer[80];
fileio->Buffer = buffer;
address = DoFileIO(fileio, wind);
if( address == buffer )
{
/* If user was positive and no error, display the name */
AutoMessage( buffer, wind);
if( fileio->Flags & MULTIPLE_FILES )
{
while( fentry2 = RetrieveEntry( &fentry1, fileio ) )
{
AutoMessage( fentry2->filePart->EntryString, wind );
}
}
}
if (!address) AutoMessage("Error in operation", wind);
if (address==-1) AutoMessage("Cancelled operation", wind);
if (FlagIsSet(fileio->Flags, DISK_HAS_CHANGED))
{
ClearFlag(fileio->Flags, DISK_HAS_CHANGED);
return(TRUE);
}
else
return(FALSE);
}
BOOL myFunc( extra,seconds,micros,mouseX,mouseY,fileio,xwind,iaddress )
ULONG extra;
APTR iaddress;
struct Window *xwind;
struct FileIO *fileio;
SHORT mouseY, mouseX;
ULONG micros,seconds;
{
return(AutoPrompt3( "This is a custom StartHandler",0,0, xwind ));
}