LTCD_070816.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:45:20 +02:00
1 parent d14bbc24f9
commit 0e9364ff4c
506 files changed
+157705 -41812

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
#define DB_FILENAME "HOME/DataBaseDemo.BIN"
#define DB_MAX_ACCOUNT 100
#define DB_ACCOUNT_BLKS 1
class Account
{ //Use $FG,2$CTRL-L$FG$ to help generate $FG,2$fmtstr$FG$s.
I1 name[32] fmtstr "$$DA-P,32,\"Name:%s\"$$\r\n";
I1 address[64] fmtstr "$$DA-P,64,\"Address:%s\"$$\r\n";
U1 pad[DB_ACCOUNT_BLKS*BLK_SIZE-64-32];
};
void InitDatabase()
{
LTFile *f;
//Write new contiguous file
f=FOpen(DB_FILENAME,"wc",DB_MAX_ACCOUNT*DB_ACCOUNT_BLKS);
FClose(f);
}
void WriteAcct()
{
LTFile *f;
Account a;
I8 acctnum;
acctnum=PmtI8("Account #",-1);
if (acctnum>=0 && acctnum<DB_MAX_ACCOUNT) {
MemSet(&a,0,BLK_SIZE);
if (DoForm(&a,"Account")) {
f=FOpen(DB_FILENAME,"w+");
FWBlks(f,&a,acctnum*DB_ACCOUNT_BLKS,DB_ACCOUNT_BLKS);
FClose(f);
}
}
}
void ReadAcct()
{
LTFile *f;
Account a;
I8 acctnum;
acctnum=PmtI8("Account #",-1);
if (acctnum>=0 && acctnum<DB_MAX_ACCOUNT) {
f=FOpen(DB_FILENAME,"r");
FRBlks(f,&a,acctnum*DB_ACCOUNT_BLKS,DB_ACCOUNT_BLKS);
FClose(f);
ClassRep("Account",&a);
}
}
void DatabaseDemo()
{
I1 ch;
if (!FindFile(DB_FILENAME))
InitDatabase;
do {
cout "$$FG,GREEN$$R$$FG$$ead or $$FG,GREEN$$W$$FG$$rite account:";
ch=ToUpper(GetChar);
CrLf;
if (ch=='R') ReadAcct;
if (ch=='W') WriteAcct;
} while (ch!=CH_CTRLQ && ch!=CH_ESC);
}
DatabaseDemo;