1# Compare two strings possibly containing shell variables as version strings.
2
3# Copyright (c) 2003
4#               Derek R. Price, Ximbiot <http://ximbiot.com>,
5#               and the Free Software Foundation, Inc.
6
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2, or (at your option)
10# any later version.
11
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20# 02111-1307, USA.
21
22# ASX_VERSION_COMPARE(VERSION-1, VERSION-2,
23#                     [ACTION-IF-LESS], [ACTION-IF-EQUAL], [ACTION-IF-GREATER])
24# -----------------------------------------------------------------------------
25# Compare two strings possibly containing shell variables as version strings.
26AC_DEFUN([ASX_VERSION_COMPARE],
27[if test "x[$1]" = "x[$2]"; then
28  # the strings are equal.  run ACTION-IF-EQUAL and bail
29  m4_default([$4], :)
30m4_ifvaln([$3$5], [else
31  # first unletter the versions
32  # this only works for a single trailing letter
33  dnl echo has a double-quoted arg to allow for shell expansion.
34  asx_version_1=`echo "[$1]" |
35                 sed 's/\([abcedfghi]\)/.\1/;
36                      s/\([jklmnopqrs]\)/.1\1/;
37                      s/\([tuvwxyz]\)/.2\1/;
38                      y/abcdefghijklmnopqrstuvwxyz/12345678901234567890123456/;'`
39  asx_version_2=`echo "[$2]" |
40                 sed 's/\([abcedfghi]\)/.\1/;
41                      s/\([jklmnopqrs]\)/.1\1/;
42                      s/\([tuvwxyz]\)/.2\1/;
43                      y/abcdefghijklmnopqrstuvwxyz/12345678901234567890123456/;'`
44  asx_count=1
45  asx_save_IFS=$IFS
46  IFS=.
47  asx_retval=-1
48  for vsub1 in $asx_version_1; do
49    vsub2=`echo "$asx_version_2" |awk -F. "{print \\\$$asx_count}"`
50    if test -z "$vsub2" || test $vsub1 -gt $vsub2; then
51      asx_retval=1
52      break
53    elif test $vsub1 -lt $vsub2; then
54      break
55    fi
56    asx_count=`expr $asx_count + 1`
57  done
58  IFS=$asx_save_IFS
59  if test $asx_retval -eq -1; then
60    m4_default([$3], :)
61  m4_ifval([$5], [else
62$5])
63  fi])
64fi
65]) # ASX_VERSION_COMPARE
66