From 2282ef61b60c1ce90ce7ac056781bfba0d7bdfec Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Sun, 6 Dec 2020 23:00:38 +0300 Subject: . --- articles.vs | 5 ----- articles/funweb.vs | 9 --------- articles/someweb.vs | 10 ---------- default.do | 5 ----- site/data/some | 8 ++++++++ vsvs | 44 -------------------------------------------- vsvs-extract | 43 +++++++++++++++++++++++++++++++++++++++++++ vsvs-locate | 2 +- vsvs-parse | 4 ++-- 9 files changed, 54 insertions(+), 76 deletions(-) delete mode 100644 articles.vs delete mode 100644 articles/funweb.vs delete mode 100644 articles/someweb.vs delete mode 100755 default.do create mode 100644 site/data/some delete mode 100755 vsvs create mode 100644 vsvs-extract diff --git a/articles.vs b/articles.vs deleted file mode 100644 index 902c495..0000000 --- a/articles.vs +++ /dev/null @@ -1,5 +0,0 @@ -template - - $title - $content - diff --git a/articles/funweb.vs b/articles/funweb.vs deleted file mode 100644 index a7770e1..0000000 --- a/articles/funweb.vs +++ /dev/null @@ -1,9 +0,0 @@ -title Web must be fun! -content - This operator can be used on a quotation or a dictionary:
- If a quotation quot is passed, it returns a new quotation - obtained by evaluating each element of quot in a separate stack.
- If a dictionary dict (with values and keys) is passed, - it returns a new dictionary obtained by evaluating each value - in the dict that is a symbol in a separate stack - (values that aren’t symbols stay as they are). diff --git a/articles/someweb.vs b/articles/someweb.vs deleted file mode 100644 index 4ef95a1..0000000 --- a/articles/someweb.vs +++ /dev/null @@ -1,10 +0,0 @@ -title Web must be! -content - Yeap! - This operator can be used on a quotation or a dictionary:
- If a quotation quot is passed, it returns a new quotation - obtained by evaluating each element of quot in a separate stack.
- If a dictionary dict (with values and keys) is passed, - it returns a new dictionary obtained by evaluating each value - in the dict that is a symbol in a separate stack - (values that aren’t symbols stay as they are). diff --git a/default.do b/default.do deleted file mode 100755 index 617cc1c..0000000 --- a/default.do +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -export title="$(vsvs-get title < $1.vs)" -export content="$(vsvs-get content < $1.vs)" -echo -n "$(vsvs-get template < articles.vs)" | shelter >$3; -redo-ifchange $1.vs articles.vs diff --git a/site/data/some b/site/data/some new file mode 100644 index 0000000..f9eae4a --- /dev/null +++ b/site/data/some @@ -0,0 +1,8 @@ +model + title string + content multiline +data + title Web must be fun! + content blah-blah + blah-blah + blah-blah diff --git a/vsvs b/vsvs deleted file mode 100755 index f486ba0..0000000 --- a/vsvs +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -# This is a parser of the Very Simple Values Storage. -# It has two arguments: an action and an object. -# Action is a string to be evaluated with key and its value provided. -action=$1 -# Object is like a path in filesystem (which pretty much it is), -# this is a string describing piece of data in storage. -object=$2 - -# Utility functions: -after () { test -z "${2##*$1*}" && echo -n "${2#*$1}" } - -# File processor: -pfile () { - # First of all, we need to lock the file. - lockfile="$base/proc/$proc/lock/$object" - mkdir -p -- "${lockfile%/*}" - echo $proc > $lockfile - lockpath="$path.lock" - if ln $lockfile $lockpath - then - # PARSER - rm $lockpath - fi - rm $lockfile -} - -# First of all, we need to locate object in filesystem. -# To do so, we will get parts of the path from the beginning of object, -# until we will run out of object or meet the file in filesystem. -test "${object::1}" == "/" && path=$base || path="." -lastpath=$object -until test -n "$lastpath" -do - # Tear another part of $lastpath until slash into $path: - path="$path/${lastpath%%/*}" - lastpath=$(after / "$lastpath") - # If $path does not exist, the object does not exist too, - test -e "$path" || exit 1 - # otherwise it can be file, then we need to parse it and exit, - # or it can be a directory, then we need to repeat the process. - test -f "$path" && pfile "$action" "$object" "$path" "$lastpath"; exit 0 -done diff --git a/vsvs-extract b/vsvs-extract new file mode 100644 index 0000000..a45d231 --- /dev/null +++ b/vsvs-extract @@ -0,0 +1,43 @@ +#!/bin/bash +after () { test -z "${2##*$1*}" && echo -n "${2#*$1}" } +vsvs-locate "$2" | { read path; read vsvspath; } || exit 1 +if test -f "$path" +then + lockfile="$base/proc/$proc/lock/" + if test "${path::1}" == "." + then lockfile="$lockfile$base$path" + else lockfile="$lockfile$path" + fi + mkdir -p -- "${lockfile%/*}" + echo $proc > $lockfile + lockpath="$path.lock" + ln $lockfile $lockpath || exit 1 # Error, cannot lock + data="$(cat $path)" + rm $lockpath + rm $lockfile + until test -z "$vsvspath" + do + data="$(echo -n "$data" | vsvs-parse " + if test \"\$key\" == \"${vsvspath%%/*}\" + then + echo \"\$value\" + exit 0 + fi")" + vsvspath=$(after / "$vsvspath") + done + echo -n "$data" | vsvs-parse "$1" +else + for key in `ls -a $path` + do + test "$key" == "." || test "$key" == ".." && continue + if test -f "$key" + then value=$(cat "$path/$key") + else + savedpath=$(pwd) + cd "$path/$key" + value=$(vsvs-archive) + cd "$savedpath" + fi + eval "$1" + done +fi diff --git a/vsvs-locate b/vsvs-locate index 5015529..21df2ac 100644 --- a/vsvs-locate +++ b/vsvs-locate @@ -1,5 +1,5 @@ #!/bin/bash -# Tear $1 into path to file (or directory) and in file, +# Tear $1 into path to file (or directory) and path in file, # if no such file exit with error. after () { test -z "${2##*$1*}" && echo -n "${2#*$1}"; } test "${1::1}" == "/" && path=$base || path="." diff --git a/vsvs-parse b/vsvs-parse index c06e777..2992136 100644 --- a/vsvs-parse +++ b/vsvs-parse @@ -9,9 +9,9 @@ do if test -z "${line%% *}" then value="${value}"$'\n'"$(after " " "$line")" else - eval $1 + test -z "$key" && eval $1 key="${line%% *}" value="$(after " " "$line")" fi done -eval $1 +test -z "$key" && eval $1 -- cgit v1.2.3