TIP: Click on subject to list as thread! ANSI
echo: qedit
to: ALL
from: JOHN W REED
date: 1995-04-03 20:10:00
subject: Get Ordinal Word Macro

    I am embarrassed by that awful kludge that I posted a day
 ago. It worked well enough after the last, most vigorous bug
 eradication, but was an absurdly convoluted way to perform a
 simple act. Also, it may not even have been perfect yet. It
 may have been unable to handle certain other rather common
 conditions. I don't know anymore, because that macro went
 into the bit bucket. It has now been replaced with a much
 better macro with a different approach and more generality.
    The following pair of macros offers the ability to get
 any ordinal word (if it exists) in any line in any loaded
 buffer. The first of the two macros is a slight rewording
 of a macro by (I think) David Marcus, and the second is my
 own supercalifragilisticexpialadocious effort. These two
 macros are meant to be used internally and not bound to a
 key.
    The simple test macro is meant to display the capability
 of the two macros working in tandem. To try it, compile the
 macros below as a single file. Execute the compiled macro to
 activate the key binding. Write whatever you like on line one
 of a test file. Press .
    Please let me know if this macro pair proves to be useful
 to you, and of course if there are any more bugs needing to
 be pounced upon with a big ol' can of Black Raid.
 /* --------------------------88------------------------- */
 constant no = False, zero = 0, one = 1, ten = 10, twenty = 20
 string emptystring[0]
 string proc iGetWordAtCursor() /* get word at cursor */
     string wordatcursor[127] = emptystring
     PushPosition()
     PushBlock()
     UnMarkBlock()
     if MarkWord() or (Left() and MarkWord())
         wordatcursor = GetMarkedText()
     endif
     PopPosition()
     PopBlock()
     return(wordatcursor)
 end
 string proc iGetOrdinalWordInLine(integer bufferid,
                                   integer linenum,
                                   integer ordinal)
     string ordinalwordinline[127] = emptystring
     integer memorycurrentid = GetBufferId(),
             scratchid = no,
             wordnum = zero
     GotoBufferId(bufferid)
     PushPosition()
     PushBlock()
     UnMarkBlock()
     GotoLine(linenum)
     if (PosFirstNonWhite() >= one)
         MarkLine()
         Set(Marking, Off)
         scratchid = CreateTempBuffer()
         if not (scratchid == no)
             CopyBlock()
             UnMarkBlock()
             GotoPos(PosFirstNonWhite())
             repeat
                 if isWord()
                     wordnum = wordnum + one
                 endif
                 EndWord()
             until (wordnum == ordinal)
                   or not WordRight()
             if (wordnum == ordinal)
                 ordinalwordinline = iGetWordAtCursor()
             endif
             AbandonFile(scratchid)
         endif
     endif
     PopPosition()
     PopBlock()
     GotoBufferId(memorycurrentid)
     return(ordinalwordinline)
 end
 proc mTest(integer line)
     string captureword[140] = emptystring
     integer counter = one
     repeat
         captureword = "Word (" + Str(counter, ten) + "): "
                     + iGetOrdinalWordInLine(GetBufferId(), line,
counter)
         Addline(captureword)
         counter = counter + one
     until not (counter <= twenty)
 end
    mTest(one)
--- FidoPCB v1.4 [ff151/a]
---------------
* Origin: SemWare Support BBS * 404-641-8968 * (1:133/314)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.