stew

a monorepo of some sort
Log | Files | Refs

commit fcf6087676b59412bf56b460d3f396a839566e18
parent a68de3466d84ec72c2838d4a4ae20a3a03588802
Author: rpa <rpa@laika>
Date:   Sat, 15 Jul 2023 22:16:44 +0000

src/tablist: probably some code

Diffstat:
Msrc/tablist/tablist.c | 51++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 11 deletions(-)

diff --git a/src/tablist/tablist.c b/src/tablist/tablist.c @@ -131,10 +131,13 @@ TLdecode(TLdecoder *r, char *buf, usize count) /******* ENCODER *******/ typedef void * (TLencstate)(TLencoder *, char *); -TLencstate _encnode, _encname, _encvalue, _encnl, _encsp, _encind, _encend; +TLencstate _encnode, _encname, _encvalue, _encnext, + _encnl, _encsp, _encind, _encend; + + +#define ENCTOS(X) ( *(TLnode **)slicegetp(X->ns[X->sp], X->cs[X->sp]) ) +// #define ENCTOS(X) ( *(TLnode **)slicegetp(X->ns[0], 0) ) -// #define ENCTOS(X) ( *(TLnode **)slicegetp(X->ns[X->sp], X->cs[X->sp]) ) -#define ENCTOS(X) ( *(TLnode **)slicegetp(X->ns[0], 0) ) TLencoder * initTLencoder(Slice *nodes) { @@ -148,9 +151,7 @@ void * _encnode(TLencoder *w, char *c) { print("node [%d %d]\n", w->sp, w->cs[w->sp]); - // TLnode *n = ENCTOS(w); - TLnode **v = slicegetp(w->ns[0], 0); - TLnode *n = *v; + TLnode *n = ENCTOS(w); assert(n != nil); _printnode(n); w->i = 0; @@ -164,7 +165,7 @@ _encname(TLencoder *w, char *c) { print("name\n"); TLnode *n = ENCTOS(w); - if (w->i >= n->name->len) return _encnl(w, c); + if (w->i >= n->name->len) return _encnext(w, c); char *s = slicegetp(n->name, w->i); *c = *s; w->i++; @@ -176,7 +177,7 @@ _encvalue(TLencoder *w, char *c) { print("value\n"); TLnode *n = ENCTOS(w); - if (w->i >= n->value->len) return _encnl(w, c); + if (w->i >= n->value->len) return _encnext(w, c); char *s = slicegetp(n->value, w->i); *c = *s; w->i++; @@ -184,11 +185,32 @@ _encvalue(TLencoder *w, char *c) } void * -_encnl(TLencoder *, char *c) +_encnext(TLencoder *w, char *c) +{ + print("next\n"); + TLnode *n = ENCTOS(w); + if (n->children->len == 0) { + w->cs[w->sp]++; + return _encnl(w, c); + } else if (n->children->len == 1) { + w->sp++; + w->ns[w->sp] = n->children; + w->cs[w->sp] = 0; + return _encsp(w, c); + } else { + return _encend(w, c); + } +} + +void * +_encnl(TLencoder *w, char *c) { print("nl\n"); *c = '\n'; - return _encend; + if (w->ns[w->sp]->len == w->cs[w->sp]) return _encend; + return _encind; + + } void * @@ -196,7 +218,14 @@ _encsp(TLencoder *, char *c) { print("sp\n"); *c = ' '; - return _encend; + return _encnode; +} + +void * +_encind(TLencoder *w, char *c) +{ + print("ind\n"); + return _encnode(w, c); } void *