home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
pufferfish
/
source
/
pufferfish.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-29
|
12KB
|
488 lines
/*
* PufferFish.c
*
* Generate Fish floppies from CD-ROM distribution
*
*/
#include <exec/types.h>
#include <utility/tagitem.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <intuition/imageclass.h>
#include <intuition/icclass.h>
#include <libraries/amigaguide.h>
#include <libraries/dos.h>
#include <dos/dosextens.h>
#include <dos/dostags.h>
#include <resources/disk.h>
#include <clib/exec_protos.h>
#include <clib/amigaguide_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>
#include <clib/graphics_protos.h>
#include <clib/icon_protos.h>
#include <clib/intuition_protos.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "WB2CLI/WB2CLI.h"
#include "buttonclass/headers.h"
#include "buttonclass/buttonclass.h"
#include "PufferFish.h"
long __stack = 20000;
extern struct Library *SysBase;
extern struct Library *IntuitionBase;
extern struct Library *UtilityBase;
extern struct Library *GfxBase;
extern struct DosLibrary *DOSBase;
struct Library *DiskBase = NULL;
struct Library *AmigaGuideBase = NULL;
static const char versionstring[] = "\0$VER: PufferFish 1.0 (29.03.94)";
struct Screen *screen;
struct DrawInfo *drawinfo;
struct Window *win;
BPTR dirlock;
struct InfoData MyInfoData;
int start_disknum, end_disknum;
int dig[8] =
{
0, 0, 0, 1,
0, 0, 0, 1
};
char *dig_text[8] =
{
"0", "0", "0", "1",
"0", "0", "0", "1",
};
unsigned char avail_disks, drives_selected;
struct MsgPort *myPort;
struct Process *myProc[5];
int firstdisk, lastdisk;
char *contentspath, *formatpath, *lhapath, *brikpath, *additional_device;
BOOL verbose;
AMIGAGUIDECONTEXT agcontext = NULL;
ULONG winbit;
Class *buttonclass;
void MakeBoxedStringClass(void);
void FreeBoxedStringClass(void);
void handle_input(void);
// Change SAS/C's Ctrl-C checking (eventually abort accidental generation of wrong floppies?)
void __regargs _CXBRK(void)
{
}
/*
* main()
*
* Handles library, window, image, gadget, help setup
* Handles input (should be separate)
*
*/
int main( int argc, char **argv )
{
ULONG arrowwidth, arrowheight, checkwidth, winwidth, winheight;
struct NewAmigaGuide nag = {NULL};
STRPTR context[] =
{
"MAIN",
"DIGITS",
"DRIVES",
"START",
NULL
};
UBYTE **ttypes;
int i;
WB2CLI((struct WBStartup *)argv,20000,DOSBase);
AmigaGuideBase = OpenLibrary( "amigaguide.library", 34 );
ttypes = ArgArrayInit( argc, argv );
firstdisk = ArgInt( ttypes, "FIRSTDISK", MIN_DISK_NUM );
lastdisk = ArgInt( ttypes, "LASTDISK", MAX_DISK_NUM );
contentspath = ArgString( ttypes, "CONTENTSPATH", CONTENTS_PATH );
formatpath = ArgString( ttypes, "FORMATPATH", FORMAT_PATH );
lhapath = ArgString( ttypes, "LHAPATH", LHA_PATH );
brikpath = ArgString( ttypes, "BRIKPATH", BRIK_PATH );
additional_device = ArgString( ttypes, "DEVICE", "" );
verbose = FindToolType( ttypes, "VERBOSE" ) ? TRUE : FALSE;
if( firstdisk < MIN_DISK_NUM )
{
firstdisk = MIN_DISK_NUM;
}
if( lastdisk < firstdisk )
{
lastdisk = MAX_DISK_NUM;
}
start_disknum = end_disknum = firstdisk;
dig[0] = start_disknum / 1000;
dig[1] = (start_disknum - dig[0] * 1000) / 100;
dig[2] = (start_disknum - dig[0] * 1000 - dig[1] * 100) / 10;
dig[3] = (start_disknum - dig[0] * 1000 - dig[1] * 100 - dig[2] * 10);
dig[4] = end_disknum / 1000;
dig[5] = (end_disknum - dig[4] * 1000) / 100;
dig[6] = (end_disknum - dig[4] * 1000 - dig[5] * 100) / 10;
dig[7] = (end_disknum - dig[4] * 1000 - dig[5] * 100 - dig[6] * 10);
for( i = 0; i < 8; i += 1 )
{
dig_text[i][0] = '0' + dig[i];
}
if( DiskBase = (struct Library *)OpenResource(DISKNAME) )
{
screen = LockPubScreen( NULL );
if( screen )
{
drawinfo = GetScreenDrawInfo( screen );
if( drawinfo )
{
MakeBoxedStringClass();
if( buttonclass = initButtonGadgetClass( IntuitionBase, UtilityBase, GfxBase ) )
{
if( make_systemimages() )
{
GetAttr( IA_Width, upimage, &arrowwidth );
GetAttr( IA_Height, upimage, &arrowheight );
GetAttr( IA_Width, checkimage, &checkwidth );
// width of digits frame
winwidth = ( arrowwidth * 11 / 2 + drawinfo->dri_Font->tf_XSize * 5 + 8);
// width of drive frame
drivenames_text[0].ITextFont = screen->Font;
winwidth += drawinfo->dri_Font->tf_XSize
+ IntuiTextLength( &drivenames_text[0] )
+ checkwidth + 4
+ 2 * drawinfo->dri_Font->tf_XSize;
// height of button frames
winheight = 2 * ((arrowheight + 2)
+ (drawinfo->dri_Font->tf_YSize + 2 + 4)
+ (arrowheight + 2)
+ drawinfo->dri_Font->tf_YSize
+ GF_TOPBORDER * 3 / 2) + drawinfo->dri_Font->tf_YSize;
if( win = OpenWindowTags( NULL,
WA_PubScreen, screen,
WA_Flags, WFLG_DEPTHGADGET | WFLG_DRAGBAR | WFLG_CLOSEGADGET | WFLG_NEWLOOKMENUS,
WA_IDCMP, GF_IDCMPFLAGS,
WA_Width, screen->WBorLeft + screen->WBorRight // window borders
+ GF_LEFTBORDER + GF_RIGHTBORDER // margins from borders
+ winwidth,
WA_Height, screen->WBorTop + screen->WBorBottom
+ drawinfo->dri_Font->tf_YSize + 1
+ GF_TOPBORDER + GF_BOTTOMBORDER
+ winheight,
WA_Activate,TRUE,
WA_Title, "PufferFish",
TAG_END ))
{
if( GfxBase->lib_Version >= 39 )
{
HelpControl( win, HC_GADGETHELP );
}
winbit = 1L << ((struct MsgPort *)win->UserPort)->mp_SigBit;
avail_disks = which_disks();
if( make_images() && make_digits() && make_drives() && make_gadgets() )
{
draw_images();
AddGList( win, uparrows[0], -1, -1, NULL );
RefreshGList( uparrows[0], win, NULL, -1 );
if( AmigaGuideBase )
{
nag.nag_BaseName = "PUFFERFISH";
nag.nag_Name = "PufferFish.guide";
nag.nag_ClientPort = "PUFFERFISH_HELP";
nag.nag_Context = context;
nag.nag_Screen = screen;
if( agcontext = OpenAmigaGuideAsync( &nag, NULL ) )
{
SetAmigaGuideContext( agcontext, 0L, NULL );
}
}
handle_input();
if( AmigaGuideBase && agcontext )
{
CloseAmigaGuide( agcontext );
}
RemoveGList( win, uparrows[0], -1 );
free_gadgets();
free_drives();
free_digits();
free_images();
}
CloseWindow( win );
}
free_systemimages();
}
freeButtonGadgetClass( buttonclass );
}
FreeBoxedStringClass();
FreeScreenDrawInfo( screen, drawinfo );
}
UnlockPubScreen( NULL, screen );
}
// NOTE: Don't close DiskBase...
}
ArgArrayDone();
if( AmigaGuideBase )
{
CloseLibrary( AmigaGuideBase );
}
}
void handle_input(void)
{
BOOL done = FALSE;
ULONG signal;
ULONG id, class, code;
void *ghelpid;
struct IntuiMessage *imsg;
struct EasyStruct easyStruct =
{
sizeof( struct EasyStruct ),
0,
NULL,
NULL,
NULL
};
struct Requester req;
LONG region, help_region;
while( !done )
{
signal = Wait( winbit );
if( signal & winbit )
{
while( imsg = (struct IntuiMessage *)
GetMsg( (struct MsgPort *)win->UserPort ) )
{
class = imsg->Class;
code = imsg->Code;
if( class == IDCMP_GADGETUP )
{
id = ((struct Gadget *)imsg->IAddress)->GadgetID;
}
ghelpid = imsg->IAddress;
ReplyMsg( (struct Message *)imsg );
switch( class )
{
case IDCMP_CLOSEWINDOW:
done = TRUE;
break;
case IDCMP_GADGETUP:
if( id < GAD_START )
{
if( code == 0x5F )
{
// Help for string/integer gadget requested
if( agcontext )
{
SetAmigaGuideContext( agcontext, GF_HELP_DIGITS, NULL );
SendAmigaGuideContext( agcontext, NULL );
}
else
{
/* amigaguide.library wasn't found, so help not available */
easyStruct.es_TextFormat = "Help not available\nYou need amigaguide.library V34";
easyStruct.es_GadgetFormat = "OK";
beginWait( win, &req );
EasyRequest( win, &easyStruct, NULL, NULL );
endWait( win, &req );
}
}
else
{
update_gadgets(id);
}
}
else if( id == GAD_START )
{
/* Select path */
if( drives_selected )
{
start_disk_generate();
}
else
{
/* No destination disk chosen */
DisplayBeep( screen );
easyStruct.es_TextFormat = "No destination drives chosen";
easyStruct.es_GadgetFormat = "OK";
beginWait( win, &req );
EasyRequest( win, &easyStruct, NULL, NULL );
endWait( win, &req );
}
}
else
{
DisplayBeep( screen );
easyStruct.es_TextFormat = "Unknown gadget";
easyStruct.es_GadgetFormat = "OK";
beginWait( win, &req );
EasyRequest( win, &easyStruct, NULL, NULL );
endWait( win, &req );
}
break;
case IDCMP_VANILLAKEY:
switch( code )
{
case 'g':
case 'G':
if( drives_selected )
{
start_disk_generate();
}
else
{
/* No destination disk chosen */
DisplayBeep( screen );
easyStruct.es_TextFormat = "No destination drives chosen";
easyStruct.es_GadgetFormat = "OK";
beginWait( win, &req );
EasyRequest( win, &easyStruct, NULL, NULL );
endWait( win, &req );
}
break;
case '0':
case '1':
case '2':
case '3':
case '4':
if( avail_disks & (1<<(code - '0')) )
{
handle_drive( GAD_DRIVE_0 + code - '0' );
refresh_gadgets();
}
RefreshGList( uparrows[0], win, NULL, -1 );
break;
case '=':
start_disknum += 1;
refresh_gadgets();
RefreshGList( uparrows[0], win, NULL, -1 );
break;
case '-':
start_disknum -= 1;
refresh_gadgets();
RefreshGList( uparrows[0], win, NULL, -1 );
break;
case '+':
end_disknum += 1;
refresh_gadgets();
RefreshGList( uparrows[0], win, NULL, -1 );
break;
case '_':
end_disknum -= 1;
refresh_gadgets();
RefreshGList( uparrows[0], win, NULL, -1 );
break;
case '\t':
ActivateGadget( integer[0], win, NULL );
RefreshGList( uparrows[0], win, NULL, -1 );
break;
}
break;
case IDCMP_GADGETHELP:
region = -1;
if( ghelpid == NULL )
{
;
}
else if( ghelpid == (APTR)win )
{
// Over window
region = 0;
}
else
{
LONG sysgtype = ((struct Gadget *)ghelpid)->GadgetType & 0xF0;
switch( sysgtype )
{
case GTYP_WDEPTH:
// Depth gadget
region = GF_NUM_GADS + 1;
break;
case GTYP_CLOSE:
// Close gadget
region = GF_NUM_GADS + 2;
break;
case GTYP_WDRAGGING:
// Window dragbar
region = GF_NUM_GADS + 3;
break;
case 0:
// + 1 since region 0 is reserved for 'window'
region = ((struct Gadget *)ghelpid)->GadgetID + 1;
break;
default:
// Other gadget
region = 0;
break;
}
}
break;
case IDCMP_RAWKEY:
switch( code )
{
case 0x5F:
if( agcontext )
{
help_region = GF_HELP_MAIN;
if( region <= 0 )
{
help_region = GF_HELP_MAIN;
}
else if( region <= GAD_PROP_2 + 1 )
{
help_region = GF_HELP_DIGITS;
}
else if( region <= GAD_DRIVE_3 + 1 )
{
help_region = GF_HELP_DRIVES;
}
else if( region <= GF_NUM_GADS )
{
help_region = GF_HELP_START;
}
SetAmigaGuideContext( agcontext, help_region, NULL );
SendAmigaGuideContext( agcontext, NULL );
}
break;
case 0x42:
// Tab key
ActivateGadget( integer[0], win, NULL );
RefreshGList( integer[0], win, NULL, -1 );
break;
default:
break;
}
break;
default:
break;
}
}
}
}
}