This commit is contained in:
parent
30aead95e0
commit
1467c1158a
3 changed files with 72 additions and 43 deletions
14
sh/main.awk
14
sh/main.awk
|
@ -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
|
||||
if (match($0, RE_SHEBANG, m)) {
|
||||
append("shebang: " m[1])
|
||||
|
@ -92,3 +105,4 @@ BEGIN {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
sh/main.sh
14
sh/main.sh
|
@ -185,11 +185,25 @@ RWX_REGEX_TARGET_FUNCTION="\
|
|||
${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}"
|
||||
|
||||
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
|
||||
RWX_CONSTANTS="$(rwx_parse_constants)"
|
||||
# parse functions
|
||||
RWX_FUNCTIONS="$(rwx_parse_functions)"
|
||||
}
|
||||
rwx_parse_aliases() {
|
||||
printf "%s" "${_rwx_code}" |
|
||||
awk \
|
||||
--assign action="alias" \
|
||||
--file "${RWX_AWK}"
|
||||
}
|
||||
rwx_parse_constants() {
|
||||
printf "%s\n" "${_rwx_code}" |
|
||||
sed --silent "s|${RWX_REGEX_TARGET_CONSTANT}|\\1|p"
|
||||
|
|
|
@ -7,6 +7,7 @@ rwx_doc() {
|
|||
[ -n "${name}" ] || return
|
||||
printf "%s" "${_rwx_code}" |
|
||||
awk \
|
||||
--assign action="doc" \
|
||||
--assign target="${name}" \
|
||||
--file "${RWX_AWK}"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue