R
Robert Dodier
Hello,
I am hoping to find byte offsets of regular expressions in a file.
I'm working on the built-in doc system for Maxima, an open-
source computer algebra system. The doc text is a Texinfo
output file. I want to find the strings " -- Function: FOO (x, y, z)
...."
and print their byte offsets, and the number of bytes from one such
string to the end of the corresponding documentation item
(which might be the next " -- Function: " item or a different regex).
Here is some pseudocode to illustrate what I am attempting --
let re1 = " --Function: <some name>"
let re2 = FOO (not sure what to put here yet)
slurp file into string S (this is OK, texinfo limits file to 300 k)
byte_offset_1 = 0
while seach for re1 beginning from byte_offset_1 succeeds
extract <some name> from re1 match
search for re2 beginnng from byte_offset_1
let byte_offset_2 = byte offset of re2 match
print <some name>, byte_offset_1, byte_offset_2
let byte_offset_1 = byte_offset_2
I'm planning to slurp the resulting output into another program
that will then carry out matching on the list of <some name> strings
and use file seek to grab the corresponding texts. That program
will be written in another programming language so let's not worry
about that now.
If anyone has some advice about making a workable Perl
program from this pseudocode, I'll be very grateful.
Thanks in advance & all the best.
Robert Dodier
I am hoping to find byte offsets of regular expressions in a file.
I'm working on the built-in doc system for Maxima, an open-
source computer algebra system. The doc text is a Texinfo
output file. I want to find the strings " -- Function: FOO (x, y, z)
...."
and print their byte offsets, and the number of bytes from one such
string to the end of the corresponding documentation item
(which might be the next " -- Function: " item or a different regex).
Here is some pseudocode to illustrate what I am attempting --
let re1 = " --Function: <some name>"
let re2 = FOO (not sure what to put here yet)
slurp file into string S (this is OK, texinfo limits file to 300 k)
byte_offset_1 = 0
while seach for re1 beginning from byte_offset_1 succeeds
extract <some name> from re1 match
search for re2 beginnng from byte_offset_1
let byte_offset_2 = byte offset of re2 match
print <some name>, byte_offset_1, byte_offset_2
let byte_offset_1 = byte_offset_2
I'm planning to slurp the resulting output into another program
that will then carry out matching on the list of <some name> strings
and use file seek to grab the corresponding texts. That program
will be written in another programming language so let's not worry
about that now.
If anyone has some advice about making a workable Perl
program from this pseudocode, I'll be very grateful.
Thanks in advance & all the best.
Robert Dodier