stew

a monorepo of some sort
Log | Files | Refs

commit 4d0d1a8baf562e323aaa75c4faf59b41656e66ac
parent 7d36f2ff42fcd7d49f9cac8f589b19fddd44ff5b
Author: rpa <rpa@laika>
Date:   Sun, 16 Apr 2023 15:17:53 +0000

src/tablist: start working on it

Diffstat:
Asrc/tablist/mkfile | 8++++++++
Asrc/tablist/readme | 20++++++++++++++++++++
Asrc/tablist/tablist.c | 39+++++++++++++++++++++++++++++++++++++++
Asrc/tablist/tablist.h | 7+++++++
4 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/src/tablist/mkfile b/src/tablist/mkfile @@ -0,0 +1,8 @@ +</$objtype/mkfile + +LIB=libtablist.a$O +OFILES=tablist.$O +HFILES=tablist.h +UPDATE= + +</sys/src/cmd/mklib diff --git a/src/tablist/readme b/src/tablist/readme @@ -0,0 +1,20 @@ +Tablist implements routines for working with structural format +described in https://github.com/nin-jin/tree.d + +It's a simple format that uses tabs and spaces to describe structure +and employs back-slashes ["\"] to mark raw data until newline. + +It looks something like this: + +root + key \value + spaces \ +root + very long hieararchy of nodes + multiline-content + \first + \second +\root-value +\ + \root + \value diff --git a/src/tablist/tablist.c b/src/tablist/tablist.c @@ -0,0 +1,39 @@ +#include <u.h> +#include <libc.h> + +#include "tablist.h" + +struct TLrow { + int indent; + TLNode *nodes; +}; + +int +_tlparseline(char *s, char *e) +{ + int ident = 0; + while (*s == '\t') { + ident++; + s++; + }; +} + +int +_tlparse(char *data, usize count) +{ + int rown = 0; + struct TLrow *rows = nil; + char *e, *p = data; + while (p < data + p) { + e = memchr(p, '\n', count - (p - data)); + if (e == nil) { + werrstr("newline not found"); + return -1; + } + if (p != e) { + _tlparseline(p, e); + } + p = e + 1; + rown++; + } +} diff --git a/src/tablist/tablist.h b/src/tablist/tablist.h @@ -0,0 +1,7 @@ +#pragma lib "../tablist/tablist.h" +typedef struct TLNode TLNode; +struct TLNode { + char *name; + char *value; + TLNode *children; +};