Category : C Source Code
Archive   : TC_CODE.ZIP
Filename : SPACE

 
Output of file : SPACE contained in archive : TC_CODE.ZIP
/* tiny-c/space manager
/*
/* initialize space to be be cells and chains
/* - always returns 0
/* - all cells placed on free-cell chain
/*
sinit int s(0),l,n [
int i
while((i=i+1)<=n) s(i)=0
s(0)=n+1;s(n+1)=0;s(n+2)=l-n
]
/*
/* print a map of the first chains in space
/* - always returns 0
/*
smap int s(0),n [
int i
while(i<=n) [
pl";pl";ps"chain;pn i
if(i==0) ps" (free-cell chain)"
if(s(i)>0) sprt(s,i)
if(s(i)==0) ps" is empty
i=i+1
]]
/*
/* print the structure of chain

in space
/* - always returns 0
/*
sprt int s(0),p [
pl"loc ptr len key;pl"
while(p=s(p)) [
pn p;pn s(p);pn s(p+1);pn s(p+2);pl"
]]
/*
/* get a block of cells from the free-cell chain of space
/* - return index of head of block
/* - return 0 if block of cells not available
/*
sget int s(0),l [
int pp,p,sp
sp=s(0)
while((p=sp)!=0) [
sp=s(p)
if(s(p+1)>=l+4) [
s(p+l)=sp
s(pp)=p+l
s(p+l+1)=s(p+1)-l
return p
]
else if (s(p+1)>=l) [
s(pp)=sp
return p
]
pp=p
]]
/*
/* append the block of cells at

to the free-cell chain of space
/* - always returns 0
/*
sfree int s(0),p,l [
int pp,sp




sp=s(0)
while((sp!=0)*(sp pp=sp;sp=s(sp)
]
s(pp)=p;s(p)=sp;s(p+1)=l
if((pp!=0)*(pp+s(pp+1)==p) [
s(p=pp)=sp;l=s(p+1)=l+s(p+1)
]
if((sp!=0)*(sp==p+l)) [
s(p)=s(sp);s(p+1)=s(p+1)+s(sp+1)
]]
/*
/* change the size of the block of cells at

in space from to
/* - return the index of the new block
/* - preserve the contents of the old block
/* - if new block smaller than old, return excess to free-cell chain
/* - return 0 if space unavailable for new block
/*
sgrow int s(0),p,l0,l1 [
int p1
if(l0>l1+2) [p1=p;sfree(s,p+l1,l0-l1)]
if(l0 if((p1=sget(s,l1))==0) return
scopy(s,p,l0,p1)
sfree(s,p,l0)
]
s(p1+1)=l1
return p1
]
/*
/* copy the cells at in space to
/* - always returns 0
/*
scopy int s(0),p0,l0,p1 [
int i
while(i s(p1+i)=s(p0+i)
i=i+1
]]
/*
/* modify the block with key on chain

in space to be of size
/* - return index of (the data part of) the block
/* - if is non-positive, delete the block & return 0
/* - if a block with key doesn't exist, allocate it
/* - if is positive & return is 0, space wasn't available
/*
sblock int s(0),p,key,l [
int pp
if(l<=0) return sdelete(s,p,key)
while(p=s(pp=p)) [
if(s(p+2)==key) [
if((p=sgrow(s,p,s(p+1),l+3))==0) return
s(pp)=p
return p+3
]
]
if((p=sget(s,l+3))==0) return
s(pp)=p;s(p)=0;s(p+1)=l+3;s(p+2)=key
return p+3
]
/*
/* locate the block with key on chain

of space




/* - return index of (the data part of) the block
/* - return 0 if block with key not found
/*
sloc int s(0),p,key [
while(p=s(p))
if(s(p+2)==key) return p+3
]
/*
/* delete the block with key from chain

in space
/* - always returns 0
/*
sdelete int s(0),p,key [
int pp
while(p=s(pp=p)) [
if(s(p+2)==key) [
s(pp)=s(p)
return sfree(s,p,s(p+1))
]
]]
(elete int s(0),p,key [
int pp
while(p=s(pp=p)) [
if(s(p+2)==key) [


  3 Responses to “Category : C Source Code
Archive   : TC_CODE.ZIP
Filename : SPACE

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/