(FILECREATED " 7-May-84 23:19:59" {PHYLUM}<LISPCORE>LIBRARY>BSEARCH.;2 3724   

      changes to:  (VARS BSEARCHCOMS)

      previous date: "30-Apr-84 19:59:49" {PHYLUM}<LISPCORE>LIBRARY>BSEARCH.;1)


(* Copyright (c) 1983, 1984 by Xerox Corporation)

(PRETTYCOMPRINT BSEARCHCOMS)

(RPAQQ BSEARCHCOMS ((FNS BFILEPOS)
		    (VARS \BFILEPOS.SHORTPATTERNL)))
(DEFINEQ

(BFILEPOS
  (LAMBDA (PATTERN FILE LOWINDEX HIGHINDEX SKIP TAIL CASEARRAY)
                                                             (* JonL " 1-Jan-84 02:34")
    (OR (STRINGP PATTERN)
	(LITATOM PATTERN)
	(SETQ PATTERN (MKSTRING PATTERN)))
    (RESETLST (PROG ((PLEN (NCHARS PATTERN))
		     (INCREMENT 128)
		     (FF (FUNCTION FILEPOS))
		     (OFPOS 0)
		     ORIGINALLYOPENP FLEN QUARTERFLEN STARTI NEXTI MAXI TEM STRM)
		    (if (SETQ TEM (OPENP FILE))
			then (SETQ ORIGINALLYOPENP T)
			     (SETQ STRM (\GETSTREAM TEM))
		      else (RESETSAVE (SETQ STRM (OPENSTREAM FILE (QUOTE INPUT)))
				      (QUOTE (PROGN (CLOSEF? OLDVALUE)))))
		    (SETQ FLEN (GETFILEINFO STRM (QUOTE LENGTH)))
		    (if (IGREATERP 0 (SETQ MAXI (IDIFFERENCE FLEN PLEN)))
			then                                 (* Who's he kidding? The PATTERN length is greater than 
							     the file length)
			     (RETURN))
		    (SETQ QUARTERFLEN (IMAX 2 (LRSH FLEN 2)))
		    (SETQ OFPOS (GETFILEPTR STRM))
		    (if (NULL LOWINDEX)
			then (SETQ LOWINDEX OFPOS)
		      elseif (ILESSP LOWINDEX 0)
			then (add LOWINDEX (ADD1 MAXI))
			     (if (ILESSP LOWINDEX 0)
				 then (SETQ LOWINDEX 0))
		      elseif (IGREATERP LOWINDEX MAXI)
			then (RETURN))                       (* Note that LOWINDEX really means low-end limit for 
							     search)
		    (if (NULL HIGHINDEX)
			then (SETQ HIGHINDEX MAX.FIXP)
		      elseif (ILESSP HIGHINDEX 0)
			then (add HIGHINDEX (ADD1 MAXI)))
		    (SETQ HIGHINDEX (IMIN HIGHINDEX MAXI))
		    (if (ILESSP HIGHINDEX LOWINDEX)
			then (ERROR "High-end index less than low-end"))
		    (if ORIGINALLYOPENP
			then (RESETSAVE (LIST STRM OFPOS)
					(QUOTE (AND RESETSTATE (APPLY (QUOTE SETFILEPTR)
								      OLDVALUE)))))
		    (SETQ NEXTI)
		    (SETQ STARTI (ADD1 HIGHINDEX))
		    (SETQ TAIL (if TAIL
				   then PLEN
				 else 0))
		FINDFIRST
		    (if NEXTI
			then (SETQ STARTI NEXTI)
		      elseif (ILEQ STARTI LOWINDEX)
			then                                 (* Looks like we never found any instance of the 
							     PATTERN)
			     (RETURN)
		      else (SETQ MAXI (SUB1 STARTI))
			   (SETQ STARTI (IMAX (PROG1 LOWINDEX 
                                                             (* Comment PPLossage))
					      (IDIFFERENCE STARTI (if (ILESSP INCREMENT QUARTERFLEN)
								      then (PROG1 INCREMENT
										  (SETQ INCREMENT
										    (LLSH INCREMENT 1)
										    ))
								    else QUARTERFLEN))))
			   (SETQ NEXTI (FFILEPOS PATTERN STRM STARTI MAXI SKIP NIL CASEARRAY))
			   (GO FINDFIRST))
		NARROWDOWN                                   (* At this point, we have one instance found at STARTI 
							     and certification that none occur at or beyond MAXI)
		    (SETQ NEXTI (IPLUS STARTI (LRSH (IDIFFERENCE MAXI STARTI)
						    1)))
		    (if (IEQP NEXTI STARTI)
			then (RETURN (IPLUS STARTI TAIL)))
		    (if (SETQ TEM (FFILEPOS PATTERN STRM NEXTI MAXI SKIP NIL CASEARRAY))
			then (SETQ STARTI TEM)
		      else (SETQ MAXI NEXTI))
		    (GO NARROWDOWN)))))
)

(RPAQQ \BFILEPOS.SHORTPATTERNL 16)
(PUTPROPS BSEARCH COPYRIGHT ("Xerox Corporation" 1983 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (364 3601 (BFILEPOS 374 . 3599)))))
STOP