Google
 

Trailing-Edge - PDP-10 Archives - steco_19840320_1er_E35 - 10,5676/teco/macros/decide.tco
There is 1 other file named decide.tco in the archive. Click here to see a list.
!;DECIDE -- SOS "Decide Mode" Simulator -- 18-Mar-79			!
!;Author: Kathleen Harlow, Univ. of Texas at Austin			!
!;This macro simulates SOS Decide Mode for TECO.  You must decide	!
!;whether you want an S (search only on this page) or an N (search	!
!;over pages) search.  You are then asked for the string to search for,	!
!;and what to replace it with.  Each time the string is found, the	!
!;line(s) will be typed out containing the string, with a vertical bar	!
!;showing where it was found.  You must choose whether or not you want	!
!;this replacement made.  All legal TECO search conventions are allowed	!
!;(I.E. ^Es) except ^Gi where i is the Q-registers 1,2,3,4,A,B,C,	!
!;D,E,G and T.								!

!;reg-a - first string!
!;reg-b - replacement string!
!;reg-c - used for input!
!;reg-d - flags null replacement string!
!;reg-e - flags S or N search!
!;reg-f - type out mode!
!;reg-g - stores input macro!
!;reg-t - temporary storage!
!;reg-1 - stores the pointer!
!;reg-2 - counts line feeds!
!;reg-3 - saves ES value!
!;reg-4 - counts line feeds!

