diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2020-06-18 19:45:40 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2020-06-18 19:45:40 -0700 |
commit | 425ef692da7e74112f88f0b368f3286dba84f846 (patch) | |
tree | d45729e90010e8d8c539031c3b72165f6884575d /sys/cmd/rc/word.c | |
parent | 0522b4bf4e125b7ceb67f7177db692aed3a0ebf9 (diff) |
feat: working parser for rc shell language
Diffstat (limited to 'sys/cmd/rc/word.c')
-rw-r--r-- | sys/cmd/rc/word.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/sys/cmd/rc/word.c b/sys/cmd/rc/word.c new file mode 100644 index 0000000..84ff40c --- /dev/null +++ b/sys/cmd/rc/word.c @@ -0,0 +1,64 @@ +#include "rc.h" + +void +pushlist(void) +{ + List *ls; + + alloc(ls); + ls->words = nil; + ls->link = shell->stack, shell->stack = ls; +} + +void +freelist(Word *w) +{ + Word *it; + while (w) { + it = w->link; + efree(w->word); + efree(w); + w = it; + } +} + +void +poplist(void) +{ + List *ls = shell->stack; + if (!ls) + panicf("shell stack underflow"); + + freelist(ls->words); + shell->stack = ls->link; + efree(ls); +} + +int +count(Word *w) +{ + int n; + for (n=0; w; n++) + w = w->link; + return n; +} + +Word* +newword(char *w, Word *link) +{ + Word *wd; + + alloc(wd); + wd->word = strdup(w); + wd->link = link; + + return wd; +} + +void +pushword(char *w) +{ + if (shell->stack == nil) + panicf("no active stack"); + shell->stack->words = newword(w, shell->stack->words); +} |