#!/bin/csh
#
# Queries the current working directory name for version and
# revision information, assuming that the directory goes by
# the name "magic-x.y.z".  This script determines the number
# x.y and returns it.
#
# Note that we need a fallback version in case of an
# unexpected directory structure. . .
#
set pkgname=`pwd`
set pkgname=${pkgname:t}
set version=${pkgname:s/magic-//}
if ( ${version} == ${pkgname} ) then
   set pkgname=`(cd ..; pwd)`
   set pkgname=${pkgname:t}
   set version=${pkgname:s/magic-//}
   # Handle condition where the directory is a symbolic link.
   if ( ${version} == "magic" ) then
      set rootnames=`(cd ../..; ls | grep magic)`
      foreach i ($rootnames)
	 if (`(cd ../..; readlink $i)` == "magic") then
	    set pkgname=$i
	    set version=${pkgname:s/magic-//}
	    break;
	 endif
      end
   endif
endif
set version=`echo $version | cut -d. -f1-2`
echo $version
