	.ENABLE SUBSTITUTION
	.ENABLE GLOBAL
	.ENABLE ESCAPE
 
	.IF	P1	EQ	"?"	.GOTO	1000$
	.IF	P1	EQ	"HELP"	.GOTO	1000$

	.SETS	FILES	P1
	.IF	FILES	NE	""	.GOTO	020$
;
	.ASKS	FILES	** Files to search
;
.020$:

	.SETS	TEXT	P2
	.IF	TEXT	NE	""	.GOTO	040$
;
	.ASKS	TEXT	** Text to search for 
;
.040$:

	.SETS	OUTFIL	P3
	.SETT	OUTS
	.IF	OUTFIL	EQ	""	.SETF	OUTS

.;
.;	NOTES ON FOLLOWING TECO MACRO:
.;	1) No tabs are in the marco, as TECO treats a tab as and insert
.;		command. So all seperation is by spaces.
.;	2) Condition find files and search commands (those commands that
.;		are proceded by a colon : must have the conditional
.;		branches immediately following the colon command or the
.;		conditional command will fail with the no aug. error. No
.;		comments are allowed between also.
.;
.;	Q-REG USAGE:
.;		1 - USED FOR GETTING NEXT FILE NAME (ASCII TEXT)
.;		2 - USED FOR NEW FILE NAME FLAG (NUMERIC)
.;		3 - USED FOR FOUND OCCURANCE FLAG AND TO TALLY TOTAL (NUMERIC)
.;		4 - USED TO TALLY NUMBER OF FILES OCCURANCES FOUND IN (NUMERIC)
.;		5 - USED FOR OUTPUT TO FILE FLAG (NUMERIC)
.;		6 - USED TO STORE CURRENT FILE NAME (ASCII TEXT)
.;		7 - USED TO INDICATE Q BUFFER TO WRITE OUT TO FILE (NUMERIC)
.;		8 - USED TO STORE ALL LINES OF OCCURANCE FOR FILR (ASCII TTEXT)
.;		9 - USED TO TALLY TOTAL NUMBER OF FILES SEARCHED (NUMERIC)
.;		A - USED TO KEEP COUNT FOR -WORKING- LIGHT
.;		B - USED FOR TOGGLE ON WORKING TO BLANKS
.;
.;XXX

	.OPEN	SEA.TEC
	.ENABLE DATA
        EI                         !START!
        128,0ET                    !DON'T EXIT ON ERROR!
        1ES                             !SET SEARCH CHAR. TO PRINT LINE!
        -1ED                            !SET OF Y CMD TO IGNORE NO OUT FILE!
        0U3                             !CLR FOUND OCCURANCE FLAG, Q REG 3!
        0U4                             !CLR # OF FILES, Q REG 4!

.DISABLE DATA
	.IFF OUTS .DATA        0U5             !OUTPUT TO TI:!
	.IFT OUTS .DATA        1U5             !OUTPUT TO OUTFIL!
	.ENABLE DATA

        0U7                             !CLR WRITE OUT Q REG 8 FLAG!
        0U9                             !CLR TOTAL # OF FILES, Q REG 9!
        0UA                             !CLR WORKING CNT!
        0UB                             !CLR BLANKS CNT!
        EN'FILES'                  !ENABLE POSSIBLE WILDCARD!
!020$:!                                 !**DO UNTIL: NO MORE FILES!
        Q7"EO030$:''               !IF NO WRITE OUT OF Q REG 8 GOTO 30$!
        HD0J                  !CLEAR TEXT BUFFER!
        13I10I10II  **!SET CR,LF!
        G6                         !SET FILE NAME AND FORMAT IT!
        I  **13I10I10I!SET CR,LF,LF!
!023$:!                                 ! !
        :]8"EO025$:''              !POP FROM PUSH DOWN LIST TO Q REG 8!
        G8                         !PUT INTO TEXT BUFFER!
        L-1L                  !PUT AT BEGINNING OF LINE!
        O023$:                     !CONTINUE UNTIL PUSH DOWN LIST EMPTY!
!025$:!                                 ! !
        HPW                        !WRITE BUFFER TO OUTPUT FILE NOW!
        0JHD                       !CLEAR BUFFER!
        0U7                        !CLR WRITE OUT FLAG!
!030$:!                                 ! !
        0U2                        !CLR NEW FILE NAME FLAG, Q REQ 2!
        :EN"EO200$:''         !SET NXT FILE NAME, FAILED? GOTO 200$!
                                        !       !
                                        !IF SET NEXT FILE NAME!
        Q5"EO035$:''               !      IF OUTPUT TO TI THEN!
        QA+1UA                     !  ADD 1 TO WORKING CNT!
        QA-01"GO035$:''            !  TIME TO PRINT WORKING? NO, GOTO 35$!
        0UA                        !  CLEAR THE CNT!
        QB"EO033$:''               !  IF EQUAL TO ZERO, GO PRINT WORKING!
        
	             
