home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / info / ch2ph next >
Encoding:
Text File  |  1992-02-05  |  4.5 KB  |  135 lines

  1. Newsgroups: comp.lang.perl
  2. Path: convex!usenet
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: ioctl, plum, and bad addresses
  5. Message-ID: <1992Jan26.205405.24775@convex.com>
  6. Sender: usenet@convex.com (news access account)
  7. Nntp-Posting-Host: pixel.convex.com
  8. Reply-To: tchrist@convex.COM (Tom Christiansen)
  9. Organization: CONVEX Realtime Development, Colorado Springs, CO
  10. References: <sherman.696137252@lea>
  11. Date: Sun, 26 Jan 1992 20:54:05 GMT
  12. X-Disclaimer: This message was written by a user at CONVEX Computer
  13.               Corp. The opinions expressed are those of the user and
  14.               not necessarily those of CONVEX.
  15. Lines: 118
  16.  
  17. From the keyboard of sherman@lea.csc.ncsu.edu (Chris Sherman):
  18. :ioctl doesn't work with DEC 4.2 Ultrix for me.  What am I doing wrong?
  19. :
  20. :#!/usr/local/bin/perl
  21. :
  22. :
  23. :    sub TIOCGETP        { 0x40067408; }
  24. :    sub TIOCSETN        { 0x8006740a; }
  25. :
  26. :
  27. :    ioctl(STDIN,&TIOCGETP,$sgttyb)
  28. :            || die "Can't ioctl TIOCGETP: $!";
  29. :    ioctl(STDIN,&TIOCSETN,$sgttyb)   ## line with error
  30. :        || die "Can't ioctl TIOCSETN: $!";
  31. :
  32. :
  33. :Results in a:
  34. :
  35. :Can't ioctl TIOCSETN: Bad address at test.pl line 10.
  36.  
  37. I believe the problem is that Ultrix needs your sgttyb structure
  38. preextended, something like this:
  39.  
  40.     $sgttyb = pack(&sgttyb'typedef(), ());
  41.  
  42. :Also, I'm using perl 4.003 because the admin staff is too busy
  43. :to upgrade at the moment.  Might that have something to do with it?
  44.  
  45. I don't think so.
  46.  
  47. :I'm trying to use plum, and the above code is taken from it, with some lines
  48. :removed.  I can't get the cbreak mode working correctly, unless I do a `stty` 
  49. :command.
  50.  
  51. :So, if you have a DEC 4.2, and recent version of perl, can you run 
  52. :this program without error?  Please send a quick note if you can, because 
  53. :then I'll know I have to get an upgraded perl.
  54.  
  55. Check out the new BSD conf file on convex.com for plum -- it's in
  56. plum-conf.shar.Z for anon FTP.   Mike Iglesisas reports that using the
  57. conf_BSD.pl there makes it work fine on his DECstation 5000/200 running
  58. Ultrix 4.2.
  59.  
  60. :Also, I have another question:
  61. :When I do a h2ph of /usr/include/sys/ioctl.h on this machine, I get the
  62. :following, with some lines removed:
  63. :
  64. :        eval 'sub _IOC_OUT {( &int)0x40000000;}';
  65. :
  66. :        eval 'sub _IOR {
  67. :            local($x,$y,$t) = @_;
  68. :            eval "( &int)( &_IOC_OUT|(($sizeof{$t}& &_IOCPARM_MASK)<<16)|($x<<8)
  69. :|$y)";
  70. :        }';
  71. :
  72. :        eval 'sub TIOCGETP { &_IOR(ord(\'t\'), 8,struct sgttyb_ULTRIX);}';
  73. :
  74. :
  75. :Of course, this doesn't work.  &TIOCGETP return nothing.  I'm gussing
  76. :that the problem is the $sizeof, which isn't going to work without
  77. :a C compiler (or something) saying how big the structure is going to
  78. :be.  How does everyone else take care of this, besides they way plum
  79. :does it, as shown at the top of this article.
  80.  
  81. Trying to make h2ph produce something tolerable to perl has always
  82. been black magic in the extreme.  This is why for plum I chose to 
  83. let people hack up config files themselves rather than trusting
  84. that they'd successfully run h2ph and c2ph.
  85.  
  86. Here's a summary of what you have to do to get good files.
  87.  
  88. What's the problem?  Getting good output files is non-trivial in the
  89. extreme.  Casting is a problem.  Assuming that %sizeof is setup is a
  90. problem.  Casts you basically need to get rid of.  With sizeof, you must:
  91.  
  92.     0) make sure you get a dump of intrinsics sizes
  93.        using the -a flag on c2ph.  this should probably go in 
  94.        types.ph in your perllib.
  95.  
  96.     1) run h2ph on all the pertinent include files.  munge the h2ph
  97.        output so calls to $sizeof{'foo'} are really foo'sizeof().   
  98.        I use this:
  99.  
  100.         s/\$sizeof{\s*&?([^}]+)}/\\'$1\\'/g && s/^(\S[^']*)\\'/$1'/g;
  101.         s/(struct|union) //g;
  102.         s/(IO(R|W|RW).*,\s*)&?(\w+)\s*\)/$1&$3\\'sizeof())/gi;
  103.  
  104.     2) use c2ph on anything you've run h2ph on so your C compiler can
  105.        give you good definitions for stuff.  
  106.  
  107.     NB: this is harder than h2ph, because you really have to get
  108.     all the prereq'd include files right, such as socket.h if you
  109.     want SIO* defined, etc.
  110.  
  111.     3) Run the following little h2pl generator:
  112.  
  113.     require 'types.ph'; # see step 0
  114.     for (@ARGV) {
  115.         %sym = %_main;
  116.         eval 'require $_';
  117.         warn $@ if $@;
  118.         for (grep(!$sym{$_}, keys %_main)) {
  119.         $@ = '';
  120.         eval '$val = &$_()';
  121.         if ($@) {
  122.             warn "couldn't eval $_: $@";
  123.         } else {
  124.             printf "\$%s = 0x%X;\n", $_, $val;
  125.         }
  126.         }
  127.     }
  128.  
  129.  
  130. The last step is important because otherwise you don't know
  131. whether your ended up with decent values for your functions
  132. or not, and no one ever checks $@ after calling the subroutines.
  133.  
  134. --tom
  135.