root/mpich2/branches/dev/kumudb/confdb/aclocal_util.m4 @ 4870

Revision 4870, 3.5 KB (checked in by kumudb, 5 months ago)

Merge from trunk to kumudb r4748:r4869

Line 
1dnl
2dnl PAC_APPEND_UNIQ_TOKEN( VARIABLE_NAME, TOKEN )
3dnl token is defined as string without any blank space in it.
4dnl
5AC_DEFUN([PAC_APPEND_UNIQ_TOKEN],[
6dnl Since PAC_APPEND_UNIQ_TOKEN may be called by PAC_MAKE_UNIQ_STRING
7dnl saved IFS should be in a different variable than MAKE_UNIQ_STRING's.
8dnl Otherwise bad thing will happen.
9save_IFS="$IFS"
10dnl eval flags=\$$1
11flags="[$]$1"
12token=$2
13dnl
14IFS=' '
15match=no
16for flag in $flags ; do
17    if test "$flag" = "$token" ; then
18        match=yes
19        break
20    fi
21done
22if test "$match" = "no" ; then
23    flags="$flags $token"
24fi
25dnl
26dnl eval $1='$flags'
27$1="$flags"
28dnl
29IFS="$save_IFS"
30])dnl
31dnl
32dnl
33dnl PAC_MAKE_UNIQ_STRING - Eliminate the duplicated substrings in the input
34dnl                        string variable.
35dnl Assumptions:
36dnl 1) substring separator of the input string is blank space.
37dnl 2) the input string does not contain any '\n' or '\&' character.
38dnl
39dnl The function has the following properties:
40dnl 1) preserves the blank space within pair of double and single quotes.
41dnl 2) preserves the order of the unique substring.
42dnl 3) elminated duplicated substring will be later in order.
43dnl
44dnl PAC_MAKE_UNIQ_STRING( VARIABLE_NAME, [REMOVED_NAME] )
45dnl
46dnl Input/Output
47dnl VARIABLE_NAME - name of the variable containing duplicated substrings.
48dnl                 On output, VARIABLE will contain no duplicated substring.
49dnl REMOVED_NAME  - name of the (optional) variable containing the elminated
50dnl                 duplicated substings.
51dnl
52AC_DEFUN([PAC_MAKE_UNIQ_STRING], [
53saveIFS="$IFS"
54dnl eval inflags=\$$1
55inflags="[$]$1"
56dnl Define separator to be used as replacement of blanks in "..." or '...'
57pac_ifs='\&'
58dnl
59dnl For Double Quote: Replace "pppp  qqqq" as "pppp&&qqqq"
60dnl
61IFS=$pac_ifs
62dnl Prepend '\&' before beginning '\"', Append '\&' after ending '\"'
63outflags=`echo $inflags | sed -e 's%\"\([^\"]*\)\"%'"$pac_ifs"'&'"$pac_ifs"'%g'`
64dnl
65dnl Use \& as separator to locate "...." where ' ' will be replaced by '\&'
66dnl
67tokens=""
68for outflag in $outflags ; do
69    case $outflag in
70    \"*\")
71        dnl Replace ' ' by $pac_ifs
72        flag=`echo $outflag | sed -e 's/ /'"$pac_ifs"'/g'`
73        tokens=$tokens$flag
74        ;;
75    *)
76        tokens=$tokens$outflag
77        ;;
78    esac
79done
80inflags=$tokens
81dnl
82dnl For Single Quote: Replace 'pppp  qqqq' as 'pppp&&qqqq'
83dnl
84IFS=$pac_ifs
85dnl Prepend '\&' before beginning '\'', Append '\&' after ending '\''
86outflags=`echo $inflags | sed -e "s%\'\([^\']*\)\'%""$pac_ifs""&""$pac_ifs""%g"`
87dnl
88dnl Use \& as separator to locate '....' where ' ' will be replaced by '\&'
89dnl
90tokens=""
91for outflag in $outflags ; do
92    case $outflag in
93    \'*\')
94        dnl Replace ' ' by $pac_ifs
95        flag=`echo $outflag | sed -e 's/ /'"$pac_ifs"'/g'`
96        tokens=$tokens$flag
97        ;;
98    *)
99        tokens=$tokens$outflag
100        ;;
101    esac
102done
103dnl
104dnl Compute the unique token list and duplicated token list.
105dnl
106IFS=' '
107uniqtokens=""
108dupltokens=""
109for token in $tokens ; do
110    match=no
111    for uniqtoken in $uniqtokens ; do
112        if test "$uniqtoken" = "$token" ; then
113            match=yes
114            break
115        fi
116    done
117    if test "$match" = "yes" ; then
118        dupltokens="$dupltokens $token"
119    else
120        uniqtokens="$uniqtokens $token"
121    fi
122done
123dnl Restore $pac_ifs to the original, i.e. ' '.
124uniqflags=`echo $uniqtokens | sed -e 's%'"$pac_ifs"'% %g'`
125duplflags=`echo $dupltokens | sed -e 's%'"$pac_ifs"'% %g'`
126dnl eval $1='$uniqflags'
127$1="$uniqflags"
128ifelse([$2],[],:,[$2="$duplflags"])
129dnl
130IFS="$saveIFS"
131])dnl
Note: See TracBrowser for help on using the browser.