/* * @(#) Driver for reading a character from keyboard in raw I/O mode */ #include #include #include #include #include /*--------------------------*/ #ifdef BSD #include #else /*--------------------------*/ #ifdef Linux #define G77 #endif #ifdef CYGWIN #define G77 #endif #ifdef G77 #include #else #include #endif /*--------------------------*/ #endif #include /*V13 #include */ /*V13 #include */ /******************************************************************************/ /* return the next key typed in hot (raw I/O) mode. */ char getkeyC(void) { #ifdef BSD struct sgttyb oldtty, newtty; char c; ioctl(0, TIOCGETP, &oldtty); newtty = oldtty; newtty.sg_flags = RAW; ioctl(0, TIOCSETP, &newtty); read(0, &c, 1); ioctl(0, TIOCSETP, &oldtty); #else struct termio oldtty, newtty; /*V13 struct termios oldtty, newtty; */ char c; ioctl(0, TCGETA, &oldtty); /*V13 tcgetattr(0, &oldtty); */ newtty = oldtty; newtty.c_iflag = BRKINT | IXON | ISTRIP; newtty.c_lflag = 0; newtty.c_cc[VEOF] = 1; ioctl(0, TCSETA, &newtty); /*V13 tcsetattr(0, TCSANOW, &newtty); */ read(0, &c, 1); ioctl(0, TCSETA, &oldtty); /*V13 tcsetattr(0, TCSANOW, &oldtty); */ #endif /* fprintf(stderr,"C:c=%c\n",c); */ /* fflush(stdout); */ return(c); } /******************************************************************************/ /* Commonly, a C routine called name_ can be called from Fortran as name; plus less-common ones */ int getkey4f_(void) { return(getkeyC()); } int _getkey4f(void) { return(getkeyC()); } int getkey4f(void) { return(getkeyC()); } int GETKEY4F(void) { return(getkeyC()); } /******************************************************************************/ #ifdef TESTPRG /* THE REMAINING LINES ARE A TEST PROGRAM. REMOVE THEM AFTER TESTING THE ROUTINE */ /* read keys in hot (raw I/O) mode until letter q is hit */ main(){ char keyvalue; keyvalue=0; fprintf(stdout,"press keys ('q' to quit)\n"); fflush(stdout); fflush(stdin); while(keyvalue!='q'){ keyvalue=getkeyC(); /*keyvalue=getkey_();*/ fprintf(stdout,"C:KEY=%c %d\n",keyvalue,keyvalue); } } #endif