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