#!/bin/sh

# *** Support for searching in included files and finding ***
# ***  exact matches added by Eduard Dulich (2:464/98).  ****
# ***
# *** Group local & echoareas, print "localareas" & "echoareas", extended
# *** config locations check added by Stas Degteff 2:5080/102 <g@grumbler.org>

echo "========================================================================"
echo "LinkedTo V 0.03 by Gabriel Plutzar (2:31/1, gabriel@hit.priv.at) & other"
echo "This file is part of FidoConfig/Husky by Matthias Tichy & people"
echo "========================================================================"

if [ "$FIDOCONFIG" = "" ] ; then
   if [ -f config ] ; then
      FIDOCONFIG=config
   elif [ -f /etc/fido/config ]; then
      FIDOCONFIG="/etc/fido/config"
   elif [ -f /usr/local/etc/fido/config ]; then
      FIDOCONFIG="/usr/local/etc/fido/config"
   else
      echo "Can't found config. Set the FIDOCONFIG enviroment variable."
   fi
fi

INCLUDES=$(grep -i include $FIDOCONFIG | cut -b8-)

if [ "$1" = "" ]
then
   echo Syntax: linkedto Address
   echo
   echo You are shown, to which Areas the Address is linked to
else
   echo The Address $1 is linked to the following Areas:
   echo
   echo "Echoareas:"
   cat "$FIDOCONFIG"|grep -i EchoArea |grep -w $1|cut -b10-40|cut -d\  -f1 -s|sort
   grep -h -i EchoArea  $INCLUDES  |grep -w $1|cut -b10-40|cut -d\  -f1 -s|sort
   echo "."
   echo "Localareas:"
   cat "$FIDOCONFIG"|grep -i LocalArea|grep -w $1|cut -b11-40|cut -d\  -f1 -s|sort
   grep -h -i LocalArea $INCLUDES  |grep -w $1|cut -b11-40|cut -d\  -f1 -s|sort
   echo "."
fi


syntax highlighted by Code2HTML, v. 0.9.1