From: "Mark E." To: djgpp-workers AT delorie DOT com Date: Tue, 7 Aug 2001 16:50:46 -0400 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: TIOCGWINSZ Message-ID: <3B701C66.28168.7C3116@localhost> X-mailer: Pegasus Mail for Win32 (v3.12c) Reply-To: djgpp-workers AT delorie DOT com Hi guys, I think it would be nice if DJGPP supported TIOCGWINSZ ioctl call to retrieve the number of rows and columns. It will help ncurses and readline "just work" without the need for more conditional code. I've deleted the "#if 0" block in sys/ioctl.h. But I don't most of things in there are worth bothering about. If there were, it would have caused enough trouble to implement before now. And I don't think it's possible to implement the ioctl commands in the Posix draft in DJGPP, so that leaves us with TIOCGWINSZ. Therefore, I think most of the unix stuff in sys/ioctl.h can be cleared out. Below is a patch to implement TIOCGWINSZ. I tried to set ws_{x,y}pixel, but I'm not sure if they're worth setting or not. If they are, please point out a better way to set them if you can. *** /cvs/djgpp/include/sys/ioctl.h Mon Aug 12 20:13:04 1996 --- include/sys/ioctl.h Tue Aug 7 16:37:46 2001 *************** of the xfer buffer in CX. Aaaaargh *** 77,83 **** #define __IS_UNIX_IOCTL(a) ((a) & 0xd0000000U) - #if 0 /* ** UNIX stuff ** --- 77,82 ---- *************** struct ttysize { *** 339,347 **** #define FIOSETOWN _IOW('f', 124, int) /* set owner */ #define FIOGETOWN _IOR('f', 123, int) /* get owner */ - - #endif /* 0 */ - int ioctl( int fd, int cmd, ...); --- 338,343 ---- *** /cvs/djgpp/src/libc/compat/ioctl/ioctl.c Sat Jun 23 16:43:08 2001 --- projects/ioctl/ioctl.c Tue Aug 7 16:18:48 2001 *************** import djgpp 2.02 *** 107,113 **** #include #include #include ! /****************************************************************************/ --- 107,113 ---- #include #include #include ! #include /****************************************************************************/ *************** static int _dos_ioctl(int fd, int cmd, i *** 251,271 **** } ! static int _unix_ioctl(int fd,int cmd, int arg){ ! /* ! ** What to do _HERE_ ? ! */ __FSEXT_Function *func = __FSEXT_get_function(fd); ! if(func){ int rv; ! if(func(__FSEXT_ioctl,&rv, &fd)) return rv; } ! /* ! ** All else fails so far. ! */ ! errno = ENOTTY; return -1; } --- 251,285 ---- } ! static int _unix_ioctl(int fd, int cmd, va_list args) ! { __FSEXT_Function *func = __FSEXT_get_function(fd); ! if(func) ! { int rv; ! if (func(__FSEXT_ioctl,&rv, &fd)) return rv; } ! switch (cmd) ! { ! case TIOCGWINSZ: ! { ! struct winsize *win; ! ! win = va_arg(args, struct winsize *); ! ! _farsetsel(_dos_ds); ! win->ws_row = _farnspeekb(0x0484) + 1; ! win->ws_col = _farnspeekw(0x044a); ! win->ws_xpixel = win->ws_col * 8; /* Assumes 8 pixel width. */ ! win->ws_ypixel = win->ws_row * _farnspeekw(0x0485); ! return 0; ! } ! } ! ! /* All else fails. */ ! errno = ENOSYS; return -1; } *************** static int _unix_ioctl(int fd,int cmd, i *** 274,285 **** ** The user callable entry point. ** */ ! int ioctl(int fd, int cmd, ...){ ! va_list args; int argcx,argdx,argsi,argdi; int narg,xarg; __FSEXT_Function *func = __FSEXT_get_function(fd); int rv; /** ** see if this is a file system extension file --- 288,300 ---- ** The user callable entry point. ** */ ! int ioctl(int fd, int cmd, ...) ! { int argcx,argdx,argsi,argdi; int narg,xarg; __FSEXT_Function *func = __FSEXT_get_function(fd); int rv; + va_list args; /** ** see if this is a file system extension file *************** int ioctl(int fd, int cmd, ...){ *** 288,298 **** if (func && func(__FSEXT_ioctl, &rv, &fd)) return rv; ! va_start(args,cmd); ! if(__IS_UNIX_IOCTL(cmd)){ ! int arg = va_arg(args, int); ! va_end(args); #ifdef TEST { int inflg = (cmd & IOC_IN) == IOC_IN; --- 303,312 ---- if (func && func(__FSEXT_ioctl, &rv, &fd)) return rv; ! va_start(args, cmd); ! if(__IS_UNIX_IOCTL(cmd)) ! { #ifdef TEST { int inflg = (cmd & IOC_IN) == IOC_IN; *************** int ioctl(int fd, int cmd, ...){ *** 309,315 **** inflg,outflg,voidflg,size); } #endif ! return _unix_ioctl(fd,cmd,arg); } /* Handle a DOS request */ /* extract arguments */ --- 323,329 ---- inflg,outflg,voidflg,size); } #endif ! return _unix_ioctl(fd, cmd, args); } /* Handle a DOS request */ /* extract arguments */ *************** int ioctl(int fd, int cmd, ...){ *** 335,341 **** #include #include ! int main (int argc, char **argv){ int fd; int res; short *s; --- 349,356 ---- #include #include ! int main (int argc, char **argv) ! { int fd; int res; short *s; Mark