search not changing seek position

Q&A's, tips, howto's

search not changing seek position

Postby ralph.ronnquist » Fri Jul 22, 2016 3:35 am

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).
ralph.ronnquist
 
Posts: 201
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: search not changing seek position

Postby Lutz » Fri Jul 22, 2016 2:34 pm

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.
Lutz
 
Posts: 5276
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: search not changing seek position

Postby Lutz » Fri Jul 22, 2016 2:55 pm

Now also working on Linux and OpenBSD: http://www.newlisp.org/downloads/develo ... nprogress/
Lutz
 
Posts: 5276
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: search not changing seek position

Postby ralph.ronnquist » Sat Jul 23, 2016 2:04 am

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).
ralph.ronnquist
 
Posts: 201
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: search not changing seek position

Postby Lutz » Mon Jul 25, 2016 4:19 pm

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.
Lutz
 
Posts: 5276
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: search not changing seek position

Postby rickyboy » Mon Jul 25, 2016 4:55 pm

Thanks, Lutz!
(Now, check out my on-line poker site. ;-)
(λx. x x) (λx. x x)
rickyboy
 
Posts: 582
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 3 guests

cron