popen2 example gives no output

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

popen2 example gives no output

John W. Eaton-6
On 12-Sep-2005, I wrote:

| (*) The ERRNO function is experimental.  Maybe it should be renamed
| "errno" instead.  Also, we need a way to get at all (most? some?) of
| the possible ERRNO values on a give system, perhaps by allowing
| something like
|
|   EAGAIN = errno ("EAGAIN");

I'm looking at this now.  Since it is a development question I'm
moving the discussion from the bug list to the maintainers list.

The simple solution to associating the list of names and error codes
would be to have just the EXXX values that are defined by POSIX
(http://www.opengroup.org/onlinepubs/009695399/basedefs/errno.h.html)
but it seems that it would be better to have whatever symbolic names
are available on a given system.  To implement this, we would need to
do some grepping through errno.h (and any files it includes).  That
seems ugly, and duplicates what Perl (at least) already does.  So it
seems to me that it would be cleaner to use Perl to generate the list
for Octave, when Octave is built.  That would introduce a build
dependency on Perl.  Is that a problem?  Perhaps we could fall back on
the list of names from POSIX if Perl is not available?  Otherwise, we
would have to duplicate a lot of fairly tricky code, and that seems
even less desirable to me.

Can some Perl guru on the list tell me how to use the Errno module in
Perl to generate a list of all the symbolic error codes, as strings?

Ultimately, I would like to generate code that looks something like
this:

  struct errno_name_value_struct
  {
    const char *name;
    const int value;
  };

  static errno_name_value_struct errno_codes
  {
    { "E2BIG", E2BIG },
    { "EACCESS", EACCESS },
    ...
    ...
    ...
    { 0, 0 },
  };

so we can implement

  EAGAIN = errno ("EAGAIN");

by doing something like (error checking omitted):

  octave_value retval = -1;

  std::string lookfor = args(0).string_value ();

  errno_name_value_struct *ptr = errno_codes;
  while (ptr->name)
    {
      if (lookfor == ptr->name)
        {
          retval = ptr->value;
          break;
        }
      else
        ptr++;
    }

  return retval;


Thanks,

jwe

Reply | Threaded
Open this post in threaded view
|

Re: popen2 example gives no output

James R. Phillips-2
--- "John W. Eaton"  wrote:

> [..] So it
> seems to me that it would be cleaner to use Perl to generate the list
> for Octave, when Octave is built.  That would introduce a build
> dependency on Perl.  Is that a problem?  Perhaps we could fall back on
> the list of names from POSIX if Perl is not available?  Otherwise, we
> would have to duplicate a lot of fairly tricky code, and that seems
> even less desirable to me.
>

I don't see a problem for building in Cygwin.  For a mingw build, relying on
perl could be problematic.

jrp

Reply | Threaded
Open this post in threaded view
|

Re: popen2 example gives no output

Bill Denney
In reply to this post by John W. Eaton-6
On Thu, 22 Sep 2005, John W. Eaton wrote:

> The simple solution to associating the list of names and error codes
> would be to have just the EXXX values that are defined by POSIX
> (http://www.opengroup.org/onlinepubs/009695399/basedefs/errno.h.html)
> but it seems that it would be better to have whatever symbolic names
> are available on a given system.  To implement this, we would need to
> do some grepping through errno.h (and any files it includes).  That
> seems ugly, and duplicates what Perl (at least) already does.  So it
> seems to me that it would be cleaner to use Perl to generate the list
> for Octave, when Octave is built.  That would introduce a build
> dependency on Perl.  Is that a problem?  Perhaps we could fall back on
> the list of names from POSIX if Perl is not available?  Otherwise, we
> would have to duplicate a lot of fairly tricky code, and that seems
> even less desirable to me.
>
> Can some Perl guru on the list tell me how to use the Errno module in
> Perl to generate a list of all the symbolic error codes, as strings?

I think that this is what you're asking for:

=== Begin Script
#!/usr/bin/perl

foreach my $key (keys(%!)) {
     print "$key\n";
}
=== End Script

I don't know all the C that you're wanting to put in there, but if it's
just what you wrote below, this script will do it (just for the static
errno_name_value_struct errno_codes part):

=== Begin Script
#!/usr/bin/perl

foreach my $key (keys(%!)) {
     print "  { \"$key\", $key },\n";
}
=== End Script

Also, I thought that Perl was already a build dependency for the
lsode_options (and *_options) code, so adding this shouldn't really be an
issue.

Bill

--
"Clothes make the man. Naked people have little or no influence on
society."
   -- Mark Twain

Reply | Threaded
Open this post in threaded view
|

Re: popen2 example gives no output

John W. Eaton-6
On 22-Sep-2005, Bill Denney wrote:

| I think that this is what you're asking for:
|
| === Begin Script
| #!/usr/bin/perl
|
| foreach my $key (keys(%!)) {
|      print "$key\n";
| }
| === End Script

Excellent.  This makes it fairly simple to generate the list that I need.

| Also, I thought that Perl was already a build dependency for the
| lsode_options (and *_options) code, so adding this shouldn't really be an
| issue.

For the *_options files, we can distribute the results because the
output files are not system dependent.  So the dependency is really a
developer dependency (similar to flex, bison, and gperf).  But now we
can't distribute the output from running perl to generate the file
because it is system dependent.  So everyone who builds Octave needs
perl (for full functionality).  So in the case of perl not being
available, we will only have the POSIX error codes (assuming they are
defined).

jwe

Reply | Threaded
Open this post in threaded view
|

Re: popen2 example gives no output

Paul Kienzle

On Sep 22, 2005, at 11:46 PM, John W. Eaton wrote:

> On 22-Sep-2005, Bill Denney wrote:
>
> | I think that this is what you're asking for:
> |
> | === Begin Script
> | #!/usr/bin/perl
> |
> | foreach my $key (keys(%!)) {
> |      print "$key\n";
> | }
> | === End Script
>
> Excellent.  This makes it fairly simple to generate the list that I
> need.
>
> | Also, I thought that Perl was already a build dependency for the
> | lsode_options (and *_options) code, so adding this shouldn't really
> be an
> | issue.
>
> For the *_options files, we can distribute the results because the
> output files are not system dependent.  So the dependency is really a
> developer dependency (similar to flex, bison, and gperf).  But now we
> can't distribute the output from running perl to generate the file
> because it is system dependent.  So everyone who builds Octave needs
> perl (for full functionality).  So in the case of perl not being
> available, we will only have the POSIX error codes (assuming they are
> defined).

I wonder if there is something similar in python?  Putting a dependency
on python and matplotlib instead of perl and gnuplot I think would be a
win.  This isn't feasible yet since matplotlib doesn't support surface
plots.

- Paul

Reply | Threaded
Open this post in threaded view
|

Re: popen2 example gives no output

John W. Eaton-6
On 23-Sep-2005, Paul Kienzle wrote:

| I wonder if there is something similar in python?  Putting a dependency
| on python and matplotlib instead of perl and gnuplot I think would be a
| win.  This isn't feasible yet since matplotlib doesn't support surface
| plots.

It looks like you can write

  import errno
  for i in errno.errorcode.keys():
    errno.errorcode[i]

to generate the list of errno symbols.

Here is the perl "script" that I ended up with in src/Makefile ($
symbols are doubled because this comes out of a Makefile):

  $(PERL) -e 'foreach $$key (keys(%!)) {
    $$x .= "#if defined ($$key)\n    { \"$$key\", $$key, },\n#endif\n";
  }; while (<>) {
    s/^ *\@SYSDEP_ERRNO_LIST\@/$$x/;
    print;
  }'

What would the same be in Python?  Can it easily go in a Makefile as a
one-liner?  If so, then we can use either Perl or Python, depending on
which is available.

jwe

Reply | Threaded
Open this post in threaded view
|

Re: popen2 example gives no output

Stéfan van der Walt
On Fri, Sep 23, 2005 at 11:29:28PM -0400, John W. Eaton wrote:

> Here is the perl "script" that I ended up with in src/Makefile ($
> symbols are doubled because this comes out of a Makefile):
>
>   $(PERL) -e 'foreach $$key (keys(%!)) {
>     $$x .= "#if defined ($$key)\n    { \"$$key\", $$key, },\n#endif\n";
>   }; while (<>) {
>     s/^ *\@SYSDEP_ERRNO_LIST\@/$$x/;
>     print;
>   }'
>
> What would the same be in Python?  Can it easily go in a Makefile as a
> one-liner?  If so, then we can use either Perl or Python, depending on
> which is available.

