Initial (manual) import

This commit is contained in:
minexew committed 2017-01-22 20:26:44 +01:00
1 parent f39611c506
commit 895fe109de
661 files changed
+245862

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
U0 BlkDevRep()
{//Block Device Report.
I64 i;
for (i=0;i<BLKDEVS_NUM;i++)
if (blkdev.blkdevs[i].bd_signature==BD_SIGNATURE_VAL)
//$LK,"ClassRep",A="MN:ClassRep"$() dumps any structure, automatically.
ClassRep(&blkdev.blkdevs[i]);
//The lastclass arg tells ClassRep the datatype.
//lastclass is a language feature of $LK,"HolyC",A="FI:::/Doc/HolyC.DD"$.
//See $LK,"::/Demo/LastClass.HC"$.
}
BlkDevRep;
+64
View File
@@ -0,0 +1,64 @@
#define DB_FILENAME "~/DataBaseDemo.BIN"
#define DB_ACCT_MAX 100
#define DB_ACCT_BLKS 1
class Acct
{//Use <CTRL-l> to help generate fmtstrs.
U8 name[32] fmtstr "$$DA-P,LEN=32,A=\"Name:%s\"$$\n";
U8 addr[64] fmtstr "$$DA-P,LEN=64,A=\"Addr:%s\"$$\n";
U8 pad[DB_ACCT_BLKS*BLK_SIZE-64-32];
};
U0 InitDatabase()
{ //Write new contiguous file
CFile *f=FOpen(DB_FILENAME,"w",DB_ACCT_MAX*DB_ACCT_BLKS);
FClose(f);
}
U0 WriteAcct()
{
CFile *f;
Acct a;
I64 acctnum;
acctnum=GetI64("Acct #",-1);
if (0<=acctnum<DB_ACCT_MAX) {
MemSet(&a,0,BLK_SIZE);
if (DocForm(&a)) {
f=FOpen(DB_FILENAME,"w+");
FWBlks(f,&a,acctnum*DB_ACCT_BLKS,DB_ACCT_BLKS);
FClose(f);
}
}
}
U0 ReadAcct()
{
CFile *f;
Acct a;
I64 acctnum;
acctnum=GetI64("Acct #",-1);
if (0<=acctnum<DB_ACCT_MAX) {
f=FOpen(DB_FILENAME,"r");
FRBlks(f,&a,acctnum*DB_ACCT_BLKS,DB_ACCT_BLKS);
FClose(f);
ClassRep(&a);
}
}
U0 DatabaseDemo()
{
I64 ch;
if (!FileFind(DB_FILENAME))
InitDatabase;
do {
"$$GREEN$$R$$FG$$ead acct, $$GREEN$$W$$FG$$rite acct or $$GREEN$$<SHIFT-ESC>$$FG$$:";
ch=ToUpper(GetChar);
'\n';
if (ch=='R') ReadAcct;
if (ch=='W') WriteAcct;
} while (ch!=CH_SHIFT_ESC && ch!=CH_ESC);
}
DatabaseDemo;
+41
View File
@@ -0,0 +1,41 @@
U0 RawAccess(I64 drv_let=0)
{
CDrv *dv=Let2Drv(drv_let);
CBlkDev *bd=Let2BlkDev(drv_let);
I64 blk,old_offset,old_size;
U8 *buf=MAlloc(BLK_SIZE);
DrvRep;
PressAKey;
ClassRep(dv);
PressAKey;
ClassRep(bd);
PressAKey;
//Temporarily change partition range to full device.
//Normally, you are limited to just your partition.
//This is obviously $BK,1$dangerous$BK,0$!
old_offset=dv->drv_offset;
old_size =dv->size;
dv->drv_offset=0;
dv->size=bd->max_blk+1;
try {
blk=GetI64("Blk to Read: ",old_offset,0,bd->max_blk);
RBlks(dv,buf,blk,1);
D(buf,BLK_SIZE);
} catch
PutExcept;
dv->drv_offset=old_offset;
dv->size =old_size;
Free(buf);
}
RawAccess;
//See $LK,"RBlks",A="MN:RBlks"$(), $LK,"WBlks",A="MN:WBlks"$(), $LK,"DrvLock",A="MN:DrvLock"$(), $LK,"DrvUnlock",A="MN:DrvUnlock"$()
//$LK,"DBlk",A="MN:DBlk"$(), $LK,"DCluster",A="MN:DCluster"$(), $LK,"BlkDevLock",A="MN:BlkDevLock"$() and $LK,"BlkDevUnlock",A="MN:BlkDevUnlock"$().
+49
View File
@@ -0,0 +1,49 @@
/*There is no FPrintF type function and no
way to grow files. Therefore, use mem to
hold the file until you are done. The $LK,"CDoc",A="MN:CDoc"$
framework is convenient for this.
*/
U0 TreeSub(CDoc *doc,CDirEntry *tmpde)
{
CDirEntry *tmpde1;
while (tmpde) {
tmpde1=tmpde->next;
if (tmpde->attr & RS_ATTR_DIR) {
DocPrint(doc,"$$TR,\"\"$$");
DocPrint(doc,"$$MA,T=\"%s\",LM=\"Cd(\\\"%s\\\");Dir;\n\"$$\n",
tmpde->name,tmpde->full_name);
if (tmpde->sub) {
DocPrint(doc,"$$ID,+2$$");
TreeSub(doc,tmpde->sub);
DocPrint(doc,"$$ID,-2$$");
}
} else
DocPrint(doc,"$$LK,\"%s\",A=\"FI:%s\"$$\n",
tmpde->name,tmpde->full_name);
//Note there is also a routine
//to delete an entire CDirEntry tree.
//See $LK,"DirTreeDel",A="MN:DirTreeDel"$().
DirEntryDel(tmpde);
tmpde=tmpde1;
}
}
U0 FPrintFDemo(U8 *output_filename=NULL)
{
I64 fuf_flags=0;
CDoc *doc=DocNew(output_filename);
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
DocPrint(doc,"$$TR-C,\"\"$$\n");
DocPrint(doc,"$$ID,+2$$");
TreeSub(doc,FilesFind("/*",fuf_flags));
DocPrint(doc,"$$ID,-2$$");
DocRecalc(doc);
if (output_filename)
DocWrite(doc,FALSE);
else
DocWrite(doc,TRUE);
DocDel(doc);
}
FPrintFDemo;
+35
View File
@@ -0,0 +1,35 @@
/*You probably don't need this. It makes a directory
tree into a flat contiguous memory chunk, suitable for
serial communication and rebuilds it into a tree on the
other end.
*/
U0 SerializeTree()
{
CDirEntry *tmpde=FilesFind("/Demo/*.DD*",FUF_RECURSE);
I64 size;
U8 *ptr;
CArcCompress *arc;
LineRep1(tmpde); //We have $LK,"CDirEntry",A="MN:CDirEntry"$.fullname
LineRep2(DocPut,tmpde);
"$$GREEN$$***************$$FG$$\n";
ptr=DirTreeSerialize(tmpde,&size);
DirTreeDel(tmpde);
D(ptr,size);
"$$GREEN$$***************:%7d$$FG$$\n",size;
arc=CompressBuf(ptr,size);
Free(ptr);
D(arc,arc->compressed_size);
"$$GREEN$$***************:%7d$$FG$$\n",size;
ptr=ExpandBuf(arc);
size=arc->expanded_size;
Free(arc);
D(ptr,size);
"$$GREEN$$***************:%7d$$FG$$\n",size;
tmpde=DirTreeUnserialize(ptr);
LineRep2(DocPut,tmpde); //We don't have $LK,"CDirEntry",A="MN:CDirEntry"$.fullname
DirTreeDel(tmpde);
}
SerializeTree;
+12
View File
@@ -0,0 +1,12 @@
U0 UnusedSpaceRep()
{
I64 i;
CDrv *dv;
for (i=0;i<26;i++)
if ((dv=Let2Drv(i+'A',FALSE)) &&
(dv->fs_type==FSt_FAT32 || dv->fs_type==FSt_REDSEA))
"%C: %7.3f%% Free\n",
Drv2Let(dv),UnusedDrvSpace(Drv2Let(dv))*100.0/(dv->size*BLK_SIZE);
}
UnusedSpaceRep;