!  PRINT BLANKS!
        0UB                        !  SET TO PRINT WORKING NEXT!
        O035$:                     !  GOTO COMMON CODE!
!033$:!                                 !  !
        
	** Working **
!  PRINT WORKING MSG!
        1UB                        !  SET TO PRINT BLANKS NEXT!
!035$:!                                 !  !
        Q9+1U9                     !  ADD 1 TO # OF FILES!
        HD                         !  CLEAR TEXT BUFFER!
        G*0J1X6                    !  GET NEXT FILE SPEC!
        0ESS:-.D         !  REMOVE DISK SPEC - TECO BUG!
        IERZJ27I27I      !  FORMAT OPEN FILE CMD!
        0J2X1M1                    !  OPEN THE FILE THRU Q REG 1!
        Y                          !  READ IN FIRST PAGE!
        0J                         !  MOVE PTR TO FRONT OF BUFFER!
!040$:!                                 !  **DO UNTIL: END OF FILE!
        :_'TEXT'"EO020$:''    !    FIND TEXT, FAILED? GOTO 020$!
                                        !    !
                                        !    IF FOUND THEN!
        Q3+1U3                     !      ADD 1 TO FOUND FLAG!
        Q5"NO100$:''               !      IF OUTPUT TO TI THEN!
        Q2"NO060$:''               !      IF PRINTED FILE NAME THEN!
        

  **       !        PRINT CR,LF!
        :G6                        !        PRINT FILE NAME!
        1U2                        !        SET FLAG, NEW FILE NAME!
         **

        !        PRINT CR,LF!
        Q4+1U4                     !        ADD 1 TO # OF FILES!
!060$:!                                 !      !
        V                          !      PRINT TEXT LINE!
        L                          !      ADVANCE ONE LINE!
        O040$:                     !      GOTO LABEL B!
                                        ! !
!100$:!                                 !      !
        1U7                        !      SET TO WRITE OUT Q REG 8!
        Q5-1"NO120$:''             !      OPENED OUTPUT FILE YET?!
        2U5                        !      SET FLAG INDICATING SO!
        EW'OUTFIL'/-CR             !      OPEN THE OUTPUT FILE!
!120$:!                                 !      !
        Q2"NO160$:''               !      IF PRINTED FILE NAME THEN!
        1U2                        !        SET FLAG, NEW FILE NAME!
        Q4+1U4                     !        ADD 1 TO # OF FILES!
!160$:!                                 !      !
        L                          !      ADVANCE A LINE!
        -1X8[8                !      CURRENT LINE TO PUSH DOWN LIST!
        O040$:                     !      GOTO LABEL B!
                                        ! !
!200$:!                                 !**EXIT TECO!
        Q3"NO260$:''               !IF DID NOT FIND OCCURANCE THEN!
        
               !  PRINT CR,LF!
          ** Search string not found  **
        
               !  PRINT CR,LF!
        O300$:                     !  GOTO COMMON CODE!
!260$:!
        

           !  PRINT CR,LF!
          ** Lines found with occurances:         Q3:=
        
               !  PRINT CR,LF!
          ** Number of files occurances found in: Q4:=
        
               !  PRINT CR,LF!
          ** Number of files searched:            Q9:=
        
               !  PRINT CR,LF!
        Q5"EO300$:''               !  IF OUTPUT TO TI ONLY THEN!
        0JHD                       !  CLEAR BUFFER!
        I

              !  INSERT CR,LF!
        I  ** Lines found with occurances:         Q3\
        I
                  !  INSERT CR,LF!
        I  ** Number of files occurances found in: Q4\
        I
                  !  INSERT CR,LF!
        I  ** Number of files searched:            Q9\
        I
                  !  INSERT CR,LF!
        HPW                        !  WRITE IT OUT TO FILE!
!300$:!
        Q5"EHKEX''                 !EXIT WITH NO OUTPUT FILE!
        Q5"NEF''                 !EXIT WITH OUTPUT FILE!
        
.DISABLE DATA
	.CLOSE
.;
.;	NOW START UP THE MACRO
.;

	.IFF	OUTS	.GOTO	300$
;
;	Time started: '<DATE>' '<TIME>'
;

.300$:
	.ENABLE QUIET
	.IFNINS	...TEC	INS	LB:[1,11]TEC
	TEC @SEA.TEC
	.WAIT TEC
	PIP SEA.TEC;*/DE/NM
	.DISABLE QUIET

	.IFF	OUTS	.EXIT
;
;	Time finished: '<DATE>' '<TIME>'
;
	.EXIT

.1000$:
;
;			Search command file
;
;	@SEA a b c
;	where:
;		a  = Is the filespec to search (DDu:file.ext;n).
;		b  = Is the search string (no spaces allowed).
;		c  = Is the optional ouput filespec. If not provided
;			then output is to TI:.
;