Maybe something like

${PYTHON} -c '
from errno import errorcode
from string import Template, join
from sys import stdin

t = Template("#if defned (\$e)\n{ \"$e\", $e, },\n#endif\n")
errstr = join([t.substitute(e=errorcode[i]) for i in errorcode.keys()])

for l in stdin:
    print l.replace("@SYSDEP_ERRNO_LIST@", errstr),
'

Regards
Stéfan

Reply | Threaded
Open this post in threaded view
|

Re: popen2 example gives no output

John W. Eaton-6
On 24-Sep-2005, Stefan van der Walt wrote:

| Maybe something like
|
| ${PYTHON} -c '
| from errno import errorcode
| from string import Template, join
| from sys import stdin
|
| t = Template("#if defned (\$e)\n{ \"$e\", $e, },\n#endif\n")
| errstr = join([t.substitute(e=errorcode[i]) for i in errorcode.keys()])
|
| for l in stdin:
|     print l.replace("@SYSDEP_ERRNO_LIST@", errstr),
| '

On my system (with Python 2.3.5) This fails for me with the following
error:

  Traceback (most recent call last):
    File "<string>", line 3, in ?
  ImportError: cannot import name Template

jwe

Reply | Threaded
Open this post in threaded view
|

Re: popen2 example gives no output

