home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
util
/
blank
/
gblanker
/
source
/
prefs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-19
|
6KB
|
193 lines
/*
* Copyright (c) 1994 Michael D. Bayne.
* All rights reserved.
*
* Please see the documentation accompanying the distribution for distribution
* and disclaimer information.
*/
#include <exec/memory.h>
#include <string.h>
#include <stdlib.h>
#include "includes.h"
#include "libraries.h"
#include "protos/protos.h"
STRPTR defTTs[] = {
"DONOTWAIT", "CX_PRIORITY=", "CX_POPUP=", "CX_POPKEY=", "BLANKKEY=",
"TIMEOUT=", "BLANKER=", "BLANKERDIR=", "LEFT=", "TOP=", "REPLACE=",
"BLANKCORNER=", "DONTCORNER=" };
#define NUMTOOLTYPES ( sizeof( defTTs ) / sizeof( STRPTR ))
BYTE *cornerStrings[] = {
"NONE", "UPPERLEFT", "UPPERRIGHT", "LOWERRIGHT", "LOWERLEFT" };
BlankerPrefs PrefsRec = { 1, TRUE, 600, 0L, 0L, "Alt Help", "Alt Delete",
"Random", "Blankers", 0L, 0L, 10L };
STRPTR longToStr( LONG num )
{
static BYTE out[32];
LONG i = 32, j;
if( !num )
return "0";
while( num )
{
out[--i] = num % 10;
num /= 10;
}
for( j = 0; j < 32 - i; j++ )
out[j] = '0' + out[i+j];
out[j] = 0;
return out;
}
STRPTR ConsTT( STRPTR DefStr, STRPTR Value )
{
STRPTR NewToolType;
if( !DefStr || !Value )
return 0L;
if( NewToolType = AllocVec( strlen(DefStr)+strlen(Value)+1, MEMF_CLEAR ))
{
strcpy( NewToolType, DefStr );
strcat( NewToolType, Value );
return NewToolType;
}
return 0L;
}
VOID SaveDefaultPrefs( BlankerPrefs *bPO )
{
BYTE *toolTypes[NUMTOOLTYPES+1], **oldToolTypes;
struct DiskObject *bDO;
LONG i;
toolTypes[0x0] = ConsTT( defTTs[0], "" );
toolTypes[0x1] = ConsTT( defTTs[1], longToStr( bPO->bp_Priority ));
toolTypes[0x2] = ConsTT( defTTs[2], bPO->bp_PopUp ? "YES" : "NO" );
toolTypes[0x3] = ConsTT( defTTs[3], bPO->bp_PopKey );
toolTypes[0x4] = ConsTT( defTTs[4], bPO->bp_BlankKey );
toolTypes[0x5] = ConsTT( defTTs[5], longToStr( bPO->bp_Timeout/10 ));
toolTypes[0x6] = ConsTT( defTTs[6], bPO->bp_Blanker );
toolTypes[0x7] = ConsTT( defTTs[7], bPO->bp_Dir );
toolTypes[0x8] = ConsTT( defTTs[8], longToStr( bPO->bp_Left ));
toolTypes[0x9] = ConsTT( defTTs[9], longToStr( bPO->bp_Top ));
toolTypes[0xA] = ConsTT( defTTs[10], bPO->bp_Flags&BF_REPLACE?"YES":"NO" );
toolTypes[0xB] = ConsTT( defTTs[11], cornerStrings[bPO->bp_BlankCorner] );
toolTypes[0xC] = ConsTT( defTTs[12], cornerStrings[bPO->bp_DontCorner] );
toolTypes[NUMTOOLTYPES] = NULL;
if( bDO = GetDiskObject( "PROGDIR:Garshneblanker" ))
{
oldToolTypes = bDO->do_ToolTypes;
bDO->do_ToolTypes = toolTypes;
PutDiskObject( "PROGDIR:Garshneblanker", bDO );
bDO->do_ToolTypes = oldToolTypes;
FreeDiskObject( bDO );
}
for( i = 0; i < NUMTOOLTYPES; i++ )
if( toolTypes[i] )
FreeVec( toolTypes[i] );
}
BlankerPrefs *LoadDefaultPrefs( VOID )
{
struct DiskObject *bDO;
if( bDO = GetDiskObject( "PROGDIR:Garshneblanker" ))
{
STRPTR tooltype;
if( tooltype = FindToolType( bDO->do_ToolTypes, "CX_PRIORITY" ))
PrefsRec.bp_Priority = atoi( tooltype );
if( tooltype = FindToolType( bDO->do_ToolTypes, "CX_POPUP" ))
PrefsRec.bp_PopUp = ( LONG )MatchToolValue( tooltype, "YES" );
if( tooltype = FindToolType( bDO->do_ToolTypes, "CX_POPKEY" ))
strcpy( PrefsRec.bp_PopKey, tooltype );
if( tooltype = FindToolType( bDO->do_ToolTypes, "BLANKKEY" ))
strcpy( PrefsRec.bp_BlankKey, tooltype );
if( tooltype = FindToolType( bDO->do_ToolTypes, "TIMEOUT" ))
PrefsRec.bp_Timeout = 10 * atoi( tooltype );
if( tooltype = FindToolType( bDO->do_ToolTypes, "BLANKER" ))
strcpy( PrefsRec.bp_Blanker, tooltype );
if( tooltype = FindToolType( bDO->do_ToolTypes, "BLANKERDIR" ))
strcpy( PrefsRec.bp_Dir, tooltype );
if( tooltype = FindToolType( bDO->do_ToolTypes, "LEFT" ))
PrefsRec.bp_Left = atoi( tooltype );
if( tooltype = FindToolType( bDO->do_ToolTypes, "TOP" ))
PrefsRec.bp_Top = atoi( tooltype );
if( tooltype = FindToolType( bDO->do_ToolTypes, "REPLACE" ))
PrefsRec.bp_Flags |=
( MatchToolValue( tooltype, "YES" ) ? BF_REPLACE : 0L );
if( tooltype = FindToolType( bDO->do_ToolTypes, "BLANKCORNER" ))
{
if( MatchToolValue( tooltype, "UPPERLEFT" ))
PrefsRec.bp_BlankCorner = BC_UPPERLEFT;
else if( MatchToolValue( tooltype, "UPPERRIGHT" ))
PrefsRec.bp_BlankCorner = BC_UPPERRIGHT;
else if( MatchToolValue( tooltype, "LOWERRIGHT" ))
PrefsRec.bp_BlankCorner = BC_LOWERRIGHT;
else if( MatchToolValue( tooltype, "LOWERLEFT" ))
PrefsRec.bp_BlankCorner = BC_LOWERLEFT;
}
if( tooltype = FindToolType( bDO->do_ToolTypes, "DONTCORNER" ))
{
if( MatchToolValue( tooltype, "UPPERLEFT" ))
PrefsRec.bp_DontCorner = BC_UPPERLEFT;
else if( MatchToolValue( tooltype, "UPPERRIGHT" ))
PrefsRec.bp_DontCorner = BC_UPPERRIGHT;
else if( MatchToolValue( tooltype, "LOWERRIGHT" ))
PrefsRec.bp_DontCorner = BC_LOWERRIGHT;
else if( MatchToolValue( tooltype, "LOWERLEFT" ))
PrefsRec.bp_DontCorner = BC_LOWERLEFT;
}
FreeDiskObject( bDO );
}
return &PrefsRec;
}
LONG EntriesInList( struct List *List )
{
struct Node *Counter;
LONG Entries;
for( Counter = List->lh_Head, Entries = 0; Counter->ln_Succ;
Counter = Counter->ln_Succ )
if( Counter->ln_Name[0] != '{' )
Entries++;
return Entries;
}
STRPTR RandomModule( VOID )
{
LONG i = EntriesInList( BlankerEntries ) - 1;
LONG Entry = RangeRand( i );
struct Node *TmpNode;
if( !i )
return "None";
for( TmpNode = BlankerEntries->lh_Head; TmpNode->ln_Name[0] == '{';
TmpNode = TmpNode->ln_Succ );
for( i = 0; i < Entry; TmpNode = TmpNode->ln_Succ )
if( TmpNode->ln_Name[0] != '{' )
i++;
for( ; TmpNode->ln_Name[0] == '{'; TmpNode = TmpNode->ln_Succ );
return TmpNode->ln_Name;
}