stew

a monorepo of some sort
Log | Files | Refs

commit a8bc4fcbe0d5907d1fa7b507fc3c37dcff773c60
parent e8fcfc35bdb4da086200c9c08bf77adac4198a65
Author: rpa <rpa@grass>
Date:   Sat, 23 Sep 2023 23:17:56 +0000

src/wdb: some rc scirpts

Diffstat:
Asrc/wdb/genindex | 33+++++++++++++++++++++++++++++++++
Asrc/wdb/new | 16++++++++++++++++
Asrc/wdb/search | 16++++++++++++++++
Asrc/wdb/tags | 7+++++++
Asrc/wdb/tagsearch | 9+++++++++
Asrc/wdb/typesearch | 9+++++++++
Asrc/wdb/ui | 16++++++++++++++++
Asrc/wdb/ui.inc | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 180 insertions(+), 0 deletions(-)

diff --git a/src/wdb/genindex b/src/wdb/genindex @@ -0,0 +1,33 @@ +#!/bin/rc + +rfork e + +fn index1 { + field=$1 + for (file in *) { + echo -n $"file^' ' + sed -n '/ *'$field' \\/p' $file | sed 's/.*\\//' + } +} + +fn indexs { + field=$1 + for (file in *) { + # echo $file + awk ' + BEGIN {pflag = 0} + /^[a-zA-Z]+/ {pflag = 0} + /^'$field'/ {pflag = 1} + /^ \\/ {if (pflag == 1) printf ("%s\t%s\n", "'$file'", substr($0, 3))} + ' $file + + } +} + +cd $home/lib/wdb/data + +echo Indexing names...; indexs name > $home/lib/wdb/index/name +echo Indexing tags...; index1 tags > $home/lib/wdb/index/tags +echo Indexing types...; index1 type > $home/lib/wdb/index/type +echo generating monodb...; wdb/print > $home/lib/wdb/index/all +echo Done. diff --git a/src/wdb/new b/src/wdb/new @@ -0,0 +1,16 @@ +#!/bin/rc + +rfork e + +id=`{uuid} +file=$home/lib/wdb/data/$id + +cat > $file <<EOF +name + \unnamed +tags \untagged +type \untyped +status \none +EOF + +echo $id diff --git a/src/wdb/search b/src/wdb/search @@ -0,0 +1,16 @@ +#!/bin/rc + +# Searches for entries by name. +# Operates on actual? data. +# returns a list of id's. + +rfork e + +# old code for operating on indexed data: +grep -i $"* $home/lib/wdb/index/name | sed 's/ .*//' | sort | uniq + +# new code for directly reading from data +# slower, and a hack +# (relies on names always and only field to start with tabslash) +# cd $home/lib/wdb/data +# grep -li '^ \\.*'^$"* * diff --git a/src/wdb/tags b/src/wdb/tags @@ -0,0 +1,7 @@ +#!/bin/rc +# print tag statistics +rfork e +lib=$home/lib/wdb +tf=$lib/index/tags + +sed 's/.* //;s/ /\n/g' $tf | sort | uniq -c | sort -r diff --git a/src/wdb/tagsearch b/src/wdb/tagsearch @@ -0,0 +1,9 @@ +#!/bin/rc +# Searches for entries by tag. +# Operates on indexed data. +# returns a list of id's. + +# TODO: should accept multiple tags + +rfork e +grep $"* $home/lib/wdb/index/tags | sed 's/ .*//' | sort | uniq diff --git a/src/wdb/typesearch b/src/wdb/typesearch @@ -0,0 +1,9 @@ +#!/bin/rc +# Searches for entries by type. +# Operates on indexed data. +# returns a list of id's. + +# TODO: should accept multiple tags + +rfork e +grep $"* $home/lib/wdb/index/type | sed 's/ .*//' | sort | uniq diff --git a/src/wdb/ui b/src/wdb/ui @@ -0,0 +1,16 @@ +#!/bin/rc + +rfork e + +guids=() + +cat <<EOF ++----------------------------------------------+ +| Welcome to the Weeb Data Base User Interface | ++----------------------------------------------+ +EOF + +while () { + . $home/bin/rc/wdb/ui.inc + main +} diff --git a/src/wdb/ui.inc b/src/wdb/ui.inc @@ -0,0 +1,74 @@ +wdb=$home/lib/wdb +data=$wdb/data +index=$wdb/index + +fn main_help { + echo \ +'h - help +i - regenerate index +s [query] - search +n - new entry +q - quit' +} + +fn printguid { + id=$1 + echo $data/$"id + cat $data/$"id + echo '---' +} + +fn printguids { + test -z $"guids || for (i in `{seq $#guids}) { + echo -n $i^': ' + printguid $guids($i) + } +} + +fn entry { + id=$1 + echo $data/$id + cat $data/$id +} + +fn main { + echo -n '→ ' + input=`{read} + cmd=$input(1) + arg=$input(2-) + switch ($"cmd) { + case h + main_help + case i + wdb/genindex + case s + guids=`{wdb/search $"arg} + echo Found $#guids entries. + printguids + case t + guids=`{wdb/tagsearch $"arg} + echo Found $#guids entries. + printguids + case T + guids=`{wdb/typesearch $"arg} + echo Fount $#guids entries. + printguids + case q + echo bye + exit + case p + printguids + case n + guids=`{wdb/new $"arg} + if (test -z $status) { + echo New entry: $data/$"guids + plumb -s 'wdb' $data/$"guids + } + case * + id=$guids($"cmd) + if ( test -n $"id -a -f $data/^$"id ) { + entry $"id + } + if not echo '?' + } +}