#!/bin/ksh #tmp=/tmp/Ci.$$ #trap 'rm $tmp 2>/dev/null' 0 database=/home/eweb/botany/public_html/cp/data/jans.db pgrep=/home/eweb/botany/bin/pgrep awk=awk valid=0 while [ $# -gt 0 ] ; do case $1 in -V ) valid=1; shift ;; * ) break ;; -* ) echo "$0: script error: option $1 is not handled" 1>&2; exit esac done # Now only pattern is left pat=$* pwd=`pwd` # if the -V flag is given then adjust pattern search to # only allow valid name entries. # if [ $valid = 1 ] then pat="N:.\%2b.*$pat" fi #echo "pattern = $pat" #echo "pwd = $pwd" ############################################################## # The old nawk-based system version of pgrep: # pgrep -i $pat < $database | nawk ' # is replaced by a custom program that runs ~10x faster # The "-u" option treats the pattern as URL encoded ############################################################## eval $pgrep -iu \'$pat\' < $database | $awk ' /./ { # this pattern counts on matching every line # and allowing lines to fall through to the # next cases... (no "next" command) matches++ } /^N: \+/ { sub("^N: ","") print "
" print "
Name" print "
" $0 "
" bold=1 next } /^N:/ { sub("^N: ","") print "
" print "
Name" print "
" $0 "
" bold=0 next } /^T:/ { sub("^T: ","") print "
Type Specimen" print "
" $0 "
" next } /^P: / { sub("^P: ","") print "
Publication" print "
" $0 "
" next } /^L: / { sub("^L: ","") print "
Location" print "
" $0 "
" next } /^XN: / { sub("^XN: ","") print "
Chromosome Count" print "
" $0 "
" next } /^XNP: / { sub("^XNP: ","") print "
Chromosome Count Publication" print "
" $0 "
" next } /^S: / { sub("^S: ","") print "
Synonym" print "
" $0 "
" next } /^VN:/ { print "
" print "
" $0 bold=0 next } /^G:/ { print "

" $0 "

" next } # if a TEXT directive is found, the generate the hot-link to # the descriptive html file. # /^TEXT:/ { line = $0 sub("^TEXT: ","",line) n=split(line, fields, " ") printf("
text: %s: ",fields[1], fields[1]); for (i=2; i<=n; i++) { printf("%s ",fields[i]); } printf("\n"); next } # if an IMAGE directive is found, the generate the hot-link to # the descriptive html file. # /^IMAGE:/ { line = $0 sub("^IMAGE: ","",line) n=split(line, fields, " ") printf("
image: %s: ",fields[1], fields[1]); for (i=2; i<=n; i++) { printf("%s ",fields[i]); } printf("\n"); next } /^[A-Z]*:/ { if (bold) { print "
" "" $0 "" "
" } else { print "
" $0 "
" } next } /^$/ { if (bold) { print "
" } print "
" print "
" bold=0 next } END { if (matches == 0) { print "

No matches found!

" if ( '$valid' == 1) { print "

If you are searching for something other than" print "a valid plant name, (eg: author, location, date," print " etc.), then you might want to try using the" print "\"show all matching entries\" option." print "This option will allow your search string" print "to match any field in the database rather" print "than just the plant name field.

" } else { print "

Your search string does not match anything in" print "the Carnivorous Plant Database. Perhaps you are" print "misspelling your query. You might try a shorter" print "abbreviation of your word, or a different spelling." print "If you still have trouble, then perhaps you might" print "try reading about how" print "search patterns work." } } } '