pipe() function in syscalls.cc

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

pipe() function in syscalls.cc

Steve Lipa
Dear Octave-maintainers:

First, let me apologize if this is a stupid question!

Could someone please give me a hint where to find the
routine in the Octave source code that is responsible for
printing out the numbers indicated below?

( I am using version 2.1.36 )

octave:1> x = pipe
x =
(
  [1] =
  {
    id = 4       // I WANT THIS ONE
    name =
    mode = r
    arch = native
    status = open
  }
  [2] =
  {
    id = 3       // I WANT THIS ONE
    name =
    mode = w
    arch = native
    status = open
  }
)

So far I haven't been able to figure out a way to assign these
numbers to a variable (using something like nth(x,2).id). Everything
I try seems to displease Octave.

So I cloned the pipe() function in syscalls.cc, so I could
have it return the numbers I need (gpipe.cc attached below)
Using "mkoctfile gpipe.cc" gives me the new function gpipe,
and this works great from the command line but gives me the
wrong answer when I invoke it from a script:

octave:2> y = gpipe   // correct behavior from command line
y =
(
  [1] =
  {
    id = 6
    name =
    mode = r
    arch = native
    status = open
  }
  [2] =
  {
    id = 5
    name =
    mode = w
    arch = native
    status = open
  }
  [3] = 6          // these numbers agree
  [4] = 5
)
octave:3> inpipe = nth(y,4)
inpipe = 5

octave:4> gptest   //gptest.m just contains one word: gpipe
ans =
(
  [1] =
  {
    id = 8
    name =
    mode = r
    arch = native
    status = open
  }
  [2] =
  {
    id = 7
    name =
    mode = w
    arch = native
    status = open
  }
  [3] = 9          // these numbers are wrong!
  [4] = 8
)

If anyone can give me some sort of clue what I am doing wrong
here I'd really appreciate it. This seems like it should be
much simpler than I am making it. My plan is to find the routine
that prints out the correct numbers and figure out where it is
getting them.

Thanks 1E6 for any help you might offer!

Steve

--

Steve Lipa
[hidden email]
gpg fingerprint = 8B68 77D7 9E09 9991 C97E  25FF 6A12 D2B9 EC7D 66C1

gpipe.cc (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

pipe() function in syscalls.cc

John W. Eaton-6
On 10-Oct-2002, Steve Lipa <[hidden email]> wrote:

| Dear Octave-maintainers:
|
| First, let me apologize if this is a stupid question!
|
| Could someone please give me a hint where to find the
| routine in the Octave source code that is responsible for
| printing out the numbers indicated below?
|
| ( I am using version 2.1.36 )
|
| octave:1> x = pipe
| x =
| (
|   [1] =
|   {
|     id = 4       // I WANT THIS ONE
|     name =
|     mode = r
|     arch = native
|     status = open
|   }
|   [2] =
|   {
|     id = 3       // I WANT THIS ONE
|     name =
|     mode = w
|     arch = native
|     status = open
|   }
| )

The pipe function is defined in syscalls.cc.  The elements of the list
are octave_file objects.  The code that prints the data in that object
is defined in the function octave_file::print_raw in ov-file.cc.

| So far I haven't been able to figure out a way to assign these
| numbers to a variable (using something like nth(x,2).id). Everything
| I try seems to displease Octave.

Why do you need the number?  It's probably best to just pretend that
the octave_file object is special and just pass it around to functions
that expect to handle file objects (fprintf, fscanf, fread, etc.).

But, if you really need it, if a file object is used in numeric
contexts, it is automatically converted to a number, so something like

  nth (x, 1) + 0

should do what you want (but I would still like to know why you need
to have the number -- maybe it would be useful to have a fileno()
function).

jwe