+#if BASH_PATTERN_SUBST
+ /* For "${v/pattern/repl}", we must find the delimiter _before_
+ * argstr() call expands possible variable references in pattern:
+ * think about "v=a; a=a/; echo ${v/$a/r}" case.
+ */
+ repl = NULL;
+ if (subtype == VSREPLACE || subtype == VSREPLACEALL) {
+ /* Find '/' and replace with NUL */
+ repl = p;
+ /* The pattern can't be empty.
+ * IOW: if the first char after "${v//" is a slash,
+ * it does not terminate the pattern - it's the first char of the pattern:
+ * v=/dev/ram; echo ${v////-} prints -dev-ram (pattern is "/")
+ * v=/dev/ram; echo ${v///r/-} prints /dev-am (pattern is "/r")
+ */
+ if (*repl == '/')
+ repl++;
+ for (;;) {
+ if (*repl == '\0') {
+ repl = NULL;
+ break;
+ }
+ if (*repl == '/') {
+ *repl = '\0';
+ break;
+ }
+ /* Handle escaped slashes, e.g. "${v/\//_}" (they are CTLESC'ed by this point) */
+ if ((unsigned char)*repl == CTLESC && repl[1])
+ repl++;
+ repl++;
+ }
+ }
+#endif
+ argstr_flags = EXP_TILDE;
+ if (subtype != VSASSIGN
+ && subtype != VSQUESTION
+#if BASH_SUBSTR
+ && subtype != VSSUBSTR
+#endif
+ ) {
+ /* EXP_CASE keeps CTLESC's */
+ argstr_flags = EXP_TILDE | EXP_CASE;
+ }
+ argstr(p, argstr_flags);
+ //bb_error_msg("str0:'%s'", (char *)stackblock() + strloc);
+#if BASH_PATTERN_SUBST
+ slash_pos = -1;
+ if (repl) {
+ slash_pos = expdest - ((char *)stackblock() + strloc);
+ STPUTC('/', expdest);
+ //bb_error_msg("repl+1:'%s'", repl + 1);
+ argstr(repl + 1, EXP_TILDE); /* EXP_TILDE: echo "${v/x/~}" expands ~ ! */
+ *repl = '/';
+ }
+#endif