lineoffset - In Reverse

Phil Davis revdev at pdslabs.net
Tue Nov 17 13:30:32 EST 2009


Hi Len,

Here's an approach that might give you what you need. It assumes the 
file is already in a "vFile" variable, and that the contents of vFile 
won't be rewritten - in other words it's disposable:

-- find an unused character to use as a line delimiter
put empty into tMarkerChar
repeat with x = 255 down to 1 -- I didn't include 0 - it might cause 
problems in this context
   if numToChar(x) is not in vFile then
      put numToChar(x) into tMarkerChar
      exit repeat
   end if
end repeat

-- exit if every ASCII char is used in the file
if tMarkerChar = empty then
   answer "Can't do it!"
   exit to top
end if

-- get the data chunk in question
replace "------------..." with tMarkerChar in vFile
set the lineDelimiter to tMarkerChar
put line -2 of vFile into tFoundSegment
set the lineDelimiter to CR

So now you've isolated your data chunk. I may have missed something, but 
this approach is simple and should work.

Hope this helps -
Phil Davis


Len Morgan wrote:
> I'm trying to parse a file, who's format I have no control over.  I 
> have found the pattern that I need but in order to make it work 
> (easily) I need the equivalent of lineoffset to work from the end mark 
> (which I can reliably find) and the start of that section which is a 
> variable number of lines above the end mark.
>
> The start of a section is a line by itself with "------------..." but 
> this same line is also used to mark off other sections that I don't 
> need.  So, what I need to do is:
>
> 1) find the line offset to the next end-of-section marker
> 2) find the line offset from #1 BACKWARDS to the first line that 
> starts with "------------..."
>
> Is there such a function?  I can always roll my own and just read 
> lines backwards from #1 above until I find the start mark but why 
> reinvent the wheel if such a function is already in revTalk.
>
> len 

-- 
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net




More information about the use-livecode mailing list