#!/bin/sh
# ----------------------------------------------------------------------------
# - aleph-query                                                              -
# - aleph default option query system                                        -
# ----------------------------------------------------------------------------
# - This program is  free software;  you can  redistribute it and/or  modify -
# - it provided that this copyright notice is kept intact.                   -
# -                                                                          -
# - This  program  is  distributed in the hope  that it  will be useful, but -
# - without  any   warranty;  without  even   the   implied    warranty   of -
# - merchantability  or fitness for a particular purpose. In not event shall -
# - the copyright holder be  liable for  any direct, indirect, incidental or -
# - special damages arising in any way out of the use of this software.      -
# ----------------------------------------------------------------------------
# - copyright (c) 1999-2003 amaury darsch                                    -
# ----------------------------------------------------------------------------

# the program name
progname=$0
# the value to query
queryval=$1
# default value to return
retrnval=$2
# the directory list to search
dirslist=
# the platform to search
platname=

# update the platform name by calling aleph-guess
update_platform () {
    guess=`dirname $progname`/aleph-guess
    platname=`$guess -n`
}

# update the platform directory list
update_dirslist () {
    defltdir=`dirname $progname`/../def
    dirslist="~/.aleph /usr/local/etc/aleph /etc/aleph $defltdir"
}

# query the value in the directory list
query_value () {
    for d in $dirslist; do
        dfile=$d/aleph-${platname}.def
	if test -f $dfile; then
	    value=`grep "^$queryval" $dfile`
	    if test $? = 0; then
		echo $value | awk '{print $2}'
		exit 0
	    fi
	fi
    done
}

# update the variables
update_platform
update_dirslist

# query the value or return default
query_value
echo $retrnval
exit 0
