home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d5xx
/
d564
/
dopro.lha
/
DoPro
/
src.lzh
/
DoProDat.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-07
|
3KB
|
136 lines
/***************************************************************************/
/* */
/* D O P R O V1.5 */
/* */
/***************************************************************************/
/* */
/* This file defines the data structures and routines for loading, saving */
/* and maintaning of the database */
/* */
/***************************************************************************/
/* maximum length of a screen title */
#define MaxTitleLen 40
/* structure for data saving */
struct MyNewScreen
{
WORD LeftEdge, TopEdge, Width, Height, Depth;
WORD OldLeftEdge, OldTopEdge, OldWidth, OldHeight;
UBYTE DetailPen, BlockPen;
UWORD ViewModes;
UWORD Type;
UBYTE DefaultTitle[MaxTitleLen];
BOOL Topaz;
ULONG DisplayID;
struct MyNewScreen *Next;
};
#define mnsSize sizeof(struct MyNewScreen)
/* the list of MyNewScreen structures */
static struct MyNewScreen *Root = NULL;
/* compares a MyNewsScreen with a NewScreen */
static BOOL CompScreen(struct MyNewScreen *mns, struct NewScreen *ns)
{
return (mns->OldLeftEdge == ns->LeftEdge)
&& (mns->OldTopEdge == ns->TopEdge)
&& (mns->OldWidth == ns->Width)
&& (mns->OldHeight == ns->Height)
&& (mns->Depth == ns->Depth)
&& (mns->DetailPen == ns->DetailPen)
&& (mns->BlockPen == ns->BlockPen)
&& (mns->ViewModes == ns->ViewModes)
&& (mns->Type == ns->Type)
&& (!strncmp(mns->DefaultTitle, ns->DefaultTitle, MaxTitleLen));
}
/* tries to find the screen in database */
ULONG CheckScreen(struct NewScreen *ns)
{
struct MyNewScreen *List = Root;
extern struct TextAttr MyAttr;
/* screen already in list ? */
while ((List != NULL) && (!CompScreen(List, ns))) List = List->Next;
if (!List)
{
/* no! */
List = AllocMem(mnsSize, MEMF_ANY);
List->OldLeftEdge = ns->LeftEdge;
List->OldTopEdge = ns->TopEdge;
List->OldWidth = ns->Width;
List->OldHeight = ns->Height;
List->Depth = ns->Depth;
List->DetailPen = ns->DetailPen;
List->BlockPen = ns->BlockPen;
List->ViewModes = ns->ViewModes;
List->Type = ns->Type;
strncpy(List->DefaultTitle, ns->DefaultTitle, MaxTitleLen);
List->Topaz = FALSE;
/* show the requester */
List->DisplayID = ScreenRequest(ns, &List->Topaz);
List->LeftEdge = ns->LeftEdge;
List->TopEdge = ns->TopEdge;
List->Width = ns->Width;
List->Height = ns->Height;
List->Next = Root;
Root = List;
}
ns->LeftEdge = List->LeftEdge;
ns->TopEdge = List->TopEdge;
ns->Width = List->Width;
ns->Height = List->Height;
if (List->Topaz) ns->Font = &MyAttr;
/* return the new DisplayID */
return List->DisplayID;
}
/* save the database and free it */
void SaveData(void)
{
struct MyNewScreen *List, *Next;
BPTR File;
File = Open("s:DoPro.config", MODE_NEWFILE);
List = Root;
if (List) Next = List->Next;
while (List)
{
Write(File, List, mnsSize);
FreeMem(List, mnsSize);
List = Next;
if (List) Next = List->Next;
}
Close(File);
}
/* load and allocate the database */
void LoadData(void)
{
struct MyNewScreen *List;
BPTR File;
if (File = Open("s:DoPro.config", MODE_OLDFILE))
{
List = AllocMem(mnsSize, MEMF_ANY);
while (Read(File, List, mnsSize) == mnsSize)
{
List->Next = Root;
Root = List;
List = AllocMem(mnsSize, MEMF_ANY);
}
FreeMem(List, mnsSize);
Close(File);
}
}