Stéfan van der Walt
On Sat, Sep 24, 2005 at 08:49:05AM -0400, John W. Eaton wrote:

> On 24-Sep-2005, Stefan van der Walt wrote:
>
> | Maybe something like
> |
> | ${PYTHON} -c '
> | from errno import errorcode
> | from string import Template, join
> | from sys import stdin
> |
> | t = Template("#if defned (\$e)\n{ \"$e\", $e, },\n#endif\n")
> | errstr = join([t.substitute(e=errorcode[i]) for i in errorcode.keys()])
> |
> | for l in stdin:
> |     print l.replace("@SYSDEP_ERRNO_LIST@", errstr),
> | '
>
> On my system (with Python 2.3.5) This fails for me with the following
> error:
>
>   Traceback (most recent call last):
>     File "<string>", line 3, in ?
>   ImportError: cannot import name Template

Yes, this is a Python 2.4 feature.  You can do something like

PYTHON=python

${PYTHON} -c '
from errno import errorcode
from string import Template, join
from sys import stdin

t = "#if defined (\%s)\n{ \"%s\", %s, },\n#endif\n"
errstr = ""
for k in errorcode.keys():
    errstr += t % tuple(3*[errorcode[k]])

for l in stdin:
    print l.replace("@SYSDEP_ERRNO_LIST@", errstr),
'

Regards
Stéfan

Reply | Threaded
Open this post in threaded view
|

Re: popen2 example gives no output

John W. Eaton-6
On 24-Sep-2005, Stefan van der Walt wrote:

| Yes, this is a Python 2.4 feature.  You can do something like
|
| PYTHON=python
|
| ${PYTHON} -c '
| from errno import errorcode
| from string import Template, join
| from sys import stdin
|
| t = "#if defined (\%s)\n{ \"%s\", %s, },\n#endif\n"
| errstr = ""
| for k in errorcode.keys():
|     errstr += t % tuple(3*[errorcode[k]])
|
| for l in stdin:
|     print l.replace("@SYSDEP_ERRNO_LIST@", errstr),
| '

I added this as another possible way to generate the list of errno
codes.

Thanks,

jwe