changelog shortlog tags branches changeset file revisions annotate raw help

Mercurial > hg > ventivac / appl/lib/venti.b

revision 118: bd3834e3d91a
parent 112: 994f59b44578
child 127: 7f377ffc9ad3
     1.1--- a/appl/lib/venti.b	Fri Aug 17 22:15:46 2007 +0200
     1.2+++ b/appl/lib/venti.b	Fri Aug 17 22:16:46 2007 +0200
     1.3@@ -555,110 +555,3 @@
     1.4 		}
     1.5 	return n;
     1.6 }
     1.7-
     1.8-gtstring(a: array of byte, o: int, n: int): string
     1.9-{
    1.10-	e := o + n;
    1.11-	if(e > len a)
    1.12-		return nil;
    1.13-	for(i := o; i < e; i++)
    1.14-		if(a[i] == byte 0)
    1.15-			break;
    1.16-	return string a[o:i];
    1.17-}
    1.18-unpackroot(d: array of byte): ref Root
    1.19-{
    1.20-	if(len d != Rootsize){
    1.21-		sys->werrstr("root entry is wrong length");
    1.22-		return nil;
    1.23-	}
    1.24-	r := ref blankroot;
    1.25-	r.version = g16(d, 0);
    1.26-	if(r.version != Rootversion){
    1.27-		sys->werrstr("unknown root version");
    1.28-		return nil;
    1.29-	}
    1.30-	o := BIT16SZ;
    1.31-	r.name = gtstring(d, o, Rootnamelen);
    1.32-	o += Rootnamelen;
    1.33-	r.rtype = gtstring(d, o, Rootnamelen);
    1.34-	o += Rootnamelen;
    1.35-	r.score = gscore(d, o);
    1.36-	o += Scoresize;
    1.37-	r.blocksize = g16(d, o);
    1.38-	o += BIT16SZ;
    1.39-	r.prev = gscore(d, o);
    1.40-	return r;
    1.41-}
    1.42-
    1.43-unpackentry(d: array of byte): ref Entry
    1.44-{
    1.45-	if(len d != Entrysize){
    1.46-		sys->werrstr("entry is wrong length");
    1.47-		return nil;
    1.48-	}
    1.49-	e := ref blankentry;
    1.50-	i := 0;
    1.51-	e.gen = g32(d, i);
    1.52-	i += BIT32SZ;
    1.53-	e.psize = g16(d, i);
    1.54-	i += BIT16SZ;
    1.55-	e.dsize = g16(d, i);
    1.56-	i += BIT16SZ;
    1.57-	e.flags = int d[i];
    1.58-	e.depth= (e.flags & Entrydepthmask) >> Entrydepthshift;
    1.59-	e.flags &= ~Entrydepthmask;
    1.60-	i += BIT8SZ;
    1.61-	i += 5;			# skip something...
    1.62-	e.size = g48(d, i);
    1.63-	i += BIT48SZ;
    1.64-	e.score = gscore(d, i);
    1.65-	i += Scoresize;
    1.66-	if((e.flags & Entryactive) == 0)
    1.67-		return e;
    1.68-	if(!checksize(e.psize) || !checksize(e.dsize)){
    1.69-		sys->werrstr(sys->sprint("bad blocksize (%d or %d)", e.psize, e.dsize));
    1.70-		return nil;
    1.71-	}
    1.72-	return e;
    1.73-}
    1.74-
    1.75-checksize(n: int): int
    1.76-{
    1.77-	if(n < 256 || n > Maxlumpsize) {
    1.78-		sys->werrstr("bad block size");
    1.79-		return 0;
    1.80-	}
    1.81-	return 1;
    1.82-}
    1.83-
    1.84-gscore(f: array of byte, i: int): Score
    1.85-{
    1.86-	s := Score(array[Scoresize] of byte);
    1.87-	s.a[0:] = f[i:i+Scoresize];
    1.88-	return s;
    1.89-}
    1.90-
    1.91-g16(f: array of byte, i: int): int
    1.92-{
    1.93-	return (int f[i] << 8) | int f[i+1];
    1.94-}
    1.95-
    1.96-g32(f: array of byte, i: int): int
    1.97-{
    1.98-	return (((((int f[i+0] << 8) | int f[i+1]) << 8) | int f[i+2]) << 8) | int f[i+3];
    1.99-}
   1.100-
   1.101-g48(f: array of byte, i: int): big
   1.102-{
   1.103-	b1 := (((((int f[i+0] << 8) | int f[i+1]) << 8) | int f[i+2]) << 8) | int f[i+3];
   1.104-	b0 := (int f[i+4] << 8) | int f[i+5];
   1.105-	return (big b1 << 16) | big b0;
   1.106-}
   1.107-
   1.108-g64(f: array of byte, i: int): big
   1.109-{
   1.110-	b0 := (((((int f[i+0] << 8) | int f[i+1]) << 8) | int f[i+2]) << 8) | int f[i+3];
   1.111-	b1 := (((((int f[i+4] << 8) | int f[i+5]) << 8) | int f[i+6]) << 8) | int f[i+7];
   1.112-	return (big b0 << 32) | (big b1 & 16rFFFFFFFF);
   1.113-}