(FILECREATED "26-Aug-85 12:12:50" {QV}<NOTECARDS>RELEASE1.2>LIBRARY>NCHACKS.;5 8256   

      changes to:  (FNS NCHACKS.RemoveDeletedIconsFromTextCards NCHACKS.TextSearch 
			NCHACKS.GlobalTextReplace NCHACKS.MakeChain)
		   (VARS NCHACKSCOMS)

      previous date: "23-Aug-85 19:26:18" {QV}<NOTECARDS>RELEASE1.2>LIBRARY>NCHACKS.;4)


(* Copyright (c) 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT NCHACKSCOMS)

(RPAQQ NCHACKSCOMS ((FNS NCHACKS.GlobalTextReplace NCHACKS.TextSearch NCHACKS.DateSearch 
			 NCHACKS.MakeChain NCHACKS.RemoveDeletedIconsFromTextCards)))
(DEFINEQ

(NCHACKS.GlobalTextReplace
  (LAMBDA (String1 String2 WildCards? Cards)                 (* rht: "26-Aug-85 12:11")

          (* * There should be an open notefile. This goes through the Cards list replacing every occurrence of text string 
	  String1 by String2. WildCards? non-nil means wild card characters may appear in String1. # matches any single 
	  character, * matches any sequence of characters, and ' can be used to quote one of the wildcard characters.)


    (for Card in (MKLIST Cards) bind (Length ←(NCHARS String1))
				     WasActiveFlg
       when (AND (NCP.ValidCard Card)
		 (EQ (NCP.CardTypeSubstance (NCP.CardType Card))
		     (QUOTE TEXT)))
       do (if (NOT (SETQ WasActiveFlg (NCP.ActiveCardP Card)))
	      then (NCP.ActivateCards Card))
	  (for
	     bind (Loc ← 0)
		  (TextStream ←(NCP.CardSubstance Card))
	     while (SETQ Loc (TEDIT.FIND TextStream String1 (ADD1 Loc)
					 NIL WildCards?))
	     do (if WildCards?
		    then (SETQ Length (ADD1 (DIFFERENCE (CADR Loc)
							(CAR Loc))))
			 (SETQ Loc (CAR Loc)))
		(TEDIT.DELETE TextStream Loc Length)
		(TEDIT.INSERT TextStream String2 Loc))
	  (if (NOT WasActiveFlg)
	      then (NCP.DeactivateCards Card)))))

(NCHACKS.TextSearch
  (LAMBDA (String WildCards? Cards ReturnLocsFlg)            (* rht: "26-Aug-85 12:10")

          (* * There should be an open notefile. This goes through the Cards list looking for occurrences of text string 
	  String. WildCards? non-nil means wild card characters may appear in String. # matches any single character, * 
	  matches any sequence of characters, and ' can be used to quote one of the wildcard characters.
	  If ReturnLocsFlg is nil, then just return list of cards containing at least one occurrence of String.
	  If ReturnLocsFlg is non-nil, then return a list of lists. Each list has first element a card id followed by the 
	  locations of occurrences of String. These are single integers is WildCards? is nil. If WildCards? is non-nil, then 
	  these are lists of start and end locations of the matching string.)


    (for Card in (MKLIST Cards) bind (Length ←(NCHARS String))
				     WasActiveFlg Hits TextStream
       when (AND (NCP.ValidCard Card)
		 (EQ (NCP.CardTypeSubstance (NCP.CardType Card))
		     (QUOTE TEXT)))
       join (if (NOT (SETQ WasActiveFlg (NCP.ActiveCardP Card)))
		then (NCP.ActivateCards Card))
	    (SETQ TextStream (NCP.CardSubstance Card))
	    (PROG1 (if ReturnLocsFlg
		       then (if (SETQ Hits (for bind (Loc ← 0) while (SETQ Loc (TEDIT.FIND
									 TextStream String
									 (ADD1 Loc)
									 NIL WildCards?))
					      collect (PROG1 Loc (if WildCards?
								     then (SETQ Loc (CAR Loc))))))
				then (LIST (CONS Card Hits)))
		     else (if (TEDIT.FIND TextStream String NIL NIL WildCards?)
			      then (LIST Card)))
		   (if (NOT WasActiveFlg)
		       then (NCP.DeactivateCards Card))))))

(NCHACKS.DateSearch
  (LAMBDA (DateString1 DateString2 Cards)                    (* rht: "23-Aug-85 00:00")

          (* * There should be an open notefile. This goes through the Cards list looking for occurrences of card parts 
	  modified between the dates DateString1 and DateString2. If DateString1 is NIL, then defaults to a very early date.
	  If DateString2 is NIL, then defaults to current date.)


    (LET ((IDate1 (OR (IDATE (OR DateString1 " 1-Jan-70 00:00:00"))
		      (IDATE " 1-Jan-70 00:00:00")))
       (IDate2 (OR (IDATE (OR DateString2 (DATE)))
		   (IDATE (DATE)))))
      (for Card in (MKLIST Cards) bind WasActiveFlg Dates Hits IDate Date
	 join (if (NOT (SETQ WasActiveFlg (NCP.ActiveCardP Card)))
		  then (NCP.ActivateCards Card))
	      (SETQ Dates (NCP.GetCardDates Card))
	      (SETQ Hits (LDIFFERENCE (LIST (if (AND (LESSP IDate1 (SETQ IDate
							      (IDATE (SETQ Date (fetch (NOTECARDDATES
											 
										    SUBSTANCEDATE)
										   of Dates)))))
						     (LESSP IDate IDate2))
						then (LIST (QUOTE SUBSTANCEDATE)
							   Date))
					    (if (AND (LESSP IDate1 (SETQ IDate
							      (IDATE (fetch (NOTECARDDATES LINKSDATE)
									of Dates))))
						     (LESSP IDate IDate2))
						then (LIST (QUOTE LINKSDATE)
							   Date))
					    (if (AND (LESSP IDate1 (SETQ IDate
							      (IDATE (fetch (NOTECARDDATES TITLEDATE)
									of Dates))))
						     (LESSP IDate IDate2))
						then (LIST (QUOTE TITLEDATE)
							   Date))
					    (if (AND (LESSP IDate1 (SETQ IDate
							      (IDATE (fetch (NOTECARDDATES 
										     PROPLISTDATE)
									of Dates))))
						     (LESSP IDate IDate2))
						then (LIST (QUOTE PROPLISTDATE)
							   Date)))
				      (LIST NIL)))
	      (PROG1 (if Hits
			 then (LIST (CONS Card Hits))
		       else NIL)
		     (if (NOT WasActiveFlg)
			 then (NCP.DeactivateCards Card)))))))

(NCHACKS.MakeChain
  (LAMBDA (LinkType Cards Position AddCRFlg)                 (* rht: "26-Aug-85 12:12")

          (* * Create links between successive cards in Cards each of type LinkType positioned at Position.)


    (for RestOfCards on Cards bind (LastCard ←(CAR (LAST Cards)))
				   Card
       until (EQ (SETQ Card (CAR RestOfCards))
		 LastCard)
       when (AND (NCP.ValidCard Card)
		 (EQ (NCP.CardTypeSubstance (NCP.CardType Card))
		     (QUOTE TEXT)))
       do (COND
	    ((AND AddCRFlg (EQ Position (QUOTE END)))
	      (NCP.CardAddText Card (CHARACTER 13)
			       Position)))
	  (NCP.LocalGlobalLink LinkType Card (CADR RestOfCards)
			       Position)
	  (COND
	    ((AND AddCRFlg (EQ Position (QUOTE START)))
	      (NCP.CardAddText Card (CHARACTER 13)))))))

(NCHACKS.RemoveDeletedIconsFromTextCards
  (LAMBDA (Cards)                                            (* rht: "26-Aug-85 12:11")

          (* * For cards in Cards of substance type TEXT, remove all deleted link icons from their substance.)


    (for Card in Cards bind Type TextStream WasActiveFlg when (AND (NCP.ValidCard Card)
								   (EQ (NCP.CardTypeSubstance
									 (SETQ Type (NCP.CardType
									     Card)))
								       (QUOTE TEXT)))
       do (OR (SETQ WasActiveFlg (NCP.ActiveCardP Card))
	      (NCP.ActivateCards Card))
	  (if (EQ (NCP.CardTypeSubstance (SETQ Type (NCP.CardType Card)))
		  (QUOTE TEXT))
	      then (SETQ TextStream (NCP.CardSubstance Card))
		   (for IconPair in (APPLY* (NCP.CardTypeInheritedField Type (QUOTE 
									     CollectLinksInCardFn))
					    Card NIL PSA.Database T T)
		      do (TEDIT.DELETE TextStream (CADR IconPair)
				       1)))
	  (OR WasActiveFlg (NCP.DeactivateCards Card)))))
)
(PUTPROPS NCHACKS COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (597 8178 (NCHACKS.GlobalTextReplace 607 . 1992) (NCHACKS.TextSearch 1994 . 3916) (
NCHACKS.DateSearch 3918 . 6155) (NCHACKS.MakeChain 6157 . 7074) (
NCHACKS.RemoveDeletedIconsFromTextCards 7076 . 8176)))))
STOP