summaryrefslogtreecommitdiff
path: root/scripts/env2string.awk
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2021-11-28 20:38:01 -0500
committerTom Rini <[email protected]>2021-11-28 20:38:13 -0500
commitc087b5ad974441d1408c028eb7087d86b6d127e9 (patch)
tree1d5efba0d146dcd1a6a449963ea738cc6e4ff73e /scripts/env2string.awk
parent1943f2a2a7c58b76812fcad2d3012036af7464ce (diff)
parent452e8c9086a9f95739582da5ccc2130e4bf1ae8b (diff)
Merge tag 'dm-pull-28nov21' of https://source.denx.de/u-boot/custodians/u-boot-dm into next
SPI flash documentation and tidy-ups Various driver model enhancements Fix up some missing unit tests with pytest
Diffstat (limited to 'scripts/env2string.awk')
-rw-r--r--scripts/env2string.awk29
1 files changed, 20 insertions, 9 deletions
diff --git a/scripts/env2string.awk b/scripts/env2string.awk
index 57d0fc8f3ba..1bfe9ed07a4 100644
--- a/scripts/env2string.awk
+++ b/scripts/env2string.awk
@@ -21,29 +21,39 @@ BEGIN {
# Skip empty lines, as these are generated by the clang preprocessor
NF {
+ do_output = 0
+
# Quote quotes
gsub("\"", "\\\"")
+ # Avoid using the non-POSIX third parameter to match(), by splitting
+ # the work into several steps.
+ has_var = match($0, "^([^ \t=][^ =]*)=(.*)$")
+
# Is this the start of a new environment variable?
- if (match($0, "^([^ \t=][^ =]*)=(.*)$", arr)) {
+ if (has_var) {
if (length(env) != 0) {
# Record the value of the variable now completed
vars[var] = env
+ do_output = 1
}
- var = arr[1]
- env = arr[2]
+
+ # Collect the variable name. The value follows the '='
+ match($0, "^([^ \t=][^ =]*)=")
+ var = substr($0, 1, RLENGTH - 1)
+ env = substr($0, RLENGTH + 1)
# Deal with += which concatenates the new string to the existing
- # variable
- if (length(env) != 0 && match(var, "^(.*)[+]$", var_arr))
- {
+ # variable. Again we are careful to use POSIX match()
+ if (length(env) != 0 && match(var, "^(.*)[+]$")) {
+ plusname = substr(var, RSTART, RLENGTH - 1)
# Allow var\+=val to indicate that the variable name is
# var+ and this is not actually a concatenation
- if (substr(var_arr[1], length(var_arr[1])) == "\\") {
+ if (substr(plusname, length(plusname)) == "\\") {
# Drop the backslash
sub(/\\[+]$/, "+", var)
} else {
- var = var_arr[1]
+ var = plusname
env = vars[var] env
}
}
@@ -65,9 +75,10 @@ END {
# empty it is not set.
if (length(env) != 0) {
vars[var] = env
+ do_output = 1
}
- if (length(vars) != 0) {
+ if (do_output) {
printf("%s", "#define CONFIG_EXTRA_ENV_TEXT \"")
# Print out all the variables