From Keith.Bierman@eng.sun.com Thu Aug 27 18:44:27 1992
Received: from Sun.COM by dkuug.dk via EUnet with SMTP (5.64+/8+bit/IDA-1.2.8)
	id AA29555; Thu, 27 Aug 92 18:44:27 +0200
Received: from Eng.Sun.COM (zigzag-bb.Corp.Sun.COM) by Sun.COM (4.1/SMI-4.1)
	id AA28473; Thu, 27 Aug 92 09:44:30 PDT
Received: from chiba.Eng.Sun.COM by Eng.Sun.COM (4.1/SMI-4.1)
	id AA28347; Thu, 27 Aug 92 09:44:32 PDT
Received: from localhost by chiba.Eng.Sun.COM (4.1/SMI-4.1)
	id AA09927; Thu, 27 Aug 92 09:44:24 PDT
Message-Id: <9208271644.AA09927@chiba.Eng.Sun.COM>
To: walt@netcom.com (Walt Brainerd)
Cc: SC22WG5@dkuug.dk
Subject: Re: (SC22WG5.187) Processing Words, Part XLIV 
In-Reply-To: Your message of "Thu, 27 Aug 92 08:49:39 PDT."
             <9208271549.AA23918@netcom.netcom.com> 
Date: Thu, 27 Aug 92 09:44:23 PDT
From: Keith.Bierman@eng.sun.com
X-Charset: ASCII
X-Char-Esc: 29


>who want to look at the document, how (for example) does one
>search for all of the occurrences of "IF" in a program example,

Typically one doesn't convert the document to do this search. A simple
script called fmgrep does fine.

>how do these systems allow one to get at the information needed

The answer, as mentioned before:

	1) "Abuse" the glossary building facility (frame)
	2) Use ones favorite language (say perl) to
           extract and build the thing (again frame/unix)

I haven't been using Word for a couple of years; one of the folks from
Microsoft can, no doubt, tell us how MS does the trick for their
elaborate books. Perhaps it should be noted that the Windows version
of Word has an entire BASIC interpreter bulit in.

For FRAME, I think #1 can work. There is ample traffic on
comp.text.frame to suggest that lots of people have no problem doing
this sort of thing. However, #2 isn't hard either, and there are
*lots* of PD tools for Frame distributed via the net.

What fmgrep looks like:

chiba:/net/chiba/home2/khb>cat /net/chiba/home2/khb/bin/sun4/fmgrep
#! /bin/sh
#
#  sg -- pipe the output of "strings" through "grep"
#        in order to grep a binary file.  Takes the same
#        options as grep, except for -n and -b.
#
#  11/1/91 written by elvis (M. Burtch)
#

USAGE="Usage:  `basename $0` [-chilsvw] [-e] pattern file(s)  [see grep(1)]"
grep_opt=""
c_flag=OFF
e_flag=OFF
l_flag=OFF
h_flag=OFF
s_flag=OFF

#  Get options.  Concatenate them into a single string (grep_opt).
#  Later, add a leading hyphen to grep_opt so it can be passed to grep.

while getopts bchilnsvwe: opt
do
	case $opt in
	c)
		c_flag=ON			# line count.  Not really necessary, but
		grep_opt=$grep_opt$opt		# in there to mimic behavior of "grep -lc"
		;;
	l)					#  show filenames only
		l_flag=ON
		grep_opt=$grep_opt$opt
		;;
	h)					#  don't display filenames
		h_flag=ON
		grep_opt=$grep_opt$opt
		;;
	s)					#  work silently
		s_flag=ON
		grep_opt=$grep_opt$opt
		;;
	i|v|w)					#  other allowable options
		grep_opt=$grep_opt$opt
		;;
	b|n)					#  line number, block number
		echo "The grep options '-b' and '-n' are not available."
		echo $USAGE
		exit
		;;
	e)					#  take expression after -e
		e_flag=ON
		pattern=$OPTARG
		grep_opt=$grep_opt$opt
		;;
	\?)					#  illegal option
		echo $USAGE
		exit
		;;

	esac

done

grep_opt_save=$grep_opt				# save option string w/o hyphen

if [ "$grep_opt" != "" ]			# if there were options in the first place
	then grep_opt="-"$grep_opt		# add leading hyphen to options
fi

shift `expr $OPTIND - 1`			# point to first non-option argument

if [ $# -lt 2 ]					# must have pattern and file
	then echo $USAGE			# remaining as arguments
	exit
fi

if [ "$e_flag" = OFF ]
	then pattern=$1
	shift
fi


for arg
do

	#  -s:  work silently.
	#  -h:  don't display filenames
	#  -l:  display only filenames

	if [ "$s_flag" = ON ]			# if only error output is desired
		then strings "arg" | grep $grep_opt "pattern"
	else
		# Don't output anything until we see if grep succeeds.  For all
		# cases but -l, this means running "strings...$pattern" twice.
		# Slow, but at least "grep -l" is the fastest way to check.
		if strings "$arg" | grep "-l$grep_opt_save" "$pattern" > /dev/null
			then if [ "$l_flag" = ON ]  && [ "$c_flag" = OFF ]	# if showing only filenames
				then echo "$arg"
			else
				if [ "$h_flag" = OFF ]		# if filenames desired
					then echo ""
					echo "$arg :"
				fi
				strings "$arg" | grep $grep_opt "$pattern"
			fi
		fi
	fi

done
chiba:/net/chiba/home2/khb>
