#!/bin/sh

# Syntax:  QASSIGNS  [-n]

# Reads stdin, prints names of Splus objects assigned thru "object"<- ,
# including quotes, to stdout.  Normally only the object name is printed;
# flag -n (no-strip) causes the entire line containing the name and <- to be
# printed.
# 
# Object definitions are taken to begin with a line which starts with
# <white-space>"<object-name>"<white-space><- i.e., things like "sqrt"<-,
# possibly with spaces and/or tabs before and after the "sqrt". 
# 
# This is intended to be used only with the output of dump().

prog=QASSIGNS

if [ $# = 1 -a "-n" = "$1" ]
then
	STRIP=cat
elif [ $# = 0 ]
then
	STRIP="sed -e 's/<-[^\"]*$//' -e 's/\"//g' -e 's/[ 	]//g'"
	# rips out (i) everything from the <- to the end of the line,
	# but only if there is no " along the way; (ii) all " ;
	# (iii) all tabs and spaces.
else
	echo "Syntax: $prog [-n]" >&2
	exit 1
fi

white="[ 	]*"     # that's [<space><tab>]*
ANY_OBJ="^${white}\".*\"${white}<-"
grep "$ANY_OBJ" | eval $STRIP
