! - - - - - - - - - - - - - - - - - - - - - - - !
!	  Responder to TECO commands		!
!	     !!TECO.TEC V03.00!!		!
!						!
!	Last edit on 12-Mar-80 by MHB		!
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Switches recognized by commands:	!
!	  /NOI-NI		 TECO,MAKE,MUNG	!
!	  /NOM-EMORY		 TECO,MAKE,MUNG	!
!	  /NOC-REATE		 TECO,MAKE,MUNG	!
!	  /GT-EDIT		 TECO,MAKE	!
!	  /VT-EDIT		 TECO,MAKE	!
!	  /VT-EDIT:H-OLD	 TECO,MAKE	!
!	  /VT-EDIT:H-OLD:S-EEALL TECO,MAKE	!
!	  /VT-EDIT:S-EEALL	 TECO,MAKE	!
!	  /VT-EDIT:S-EEALL:H-OLD TECO,MAKE	!
!	  /SC-ROLL		 TECO,MAKE	!
!	  /SC-ROLL:n		 TECO,MAKE	!
!	  /FI-ND		 TECO		!
!	  /IN-SPECT		 TECO		!
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Entry conditions:			!
!	    Q-reg 1				!
!		+32768 => EITECO$ already tried	!
!		 other => Bit flags (see below)	!
!		    -1 => Same as +32768 only	!
!	    This macro (see ** notes)		!
!		Active EI -or-			!
!		Q-reg Y				!
!	    DCL/CCL/MCR command			!
!		Text buffer -or-		!
!		Q-reg Z (if text buffer empty)	!
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Q-register usage:			!
!	  0 % Scratch				!
!	  0 $ Scratch				!
!	  1 % Bit encoded flags (see below)	!
!	  1 $ Top level directory specification	!
!	  2 % Number of scrolling lines		!
!	  2 $ Scratch				!
!	  9 % Bit flags from initializer	!
!	  9 $ File specification for memory	!
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Bit encoded flags (in Q-reg 1)		!
!	  Load VTEDIT		    +1		!
!	  Inspect file		    +2		!
!	  Don't use memory	    +4		!
!	  Find position marker	    +8		!
!	  Use VTEDIT SEEALL mode   +16		!
!	  Use VTEDIT hold mode	   +32		!
!	  Load GTEDIT		   +64		!
!	  Use scrolling mode	  +128		!
!	  No automatic creation	  +256		!
!	  Yank needs doing	 +2048		!
!	  Initialization done	 +4096		!
!	  Force memory write	 +8192		!
!	  Announce file used	+16384		!
!	  Memory used		+32768		!
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Set up our operating environment	!
! - - - - - - - - - - - - - - - - - - - - - - - !
! Shut ourselves off (** deleted if we're in Y)	!
@EI%%
! Remove old copy (** deleted if we're in Y)	!
0,0XY
! Save old context; set our context		!
[9 0,0X9
[0 0,0X0
[2 0,0X2
10U0 [0 ^D
^XU0 [0 0^X
EDU0 [0 ED&4ED
EUU0 [0 -1EU
ESU0 [0 0ES
ETU0 [0 32768#32#8#1,0ET
Q1U0 0U1 [1 0,0X1
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Try for private command decoder		!
! - - - - - - - - - - - - - - - - - - - - - - - !
! Fix entry value for old enterers...		!
Q0+1"E 32768U0 '
! Do EITECO$ if not already tried		!
! (** Q0&32768"E becomes 32768"E if we're in Y)	!
Q0&32768"E :@EI%TECO%"S ]1 Q0#32768U1 [1 J @O!DONE! ' '
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Do initial set up			!
! - - - - - - - - - - - - - - - - - - - - - - - !
! Get command into text buffer if not already	!
Z"E GZ 0,0XZ '
! Fix up spacing on command			!
J ::@FS%^ES%%^[ ZJ -:@S%^ES%"S .-Z"E @FR%% ' '
! Just quit if no command at all		!
Z"E @O!DONE! '
! Default bit encoded flags			!
Q0&32767U1
! Default directory specification to null	!
0,0X1
! Default memory file specification to null	!
0,0X9
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Handle private initializers		!
! - - - - - - - - - - - - - - - - - - - - - - - !
! Parse /NOINI if present			!
J :@FS%^ES/NOI%%"S @O!/NOINI! '
J :@FS%/NOI%%"S !/NOINI!
::@FS%N%%"S ::@FS%I%%^[ '
::@FS%^ES%%"S 0A"A @I% % ' ' Q1#4096U1 '
! Do private initializer if desired		!
Q1&4096"E
! Start of private initializer processing	!
HX0 HK EP EA EF
! Use built in "INI" and "MEM" if available	!
:@EG%INI%"S G* J ::@FS%$%%"S HX1 HK
:@ER%^EQ1%"S Y HX1 HK EC G1 |
@^A/%Can't find initialization file "/ :G1 @^A/"
/ ' ' 0,0X1 |
! Else form default directory specification	!
0,0X1 -1EJ-5"E @EN%*.*% :@EN%%"S G*
J @S%[% R 0K @FS%.%]% J @S%]% 0,.X1 HK ' '
! Try for initialization from TECO.INI		!
:@ER%^EQ1TECO.INI%"S Y HX9 HK EC G9 0,0X9 ' '
! Use private initializer code if any		!
@ER%% @EW%% Z"N ZJ .U0 G1 @I%=% G0 Q0J ZX9 ZK
]1
]0 Q0ET
]0 Q0ES
]0 Q0EU
]0 Q0ED
]0 Q0^X
]0 Q0^R
]2
HX0 HK G9 J @S%=% 0,.-1X9 0,.K M0+0U9
0,0X0
[2 0,0X2
10U0 [0 ^D
^XU0 [0 0^X
EDU0 [0 ED&4ED
EUU0 [0 -1EU
ESU0 [0 0ES
ETU0 [0 32768#32#8#1,0ET
[1
G9 ^YX1 ^YK 0,0X9
! Set initializer defaulted bit encoded flags	!
Q9U1
! Fix up spacing on command again		!
J ::@FS%^ES%%^[ ZJ -:@S%^ES%"S .-Z"E @FR%% ' '
! Is there any command there at all?		!
Z"E @O!SCOPES! '
! End of private initializer processing		!
| G0 ' '
! Parse /NOMEMORY if present			!
J :@FS%^ES/NOM%%"S @O!/NOMEMORY! '
J :@FS%/NOM%%"S !/NOMEMORY!
::@FS%E%%"S ::@FS%M%%"S ::@FS%O%%"S ::@FS%R%%"S ::@FS%Y%%^[ ' ' ' '
::@FS%^ES%%"S 0A"A @I% % ' ' Q1#4U1 '
! Parse /NOCREATE if present			!
J :@FS%^ES/NOC%%"S @O!/NOCREATE! '
J :@FS%/NOC%%"S !/NOCREATE!
::@FS%R%%"S ::@FS%E%%"S ::@FS%A%%"S ::@FS%T%%"S ::@FS%E%%^[ ' ' ' '
::@FS%^ES%%"S 0A"A @I% % ' ' Q1#256U1 '
! "TECO @file" is "MUNG file" if not RSTS/E	!
-1EJ-4"N J ::@S%TE%"S < 0A"A C > ' ::@S%^ES@%"S
0K @I%MUNG % ' ' '
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Decode MUNG command			!
! - - - - - - - - - - - - - - - - - - - - - - - !
! Is the command 'MUNG' ?			!
J ::@FS%MU%%"S
! Yes, it is 'MUNG', do correct thing		!
< 0A"A D > ' ::@FS%^ES%%^[
! Remove a leading " if VAX/VMS			!
-1EJ-5"E J ::@FS%"%%"S ::@FS%^ES%%^[ ' '
! Isolate the file to MUNG and argument string	!
ZU0
J :@S%/%"S R .-Q0"L .U0 ' '
J :@S%^ES%"S .-Q0"L .U0 ' '
J < @S%,%; .U1
Q1-1J -:@S%[%"S :@S%]%"S .-Q1"G F< ' ' '
Q1-1J -:@S%<%"S :@S%>%"S .-Q1"G F< ' ' '
Q1-1J -:@S%(%"S :@S%)%"S .-Q1"G F< ' ' '
Q1-1J .-1-Q0"L D .U0 ' 0; >
Q0J < -.; -1A-32"N -1A-9"N 0; ' ' -D >
0,.X0 ::@S%^ES%^[ 0,.K
:Q0"E @^A/?How can I MUNG nothing?
/ ^C^C '
@EI%^EQ0% J @O!DONE!
! End of 'MUNG' command processing		!
'
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Decode common command switches		!
! - - - - - - - - - - - - - - - - - - - - - - - !
! Parse /GTEDIT if present			!
J :@FS%^ES/GT%%"S @O!/GTEDIT! '
J :@FS%/GT%%"S !/GTEDIT!
::@FS%E%%"S ::@FS%D%%"S ::@FS%I%%"S ::@FS%T%%^[ ' ' '
::@FS%^ES%%"S 0A"A @I% % ' ' Q1#64U1 '
! Parse /VTEDIT if present			!
J :@FS%^ES/VT%%"S @O!/VTEDIT! '
J :@FS%/VT%%"S !/VTEDIT!
::@FS%E%%"S ::@FS%D%%"S ::@FS%I%%"S ::@FS%T%%^[ ' ' '
! Sub-parse :HOLD if present			!
::@FS%:H%%"S
::@FS%O%%"S ::@FS%L%%"S ::@FS%D%%^[ ' '
Q1#32U1 '
! Sub-parse :SEEALL if present			!
::@FS%:S%%"S
::@FS%E%%"S ::@FS%E%%"S ::@FS%A%%"S ::@FS%L%%"S ::@FS%L%%^[ ' ' ' '
Q1#16U1 '
! Sub-parse :HOLD again if present		!
::@FS%:H%%"S
::@FS%O%%"S ::@FS%L%%"S ::@FS%D%%^[ ' '
Q1#32U1 '
::@FS%^ES%%"S 0A"A @I% % ' ' Q1#1U1 '
! Parse /SCROLL if present			!
J :@FS%^ES/SC%%"S @O!/SCROLL! '
J :@FS%/SC%%"S !/SCROLL!
::@FS%R%%"S ::@FS%O%%"S ::@FS%L%%"S ::@FS%L%%^[ ' ' '
! Sub-parse :n if present			!
::@FS%:%%"S \U2 @FR%% | 0U2 '
::@FS%^ES%%"S 0A"A @I% % ' ' Q1#128U1 '
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Decode TECO command			!
! - - - - - - - - - - - - - - - - - - - - - - - !
! Is the command 'TECO' ?			!
J ::@FS%TE%%"S
! Yes, it is 'TECO', do correct thing		!
< 0A"A D > ' ::@FS%^ES%%^[
! Parse /INSPECT if present			!
J :@FS%^ES/IN%%"S @O!/INSPECT! '
J :@FS%/IN%%"S !/INSPECT!
::@FS%S%%"S ::@FS%P%%"S ::@FS%E%%"S ::@FS%C%%"S ::@FS%T%%^[ ' ' ' '
::@FS%^ES%%"S 0A"A @I% % ' ' Q1#2U1 '
! Parse /FIND if present			!
J :@FS%^ES/FI%%"S @O!/FIND! '
J :@FS%/FI%%"S !/FIND!
::@FS%N%%"S ::@FS%D%%^[ '
::@FS%^ES%%"S 0A"A @I% % ' ' Q1#8U1 '
! Now we can strip out all spaces/tabs		!
J < @FS%^ES%%; >
! Default file if none and not /NOMEMORY	!
Q1&4#Z"E :@EG%MEM%"S G* J ::@FS%$%%"S F| ' |
! Form default directory specification if none	!
Z"E :Q1"E -1EJ-5"E @EN%*.*% :@EN%%"S G*
J @S%[% R 0K @FS%.%]% J @S%]% 0,.X1 HK ' ' '
! Form file specification of memory if none	!
:Q9"E 0EJ+100\ J D G1 @I%TECF% ZJ @I%.TMP%
-1EJ-4"E @I%<60>/MODE:#3000% |
-1EJ-7"N @I%;1/-CR% ' ' HX9 HK ' G9 '
! Try to read the memory file			!
HX0 HK EP EA EF :@ER%^EQ0%"S Y L
."N -1A-10"E -D ' ' ."N -1A-13"E -D ' '
ZK HX0 HK EC G0 ' @ER%% @EW%% 0,0X0 '
! Strip out all spaces/tabs from memory		!
J < @FS%^ES%%; >
! Parse /FIND on memory if present		!
J :@FS%/FI%%"S
::@FS%N%%"S ::@FS%D%%^[ '
Q1#8192#8U1 '
! Say memory used if we found something		!
Z"N Q1#32768#16384U1 ' '
! Announce the file if requested		!
Q1&16384"N Q1&2"E @^A/Edi/ | @^A/Inspec/ '
@^A/ting file "/ HT @^A/"
/ '
! Exit or error if no file			!
Z"E Q1&2"E @O!SCOPES! '
@^A/?How can I inspect nothing?
/ ^C^C '
! Check for output=input format			!
Q1&2"E J :@S%=%"S 0,.-1X0 0,.K ZU0 HX2 HK
:Q2"N :@ER%^EQ2%"U G2 HX0 HK @O!NOTFND! ' '
:Q0"N @EW%^EQ0% ' Q0"N Q1#2048U1 ' @O!REMEM! ' '
! Check for editing file			!
HX0 HK Q1&2"E :@EB%^EQ0%"S Q1#2048U1 @O!REMEM! '
Q1&256"N Q1&32768"E @O!NOTFND! ' '
@^A/%Can't find file "/ :G0 @^A/"
/ Q1&32768"E @^A/%Creating new file
/ @O!CREATE! | @^A/%Ignoring TECO's memory
/ Q1#8192U1 0,0X0 @O!REMEM! ' '
! It must be inspect file by now...		!
:@ER%^EQ0%"S Q1#2048U1 @O!SCOPES! '
! File not found type error, so say so		!
!NOTFND!
@^A/?Can't find file "/ :G0 @^A/"?
/ ^C^C
! End of 'TECO' command processing		!
'
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Decode MAKE command			!
! - - - - - - - - - - - - - - - - - - - - - - - !
! Is the command 'MAKE' ?			!
J ::@FS%MA%%"S
! Yes, it is 'MAKE', do correct thing		!
< 0A"A D > ' ::@FS%^ES%%^[
! Now we can strip out all spaces/tabs		!
J < @FS%^ES%%; >
! Check for null and fancy messages...		!
Z"E @^A/?How can I MAKE nothing?
/ ^C^C '
Z-4"E J ::@S%LOVE%"S @^A/Not war?
/ ' '
! Set file for creation				!
HX0 HK
! Do file creation				!
!CREATE!
@EW%^EQ0% @O!REMEM!
! End of 'MAKE' command processing		!
'
! - - - - - - - - - - - - - - - - - - - - - - - !
!	We couldn't recognize the command	!
! - - - - - - - - - - - - - - - - - - - - - - - !
! We could not recognize this command		!
@^A/%Unrecognized command "/ HT HK @^A/"
/ @O!SCOPES!
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Write TECO's memory			!
! - - - - - - - - - - - - - - - - - - - - - - - !
!REMEM!
! Remember the file name in Q0 if desired	!
Q1&8192"N @O!WRITE! '
Q1&(32768#4)"N @O!SCOPES! '
:Q0"E @O!SCOPES! '
! Write the memory				!
!WRITE!
:@EG%MEM%"S ZJ G* ^SC
::@FS%$%%"U ZK :@EG%MEM ^EQ0%^[ | ZX9 ZK F| ' |
! Form default directory specification if none	!
:Q9"E :Q1"E -1EJ-5"E @EN%*.*% :@EN%%"S ZJ .U0 G* Q0J
@S%[% R Q0,.K @FS%.%]% Q0J @S%]% Q0,.X1 Q0,ZK ' ' '
! Form file specification of memory if none	!
G1 ^YX9 ^YK :@^U9%TECF%
0EJ+100\ .-2,.:X9 -3D :@^U9%.TMP%
-1EJ-4"E :@^U9%<60>/MODE:#3000% |
-1EJ-7"N :@^U9%;1/-CR% ' ' '
! Write the memory file				!
EA :@EW%^EQ9%"S G0 ^YPW ^YK ' EF @EW%% '
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Invoke scope editing macro		!
! - - - - - - - - - - - - - - - - - - - - - - - !
!SCOPES!
! If /GTEDIT specified, do scope check		!
Q1&64"N ET&1024"E @^A/%You don't have a refresh scope
/ Q1#64-64U1 ' '
! If /VTEDIT specified, check scope; set modes	!
Q1&1"N ET&512"E @^A/%Your terminal is not an interactive scope
/ Q1#1-1U1 | 0,3:W^[ Q1&16"N -1,3:W^[ ' 0,5:W^[ Q1&32"N -1,5:W^[ ' ' '
! Give up if all scopes were disabled		!
Q1&(64#1)"E @O!YANK! '
! Find where the scope editing macro is located	!
Q1&64"N @^U9%GTE% | @^U9%VTE% '
:@EG%^EQ9%"S @^U1%% G* ^YX9 ^YK | :@^U9%DIT%
! Form default directory specification if none	!
:Q1"E -1EJ-5"E @EN%*.*% :@EN%%"S ZJ .U0 G* Q0J
@S%[% R Q0,.K @FS%.%]% Q0J @S%]% Q0,.X1 Q0,ZK ' ' ' '
! Try to get the scope editing macro		!
:Q9"N :@EI%^EQ1^EQ9%"S Q1#2048-2048U1 @O!YANK! ' '
! Form library directory specification		!
:@EG%LIB%"S G* ^YX1 ^YK | @^U1%% ' :Q1"E
@^U1%LB:[1,2]% -1EJ-7"E @^U1%SY:% '
-1EJ-5"E @^U1%SYS$LIBRARY:% ' -1EJ-4"E @^U1%$% ' '
! Try to get the scope editing macro again	!
Q1&64"N @^U9%GTEDIT% | @^U9%VTEDIT% '
:Q1"N :@EI%^EQ1^EQ9%"S Q1#2048-2048U1 @O!YANK! ' '
@^A/%The / :G9 @^A/ macro is not available
/
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Do a Yank command if needed		!
! - - - - - - - - - - - - - - - - - - - - - - - !
!YANK!
! Do a Yank command if needed and won't be done	!
Q1&2048"N Y '
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Find position marker			!
! - - - - - - - - - - - - - - - - - - - - - - - !
! If /FIND specified, find the ~~/\~~		!
J Q1&8"N @^A/Finding position marker...
/ @EW%% G* ^YX0 ^YK -1^X
:Q0"N :@FN%~~/\~~
%%U0 | :@F_%~~/\~~
%%U0 ' 0^X
Q0"U @^A/?Position marker not found?
/ ^C^C ' '
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Enter scrolling mode			!
! - - - - - - - - - - - - - - - - - - - - - - - !
! If /SCROLL specified, check scope; set mode	!
Q1&128"N ET&512"E @^A/%Your terminal is not an interactive scope
/ | Q2"E 2:W/4U2 ' Q2,7:W-Q2"N @^A/%Your terminal doesn't support scrolling
/ ' ' '
! - - - - - - - - - - - - - - - - - - - - - - - !
!	Restore caller's operating environment	!
! - - - - - - - - - - - - - - - - - - - - - - - !
!DONE!
! All finished, restore context			!
]1
]0 Q0ET
]0 Q0ES
]0 Q0EU
]0 Q0ED
]0 Q0^X
]0 Q0^R
]2
]0
]9
! 0,0XY (** added if we're in Y)		!
! Final double ESCape (** deleted if we're in Y)!


