(FILECREATED "14-Jan-86 10:03:52" {DANTE}<RCLARKE>MODEL>FILLPRINT.;3 3920   

      changes to:  (FNS FILLPRINT)

      previous date: "15-Dec-85 13:04:11" {FLOPPY}FILLPRINT.;1)


(PRETTYCOMPRINT FILLPRINTCOMS)

(RPAQQ FILLPRINTCOMS ((* Functions for paragraph formatted printing into windows.)
			(FNS FILLPRIN FILLPRINT)))



(* Functions for paragraph formatted printing into windows.)

(DEFINEQ

(FILLPRIN
  [LAMBDA (WORD DSTRM LMARG RMARG)                           (* M.Model "26-Nov-85 21:48")

          (* print WORD on DSTRM, inserting LF first if it won't fit on current line. If a new line is needed, begin it at 
	  DSPXPOSITION LMARG (DSPLEFTMARGIN if NIL). -
	  The right edge of the line is specified by RMARG (DSPRIGHTMARGIN if NIL).)


    (COND
      [(IGREATERP (IPLUS (DSPXPOSITION NIL DSTRM)
			     (STRINGWIDTH WORD DSTRM))
		    (OR RMARG (DSPRIGHTMARGIN NIL DSTRM)))
	(COND
	  ([OR (NEQ (CHARCODE % )
			(CHCON1 WORD))
		 (for N from 2 to (NCHARS WORD) thereis (NEQ (QUOTE % )
									 (NTHCHAR WORD N]
                                                             (* slight efficiency hack: looking at first character 
							     is cheap; if first is space, probably the rest are too
							     so check explicitly.)
	    (TERPRI DSTRM)
	    (AND LMARG (DSPXPOSITION LMARG DSTRM))
	    (PRIN3 WORD DSTRM]
      (T (PRIN3 WORD DSTRM])

(FILLPRINT
  [LAMBDA (STR DSTRM INDENT LMARG RMARG FONT)                (* edited: "14-Jan-86 10:01")

          (* Print a string in a window, inserting carriage returns whenever there is no room on the current line for the 
	  next word. -
	  The first line will start at INDENT+LMARG (current if NIL) and subsequent lines (if necessary) will begin at LMARG 
	  (DSPLEFTMARGIN if NIL). -
	  RMARG specifies the right edge for printing (default is DSPRIGHTMARGIN) -
	  Return maximum DSPXPOSITION reached.)



          (* 14-NOV-84: changed from packing atoms to creating strings then from unpacking STR to walking it and using 
	  SUBSTRING. This cut the time in about half and essentially eliminated swapping; traded some string space for lots 
	  of lists.)


    (RESETLST [RESETSAVE (DSPFONT FONT DSTRM)
			     (QUOTE (PROGN (DSPFONT OLDVALUE DSTRM]
		(bind (TAILPOS ← 0)
			POS MAXX
		   eachtime (SETQ POS (ADD1 TAILPOS))
			      (SETQ TAILPOS (STRPOS " " STR POS))
		   repeatwhile TAILPOS first (DSPXPOSITION [SETQ MAXX
								   (IPLUS (OR INDENT 0)
									    (OR LMARG
										  (DSPXPOSITION
										    NIL DSTRM]
								 DSTRM)
		   do (AND (NTHCHAR STR POS)
			       (NEQ (NTHCHAR STR POS)
				      (QUOTE % ))
			       (FILLPRIN (SUBSTRING STR POS (AND TAILPOS (SUB1 TAILPOS))
							(CONSTANT "ADSF."))
					   DSTRM LMARG RMARG))
                                                             (* EQ only when first char is a space, in which case 
							     pass on FILLPRIN but process the space.)
			(SETQ MAXX (MAX MAXX (DSPXPOSITION NIL DSTRM)))
			[COND
			  ((IGREATERP (IPLUS (DSPXPOSITION NIL DSTRM)
						 (STRINGWIDTH " " DSTRM))
					(OR RMARG (DSPRIGHTMARGIN NIL DSTRM)))
			    (TERPRI DSTRM)
			    (DSPXPOSITION LMARG DSTRM))
			  (T (OR (EQUAL LMARG (DSPXPOSITION NIL DSTRM))
				   (PRIN3 " " DSTRM]
		   finally (COND
			       ((NOT (EQUAL (OR LMARG (DSPLEFTMARGIN NIL DSTRM))
						(DSPXPOSITION NIL DSTRM)))
				 (SETQ MAXX (MAX MAXX (DSPXPOSITION NIL DSTRM)))
				 (TERPRI DSTRM)))
			     (RETURN MAXX])
)
(PUTPROPS FILLPRINT COPYRIGHT (NONE))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (404 3860 (FILLPRIN 414 . 1509) (FILLPRINT 1511 . 3858)))))
STOP