#!/bin/csh
# Add a PS file to a WAIS index
# Jim Davis Friday 26 June 92

# check number of args
if ($#argv < 2) goto usage

set DB = $1

# discard arg 1. 
# Now all remaining args are the names of ps files
shift

# for each name in the remaining arguments
foreach PS ($*)

# The backquote causes shell to evaluate the form and return the string
# add suffix ps if its missing.  Easiest way to do this is to
# strip it off if it is there, then add it.  But then you have to add
# the directory back again.  Such modularity!
set PS = `dirname $PS`/`basename $PS ".ps"`.ps

# If the WAIS index already exists we don't want to overwrite it
# because this script adds files one at a time.
# if you want to overwrite it, erase it first.
if (-e $DB.src) then
 set  append = "-a "
else
 set append = ""
endif

# check that PS file exist.
if (-e $PS) else
 echo PS file $PS does not exist
 exit 1
endif

# $$ appends the process id, which makes it more likely to be unique
set TEMP = /tmp/keywords$$

# extract keywords from the file.
# Maybe someday add a step to remove the hyphenation at ends of lines
ps2ascii -w 132 $PS | tr A-Z a-z | tr -cs a-z '\012' | sort | uniq > $TEMP

waisindex -d $DB $append -T PS -keyword_file $TEMP -nocontents $PS

rm $TEMP
end

exit 0

# print error message
usage:
 echo "usage: `basename $0` WAIS-INDEX PS-FILE"
 exit 1
