diff options
| author | David du Colombier <0intro@gmail.com> | 2013-09-23 23:00:39 +0200 |
|---|---|---|
| committer | David du Colombier <0intro@gmail.com> | 2013-09-23 23:00:39 +0200 |
| commit | 6f4d00ee45693290fae042b27536b54f77b96acd (patch) | |
| tree | 60ad31bf16ed2000661c02345dd2a63851588a5d /src/cmd/fossil/walk.c | |
| parent | fea86f063930ea187f1c77e93207ac8d39125520 (diff) | |
| download | plan9port-6f4d00ee45693290fae042b27536b54f77b96acd.tar.gz plan9port-6f4d00ee45693290fae042b27536b54f77b96acd.zip | |
fossil: import from plan 9
R=rsc
https://codereview.appspot.com/7988047
Diffstat (limited to 'src/cmd/fossil/walk.c')
| -rw-r--r-- | src/cmd/fossil/walk.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/cmd/fossil/walk.c b/src/cmd/fossil/walk.c new file mode 100644 index 00000000..802af640 --- /dev/null +++ b/src/cmd/fossil/walk.c @@ -0,0 +1,65 @@ +/* + * Generic traversal routines. + */ + +#include "stdinc.h" +#include "dat.h" +#include "fns.h" + +static uint +etype(Entry *e) +{ + uint t; + + if(e->flags&VtEntryDir) + t = BtDir; + else + t = BtData; + return t+e->depth; +} + +void +initWalk(WalkPtr *w, Block *b, uint size) +{ + memset(w, 0, sizeof *w); + switch(b->l.type){ + case BtData: + return; + + case BtDir: + w->data = b->data; + w->m = size / VtEntrySize; + w->isEntry = 1; + return; + + default: + w->data = b->data; + w->m = size / VtScoreSize; + w->type = b->l.type; + w->tag = b->l.tag; + return; + } +} + +int +nextWalk(WalkPtr *w, uchar score[VtScoreSize], uchar *type, u32int *tag, Entry **e) +{ + if(w->n >= w->m) + return 0; + + if(w->isEntry){ + *e = &w->e; + entryUnpack(&w->e, w->data, w->n); + memmove(score, w->e.score, VtScoreSize); + *type = etype(&w->e); + *tag = w->e.tag; + }else{ + *e = nil; + memmove(score, w->data+w->n*VtScoreSize, VtScoreSize); + *type = w->type-1; + *tag = w->tag; + } + w->n++; + return 1; +} + |
