Forum Navigation
You need to log in to create posts and topics.

Re: Parsing

Posted by: sperling <sperling@...>

>I need my program to parse some fairly sizable text based files. The file
>specification is quite loose, however, so I can't know exactly where each
>element of the file will be. What I'm looking for is a fast way to locate,
>for example, the first character in the handle that is NOT a white space
>(CHR's 9 through 13) or the first character that IS the start of a
>subsection: ({[< and such. I'm using some FN MUNGER code that was posted
>here a while back for most of my parsing, but I haven't found a way to do
>this with that yet.
>
>While I'm at it, if anyone knows a way to search for a string that is not
>within a subsection (a pair of the above characters: {}, (), etc.) I'd
>appreciate hearing that, as well. My current solution is to search for the
>string, and then search for the start and end of the subsections leading up
>to the string and making sure that the last subsection ends before the
>string begins. It works, but it seems to me like there should be a faster
>method.
>
>Thanks in advance.
>
>-- Brian Victor

Brian:

I don't know about using MUNGER (I've never used it), but if I were to
parse a sizable text file, I would first open the text file and place it in
memory:

OPEN "I",1,fileName$,,volRefNum% 'open file
fileSize& = LOF (1,1) 'determine size of file
gTextH& = FN NEWHANDLE(fileSize&) 'get memory allocation
LONG IF gText& _nil
osErr% = FN HLOCK(gTextH&)
READ FILE #1, [gTextH&], fileSize&
osErr% = FN HUNLOCK(gTextH&)
XELSE
osErr% = _mFulErr 'check for error
END IF
gOffSet& = 0

Then I would start at the beginning of the text file (i.e., gTextH&) and go
through it a byte at a time (INC(gOffSet&)) while evaluating "a" (ASCII):

LOCAL FN readByte 'read 1 byte
DIM a
a = PEEK ( [gTextH&] + gOffSet&)
INC (gOffSet&)
END FN = a

That would be pretty fast.

tedd

_____________________________________________________________________
tedd f. sperling <mailto:sperling@sperling.com>
http://www.sojourn.com/sperling/