mk/make-release.txt: fix [51febf7e]: cat references were already present
[s-mailx.git] / mk / su-quote-rndtrip.sh
bloba27c0665221013ef07fa762d5f497b4d6287ed48
1 #!/bin/sh -
2 #@ Round trip quote strings in POSIX shell. E.g.,
3 #@ set -- x 'a \ b' "foo'" "\\'b\\a\\r\\" AƤ
4 #@ printf "%s: <%s><%s><%s><%s><%s>\n" "$#" "${1}" "${2}" "${3}" "$4" "$5"
5 #@ saved_parameters=`quote_rndtrip "$@"`
6 #@ eval "set -- $saved_parameters"
7 #@ printf "%s: <%s><%s><%s><%s><%s>\n" "$#" "${1}" "${2}" "${3}" "$4" "$5"
9 # 2017 Robert Elz (kre).
10 # 2017 - 2020 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
11 # Public Domain
13 # Though slower use a subshell version instead of properly restoring $IFS
14 # and flags, as elder shells may not be able to properly restore flags via
15 # "set +o" as later standardized in POSIX, and it seems overkill to handle
16 # all possible forms of output "set +o" may or may not actually generate.
17 quote__rndtrip() (
18 case "$1" in
19 *\'*) ;;
20 *) printf "'%s'" "$1"; return 0;;
21 esac
22 a="$1" s= e=
23 while case "$a" in
24 \'*) a=${a#?}; s="${s}\\\\'";;
25 *\') a=${a%?}; e="${e}\\\\'";;
26 '') printf "${s}${e}"; exit 0;;
27 *) false;;
28 esac
30 continue
31 done
32 IFS=\'
33 set -f
34 set -- $a
35 r="${1}"
36 shift
37 for a
39 r="${r}'\\''${a}"
40 done
41 printf "${s}'%s'${e}" "${r}"
42 exit 0
45 quote_rndtrip() (
47 for i
49 [ -n "$j" ] && printf ' '
50 j=' '
51 quote__rndtrip "$i"
52 done
55 quote_string() (
57 for i
59 [ -n "$j" ] && printf '\\ '
60 j=' '
61 quote__rndtrip "$i"
62 done
65 # s-sh-mode