home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 9
/
FreshFishVol9-CD2.bin
/
bbs
/
util
/
gblanker-38.8.lha
/
GBlanker
/
GSource
/
BGUI
/
PrefInterp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-12-31
|
20KB
|
556 lines
#include <exec/memory.h>
#include <libraries/bgui_macros.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>
#include <clib/bgui_protos.h>
#include <clib/asl_protos.h>
#include "/Libraries/Garshnelib/Garshnelib_protos.h"
#include <clib/alib_protos.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/bgui_pragmas.h>
#include <pragmas/asl_pragmas.h>
#include "/Libraries/Garshnelib/Garshnelib_pragmas.h"
#include <ctype.h>
#include <string.h>
#include "PrefInterp.h"
#include "/protos/parse.h"
#include "/protos/var.h"
#include "/defs.h"
extern struct Library *DOSBase;
ULONG Map[] = { SLIDER_Level, INDIC_Level, TAG_END };
struct IBox WinBox, OldBox;
struct Library *IntuitionBase, *BGUIBase, *GarshnelibBase;
Object *ModuleObj, **Objects;
struct Window *ModuleWnd;
struct MsgPort *ReplyPort = 0L;
ULONG ModuleSigs = 0L;
LONG NumGadgets;
VOID *Memory = 0L;
PrefObject *Prefs;
STRPTR MakeBoxVarName( STRPTR ProgName, STRPTR IfcName )
{
static BYTE FileName[108], *Ptr;
strcpy( FileName, ProgName );
strcat( FileName, "/" );
strcat( FileName, IfcName );
if( Ptr = strstr( FileName, ".ifc" ))
*Ptr = '\0';
strcat( FileName, ".win" );
return FileName;
}
VOID FontRequest( struct TextAttr *Attr )
{
struct Library *AslBase = OpenLibrary( "asl.library", 37L );
struct FontRequester *fReq;
if( !AslBase )
return;
fReq = AllocAslRequestTags( ASL_FontRequest,
ASL_FontName, Attr->ta_Name,
ASL_FontHeight, Attr->ta_YSize,
ASL_MaxHeight, 100, TAG_DONE );
if( fReq )
{
if( AslRequestTags( fReq,
ASLFO_Window, ModuleWnd,
ASLFO_SleepWindow, TRUE,
ASLFO_TitleText, ( LONG )"Please choose a font...",
TAG_DONE ))
{
CopyMem( fReq->fo_Attr.ta_Name, Attr->ta_Name, 31 );
Attr->ta_YSize = fReq->fo_Attr.ta_YSize;
}
FreeAslRequest( fReq );
}
CloseLibrary( AslBase );
}
VOID SendMessageToPort( LONG Type, STRPTR PortName )
{
struct MsgPort *ForeignPort;
BlankMsg *ClientMsg;
if( ForeignPort = FindPort( PortName ))
{
if( ClientMsg = AllocPooled( Memory, sizeof( BlankMsg )))
{
ClientMsg->bm_Mess.mn_ReplyPort = ReplyPort;
ClientMsg->bm_Mess.mn_Length = sizeof( BlankMsg );
ClientMsg->bm_Type = Type;
PutMsg( ForeignPort, ( struct Message * )ClientMsg );
}
}
}
LONG main( LONG argc, STRPTR argv[] )
{
Object *VertGroup, *SaveBtn, *TestBtn, *CancelBtn, *DisplayBtn, *CtrlGrp;
Object *NameInf, *SizeInf;
LONG i, j, LastNonGrp = 0, DispID = -1, Min, Max, *Types, rc, ID, Sigs;
BYTE DescripName[108], PrefsName[108], BogusBuf[128], ValidPrefs = FALSE;
STRPTR *Labels, *KeyStrs, BoxVarName;
ULONG Args[] = { 0L, 0L };
Object **Indics;
BPTR Descrip, Tmp;
if( argc != 2 )
return RETURN_WARN;
if( FindPort( "GarshnePrefs" ))
return RETURN_WARN;
IntuitionBase = OpenLibrary( "intuition.library", 37 );
BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION );
GarshnelibBase = OpenLibrary( "Garshnelib.library", 37 );
if( !IntuitionBase || !BGUIBase || !GarshnelibBase )
goto JAIL;
if(!( Memory = CreatePool( MEMF_CLEAR, 1024, 512 )))
goto JAIL;
if(!( ReplyPort = CreatePort( "GarshnePrefs", 0L )))
goto JAIL;
strcpy( DescripName, argv[1] );
strcat( DescripName, ".ifc" );
strcpy( PrefsName, argv[1] );
strcat( PrefsName, ".prefs" );
if(!( Descrip = Open( DescripName, MODE_OLDFILE )))
goto JAIL;
NumGadgets = ScanDigit( Descrip );
Objects = AllocPooled( Memory, sizeof( Object * ) * ( NumGadgets + 1 ));
Indics = AllocPooled( Memory, sizeof( Object * ) * ( NumGadgets + 1 ));
Prefs = AllocPooled( Memory, sizeof( PrefObject ) * ( NumGadgets + 1 ));
Types = AllocPooled( Memory, sizeof( LONG ) * ( NumGadgets + 1 ));
KeyStrs = AllocPooled( Memory, sizeof( STRPTR ) * ( NumGadgets + 1 ));
if( !Objects || !Indics || !Prefs || !Types || !KeyStrs )
goto PREJAIL;
VertGroup = BGUI_NewObject( BGUI_GROUP_GADGET,
GROUP_Style, GRSTYLE_VERTICAL,
HOffset( 3 ), VOffset( 3 ), Spacing( 3 ),
TAG_END );
BoxVarName = MakeBoxVarName( FilePart( argv[0] ), FilePart( argv[1] ));
if( GetVar37( BoxVarName, ( STRPTR )&WinBox, sizeof( struct IBox ),
GVF_BINARY_VAR|GVF_DONT_NULL_TERM ) != -1 )
{
OldBox = WinBox;
ModuleObj = BGUI_NewObject( BGUI_WINDOW_OBJECT,
WINDOW_MasterGroup, VertGroup,
WINDOW_Title, FilePart( argv[1] ),
WINDOW_Bounds, &WinBox,
TAG_END );
}
else
{
ModuleObj = BGUI_NewObject( BGUI_WINDOW_OBJECT,
WINDOW_MasterGroup, VertGroup,
WINDOW_Title, FilePart( argv[1] ),
TAG_END );
}
if( Tmp = Open( PrefsName, MODE_OLDFILE ))
{
Read( Tmp, Prefs, sizeof( LONG )); /* Ignore entry count */
if( Read( Tmp, Prefs, sizeof( PrefObject ) * NumGadgets ) ==
sizeof( PrefObject ) * NumGadgets )
ValidPrefs = TRUE;
Close( Tmp );
}
for( i = 0; i < NumGadgets; i++ )
{
STRPTR IDStr, LabelStr;
IDStr = ScanToken( Descrip );
switch( tolower( IDStr[0] ))
{
case 'c':
Types[i] = GAD_CYCLE;
break;
case 'd':
Types[i] = ( tolower( IDStr[1] ) == 'i' )? GAD_DISPLAY : GAD_DELIM;
break;
case 'f':
Types[i] = GAD_FONT;
break;
case 's':
Types[i] = ( tolower( IDStr[1] ) == 'l' )? GAD_SLIDER : GAD_STRING;
break;
}
switch( Prefs[i].po_Type = Types[i] )
{
case GAD_CYCLE:
LabelStr = ScanToken( Descrip );
KeyStrs[i] = ScanToken( Descrip );
Labels = ScanTokenArray( Descrip );
if( ValidPrefs )
ScanDigit( Descrip );
else
Prefs[i].po_Active = ScanDigit( Descrip );
Objects[i] =
BGUI_NewObject( BGUI_CYCLE_GADGET,
GA_ID, i + 10,
LAB_Label, LabelStr,
LAB_Underscore, '_',
FRM_Type, FRTYPE_BUTTON,
CYC_Labels, Labels,
CYC_Active, Prefs[i].po_Active,
TAG_DONE );
break;
case GAD_SLIDER:
LabelStr = ScanToken( Descrip );
KeyStrs[i] = ScanToken( Descrip );
Min = ScanDigit( Descrip );
Max = ScanDigit( Descrip );
if( ValidPrefs )
ScanDigit( Descrip );
else
Prefs[i].po_Level = ScanDigit( Descrip );
Objects[i] =
BGUI_NewObject( BGUI_SLIDER_GADGET,
GA_ID, i + 10,
LAB_Label, LabelStr,
LAB_Underscore, '_',
SLIDER_Min, Min,
SLIDER_Max, Max,
SLIDER_Level, Prefs[i].po_Level,
TAG_DONE );
Indics[i] =
BGUI_NewObject( BGUI_INDICATOR_GADGET,
INDIC_Min, Min,
INDIC_Max, Max,
INDIC_Level, Prefs[i].po_Level,
INDIC_Justification, IDJ_CENTER,
TAG_DONE );
break;
case GAD_FONT:
if( ValidPrefs )
{
ScanToken( Descrip );
ScanDigit( Descrip );
}
else
{