(FILECREATED "22-Aug-86 12:23:34" {CSLI}PS:<SAMI>MULTIPLE-HARDCOPY.;2 8769   

      changes to:  (FILEVARS MULTIPLE-HARDCOPYCOMS)
		   (FNS MH.MAKE.GLOSSARY MULTIPLE.HARDCOPY MH.GET.INPUT.FILE MH.GET.PAGE# 
			MH.SET.STARTINGPAGE#)
		   (VARS MULTIPLE-HARDCOPYCOMS)

      previous date: "22-Aug-86 11:37:58" {CSLI}PS:<SAMI>MULTIPLE-HARDCOPY.;1)


(PRETTYCOMPRINT MULTIPLE-HARDCOPYCOMS)

(RPAQQ MULTIPLE-HARDCOPYCOMS [(FNS MH.GET.INPUT.FILE MH.MAKE.GLOSSARY MULTIPLE.HARDCOPY 
				     MH.SET.STARTINGPAGE# MH.GET.PAGE# TOC)
				(P (TEDIT.ADD.MENUITEM TEDIT.DEFAULT.MENU (QUOTE (MULTIPLE% HARDCOPY
										   (QUOTE 
										MULTIPLE.HARDCOPY)
										   
								      "HARDCOPY A LIST OF FILES."])
(DEFINEQ

(MH.GET.INPUT.FILE
  [LAMBDA (FILE)                                             (* edited: "22-Aug-86 12:11")

          (* Returns the file if the file is accessible or otherwise pesters the unwitting user until an existing file is 
	  supplied or nil to abort)


    (PROG NIL
	LOOP(OR FILE (RETURN))
	    (AND (INFILEP FILE)
		   (RETURN FILE))
	    (printout T (CONCAT FILE " [not found.] ")
		      T "TYPE ANOTHER INPUT FILE (NIL TO ABORT): ")
	    (SETQ FILE (READ T))
	    (OR FILE (RETURN))
	    (GO LOOP])

(MH.MAKE.GLOSSARY
  [LAMBDA (FILENAME)                                         (* edited: "22-Aug-86 12:14")

          (* This function relies on the function TOC (written by Nick Briggs) to produce a table of contents.
	  It just takes the TEdit stream returned by TOC and TEDIT.PUTs it to a file.)


    (COND
      ((BOUNDP (QUOTE MULTIPLE.HARDCOPY.LIST))
	(TEDIT.PUT (TOC MULTIPLE.HARDCOPY.LIST)
		     FILENAME))
      (T (PRINTOUT T "MULTIPLE.HARDCOPY MUST BE RUN FIRST" T])

(MULTIPLE.HARDCOPY
  [LAMBDA (STREAM FILELST GLOSSARY.FILE TOFILE? DONTSEND UNFORMATTED? BREAKPAGETITLE SERVER 
		  PRINTOPTIONS)                              (* edited: "22-Aug-86 12:23")

          (* HARDCOPIES all the files in FILELST making sure that the files are numbered consecutively.
	  If STREAM is supplied then it should be a TEdit stream. The intent is that one could set up one's desired page 
	  looks in a TEdit window and then pass that TEdit stream to MULTIPLE.HARDCOPY which will use those page looks.
	  If a STREAM is not given then a fresh TEdit window is started. FILELST should be a list of files to hardcopy in the
	  order that they should be numbered. GLOSSARY.FILE, if given, should be the name of a file. If given then after 
	  MULTIPLE.HARDCOPY is done hardcopying it will use the MH.MAKE.GLOSSARY to make a table of contents for the files 
	  and save the table of contents in GLOSSARY.FILE. If TOFILE? is NON-NIL then an IP file will be created for each 
	  file in FILELST that is the same name as the file but with extension IP. If DONTSEND is NON-NIL then the files will
	  not be sent to the printer (this only makes sense if you're creating IP files). If UNFORMATTED? is NON-NIL then the
	  files will be hardcopied without formatting information. BREAKPAGETITLE, SERVER and PRINTOPTIONS are the same as 
	  per TEDIT.HARDCOPY. After MULTIPLE.HARDCOPY is done, it returns a variable MULTIPLE.HARDCOPY.LIST which is a useful
	  list of information about this hardcopy process. The list is of the form: (<starting page#> %.
	  <list of pairs>) where each pair is of the form (<name of file> <start page# of file>))


    (PROG* (FRAME LOCALINFO INITIAL.DEFAULTPG PG)
           (OR FILELST (SETQ FILELST (TTYIN "FILELST TO HARDCOPY>>"))
		 (RETURN (PRINTOUT T "No filelst specified.")))
           [OR STREAM (SETQ STREAM (TEXTSTREAM (PROCESSPROP (TEDIT (MH.GET.INPUT.FILE
									       (CAR FILELST)))
								    (QUOTE WINDOW]
           (COND
	     ((ATOM FILELST)
	       (SETQ FILELST (LIST FILELST)))
	     (FILELST))
           (SETQ FRAME (OR (fetch TXTPAGEFRAMES of (TEXTOBJ STREAM))
			       TEDIT.PAGE.FRAMES))
           [SETQ LOCALINFO (fetch REGIONLOCALINFO of (COND
							     ((LISTP FRAME)
							       (CAR FRAME))
							     (T FRAME]
           [SETQ INITIAL.DEFAULTPG (AND (LISTGET LOCALINFO (QUOTE STARTINGPAGE#))
					    (SUB1 (LISTGET LOCALINFO (QUOTE STARTINGPAGE#]
           (SETQ PG (OR INITIAL.DEFAULTPG 0))
           (SETQ MULTIPLE.HARDCOPY.LIST NIL)
           (ADVISE (QUOTE TEDIT.PROMPTPRINT)
		     (QUOTE BEFORE)
		     (QUOTE (SETQ PG MSG)))
           [for FILE in FILELST do (PROGN (SETQ FILE (MH.GET.INPUT.FILE FILE))
						  (OR FILE (RETURN))
						  (PROMPTPRINT "MULTIPLE.HARDCOPY: " (FULLNAME
								   FILE))
						  (TEDIT.GET (TEXTOBJ STREAM)
							       FILE UNFORMATTED?)
						  (replace TXTPAGEFRAMES of (TEXTOBJ STREAM)
						     with FRAME)
						  (MH.SET.STARTINGPAGE# (ADD1 PG)
									  FRAME)
						  (TEDIT.HARDCOPY STREAM
								    (COND
								      (TOFILE? (PACKFILENAME
										 (QUOTE NAME)
										 TOFILE?
										 (QUOTE EXTENSION)
										 (QUOTE IP)))
								      (T NIL))
								    DONTSEND BREAKPAGETITLE SERVER 
								    PRINTOPTIONS)
						  (SETQ PG (MKATOM (MH.GET.PAGE# PG)))
						  (SETQ MULTIPLE.HARDCOPY.LIST
						    (NCONC1 MULTIPLE.HARDCOPY.LIST
							      (CONS FILE PG]
           (UNADVISE TEDIT.PROMPTPRINT)
           (MH.SET.STARTINGPAGE# (AND INITIAL.DEFAULTPG (ADD1 INITIAL.DEFAULTPG))
				   FRAME)
           (RETURN (COND
		       (MULTIPLE.HARDCOPY.LIST (SETQ MULTIPLE.HARDCOPY.LIST
						 (CONS (OR (AND INITIAL.DEFAULTPG (ADD1
									INITIAL.DEFAULTPG))
							       1)
							 MULTIPLE.HARDCOPY.LIST))
					       (COND
						 (GLOSSARY.FILE (MH.MAKE.GLOSSARY GLOSSARY.FILE)
								(PRINTOUT T (CONCAT 
									     "Glossary file in: "
										      (FULLNAME
											GLOSSARY.FILE)
										      )
									  T)))
					       MULTIPLE.HARDCOPY.LIST])

(MH.SET.STARTINGPAGE#
  [LAMBDA (PG# PAGE.FRAMES)                                  (* edited: "22-Aug-86 12:15")
                                                             (* Sets the starting page of a PAGE.FRAME.)
    [COND
      ((LISTP PAGE.FRAMES)
	(SETQ PAGE.FRAMES (CAR PAGE.FRAMES]
    (LET ((LOCAL.INFO (fetch REGIONLOCALINFO of PAGE.FRAMES)))
         (COND
	   (LOCAL.INFO (LISTPUT (fetch REGIONLOCALINFO of PAGE.FRAMES)
				  (QUOTE STARTINGPAGE#)
				  PG#))
	   (T (replace REGIONLOCALINFO of PAGE.FRAMES with (LIST (QUOTE STARTINGPAGE#)
									 PG#])

(MH.GET.PAGE#
  [LAMBDA (STR)                                              (* edited: "22-Aug-86 12:13")

          (* This is meant to extract a number from a string such as "2pgs done." which is what TEdit prints out when it's 
	  finished hardcopying something. This is unfortunately the way this program relies on to extract how many pages a 
	  file was hardcopied.)


    (LET ((CH (GNC STR)))
         (COND
	   ((NUMBERP (MKATOM CH))
	     (CONCAT CH (MH.GET.PAGE# STR)))
	   (T ""])

(TOC
  [LAMBDA (FILE)                                             (* edited: "22-Aug-86 11:48")
                                                             (* (* N.H.Briggs " 8-Apr-86 11:23"))
    (LET (TOCSTREAM TOCINFO TOCOUTSTREAM STARTPAGE)
         (if (LISTP FILE)
	     then (SETQ TOCINFO FILE)
	   else [SETQ TOCINFO (READ (SETQ TOCSTREAM (OPENSTREAM FILE (QUOTE INPUT]
		  (CLOSEF TOCSTREAM))
         (SETQ TOCOUTSTREAM (OPENTEXTSTREAM ""))
         (SETQ STARTPAGE (CAR TOCINFO))
         [for TOCENTRY in (CDR TOCINFO)
	    do (TEDIT.INSERT TOCOUTSTREAM (FILENAMEFIELD (CAR TOCENTRY)
							       (QUOTE NAME)))
		 (TEDIT.INSERT TOCOUTSTREAM (CHARACTER (CHARCODE TAB)))
		 (TEDIT.INSERT TOCOUTSTREAM (MKSTRING STARTPAGE))
		 (TEDIT.INSERT TOCOUTSTREAM (CHARACTER (CHARCODE CR)))
		 (SETQ STARTPAGE (ADD1 (CDR TOCENTRY]
         (TEDIT.PARALOOKS TOCOUTSTREAM (QUOTE (TABS (NIL (360 . DOTTEDLEFT))
							RIGHTMARGIN 456))
			    1
			    (GETEOFPTR TOCOUTSTREAM))
     TOCOUTSTREAM])
)
(TEDIT.ADD.MENUITEM TEDIT.DEFAULT.MENU (QUOTE (MULTIPLE% HARDCOPY (QUOTE MULTIPLE.HARDCOPY)
								  "HARDCOPY A LIST OF FILES.")))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (717 8614 (MH.GET.INPUT.FILE 727 . 1306) (MH.MAKE.GLOSSARY 1308 . 1825) (
MULTIPLE.HARDCOPY 1827 . 6270) (MH.SET.STARTINGPAGE# 6272 . 6917) (MH.GET.PAGE# 6919 . 7454) (TOC 7456
 . 8612)))))
STOP