action/alias,doc
All checks were successful
/ job (push) Successful in 4m28s

This commit is contained in:
Marc Beninca 2025-07-06 06:41:44 +02:00
parent 30aead95e0
commit 1467c1158a
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
3 changed files with 72 additions and 43 deletions

View file

@ -41,6 +41,19 @@ BEGIN {
} }
{ {
if (action == "alias") {
if (match($0, RE_ALIAS, m)) {
append(m[1])
} else if (match($0, RE_FUNCTION, m)) {
n = split(doc, array, "\n")
for (i = 1; i<= n; i++) {
print array[i] "() { " m[1] " \"${@}\" ; }"
}
reset()
} else {
reset()
}
} else if (action == "doc") {
# doc # doc
if (match($0, RE_SHEBANG, m)) { if (match($0, RE_SHEBANG, m)) {
append("shebang: " m[1]) append("shebang: " m[1])
@ -92,3 +105,4 @@ BEGIN {
} }
} }
} }
}

View file

@ -185,11 +185,25 @@ RWX_REGEX_TARGET_FUNCTION="\
${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}" ${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}"
rwx_parse_code() { rwx_parse_code() {
# parse aliases
local line
RWX_ALIASES="$(rwx_parse_aliases)"
while IFS= read -r line; do
eval "${line}"
done <<EOF
${RWX_ALIASES}
EOF
# parse constants # parse constants
RWX_CONSTANTS="$(rwx_parse_constants)" RWX_CONSTANTS="$(rwx_parse_constants)"
# parse functions # parse functions
RWX_FUNCTIONS="$(rwx_parse_functions)" RWX_FUNCTIONS="$(rwx_parse_functions)"
} }
rwx_parse_aliases() {
printf "%s" "${_rwx_code}" |
awk \
--assign action="alias" \
--file "${RWX_AWK}"
}
rwx_parse_constants() { rwx_parse_constants() {
printf "%s\n" "${_rwx_code}" | printf "%s\n" "${_rwx_code}" |
sed --silent "s|${RWX_REGEX_TARGET_CONSTANT}|\\1|p" sed --silent "s|${RWX_REGEX_TARGET_CONSTANT}|\\1|p"

View file

@ -7,6 +7,7 @@ rwx_doc() {
[ -n "${name}" ] || return [ -n "${name}" ] || return
printf "%s" "${_rwx_code}" | printf "%s" "${_rwx_code}" |
awk \ awk \
--assign action="doc" \
--assign target="${name}" \ --assign target="${name}" \
--file "${RWX_AWK}" --file "${RWX_AWK}"
} }