getting *term window dimensions w/o curses

Donn Cave donn at u.washington.edu
Mon Aug 6 12:21:00 EDT 2001


Quoth sill at optonline.net (Andrei Kulakov):
|> In article <slrn9mqmjl.2rf.sill at sill.silmarill.org>,
|> sill at optonline.net (Andrei Kulakov) writes:
|> 
|>| Anyway, this solution doesn't work in 2.1 - termios module doesn't
|>| have this attribute, (TERMIOS is deprecated and doesn't have it either).
|
| >>> termios.TIOCGWINSZ
| Traceback (most recent call last):
|   File "<stdin>", line 1, in ?
|   AttributeError: 'termios' module has no attribute 'TIOCGWINSZ'
|
| Doh :/ What could be the problem? Anyone know?

Python tries to analyze C include files to get those symbols.
Amazing that it works as well as it does, but most ioctls like
that are beyond its grasp, because they're actually macros that
Python doesn't know how to evaluate.  I'm kind of surprised if
anyone gets TIOCGWINSZ, but one way that could happen is if the
party responsible for the distribution went and added symbols
that the standard procedure couldn't get.  I append a program
that generates values for ioctls, using the C compiler.

	Donn Cave, donn at u.washington.edu
----------------------------------------
#!/usr/bin/awk -f
BEGIN {
	print "#include <stdio.h>" > "ioctl_cxd.c"
	print "#include <sys/ioctl.h>" > "ioctl_cxd.c"
	print "" > "ioctl_cxd.c"
	print "int" > "ioctl_cxd.c"
	print "main(int argc, char **argv)" > "ioctl_cxd.c"
	print "{" > "ioctl_cxd.c"
	while (getline < "/usr/include/sys/ioctl.h") {
		if ($1 == "#define" && $2 !~ /)/ && $3 ~ /^_IO/) {
			print "#ifdef", $2 > "ioctl_cxd.c"
			print " printf(\"" $2 " = 0x%x\\n\", " $2 ");" > "ioctl_cxd.c"
			print "#endif" > "ioctl_cxd.c"
		}
	}
	print " return 0;" > "ioctl_cxd.c"
	print "}" > "ioctl_cxd.c"
	close("ioctl_cxd.c")
	system("cc ioctl_cxd.c -o ioctl_cxd && ./ioctl_cxd");
}



More information about the Python-list mailing list