;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 126.145
;;; Reason:
;;;  LOAD-PATCHES messages concerning changed system status were a bit
;;;  unclear.  Instead of "SYSTEM is now OBSOLETE", implying that the system
;;;  software itself is obsolete, say "SYSTEM (version 126) is now OBSOLETE."
;;; Written 10-Nov-88 17:29:53 by keith (Keith Corbett) at site Gigamos Cambridge
;;; while running on Johannes Brahms from band 1
;;; with Experimental System 126.144, Obsolete ZWEI 126.30, Obsolete ZMail 74.17, Obsolete Local-File 76.0, Obsolete File-Server 25.0, Obsolete Lambda-Diag 18.1, Obsolete Unix-Interface 15.0, Obsolete Tape 26.4, Microcode 1762, SDU Boot Tape 3.14, SDU ROM 103, 10/17.



; From file DJ: L.SYS2; PATCH.LISP#193 at 10-Nov-88 17:29:54
#10R SYSTEM-INTERNALS#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "SYSTEM-INTERNALS")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: SYS2; PATCH  "

(defun load-patches-for-systems (system-names selective-p verbose-p unreleased-p force-through-unfinished-patches-p)
  (LET ((FIRST-SYSTEM T) (something-changed nil))  ; This is the first system being patched.
    (DOLIST (PATCH SYSTEM-NAMES)
      (CATCH-ERROR-RESTART (ERROR "Give up on patches for ~A." (CAR PATCH))
	(LET* ((PATCH-DIR (READ-PATCH-DIRECTORY PATCH T))
	       (NEW-VERS (PATCH-DIR-VERSION-LIST PATCH-DIR))
	       (MAJOR (PATCH-VERSION PATCH))
	       (binary-file-type (system-default-binary-file-type (patch-system patch)))
	       PATCHES-NOT-LOADED
	       (CHANGE-STATUS T)		;Ok to change the system status
	       (UNRELEASED-CONSIDERED NIL)	;T if considering unreleased patches.
	       (PATCH-SKIPPED NIL)	;T if considering patches after skipping one.
	       (PROCEED-FLAG (NOT SELECTIVE-P))) ; Has the user said to proceed?
	  (IF (AND (NULL PATCH-DIR) VERBOSE-P)
	      (FORMAT T "~&Skipping system ~A, whose patch directory cannot be accessed.~%"
		      (CAR PATCH))
	    (progn
	      ;; Get list of patches of this system not already loaded.
	      (SETQ PATCHES-NOT-LOADED
		    (CDR (MEMASSQ (VERSION-NUMBER (FIRST (PATCH-VERSION-LIST PATCH)))
				  NEW-VERS)))
	      ;; Maybe announce the system.
	      (WHEN (AND PATCHES-NOT-LOADED VERBOSE-P)	;verbose and silent is nonsense
		(FRESH-LINE *STANDARD-OUTPUT*)
		(UNLESS FIRST-SYSTEM (TERPRI))
		(FORMAT T "~&Patches for ~A (Current version is ~D.~D):"
			(PATCH-NAME PATCH) MAJOR (CAAR (LAST NEW-VERS))))
	      (DOLIST (VERSION PATCHES-NOT-LOADED)
		(LET* ((FILENAME (PATCH-SYSTEM-PATHNAME (PATCH-NAME PATCH) :PATCH-FILE
							(PATCH-VERSION PATCH)
							(VERSION-NUMBER VERSION)
							binary-file-type)))
		  ;; NIL is used to mark patches that are reserved, but not finished.
		  ;; We can't load any more patches without this one, in order to
		  ;; make sure that any two systems claiming to be version xx.yy
		  ;; always have exactly the same set of patches loaded.  Punt.
		  ;; If someone forgets to finish a patch, we assume a hacker will
		  ;; eventually see what is happening and fix the directory to unstick
		  ;; things.  We might at least say the patches are unfinished.
		  (UNLESS (VERSION-EXPLANATION VERSION)
		    (WHEN VERBOSE-P
		      (FORMAT T "~&There are unfinished patches in ~A."
			      (PATCH-NAME PATCH)))
		    (UNLESS FORCE-THROUGH-UNFINISHED-PATCHES-P
		      (RETURN)))
		  (WHEN (VERSION-UNRELEASED VERSION)
		    (WHEN VERBOSE-P
		      (FORMAT T "~&There are unreleased patches in ~A."
			      (PATCH-NAME PATCH)))
		    (OR
		      FORCE-THROUGH-UNFINISHED-PATCHES-P 
		      UNRELEASED-P
		      UNRELEASED-CONSIDERED
		      (EQ (PATCH-STATUS PATCH) :INCONSISTENT)
		      (AND SELECTIVE-P
			   (WITH-TIMEOUT ((* 5 60. 60.)
					  (FORMAT T " -- timed out, No.")
					  NIL)
			     (FORMAT T "~&Such patches are subject to change; therefore,
  you should not load them if you are going to dump a band.
  If you are not going to dump a band, it is reasonable
  to load these patches to benefit from the improvements in them.")
			     (SETQ PROCEED-FLAG NIL)
			     (Y-OR-N-P "Consider the unreleased patches? (Automatic No after 5 minutes) ")))
		      (RETURN))
		    (SETQ UNRELEASED-CONSIDERED T))
		  (WHEN VERBOSE-P
		    (PRINT-PATCH (PATCH-VERSION PATCH) VERSION))
		  (SELECTQ-EVERY
		    (COND (PROCEED-FLAG)
			  (T (WITH-TIMEOUT ((* 5 60. 60.)
					    (FORMAT T " -- timed out, Proceed.")
					    'PROCEED)
			       (FQUERY '(:CHOICES (((T "Yes.") #\Y #\SP #\T #\HAND-UP)
						   ((NIL "No.") #\N #\RUBOUT #\HAND-DOWN)
						   ((PROCEED "Proceed.") #\P)))
				       "Load? (Automatic Proceed after 5 minutes) "))))
		    (NIL
		     ;; "No", don't load any more for this system.
		     ;; Also don't change the status.
		     ;; Except, if we are considering unreleased patches,
		     ;; loading out of order is no worse than loading unreleased
		     ;; patches in the first place, so keep on offering.
		     (SETQ CHANGE-STATUS NIL)
		     (UNLESS (OR FORCE-THROUGH-UNFINISHED-PATCHES-P
				 UNRELEASED-CONSIDERED)
		       (RETURN NIL))
		     (WHEN (EQ VERSION (CAR (LAST PATCHES-NOT-LOADED)))
		       ;; Don't give a spiel about following patches
		       ;; if there are none.
		       (RETURN NIL))
		     (UNLESS (OR PATCH-SKIPPED
				 (EQ (PATCH-STATUS PATCH) ':INCONSISTENT))
		       (FORMAT T "~&If you load any following patches for this system,
  they will be out of sequence, so you must not dump a band.")
		       (SETQ PATCH-SKIPPED T)))
		    (PROCEED
		     ;; "Proceed" with the rest for this system.
		     (SETQ PROCEED-FLAG T))
		    ((T PROCEED)
		     ;; "Yes" or "Proceed", do this one.
		     (SETQ SOMETHING-CHANGED T)
		     ;; Unfinished, unreleased or out of sequence =>
		     ;;  mark system as inconsistent.
		     (WHEN (OR PATCH-SKIPPED
			       (NULL (VERSION-EXPLANATION VERSION))
			       (VERSION-UNRELEASED VERSION))
		       (UNLESS (EQ (PATCH-STATUS PATCH) ':INCONSISTENT)
			 (SETF (PATCH-STATUS PATCH) ':INCONSISTENT)
			 (FORMAT T "~&~A is now inconsistent; do not dump a band."
				 (PATCH-NAME PATCH))))
		     ;; Avoid error if non ex file, if patch is known to be unfinished.
		     (CONDITION-CASE-IF (NULL (VERSION-EXPLANATION VERSION)) ()
			 (load-patch-file filename verbose-p)
		       (FS:FILE-NOT-FOUND
			(WHEN VERBOSE-P
			  (FORMAT T "~&File ~A does not exist, ignoring this patch."
				  FILENAME))))
		     (PUSH VERSION (PATCH-VERSION-LIST PATCH))))))
	      (AND CHANGE-STATUS
		   (NEQ (PATCH-STATUS PATCH) ':INCONSISTENT)
		   (LET ((NEW-STATUS (PATCH-DIR-STATUS PATCH-DIR)))
		     (COND ((NEQ (PATCH-STATUS PATCH) NEW-STATUS)
			    (SETQ SOMETHING-CHANGED T)
			    (WHEN VERBOSE-P
			      (FORMAT T "~&~A (version ~D) is now ~A."
				      (PATCH-NAME PATCH)
				      major
				      (FOURTH (ASSQ NEW-STATUS
						    SYSTEM-STATUS-ALIST))))
			    ;; Update the status.
			    (SETF (PATCH-STATUS PATCH) NEW-STATUS)))))))))
      (SETQ FIRST-SYSTEM NIL))
    something-changed))

))
