system: You are "Chris Antos (Exchange)", a caller on a 1990s BBS posting in the Qedit message echo. Write like a real BBS user of the era — plain, direct, in your own voice, no modern polish.

user: You are replying to All about "RE: Help on a Macro".

They wrote:
> -----Original Message-----
> From:	Skip Gore [SMTP:sg@peganet.com]
> Sent:	Thursday, August 21, 1997 11:21 AM
> To:	tsepro@semware.com
> Subject:	Re: Help on a Macro
>
> Comment to Carlo,
>
> I really appreciate your help and the macro you provided:
>
>
>  proc main()
>    replace("^", "replace(", "gx")
>    replace("$", ")", "gx")
>    begfile()
>    insertline("proc main()")
>    endfile()
>    addline("end")
> end
>
>
> It takes a file of:
>
>
> "{[a-z]}U{[a-z]}", "\1u\2", "x"
> "{[a-z]}T'", "\1?"+chr(34), "ix"
> "die", " the", "w"
> "took", "look", "w"
>
>
> and puts it in the format of:
>
>
> Replace("{[a-z]}U{[a-z]}", "\1u\2", "x")
> Replace("{[a-z]}T'", "\1?"+chr(34), "ix")
> Replace("die", " the", "w")
> Replace("took", "look", "w")
>
>
> That is exactly what I apparently asked for.  However, I am not good
> making myself clear and do not know how to write specs for a macro.
> I am currently using the following macro, but it will not allow the
> option to be used correctly:
>
>
> constant _FIRST = 1, _NEXT = 2, _PREVIOUS = 3
>
> integer lBuff = 0
>
> string FindStr[255] = "", ReplStr[255] = "", OptStr[255] = ""
>
> integer proc GetListFile()
>     integer cBuff = GetBufferId()
>
>     if lBuff == 0
>         lBuff = CreateTempBuffer()
>     else
>         EmptyBuffer(lBuff)
>         GotoBufferId(lBuff)
>     endif
>
>     if not InsertFile(SplitPath(CurrMacroFilename(),
> _DRIVE_|_PATH_)+"exchange.lst", _DONT_PROMPT_)
>         if NumLines() < 1
>             Warn("No File - Quitting")
>             GotoBufferId(cBuff)
>             EmptyBuffer(lBuff)
>             return(FALSE)
>         endif
>     else
>         UnMarkBlock()
>     endif
>     GotoBufferId(cBuff)
>     return(lBuff)
> end
>
> integer proc GetFindSet(integer direction)
>     integer cBuff = GetBufferId()
>
>
>     GotoBufferId(lBuff)     // Goto the list buffer
>     case direction
>         when _FIRST
>             BegFile()       // Goto beginning of file
>         when _NEXT
>             if not Down()   // Goto next line
>                 GotoBufferId(cBuff)
>                 return(FALSE)
>             endif
>         when _PREVIOUS
>             if not Up()     // Goto previous line
>                 GotoBufferId(cBuff)
>                 return(FALSE)
>             endif
>     endcase
>     BegLine()
>     if
> lFind(Chr(34)+"{.*}"+Chr(34)+".*"+Chr(34)+"{.*}"+Chr(34)+".*"+Chr(34)+
> "{.*}"+Chr(34),"gxc")
>         FindStr = GetFoundText(1)
>         ReplStr = GetFoundText(2)
>         OptStr = GetFoundText(3)
>     else
>         GotoBufferId(cBuff)
>         return(FALSE)
>     endif
>     GotoBufferId(cBuff)
>     return(TRUE)
> end
>
> proc WhenLoaded()
>
>     if not GetListFile()
>         Warn("Couldn't load list file - aborting!")
>         AbandonFile(lBuff)
>         PurgeMacro(CurrMacroFilename())
>         return()
>     endif
>
>     if not GetFindSet(_FIRST)
>         Warn("Couldn't find initial set in list file - aborting!")
>         AbandonFile(lBuff)
>         PurgeMacro(CurrMacroFilename())
>         return()
>     endif
> end
>
> proc ReplaceString()
>     MarkFoundText()
>     DelBlock()
>     InsertText(ReplStr)
> end
>
> proc GetNextSet()
>     if not GetFindSet(_NEXT)
>         warn("No more sets in list file!")
>     else
>         BegFile()
>         BegLine()
>         if not Find(FindStr, OptStr)
>             warn("Find string not found in "+CurrFileName())
>         endif
>     endif
> end
>
> proc GetPrevSet()
>     if not GetFindSet(_PREVIOUS)
>         warn("No previous set in list file!")
>     else
>         BegFile()
>         BegLine()
>         if not Find(FindStr, OptStr)
>             warn("Set not found in "+CurrFileName())
>         endif
>     endif
> end
>
> proc mFindNext()
>     if not Find(FindStr, OptStr+"+")
>         GetNextSet()
>     endif
> end
>
> <Grey+> mFindNext()
> <Grey-> ReplaceString()
> <Grey/> GetNextSet()     // From the exchange.lst file
> <Grey*> GetPrevSet()     // From the exchange.lst file
> <KeyPad.>   Message(FindStr;",";ReplStr;",";OptStr)
>
>
> Is there a way to make the "x" option to be used correctly as in the
> following:
>
>
> "{[a-z]}U{[a-z]}", "\1u\2", "x"
>
>
> Everytime I try to modify the macro I get a replacement string of:
>
>
> \1u\2
>
>
> which is inserted into the file currently being edited.
>
> I hope I haven't confused everyone. <Grin>  Any ADDITIONAL help will
> greatly appreciated.
>
> Thanks in advance,
>
> Skip
>

Write your reply.

assistant: From: "Chris Antos (Exchange)" <chrisant@Exchange.MICROSOFT.com>
skip, you wrote your own function to do the replace.  you should use the
built-in TSE function.
change your ReplaceString so instead of marking the found text, deleting
it, and inserting the replace text, you instead just call lReplace with
the appropriate parameters.  the options string may need some extra
options added for instance "c" or "1" (the "1" forces it to only do one
replacement).
//chris
snip===============================================================snip
snip===============================================================snip
snip===============================================================snip
snip===============================================================snip
snip===============================================================snip
snip===============================================================snip
at
"x"
snip===============================================================snip
snip===============================================================snip
snip===============================================================snip
snip===============================================================snip
snip===============================================================snip
snip===============================================================snip
be