I suggest also looking at SPLIT and SKIP, as well as PARSE and WORD, to =
sort out your text buffer. The snippet below shows how I use them to =
break out buffer lines delimited by carriage returns and line feeds. I =
am sure there are better examples lurking out there, but ...
Also, are you sure you're not resetting to the start of the buffer each =
time (you just mention the length)?
---------------- Snippet ------------------
\ Note: tbuf is a dynamic text buffer. "tbuf TEXT" returns the adr and =
count
\ tbuf ?TEXT is the same, but checks for an empty buffer and =
always
\ returns a $
: /NUMLINES ( -) \ count number of lines in buffer, update NUMLINES
0 TO NUMLINES
tbuf TEXT DUP IF =20
1 TO NUMLINES
BEGIN
13 ( cr) SPLIT 2DROP ( - a2 u2) DUP 0> IF ( another line)
13 SKIP 1 +TO NUMLINES TRUE
ELSE FALSE THEN
FALSE =3D UNTIL=20
THEN 2DROP ;
: line>$ ( u - a len) \ return adr and count of specified line
/NUMLINES NUMLINES 0=3D IF DROP tbuf ?TEXT EXIT THEN
NUMLINES 1- MIN 0 MAX 0 0 0 LOCALS| adr len #lines line# |
tbuf TEXT BEGIN
13 ( lf) SPLIT ( - a2 u2 a1 u1) TO len TO adr DUP 0> IF ( another =
line)
13 SKIP #lines line# =3D 1 +TO #lines
ELSE TRUE THEN
UNTIL 2DROP adr len 10 ( lf) SKIP ;
-----Original Message-----
From: Jeffrey Massung [mailto:jma_at_mfire.com]
Sent: Monday, March 22, 2004 10:21 AM
To: sftalk_at_forth.com
Subject: [sftalk] overriding length of source buffer
I'm in the process of coding a text parser and everything is working as
planned. I'm using all the Forth parsing routines to parse tokens, etc. =
I=3D
'm
now at the stage of stripping comments from each source line, and I =
can't=3D
seem
to do this the way I want.
I'd like to override the length of the SOURCE text so that WORD and =
PARSE=3D
will
not go past it. All comments are single line and begin with ; . Using =
PAR=3D
SE I
can get the occurance of the first ; but I can't seem to write that =
lengt=3D
h
back into the #TIB buffer.
Any ideas on how I can to this? Thanks.
Jeff
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug=20
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Mon Mar 22 2004 - 14:26:20 PST
Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!
This archive was generated 09-Feb-2012. Archive updated nightly.