diff options
author | P. J. McDermott <pj@pehjota.net> | 2014-11-24 15:28:32 (EST) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2014-11-24 15:28:32 (EST) |
commit | ad6a802106dbb5432d8f65e3803f658abda8c7c6 (patch) | |
tree | f8070c4c1fed7193a240c053fc0d7d4abbf4d549 | |
parent | 8ed1b04d2ac1e200a33338a00f35176cefdc8e7d (diff) |
kconfigpp: Substitute variables
-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 "${@}" |