Implement replace and replace_sub to allow for keyword/value/replacement
[openresolv] / resolvconf.in
index d96ce0bee2f53e0eedd4b4c91b0bdf331dd6dd74..e4c2747fbfb4e673374f734c2cf040c7553f5d73 100644 (file)
@@ -354,6 +354,47 @@ echo_append()
        echo
 }
 
+replace()
+{
+       local r= k= f= v= val= sub=
+
+       while read -r keyword value; do
+               for r in $replace; do
+                       k="${r%%/*}"
+                       r="${r#*/}"
+                       f="${r%%/*}"
+                       r="${r#*/}"
+                       v="${r%%/*}"
+                       case "$keyword" in
+                       $k)
+                               case "$value" in
+                               $f) value="$v";;
+                               esac
+                               ;;
+                       esac
+               done
+               val=
+               for sub in $value; do
+                       for r in $replace_sub; do
+                               k="${r%%/*}"
+                               r="${r#*/}"
+                               f="${r%%/*}"
+                               r="${r#*/}"
+                               v="${r%%/*}"
+                               case "$keyword" in
+                               $k)
+                                       case "$sub" in
+                                       $f) sub="$v";;
+                                       esac
+                                       ;;
+                               esac
+                       done
+                       val="$val${val:+ }$sub"
+               done
+               printf "%s %s\n" "$keyword" "$val"
+       done
+}
+
 make_vars()
 {
        local newdomains= d= dn= newns= ns=
@@ -369,7 +410,7 @@ make_vars()
                eval "$(echo_prepend | parse_resolv)"
        fi
        if [ -z "$VFLAG" ]; then
-               eval "$(list_resolv -l "$@" | parse_resolv)"
+               eval "$(list_resolv -l "$@" | replace | parse_resolv)"
        fi
        if [ -n "$name_servers_append" -o -n "$search_domains_append" ]; then
                eval "$(echo_append | parse_resolv)"