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

View file

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