Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: [9fans] reading addr always returns #0,#0?

249 views
Skip to first unread message

James A. Robinson

unread,
Aug 31, 2013, 1:29:31 PM8/31/13
to
On Sat, Aug 31, 2013 at 10:23 AM, James A. Robinson <ji...@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

James A. Robinson

unread,
Aug 31, 2013, 1:23:55 PM8/31/13
to
Say I have an acme window with a $winid of 2.
If I type the following commands:

$ echo -n , | 9p write acme/2/addr
$ echo dot=addr | 9p write acme/2/ctl

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?

Jim

Alexander Sychev

unread,
Sep 2, 2013, 6:13:56 AM9/2/13
to
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 (
        "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
--
Best regards,
  santucco

dexen deVries

unread,
Sep 2, 2013, 6:38:26 AM9/2/13
to
On Monday 02 of September 2013 14:13:56 Alexander Sychev wrote:
> 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 :-)


or use 9p rdwr:


echo -n , | 9p write acme/2/addr
echo 'dot=addr' | 9p rdwr acme/2/ctl

--
dexen deVries

[[[↓][→]]]

Take care of the luxuries and the necessities will take care of themselves.
-- L. Long

James A. Robinson

unread,
Sep 2, 2013, 11:25:30 AM9/2/13
to
Thank you both for the explanation!
0 new messages