/[polypkg]/trunk/pp.expand
ViewVC logotype

Contents of /trunk/pp.expand

Parent Directory Parent Directory | Revision Log Revision Log


Revision 189 - (show annotations)
Wed Oct 15 22:57:46 2008 UTC (13 months ago) by dleonard
File size: 2048 byte(s)
remove archaic vararg form: ${1+"$@"} -> "$@"  
1 #
2 # {}-expansion is a tricky problem. Not all shells seem to be the same,
3 # but this is such a useful thing to have. It turns out that some korn
4 # shells have something similar available when bourne shells don't.
5 # The glob format is @(word|word|word) instead of {word,word,word}.
6 #
7
8 pp_expand_path=
9
10 #@ pp_expand_test_usr_bin(): returns true if input is /usr and /bin
11 pp_expand_test_usr_bin () {
12 awk '$1 == "/usr" || $2 == "/usr" {usr++}
13 $1 == "/bin" || $2 == "/bin" {bin++}
14 END { if (usr == 1 && bin == 1) exit(0); else exit(1); }'
15 }
16
17 #@ pp_set_expand_converter_or_reexec(arg...): sets $pp_expand_path
18 pp_set_expand_converter_or_reexec () {
19 test -d /usr -a -d /bin ||
20 pp_die "missing /usr or /bin"
21 echo /usr /bin | pp_expand_test_usr_bin || pp_die "pp_expand_test_usr_bin?"
22 if (eval "echo /{usr,bin}" | pp_expand_test_usr_bin) 2>/dev/null; then
23 pp_expand_path=pp_expand_path_brace
24 elif (eval "echo /@(usr|bin)" | pp_expand_test_usr_bin) 2>/dev/null; then
25 pp_expand_path=pp_expand_path_at
26 else
27 test x"$pp_expand_rexec" != x"true" ||
28 pp_die "problem finding shell that can do brace expansion"
29 for shell in ksh ksh93 bash; do
30 if ($shell -c 'echo /{usr,bin}' |
31 pp_expand_test_usr_bin) 2>/dev/null ||
32 ($shell -c 'echo /@(usr|bin)' |
33 pp_expand_test_usr_bin) 2>/dev/null
34 then
35 pp_debug "switching to shell $shell"
36 pp_expand_rexec=true exec $shell "$0" "$@"
37 fi
38 done
39 pp_die "cannot find a shell that does brace expansion"
40 fi
41 }
42
43 #@ pp_expand_path_brace(path): writes all expansions of path to stdout
44 pp_expand_path_brace () {
45 typeset f
46 eval "for f in $1; do echo \"\$f\"; done|sort -u"
47 }
48
49 #@ pp_expand_path_at(path): writes all expansions of path to stdout
50 # works by translating {word,word} into @(word|word) then evaluating
51 # FIXME: this function will break if there are commas, braces or escapes
52 pp_expand_path_at () {
53 typeset f
54 eval "for f in `
55 echo "$1" | sed -e 's/{/@(/g' -e 's/}/)/g' -e 's/,/|/g'
56 `; do echo \"\$f\"; done|sort -u"
57 }

Ted.Percival@quest.com
ViewVC Help
Powered by ViewVC 1.1.2