#! /bin/ksh

# makesindex: make the subject index

function kexpand
{
sed '
	s/\<T\>/ZZZ/
	s/\<TI\>/ZZZ/
	s/\<TIK\>/Keyboard input/
	s/\<TIP\>/Pointing device input/
	s/\<TIV\>/Voice\/Speech input/
	s/\<TIO\>/ZZZ/
	s/\<TO\>/ZZZ/
	s/\<TOS\>/Screen output/
	s/\<TOV\>/Voice\/Speech output/
	s/\<TON\>/Non-speech output/
	s/\<TOO\>/ZZZ/
	s/\<L\>/Process lifecycle/
	s/\<LA\>/Analysis/
	s/\<LD\>/Design/
	s/\<LP\>/Prototyping/
	s/\<LI\>/Implementation/
	s/\<LE\>/Evaluation/
	s/\<LO\>/ZZZ/
	s/\<A\>/ZZZ/
	s/\<AC\>/Computer-supported cooperative work/
	s/\<AH\>/Hypermedia\/Information systems/
	s/\<AI\>/Intelligent\/Expert systems/
	s/\<AX\>/Complex systems/
	s/\<AS\>/Special populations/
	s/\<AO\>/ZZZ/
	s/\<M\>/ZZZ/
	s/\<ME\>/Empirical studies/
	s/\<MC\>/Case studies/
	s/\<MD\>/ZZZ/
	s/\<MS\>/Survey/
	s/\<MM\>/Models and theories/
	s/\<MO\>/ZZZ/
	s/\<O\>/ZZZ/
	s/\<VDT\/VDU\>/VDT (Video Display Terminal\/Unit)/
	s/\<CRT\>/CRT (Cathode Ray Tube - screen)/
	s/\[//
	s/\]//
	s/[*="]//g
	/^ZZZ$/d
	s/ZZZ//
	'
}

function xrefs
{
echo "
Process Lifecycle	[See] Analysis, Design, Prototyping, Implementation, Evaluation
Lifecycle Process	[See] Analysis, Design, Prototyping, Implementation, Evaluation
Methodology	[See] Case study, Empirical studies, Field studies, Hardware development, Models and Theories, Position Paper, Software development, Survey, Wizard of Oz
Applications	[See] Complex systems, Computer-supported cooperative work, Databases, Hypermedia/Information systems, Intelligent/Expert systems, Special populations
Devices	[See] Input Devices, Hardware development
Input Devices	[See] Keyboard input, Pointing device input, Specific devices: (cursor, joystick, keyboard, keypad, mouse, stylus, touchpad, touchscreen, trackball)
Speech	[See] Voice/Speech
Expert systems	[See] Intelligent/Expert systems
Artificial Intelligence	[See] Intelligent/Expert systems
Information Systems	[See] Hypermedia/Information systems
User characteristics	[See] Aging, Blind, Computer anxiety, Disability, Education, Expert, Individual, Localization/Translation, Mentally retarded, Novice, Older, Physical, Self-Conscious, Time stress
Output	[See] Coding, CRT/VDU/VDT, Display Format, Highlighting, Screen output
Search, visual	[See] Visual search
"
}


# make a smaller file with ID, Contents page, and Keywords
if test hph.bib -nt sindex.bib
then
	echo "$0: grabbing keywords from master file" > /dev/tty
	ssextract -f C,I,K  hph.bib |
		kexpand > sindex.bib
fi

# make a file with each page number and keyword paired
if test sindex.bib -nt sindex.tmp
then
	echo "$0: building inverted index" > /dev/tty
	ID=`ssformat -t %I sindex.bib`
	for i in $ID
	do
		r=`sssearch I=$i sindex.bib`
		page=`echo "$r" | grep %C | sed -e 's/^.* //' -e 's/-.*$//'`
		echo "$r" | ssformat -t %K |
			while read keyword
			do
				echo "$page	\"$keyword\""
			done
	done | dsort 2 n1 | uniq > sindex.tmp
fi

# gather duplicates into one-line entries
echo "$0: formatting index" > /dev/tty
(
keyword=
while read keyline
do
	set -- $keyline
	page=$1; shift
	if test "$*" != "$keyword"
	then
		echo ""
		print -n "$*,	"
		keyword="$*"
	fi
	print -n "$page, "
done < sindex.tmp | sed "s/, $//"
xrefs
) | sort > sindex.out

exit
KEYS=`ssformat -t %K sindex.bib | sort -u`

exit
ssformat -t %K sindex.bib |
	sort |
		uniq -c > sindex.out
while read keyword
do
	sssearch 
done < sindex.out


exit

Maybe indicate which are reviewer categories
Maybe indicate strength (* or bold)
Make a .bib file with everything, convert to HTML
	expand hierarchy of keywords for .bib (LP -> Process lifecycle: Prototyping)

