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.
/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).
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:
> (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.
Now also working on Linux and OpenBSD: http://www.newlisp.org/downloads/development/inprogress/
Thanks. Though, there's still something funny with search, and now read-line (and seek).
E.g.
$ ./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).
Now works on all cases and platforms:
http://www.newlisp.org/downloads/development/inprogress/
> (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.
Thanks, Lutz!
(Now, check out my on-line poker site. ;-)