Shiva <
subrama...@gmail.com> wrote in
news:5ecf1339-0d13-41e7...@googlegroups.com:
> Say I need a macro that will do this.
>
> In tacl prompt I type:
>
> RUN MACRO FILENAME
Use a ROUTINE instead of a MACRO -- there is an excellent argument-parsing tool called
#ARGUMENT which is available in ROUTINEs but not in MACROs.
> And within the macro I've to define the words which need to be
> found and replaced with some other words. Like say, if inside
> the file there's a word called "Shiva" written 'n' number of
> times, it needs to be changed to "Sam" n number of times. Not
> just one find and replace text - two or three, basically many.
> Like "Keith" to "Robin". And "Randall" to "Max". The length of
> the characters may differ. The file is of type 101. Also, I'd
> like to add that usually when you find and replace it will not
> go beyond 132 characters so you need not worry about that
> coherency.
>
> Is there a way to do it? If so, can you please let me in on it?
Sure. Your TACL routine should:
- have a list of word pairs specifying what should be replaced with what
- start EDIT as an INLINE process
- scan down the line of word pairs, building an EDIT CHANGE command for each pair and
feeding that command to the EDIT process
- shut down EDIT when at end of list
If you want to write that yourself, stop reading this post right here.
.
.
.
.
.
I warned you.
.
.
.
.
?TACL ROUTINE
==
== CAUTION: written off the top of my head 5 minutes ago; UNTESTED
==
#FRAME
#PUSH #INLINEPROCESS, #INLINEPREFIX
#PUSH edit^command, string1, string2, filename
== this is the reason for using ROUTINE instead of MACRO:
== ROUTINE allows use of #ARGUMENT, MACRO doesn't.
== Command below verifies that argument supplied is both a valid filename,
== *and* is the name of an existing file.
SINK [#ARGUMENT /VALUE filename/ FILENAME]
== Without & at the end of the #DEF command, the first line of the variable would be empty.
[#DEF replace^list TEXT |BODY|&
Shiva Sam
Keith Robin
Randall Max
]
INLPREFIX **
EDIT /INLINE/
** G [filename]
[#LOOP |WHILE| NOT [#EMPTYV replace^list] |DO|
#SETMANY string1 string2, [#EXTRACT replace^list]
** CQWA/[string1]/[string2]/A
== Edit command parsed:
== C = change
== Q = Quiet (don't echo changes to terminal)
== W = Whole word (e.g. 'Sam' matches 'Sam' but not 'Samuel')
== A = All occurrences (if string occurs multiple times on one line, change all of them;
== without this, only the first occurrence on a line is changed)
== /string1/string2/ tells Edit to change string1 to string2
== A = All (apply command to all lines in file)
==
] == end Loop
INLEOF
#UNFRAME