Sujet : Re: Reverse SCAN SPLIT
De : albert (at) *nospam* spenarnc.xs4all.nl
Groupes : comp.lang.forthDate : 10. Oct 2024, 09:00:02
Autres entêtes
Organisation : KPN B.V.
Message-ID : <nnd$231a8f43$45dbf325@e6f1a2d146514222>
References : 1
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
5c65a8f1fdfc3e9937a825842fe23dc2758f48ef@i2pn2.org>,
dxf <
dxforth@gmail.com> wrote:
Earlier I mentioned scanning in reverse. Here's an implementation.
>
[undefined] dxforth [if]
: \CHAR ( a u -- a2 u2 c ) 1- 2dup + c@ ;
[then]
>
\ As for SCAN but scan from end
: SCAN< ( a u c -- a2 u2 | a 0 )
>r over swap begin dup while \char r@ = until 1+ then
rot drop rdrop ;
Compare that with the meticulously designed, exhaustedly specified
and eminently useful -- $/ -- .
After 40 years it has not taken over the world ...
NAME: $/
STACKEFFECT: sc c --- sc1 sc2
DESCRIPTION: []
Find the first c in the string constant sc and split it at that
address. Return the strings after and before c into sc1 and sc2
respectively. If the character is not present sc1 is a null string
(its address is zero) and sc2 is the original string. Both sc1 and sc2
may be empty strings (i.e. their count is zero), if c is the last or
first character in sc .
(sc is c-addr len )
The subtle difference between an empty string (a-add 0 ) and
a null-string ( 0 0 ) allows you to handle empty lines in a file
gracefully.
>
\ As for SPLIT but scan from end. Latter string is topmost.
: SPLIT< ( a u c -- a2 u2 a3 u3 )
>r 2dup r> scan< 2swap 2 pick /string ;
If you go for SPLIT< from end define SCAN< .
I have named it $\
Get the name of an executable from the source file:
"aap.frt" &. $\ 2DROP TYPE
aap OK
These words are elementary and should be defined in the core
in assembler, possibly (Intel) taking advantage of the string
words.
SSLAS0:
POP AX _C{ char}
POP CX _C{ count}
MOV BX,CX
POP DI _C{ addr}
OR DI,DI _C{Clear zero flag.}
MOV DX,DI _C{ Copy}
CLD _C{ INC DIRECTION}
REPNZ SCASB _C{ Compare BYTE} <<<<<<<<<<<
JZ SSLAS1
<loads of stuff to handle the corner cases)
>
<SNIP>
Groetjes Albert
-- Temu exploits Christians: (Disclaimer, only 10 apostles)Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style WallArt For Home, Office And Garden Decor - Perfect For Windows, Bars,And Gifts For Friends Family And Colleagues.