diff options
Diffstat (limited to 'kconfigpp')
-rw-r--r-- | kconfigpp/kconfigpp.sh | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/kconfigpp/kconfigpp.sh b/kconfigpp/kconfigpp.sh index 90b03f1..0518544 100644 --- a/kconfigpp/kconfigpp.sh +++ b/kconfigpp/kconfigpp.sh @@ -22,33 +22,62 @@ set -u main() { + local script= + local arg= + local var= + local val= + + if [ ${#} -lt 1 ]; then + usage >&2 + exit 1 + fi + + script='' + for arg in "${@}"; do + case "${arg}" in + *=*) + IFS='=' read var val <<-EOF + ${arg} + EOF + val="$(printf '%s' "${val}" | sed 's|/|\\/|g')" + script="${script}s/\$${var}/${val}/g;" + shift 1 + ;; + *) + break + esac + done + if [ ${#} -ne 1 ]; then usage >&2 exit 1 fi - parse "${1}" + parse "${1}" "${script}" } usage() { - printf 'Usage: %s <kconfig-file>\n' "${0}" + printf 'Usage: %s [<var>=<val> ...] <kconfig-file>\n' "${0}" } parse() { local file="${1}" + local script="${2}" local line= while IFS='' read line; do if [ "x${line}" != "x${line#source}" ]; then line="$(printf '%s' "${line}" | \ sed 's/^source[ \t][ \t]*"*\([^"]*\).*$/\1/')" - parse "${line}" + parse "${line}" "${script}" else printf '%s\n' "${line}" fi - done <"${file}" + done <<-EOF + $(sed "${script}" <"${file}") + EOF } main "${@}" |