From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 2 Sep 2013 14:13:56 +0400 Message-ID: From: Alexander Sychev To: jimr@highwire.stanford.edu, Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=047d7ba9755c7eb91604e563d420 Subject: Re: [9fans] reading addr always returns #0,#0? Topicbox-Message-UUID: 78b6a6da-ead8-11e9-9d60-3106f5b1d025 --047d7ba9755c7eb91604e563d420 Content-Type: text/plain; charset=ISO-8859-1 Hi, The problem is the "addr" file is closed between your calls. When you open the "addr" file next time, an internal address is set to 0,0. But after the writing the address is actual and if you read "data" file you will see the text according to your address. I you write the code on C or Go without a closing a descriptor of "addr" file, everything will be ok :-) <-------------------------------------------------------------------------------------> santucco@santucco ~/work/go/src/test $ cat test.go package main import ( "bitbucket.org/santucco/goacme" "fmt" "io" ) func main() { w, err:=goacme.New() if err!=nil { panic(err) } defer w.Close() if _, err:=w.Write([]byte("test\ntest2\n")); err!=nil { panic(err) } if err:=w.WriteAddr("#5,#10"); err!=nil { panic(err) } f, err:=w.File("addr") if err!=nil { panic(err) } b:=make([]byte,100) if _, err:=f.Read(b); err!=nil&&err!=io.EOF { panic(err) } fmt.Println(string(b)) } santucco@santucco ~/work/go/src/test $ go build santucco@santucco ~/work/go/src/test $ ./test 5 10 <-------------------------------------------------------------------------------------> Best regards, santucco On Sat, Aug 31, 2013 at 9:29 PM, James A. Robinson < jimr@highwire.stanford.edu> wrote: > On Sat, Aug 31, 2013 at 10:23 AM, James A. Robinson < > jimr@highwire.stanford.edu> wrote: > >> I see the entire text of the window get selected. >> I had assumed that if I then read addr that I would >> get back two numbers, 0 and the final byte offset >> of the file (it is a non-zero length file). >> >> However, I get back two zeros: >> >> $ 9p read acme/2/addr >> 0 0 >> >> What am I missing? >> > > I should have said character offset, not byte offset. > I was also experimenting with using addr=dot, but > didn't see any change in behavior. > > Jim > > -- Best regards, santucco --047d7ba9755c7eb91604e563d420 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,
The problem is the "addr" file is closed= between your calls. When you open the "addr" file next time, an = internal address is set to 0,0.
But after the writing the address= is actual and if you read "data" file you will see the text acco= rding to your address.
=A0
I you write the code on C or Go without a closing a desc= riptor of "addr" file, everything will be ok :-)
<--= ---------------------------------------------------------------------------= -------->
santucco@santucco ~/work/go/src/test $ cat test.go
pack= age main

import (
=A0 =A0 =A0 =A0 "fmt"
=A0 =A0 =A0 =A0 "io&quo= t;
)

func main() {
=A0 =A0 =A0= =A0 w, err:=3Dgoacme.New()
=A0 =A0 =A0 =A0 if err!=3Dnil {
=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 panic(err)
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 defer w.Close()
= =A0 =A0 =A0 =A0 if _, err:=3Dw.Write([]byte("test\ntest2\n")); er= r!=3Dnil {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 panic(err)
= =A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 if err:=3Dw.WriteAddr("#5,= #10"); err!=3Dnil {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 panic(err)
=A0 =A0 =A0 =A0 }=
=A0 =A0 =A0 =A0 f, err:=3Dw.File("addr")
=A0= =A0 =A0 =A0 if err!=3Dnil {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pani= c(err)
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 b:=3Dmake([]by= te,100)
=A0 =A0 =A0 =A0 if _, err:=3Df.Read(b); err!=3Dnil&&err!=3Dio.= EOF {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 panic(err)
=A0 = =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 fmt.Println(string(b))
}<= /div>
santucco@santucco ~/work/go/src/test $ go build
santucco@santucco ~/work/go/src/test $ ./test
=A0 =A0 =A0 = =A0 =A0 5 =A0 =A0 =A0 =A0 =A010=A0

<-----= ---------------------------------------------------------------------------= ----->
Best regards,
=A0 santucco


On Sat, Aug 31, 2013 at 9:29 PM, Jam= es A. Robinson <jimr@highwire.stanford.edu> wrote:<= br>
=
On Sat, Aug 31, 2013 at 10:23 AM, James A. Robinson <jimr@highwire.stanford.edu> wrote:
I see t= he entire text of the window get selected.
I had assumed that if = I then read addr that I would
get back two numbers, 0 and the final byte offset
of the fil= e (it is a non-zero length file).

However, I get back two zeros:

$ 9p read acme/2/addr
=A0 =A0 =A0 =A0 =A0 0 =A0 =A0 =A0 =A0 =A0 = 0=A0

What am I missing?

I should have said character offset, not byte offset.
I was also experimenting with using addr=3Ddot, = but
didn't see any change in behavior.<= /div>

Jim




--
Best regards= ,
=A0 santucco
--047d7ba9755c7eb91604e563d420--