Compare commits

..

No commits in common. "465f0ba475f67c24adda2e5440ffec49d17bd8ba" and "9d7c77b881120d7185e9cb1cb8c42e344c4f8138" have entirely different histories.

2 changed files with 61 additions and 69 deletions

View file

@ -1,5 +1,4 @@
#! /usr/bin/env sh #! /usr/bin/env sh
# main module
# ╭──────╮ # ╭──────╮
# │ main │ # │ main │
@ -9,7 +8,6 @@
# │ main │ constants │ # │ main │ constants │
# ╰──────┴───────────╯ # ╰──────┴───────────╯
# name of the entrypoint file
RWX_MAIN_NAME="main.sh" RWX_MAIN_NAME="main.sh"
RWX_SELF_NAME="rwx" RWX_SELF_NAME="rwx"
@ -63,20 +61,44 @@ rwx_main() {
# │ main │ cache │ # │ main │ cache │
# ╰──────┴───────╯ # ╰──────┴───────╯
RWX_CODE=""
# cache source code of a module
rwx_cache() { rwx_cache() {
local root="${1}" local root="${1}"
local module="${2}" local module="${2}"
local name="${module%.sh}" local name="${module%.sh}"
local path="${root}/${module}" local path="${root}/${module}"
local text local fill text
fill="$(rwx_fill "${#name}")"
text="$(cat "${path}")" text="$(cat "${path}")"
RWX_CODE="${RWX_CODE}\ case "${text}" in
#↓ ${name} "#!"*)
${text} RWX_CODE="${text}
"
# ╭───┬────┬─${fill}─╮
# │ ↖ │ sh │ ${name} │
# ╰───┴────┴─${fill}─╯"
;;
*)
RWX_CODE="${RWX_CODE}
# ╭───┬────┬─${fill}─╮
# │ ↙ │ sh │ ${name} │
# ╰───┴────┴─${fill}─╯
${text}"
;;
esac
}
# ╭──────┬──────╮
# │ main │ fill │
# ╰──────┴──────╯
rwx_fill() {
local index="${1}"
while [ "${index}" -gt 0 ]; do
printf "%s" "${2}"
index=$((index - 1))
done
} }
# ╭──────┬────────╮ # ╭──────┬────────╮
@ -93,17 +115,16 @@ rwx_source() {
count=0 count=0
__rwx_log "" \ __rwx_log "" \
". ${root}" ". ${root}"
local modules="$(rwx_find_shell "${root}" "${file}")" rwx_ifs_set
while IFS= read -r module; do for module in $(rwx_find_shell "${root}" "${file}"); do
count=$((count + 1)) count=$((count + 1))
__rwx_log "$(printf "%02d" "${count}") ${module%.sh}" __rwx_log "$(printf "%02d" "${count}") ${module%.sh}"
# shellcheck disable=SC1090 # shellcheck disable=SC1090
. "${root}/${module}" . "${root}/${module}"
# cache code # cache code
rwx_cache "${root}" "${module}" rwx_cache "${root}" "${module}"
done <<EOF done
${modules} rwx_ifs_unset
EOF
} }
# ╭──────┬─────╮ # ╭──────┬─────╮
@ -188,22 +209,22 @@ rwx_parse() {
local func="${ws}(${ws})${ws}{.*" local func="${ws}(${ws})${ws}{.*"
local id="[_a-zA-Z][_a-z0-9A-Z]*" local id="[_a-zA-Z][_a-z0-9A-Z]*"
local line local line
rwx_ifs_set
RWX_CONSTANTS="" RWX_CONSTANTS=""
printf "%s\n" "${RWX_CODE}" | for line in $(echo "${RWX_CODE}" |
grep "${start}${constant}${setting}" | grep "${start}${constant}${setting}" |
sed "s|${start}\\(${constant}\\)${setting}|\\1|" | sed "s|${start}\\(${constant}\\)${setting}|\\1|"); do
while IFS= read -r line; do
RWX_CONSTANTS="${RWX_CONSTANTS}${line} RWX_CONSTANTS="${RWX_CONSTANTS}${line}
" "
done done
RWX_FUNCTIONS="" RWX_FUNCTIONS=""
printf "%s\n" "${RWX_CODE}" | for line in $(echo "${RWX_CODE}" |
grep "${start}${id}${func}" | grep "${start}${id}${func}" |
sed "s|${start}\\(${id}\\)${func}|\\1|" | sed "s|${start}\\(${id}\\)${func}|\\1|"); do
while IFS= read -r line; do
RWX_FUNCTIONS="${RWX_FUNCTIONS}${line} RWX_FUNCTIONS="${RWX_FUNCTIONS}${line}
" "
done done
rwx_ifs_unset
} }
# ╭──────┬─────╮ # ╭──────┬─────╮

View file

@ -1,50 +1,22 @@
# self module
# meta doc # meta doc
rwx_doc() { rwx_doc() {
local name="${1}" local name="${1}"
[ -n "${name}" ] || return [ -n "${name}" ] || return
local constant doc func line module local doc line module
printf "%s\n" "${RWX_CODE}" | while IFS= read -r line; do rwx_ifs_set
case "${line}" in for module in $(rwx_find_shell "${RWX_ROOT_SYSTEM}"); do
"#!"*) doc="" ;; while read -r line; do
"#↓"*) case "${line}" in
doc="" "#"*) doc="${doc}${line}" ;;
module="$(echo "${line}" | sed "s|#↓ \\(.*\\)|\\1|")" "${name}() {")
echo "${doc}"
return
;; ;;
"#"*) *) doc="" ;;
[ -n "${doc}" ] && doc="${doc} esac
" done <"${RWX_ROOT_SYSTEM}/${module}"
doc="${doc}${line}"
;;
*"="*)
constant="$(echo "${line}" | sed "s|^\\(.*\\)=.*|\\1|")"
if [ "${constant}" = "${name}" ]; then
echo "${doc}"
return
else
doc=""
fi
;;
*"("*")"*"{"*)
func="$(echo "${line}" | sed "s|^\\(.*\\)() {.*|\\1|")"
if [ "${func}" = "${name}" ]; then
echo "${doc}"
return
else
doc=""
fi
;;
*)
if [ "${module}" = "${name}" ]; then
echo "${doc}"
return
else
doc=""
fi
;;
esac
done done
rwx_ifs_unset
} }
# ╭──────┬───────╮ # ╭──────┬───────╮
@ -155,17 +127,16 @@ export ENV=\"${RWX_MAIN_PATH}\"
# ╰──────┴────────╯ # ╰──────┴────────╯
rwx_self_subset() { rwx_self_subset() {
local argument file root local argument path
for argument in "${@}"; do for argument in "${@}"; do
root="${RWX_ROOT_SYSTEM}/${argument}" path="${RWX_ROOT_SYSTEM}/${argument}"
file="${argument}.sh" if [ -d "${path}" ]; then
if [ -d "${root}" ]; then
local file local file
for file in $(rwx_find_shell "${root}"); do for file in $(rwx_find_shell "${path}"); do
echo "${argument}/${file}" echo "${argument}/${file}"
done done
elif [ -f "${RWX_ROOT_SYSTEM}/${file}" ]; then elif [ -f "${path}" ]; then
echo "${file}" echo "${argument}"
fi fi
done done
} }