#! /bin/sh
#
#                             COPYRIGHT
# 
#   PCB, interactive printed circuit board design
#   Copyright (C) 1994,1995,1996 Thomas Nau
# 
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
# 
#   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.  See the
#   GNU General Public License for more details.
# 
#   You should have received a copy of the GNU General Public License along
#   with this program; if not, write to the Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# 
#   Contact addresses for paper mail and Email:
#   Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
#   Thomas.Nau@rz.uni-ulm.de
#
#
# starts a test installation of pcb

# execute pcb

HID="WITH_GUI"

# If the first argument is "-gdb" then run PCB inside the gdb
# debugger.  

GDB=${GDB:-gdb}

# Use  --g-fatal-warnings with the gtk HID to cause gtk-WARNING's to
# abort.

TEST_PATHS=""
TEST_PATHS="$TEST_PATHS --lib-path @TOP_BUILDDIR@/lib"
TEST_PATHS="$TEST_PATHS --lib-newlib @TOPSRCDIR@/newlib:@TOP_BUILDDIR@/lib/pcblib-newlib"
TEST_PATHS="$TEST_PATHS --element-path @TOP_BUILDDIR@/lib"
TEST_PATHS="$TEST_PATHS --font-path @TOPSRCDIR@/src"
if [ "x$HID" != "xbatch" ]; then
  TEST_PATHS="$TEST_PATHS --pcb-menu @TOP_BUILDDIR@/src"
fi

TEST_CMDS="--lib-command-dir @TOP_BUILDDIR@/lib"

# note:  To do command line exporting, pcb requires the "-x <export_hid>" command to appear first.  For example
#
#   pcb -x bom [other args] pcbfile
#
# as opposed to
#
#  pcb [other args] -x bom pcbfile
#

use_gdb=no
args=""
export_args=""

while test $# -ne 0 ; do
	case $1 in
		-gdb)
			use_gdb=yes
			;;
		-x)
			export_args="$1 $2"
			shift
			;;
		*.pcb)
			file="$1"
			;;
		*)
			args="$args $1"
			;;
	esac
	shift
done

# build up the complete argument list
arg_list="$export_args $TEST_PATHS $TEST_CMDS $args"

if test $use_gdb = yes ; then
	tmpf=/tmp/pcbtest.$$.gdb
	cat > $tmpf << EOF
set args $arg_list "$file"
EOF
	$GDB -x $tmpf @TOP_BUILDDIR@/src/pcb
	rm -f $tmpf
else
	exec @TOP_BUILDDIR@/src/pcb $arg_list "$file"
fi

