commit d139e0cb9b2997316ddd0d29417d7b8e9e1f95d7
parent 4a719ad817fa583f48b8150f00bc2c0ef9f52723
Author: rpa <rpa@grass>
Date: Sat, 12 Aug 2023 23:46:03 +0000
src/tablist: it just works?
Diffstat:
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/src/tablist/example.tl b/src/tablist/example.tl
@@ -1,9 +1,12 @@
-Uno
- uno
- 1
-Duo
- duo
- 2
-\Uno
- \uno
- \1
+0UnoUnoUno
+1Uno 1Duo 1Tres
+3Uno
+ 3Duo
+ 3Tres
+ 3Quad
+ 5Quint
+\uno
+ \duo
+ \tres
+ \quad
+ \quint
diff --git a/src/tablist/mkfile b/src/tablist/mkfile
@@ -6,3 +6,6 @@ HFILES=tablist.h
UPDATE=
</sys/src/cmd/mklib
+
+mktest:V:
+ mk -f mktest
diff --git a/src/tablist/tablist.c b/src/tablist/tablist.c
@@ -114,8 +114,6 @@ TLdecode(TLdecoder *r, char *buf, usize count)
r->stack[r->sp] = new;
- print("indent %d sp %d %.*s\n", r->indent, r->sp, new->name->len, new->name->p);
-
if (buf[i] == ' ') r->state = Node, r->indent = -1, i++;
else r->state = Begin, i++;
break;
@@ -145,8 +143,6 @@ TLdecode(TLdecoder *r, char *buf, usize count)
r->stack[r->sp] = new;
- print("indent %d sp %d %.*s\n", r->indent, r->sp, new->value->len, new->value->p);
-
r->state = Begin, i++;
break;
@@ -225,10 +221,10 @@ _encnext(TLencoder *w, char *c)
TLnode *fc = nil;
if (n->children->len > 0) fc = *(TLnode **)slicegetp(n->children, 0);
if (n->children->len == 0) {
- print("no children\n");
w->cs[w->sp]++;
return _encnl(w, c);
} else if ((n->children->len == 1) && (fc->name != nil)) {
+ if (w->sp == 0) w->sp++;
w->ns[w->sp] = n->children;
w->cs[w->sp] = 0;
return _encsp(w, c);
@@ -243,10 +239,8 @@ _encnext(TLencoder *w, char *c)
void *
_encnl(TLencoder *w, char *c)
{
- print("nl\n");
*c = '\n';
while (w->cs[w->sp] == w->ns[w->sp]->len) {
- print("sp %d\n", w->sp);
w->sp--;
if (w->sp < 0) return _encend;
w->cs[w->sp]++;
@@ -277,7 +271,7 @@ void *
_encend(TLencoder *, char *c)
{
*c = '\0';
- return _encend;
+ return nil;
}
int
@@ -285,7 +279,7 @@ TLencode(TLencoder *w, char *buf, usize count)
{
usize i;
for (i = 0; i < count; i++) {
- if (w->state == _encend) return i;
+ if (w->state == nil) return i;
w->state = w->state(w, buf+i);
}
return i;