#!/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 accepted=0 cultivar=0 while [ $# -gt 0 ] ; do case $1 in -C ) cultivar=1; shift ;; -A ) accepted=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 -A flag is given then adjust pattern search to # only allow accepted name entries. # if [ $accepted = 1 ] then pat="[NFG]:.\%2b.*$pat" fi # if the -C flag is given then adjust pattern search to # only allow cultivar name entries. # if [ $cultivar = 1 ] then pat="[NFG]:.\%24.*$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 ############################################################## if [ $accepted = 1 ] then echo "

Query results: Accepted names only

" elif [ $cultivar = 1 ] then echo "

Query results: Cultivar names only

" else echo "

Query results: All matching fields

" fi echo "
" eval $pgrep -iu \'$pat\' < $database | $awk ' /./ { print "in ." # this pattern counts on matching every line # and allowing lines to fall through to the # next cases... (no "next" command) matches++ } /^[^+]/ { print "in ^[^+]" # if a line does not begin with a "+", then we # are not in a text block, so set intext=0 and # fall through to next case if (intext) { print "" } intext=0; } /^N: \+/ { print "in ^N: \+" print "
" print "
" $0 "" bold=1 next } /^N:/ { print "in ^N:" print "
" print "
" $0 bold=0 next } /^VN:/ { print "in ^VN:" print "
" print "
" $0 bold=0 next } /^F:/ { print "in ^F:" print "

" $0 "

" next } /^G:/ { print "in ^G:" print "

" $0 "

" next } # if a TEXT directive is found, the generate the hot-link to # the descriptive html file. # /^TEXT:/ { print "in ^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:/ { print "in ^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-Za-z]*:/ { print "in ^[A-Za-z]*:" if (bold) { print "
" "" $0 "" "
" } else { print "
" $0 "
" } next } /^$/ { print "in ^$" print "
" bold=0 next } #text continuation line /^\+/ { print "in ^+" if (!intext) { print "
" } intext++ xyz = $0 sub("^\+[ ]*","",xyz) print xyz next; } // { print "in //" # ignore anything not explicitly matched next; } END { print "in END" if (matches == 0) { print "

No matches found!

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

If you are searching for something other than" print "an accepted 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 if ( '$cultivar' == 1) { print "

If you are searching for something other than" print "a cultivar name, (eg: the author, location," print "date, 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." } } } '