Page 1 of 1
search not changing seek position
Posted: Fri Jul 22, 2016 3:35 am
by ralph.ronnquist
It seems there's something funny with mixing
search and
seek (or
read-line). The following is an illustration with an appropriate some-data-file.txt which has "some text" here and there.
Code: Select all
/root/newlisp-10.7.1/newlisp
newLISP v.10.7.1 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h
> (open "some-data-file.txt" "r")
3
> (seek 3)
0
> (search 3 "some text" true)
548
> (seek 3)
0
> (search 3 "some text" nil)
64812
> (seek 3)
0
> (search 3 "some text" true)
64821
It looks like
search keeps its own file position, separate from what
seek uses (and what
read-line uses).
Re: search not changing seek position
Posted: Fri Jul 22, 2016 2:34 pm
by Lutz
Seems to be a bug on Linux and OpenBSD,
(seek 3) should return the position of the search.
It is fine on Mac OSX, Windows and FreeBSD:
Code: Select all
> (open "newlisp.c" "r")
3
> (seek 3)
0
> (search 3 "you")
134
> (seek 3)
134
> (search 3 "You")
611
> (seek 3)
611
>
Not sure what is going on in Linux and OpenBSD.
Re: search not changing seek position
Posted: Fri Jul 22, 2016 2:55 pm
by Lutz
Re: search not changing seek position
Posted: Sat Jul 23, 2016 2:04 am
by ralph.ronnquist
Thanks. Though, there's still something funny with
search, and now
read-line (and
seek).
E.g.
Code: Select all
$ ./newlisp
newLISP v.10.7.1 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h
> (open "newlisp.c" "r")
3
> (search 3 "You")
611
> (read-line 3)
"You should have received a copy of the GNU General Public License"
> (search 3 "see")
90748
> (read-line 3)
" along with this program. If not, see <http://www.gnu.org/licenses/>."
> (seek 3 90748)
90748
> (read-line 3)
"*/"
>
It now is as if
read-line dup's the file descriptor?? Or is it the internal function
getIOstream that is the culprit?
Obviously I don't have any deeper insight in the implementation here. For example, I also got quite confused about the
search implementation, which successively loads and scans 4K blocks; how it deals with the case where the search string matches across a block boundary.
In any case, I've reworked my script to rather just use successive
read-line, and then sniff at each line (since my search strings in this script are all within single lines).
Re: search not changing seek position
Posted: Mon Jul 25, 2016 4:19 pm
by Lutz
Now works on all cases and platforms:
http://www.newlisp.org/downloads/develo ... nprogress/
Code: Select all
> (open "newlisp.c" "r")
3
> (search 3 "you")
134
> (seek 3)
134
> (search 3 "You")
611
> (seek 3)
611
> (search 3 "see")
715
> (read-line 3)
"see <http://www.gnu.org/licenses/>."
> (seek 3)
751
> (read-line 3)
"*/"
> (read-line 3)
""
> (seek 3)
755
> (search 3 "see")
1813
> (read-line 3)
"see LINUX */"
>
ps: search terms going over different file blocks has always been taken care off and is not a problem.
Re: search not changing seek position
Posted: Mon Jul 25, 2016 4:55 pm
by rickyboy
Thanks, Lutz!
(Now, check out my on-line poker site. ;-)