harrison@csl.dl.nec.com (Mark Harrison) (05/15/91)
I am having a problem getting the value needed for an TIOCGWINSZ (get window size) ioctl. If I hardcode the value printed by the C program, everything works correctly. I have run "h2ph * */*" in /usr/include. Anybody have a clue? Thanks in advance! C program: > #include <sys/ioccom.h> > #include <sys/ttycom.h> > main(){printf("%d\n", TIOCGWINSZ);} from ioccom.ph: > eval 'sub _IOR { > local($x,$y,$t) = @_; > eval "( &_IOC_OUT|(($sizeof{$t}& &_IOCPARM_MASK)<<16)|(ord(\'$x\')<<8)|$y)"; > }'; from ttycom.ph: > eval 'sub TIOCGWINSZ { &_IOR("t", 104, struct winsize);}'; My program: #!/usr/local/bin/perl require "sys/ioccom.ph"; require "sys/ttycom.ph"; $x = &TIOCGWINSZ; print "x =", $x, ":\n"; print "TIOCGWINSZ =", &TIOCGWINSZ, ":\n"; ioctl(STDIN, &TIOCGWINSZ, $gettyval) || die "can't get window size"; #ioctl(STDIN, 1074295912, $gettyval); # <-- this one works ok. ($Rows, $Cols) = unpack("ss", $gettyval); ~ My output: > x =: > TIOCGWINSZ =: > can't get window size at foo line 13. -- Mark Harrison | Note: harrison@ssd.dl.nec.com and harrison@csl.dl.nec.com | necssd!harrison are not operating at (214)518-5050 | present. Please forward mail through the | above address. Sorry for the inconvenience.
tchrist@convex.COM (Tom Christiansen) (05/16/91)
From the keyboard of harrison@csl.dl.nec.com (Mark Harrison): :I am having a problem getting the value needed for an TIOCGWINSZ (get :window size) ioctl. If I hardcode the value printed by the C program, :everything works correctly. I have run "h2ph * */*" in /usr/include. : :Anybody have a clue? Thanks in advance! Try checking $@ after the function call. --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "So much mail, so little time."
harrison@csl.dl.nec.com (Mark Harrison) (05/20/91)
Following up to my own article, I am coming closer to figuring out why my ioctl's are not working. It seems that I am not getting a definition of struct something, or of &int. Any suggestions? Did I leave out a step somewhere to the the definitions of struct and &int? These lines are from /usr/local/lib/perl/sys/ttycom.ph: > eval 'sub TIOCGWINSZ { &_IOR("t", 104, struct winsize);}'; > eval 'sub TIOCSCTTY { &_IO("t", 132);}'; > eval 'sub TIOCGPGRP { &_IOR("t", 119, &int);}'; my test program: ---------------- #!/usr/local/bin/perl require "sys/ioctl.ph"; require "sys/ioccom.ph"; require "sys/ttycom.ph"; print "defined(&TIOCSCTTY)=", defined(&TIOCSCTTY), "\n"; $x = &TIOCSCTTY; print "value is :$x:\n\n"; print "defined(&TIOCGWINSZ)=", defined(&TIOCGWINSZ), "\n"; $x = &TIOCGWINSZ; print "value is :$x:\n\n"; print "defined(&TIOCGPGRP)=", defined(&TIOCGPGRP), "\n"; $x = &TIOCGPGRP; print "value is :$x:\n\n"; Output: ------- defined(&TIOCSCTTY)=1 value is :536900740: defined(&TIOCGWINSZ)=1 value is :: defined(&TIOCGPGRP)=1 Undefined subroutine "main'int" called at (eval) line 1. -- Mark Harrison | Note: harrison@ssd.dl.nec.com and harrison@csl.dl.nec.com | necssd!harrison are not operating at (214)518-5050 | present. Please forward mail through the | above address. Sorry for the inconvenience.
tchrist@convex.COM (Tom Christiansen) (05/21/91)
From the keyboard of harrison@csl.dl.nec.com (Mark Harrison):
:Following up to my own article, I am coming closer to figuring out
:why my ioctl's are not working.  It seems that I am not getting a
:definition of struct something, or of &int.
:Any suggestions?  Did I leave out a step somewhere to the the
:definitions of struct and &int?
yes: you should first of all have %sizeof defined, so that
    $sizeof{'int'} = 4; # or whatever
    $sizeof{'struct winsize'} = 8; # or whatever
There are some old tools I once wrote in the src/perl/h2pl directory that
can serve as a starting point for this.
:These lines are from /usr/local/lib/perl/sys/ttycom.ph:
:>       eval 'sub TIOCGWINSZ { &_IOR("t", 104, struct winsize);}';
should be
         eval 'sub TIOCGWINSZ { &_IOR("t", 104, \'struct winsize\');}';
:>       eval 'sub TIOCSCTTY { &_IO("t", 132);}';
:>       eval 'sub TIOCGPGRP { &_IOR("t", 119, \'int\');}';
:#!/usr/local/bin/perl
:require "sys/ioctl.ph";
:require "sys/ioccom.ph";
:require "sys/ttycom.ph";
:defined(&TIOCSCTTY)=1
:value is :536900740:
:
:defined(&TIOCGWINSZ)=1
:value is ::
:
:defined(&TIOCGPGRP)=1
:Undefined subroutine "main'int" called at (eval) line 1.
You really ought to check $@ after calling these.  I would bet that you've 
got other evals blowing up in there.
--tom
--
Tom Christiansen		tchrist@convex.com	convex!tchrist
		"So much mail, so little time."