home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / TERM_OPT.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  93 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **
  5. **  This was written under AIX 3.2.5.1
  6. **  (Cripes just a few more numbers please.)
  7. **
  8. **  Terminal functions
  9. **
  10. **  Option 0 - Turns the ECHO on.
  11. **         1 - Turns the ECHO off.
  12. **         2 - Waits forever for keyboard activity.
  13. **
  14. **  Public Domain *IX terminal functions.
  15. **  Slung together by Steve Poole for RBS's SNIPPETS.
  16. **
  17. */
  18.  
  19. #define _POSIX_SOURCE 1
  20.  
  21. #include <termios.h>
  22. #include <sys/types.h>
  23. #include "unxconio.h"
  24.  
  25. int term_option(option)
  26. int  option;
  27. {
  28.   struct termios attributes;
  29.  
  30.     switch(option)
  31.     {
  32. /*
  33. **  Turn echo on
  34. */
  35.       case 0:
  36.              if(tcgetattr(STDIN_FILENO,&attributes) != 0)
  37.                return (-1);
  38.              attributes.c_lflag |= ECHO;
  39.              if(tcsetattr(STDIN_FILENO,TCSANOW,&attributes) != 0)
  40.                return (-1);
  41.              break;
  42. /*
  43. **  Turn echo off
  44. */
  45.       case 1:
  46.              if(tcgetattr(STDIN_FILENO,&attributes) != 0)
  47.                return (-1);
  48.              attributes.c_lflag &= ~(ECHO);
  49.              if(tcsetattr(STDIN_FILENO,TCSAFLUSH,&attributes) != 0)
  50.                return (-1);
  51.              break;
  52. /*
  53. **  Wait forever for the keyboard to be touched. (AHHHHHH!!!!!!!)
  54. */
  55.       case 2:
  56.              if(tcgetattr(STDIN_FILENO,&attributes) != 0)
  57.                return (-1);
  58.              attributes.c_lflag    &= ~(ICANON);
  59.              attributes.c_cc[VMIN]  = 1;
  60.              attributes.c_cc[VTIME] = 1;
  61.              if(tcsetattr(STDIN_FILENO,TCSANOW,&attributes) != 0)
  62.                return (-1);
  63.              break;
  64. /*
  65. **  Don't be a bozo, call it with something
  66. */
  67.       default:
  68.               printf("Error in terminal options routine, "
  69.                     "BAD OPTION %d\n",option);
  70.               return(-1);
  71.               break;
  72.     }
  73. }
  74.  
  75. #ifdef TEST
  76.  
  77. main(argc,argv)
  78. int  argc;
  79. char *argv[];
  80. {
  81.   int  option,istat;
  82.   char buffer[2];
  83.  
  84.   option = atoi(argv[1]);
  85.   istat = term_option(option);
  86.   istat = read(STDIN_FILENO,&buffer,1);
  87.   if(istat < 0)
  88.     printf("Error on READ\n");
  89.   return 0;
  90. }
  91.  
  92. #endif /* TEST */
  93.