[a[b[c[d[e[f[g[t[1[2[3[4          !;save q-regs!
.u1               !;save pointer!
0u2               !;initialize regs!
esu3              !;store value of ES in register 3!
0es
0u4
0ua 0ub 0uc 0ud 0ue 0uf 0ug 0ut


!;Insert the macro for inputting a character into the buffer!

i^T!get!
^R^Tuc            !;get a character and store it in register C!

qc-^O33"e         !;is character an altmode?!
q1-."e            !;Yes its an altmode!
                  !;Is this the only character?!

              !;Only character so output a CR!
ogotit'        !;and stop inputting!

r1a-18"n          !;was last character ^R?!
c                 !;No, so output a carriage return!


ogotit'        !;and stop inputting!
d'             !;Last character was ^R so delete it!

qc-^O177"e        !;Was the last character a RUBout?!
q1-."n            !;Last character was RUB, is this the!
                  !;beginning of the string?!
r                 !;No, back over the last character!

!;Check to see if we are deleting an end of line character!
1a-13"l
1a-9"g
q2-1u2''           !;We are deleting end of line,so decrement!
                   !; end of line counter!
1a-13"e            !;Are we deleting a CR?!
q2"e               !;Yes, is the previous line the first line?!
                   !;Yes, output a CRLF!


q1,.t              !;and type the line!
d                  !;delete the CR!
oget'           !;and go get another character!

!;Previous line was not the first line of input!
.ut                !;store the pointer!
-sl         !;and search backwards for an end of line!

               !;Type a carriage return!
.,qtt              !;and the previous line!
qtj                !;Jump back to last place of input!
d                  !;Delete the CR!
oget'           !;and go get another character!

!;We aren't deleting an end of-line character, so!
d                  !;delete the character!
^A^H'           !;type a Control-H!
oget'           !;and go get another character!

qc-^O10"e          !;Is character a Control-H?!
q1-."n             !;Yes, is this the first character?!
r                  !;No, back over the previous character!

!Is this an end of line!
1a-13"l
1a-9"g
q2-1u2''           !;Yes, decrement the end of line counter!
1a-13"e            !;Are we deleting a CR?!
q2"e               !;Yes, is the previous line the first line?!

               !;Yes, type a CRLF!
q1,.t              !;and the previous line!
d                  !;Delete the CR!
oget'             !;and go get another character!

!;The previous line was not the first line, so!
.ut                  !;store the pointer!
-sl           !;search backwards for an end of line!

                 !;type a CRLF!
.,qtt                !;type the previous line!
qtj                  !;Jump back to last place of input!
d                    !;Delete the CR!
oget'             !;and go get another character!

!;The character we are deleting is not and end of line, so!
d'                   !;delete the character!
oget'             !;and go get another one!

!;Is the character and end of line character?!
qc-^O15"l
qc-^O11"g
%2''                 !;Yes, increment the end of line counter!

qc-^O25"e            !;Is the character a control-U?!
^U
                 !;Yes, so type ^U CRLF!
q2"e                 !;Is this the first line?!
q1,.k                !;Yes, kill this line!
oget'             !;and go get another character!

!;This line is not the first line!
0k                   !;Kill this line!
oget'             !;and go get another character!

qci               !;Insert the character (finally)!
oget              !;and go get another one!

!;We've got the whole string now!
!gotit!

!;and this is the end of the input macro!

!;Store the input macro in register g!
q1,.xg
!;and delete it from the buffer!
q1,.k

!;Now we're really starting!
!;FIND OUT IF HE WANTS AN S OR AN N SEARCH!
S or N search?      !;Type the question!

!srchtyp!
uc           !;get his answer and store in register C!

             !;Type a CRLF!

qc-^O140"g     !;Is this a lower case character?!
qc-^O40uc'   !;Yes, change it to upper case!

qc-^^H"e     !;Is it an H? Type the help message!
Type S to search only on this page, N to search over pages

osrchtyp'   !;and go ask him again!

qc-^^N"e     !;Is it an N?!
1ue          !;Yes, flag it in register E!
ofirstrg'   !;and go get the first string!

qc-^^S"n    !;Is it an S?!
S or N?   !;No, ask him again!
osrchtyp'  !;and go back to wait for his answer!


!;We've found out what kind of search he wants, 0 in reg E
means S, 1 in reg E means N.  Now let's get the search string!

!firstrg!

!;Ask for the first string!
First string (end with an altmode): 
mg                !;Execute the input macro to get the first string!

q1-."e            !;Is the string null?!
% Null string illegal
                !;Yes, type an error message!
ofirstrg'        !;and go ask him for the string again!

!;The string wasn't null!
q1,.xa            !;so store the string in reg-A!
q1,.k             !;and delete it from the buffer!

!;Now we've got the search string, let's get the replacement
string!
!;Ask him for the replacement string!
Replacement string: 
[2                !;Store register 2 (end of line counter)!
0u2               !;Initialize reg 2 to 0!

mg                !;Execute the input macro and get the!
                  !;replacement string!

q1,.xb            !;Store the replacement string in reg B!
q1,.k             !;and delete the string from the buffer!

[2]4[2            !;Push reg 2 on stack, store it in 4, then!
                  !;get the old value of reg-2!

!;Now that we've finally got both strings, tell him what!
!;the commands are, and let's get rolling!

Commands are E, G, N, Y, <blank>, <CR>, <LF>, I, /, or \.
Type H for help.



!again!

!;FIND THE STRING AND TYPE OUT THE LINE(S) CONTAINING IT!
qe"e              !;Is register E a 0!
:sa"e             !;Yes, so we'll do an S search for!
                     !;the search string (the one stored in!
                     !;reg A. Was the search succesful?!
ofinish'            !;No, so finish up!
osearch'            !;Yes, the search was successful!

!;Reg E contained a 1, so we'll do an N search!
:na"e            !;Search for the search string!
                    !;and see if was successful!
ofinish'           !;Search failed, so finish!

!;We've found the string we're searching for, find out what!
!;he wants to do!

!search!
i|                  !;Insert | to show end of string!
-q2tt               !;type out as many lines as the!
                     !;string is!
-d                   !;Get rid of the |!

!;GET THE COMMAND AND PROCESS IT!

!input!
uc                 !;store the command in reg C!
qc-^O140"g            !;Is this a lower case character?!
qc-^O40uc'           !;Yes, change it to upper case!

qc-^^E"e              !;Is it an E?!
xit
                    !;Yes, type XIT!
ofinish'             !;and let's finish!

qc-^^N"e              !;Is it an N?!
o  [Rejected]
                    !;Yes, type an O!
oagain'              !;and let's go search again!

qc-^^Y"e              !;Is it a Y?!
es                !;Yes, type ES, and [ACCEPTED]!
!yes![Accepted]

-fsab           !;Now substitute our replacement string!
                      !;for the string we found!

qf"n                  !;Is reg-F = 0!
-q4tt'                !;No, so show him the replacement!
oagain'              !;and let's go search again!

qc-^O15"e             !;Is it a CR?!
                    !;Yes, pick up the inevitable LF!
oyes'                !;and go make the replacement!

qc-^O12"e             !;Is it a line feed?!
oyes'                !;Yes, go make the replacement!

qc-^^ "e              !;Is it a space?!
oyes'                !;Yes, go make the replacement!

qc-^^G"e              !;Is it a G?!
o
                    !;Yes, type out an O!
-fsab           !;First, make the last replacement!
qf"n                  !;Is reg F = 0?!
-q4tt'                !;No, so show him the replacement!

qe"e                  !;Check for an S or N search, 1 in reg E!
                      !;means N, 0 in reg E means S!
<fsab;          !;S search. Substitute all occurrences!
                      !;of the search string for the replacement string!
qf"n                  !;We made a substitution, now check to see if!
                      !;the typeout flag is set (1 in reg F)!
-q4tt'                !;Typeout flag is set, so show him the replacement!
>ofinish'            !;We've made all the substitutions, so finish!

<fnab;          !;N search.  Substitute all occurrences of the!
                      !;search string with the replacement string!
qf"n                  !;We made a substitution, now check to see if!
                      !;the typeout flag is set (1 in reg F)!
-q4tt'                !;Typeout flag is set, so show the replacement!
>ofinish'            !;We've made all the replacements, so finish!

qc-^^H"e              !;Is the character an H?!
!;Yes, so output the Help message!
elp

Commands:

Exit`	Don't perform this substitution, halt the search, and
`	return to command mode.
Go`	Do this substitution, continue searching, but suppress further
`	decide mode stopping.
Help`	Type this text.
No`	Don't perform this substitution, but continue searching.
Yes, blank, CR, or LF`	Perform this substitution and continue searching.
I`       Delete the string found and allow you to insert a replacement.
/`       Print the line(s) after the replacement is made.
\`       Do not print the line(s) after the replacement is made
`        (default).



!;We've wiped out the type out if he's on a CRT, so show it to!
!;him again!
!shostrng!
i|                   !;Insert the | again to show end of string!
-q2tt                 !;Type out the lines!
-d                    !;Delete the |!
oinput'              !;and go ask him for a command!

qc-^^/"e              !;Is the command a /?!
1uf                   !;It's a /, store 1 in reg F to flag that!
                      !;he wants to see the replacement after it's been!
                      !;made!

                    !;Type a CR!
oshostrng'           !;Go show him the string again!

qc-^^\"e              !;Is the command a \!
0uf                   !;Yes, store 0 in reg F to take flag for typeout!
                        !;after replacement off!

                      !;Type a CR!
oshostrng'             !;and go show him the string again!

qc-^^I"e                !;Is the command an I (insert new string)?!
[2                      !;Yes, it's an I, store contents of reg-2!
                        !;which contains number of end of lines in!
                        !;the search string!
!;Type out a message!
nsert
New string (end with an altmode): 
-fsa            !;Delete the string found!
.u1                   !;Store the pointer!
mg                  !;Execute the input macro!
]2                  !;Get back contents of reg-2!
qf"n                !;Is typeout flag in reg-F set?!
-q4tt'              !;Yes, show him the replacement!
oagain'            !;Go search again!

!;If it is none of the commands, it's illegal, so ask for the!
!;command again!
What?

oinput             !;go get another command!

!;This is the finish!
!finish!             !;Quit!
q3es                 !;Restore ES value!
]4]3]2]1]t]g]f]e]d]c]b]a           !;restore registers!