home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: convex!usenet
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: ioctl, plum, and bad addresses
- Message-ID: <1992Jan26.205405.24775@convex.com>
- Sender: usenet@convex.com (news access account)
- Nntp-Posting-Host: pixel.convex.com
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- Organization: CONVEX Realtime Development, Colorado Springs, CO
- References: <sherman.696137252@lea>
- Date: Sun, 26 Jan 1992 20:54:05 GMT
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 118
-
- From the keyboard of sherman@lea.csc.ncsu.edu (Chris Sherman):
- :ioctl doesn't work with DEC 4.2 Ultrix for me. What am I doing wrong?
- :
- :#!/usr/local/bin/perl
- :
- :
- : sub TIOCGETP { 0x40067408; }
- : sub TIOCSETN { 0x8006740a; }
- :
- :
- : ioctl(STDIN,&TIOCGETP,$sgttyb)
- : || die "Can't ioctl TIOCGETP: $!";
- : ioctl(STDIN,&TIOCSETN,$sgttyb) ## line with error
- : || die "Can't ioctl TIOCSETN: $!";
- :
- :
- :Results in a:
- :
- :Can't ioctl TIOCSETN: Bad address at test.pl line 10.
-
- I believe the problem is that Ultrix needs your sgttyb structure
- preextended, something like this:
-
- $sgttyb = pack(&sgttyb'typedef(), ());
-
- :Also, I'm using perl 4.003 because the admin staff is too busy
- :to upgrade at the moment. Might that have something to do with it?
-
- I don't think so.
-
- :I'm trying to use plum, and the above code is taken from it, with some lines
- :removed. I can't get the cbreak mode working correctly, unless I do a `stty`
- :command.
-
- :So, if you have a DEC 4.2, and recent version of perl, can you run
- :this program without error? Please send a quick note if you can, because
- :then I'll know I have to get an upgraded perl.
-
- Check out the new BSD conf file on convex.com for plum -- it's in
- plum-conf.shar.Z for anon FTP. Mike Iglesisas reports that using the
- conf_BSD.pl there makes it work fine on his DECstation 5000/200 running
- Ultrix 4.2.
-
- :Also, I have another question:
- :When I do a h2ph of /usr/include/sys/ioctl.h on this machine, I get the
- :following, with some lines removed:
- :
- : eval 'sub _IOC_OUT {( &int)0x40000000;}';
- :
- : eval 'sub _IOR {
- : local($x,$y,$t) = @_;
- : eval "( &int)( &_IOC_OUT|(($sizeof{$t}& &_IOCPARM_MASK)<<16)|($x<<8)
- :|$y)";
- : }';
- :
- : eval 'sub TIOCGETP { &_IOR(ord(\'t\'), 8,struct sgttyb_ULTRIX);}';
- :
- :
- :Of course, this doesn't work. &TIOCGETP return nothing. I'm gussing
- :that the problem is the $sizeof, which isn't going to work without
- :a C compiler (or something) saying how big the structure is going to
- :be. How does everyone else take care of this, besides they way plum
- :does it, as shown at the top of this article.
-
- Trying to make h2ph produce something tolerable to perl has always
- been black magic in the extreme. This is why for plum I chose to
- let people hack up config files themselves rather than trusting
- that they'd successfully run h2ph and c2ph.
-
- Here's a summary of what you have to do to get good files.
-
- What's the problem? Getting good output files is non-trivial in the
- extreme. Casting is a problem. Assuming that %sizeof is setup is a
- problem. Casts you basically need to get rid of. With sizeof, you must:
-
- 0) make sure you get a dump of intrinsics sizes
- using the -a flag on c2ph. this should probably go in
- types.ph in your perllib.
-
- 1) run h2ph on all the pertinent include files. munge the h2ph
- output so calls to $sizeof{'foo'} are really foo'sizeof().
- I use this:
-
- s/\$sizeof{\s*&?([^}]+)}/\\'$1\\'/g && s/^(\S[^']*)\\'/$1'/g;
- s/(struct|union) //g;
- s/(IO(R|W|RW).*,\s*)&?(\w+)\s*\)/$1&$3\\'sizeof())/gi;
-
- 2) use c2ph on anything you've run h2ph on so your C compiler can
- give you good definitions for stuff.
-
- NB: this is harder than h2ph, because you really have to get
- all the prereq'd include files right, such as socket.h if you
- want SIO* defined, etc.
-
- 3) Run the following little h2pl generator:
-
- require 'types.ph'; # see step 0
- for (@ARGV) {
- %sym = %_main;
- eval 'require $_';
- warn $@ if $@;
- for (grep(!$sym{$_}, keys %_main)) {
- $@ = '';
- eval '$val = &$_()';
- if ($@) {
- warn "couldn't eval $_: $@";
- } else {
- printf "\$%s = 0x%X;\n", $_, $val;
- }
- }
- }
-
-
- The last step is important because otherwise you don't know
- whether your ended up with decent values for your functions
- or not, and no one ever checks $@ after calling the subroutines.
-
- --tom
-