home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo3.zoo / demo / misc / set_console.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-24  |  818 b   |  48 lines

  1. /* redirect sun console output to this window */
  2.  
  3. #include <stdio.h>
  4. #include <sys/ioctl.h>
  5. #include <sys/types.h>
  6. #include <sundev/kbio.h>
  7.  
  8. main(argc,argv)
  9. int argc;
  10. char **argv;
  11.     {
  12.     int fd;
  13.     int kbd;
  14.     int one = 1;
  15.     int mode = 0;
  16.    char *name, *ttyname();
  17.  
  18.     /* make sure kbd is in direct mode */
  19.  
  20.     if ((kbd = open("/dev/kbd",0)) < 0 ) {
  21.         perror("open");
  22.         exit(1);
  23.         }
  24.     if (ioctl(kbd,KIOCGDIRECT,&mode) < 0 ) {
  25.         perror("kbd ioctl");
  26.         exit(1);
  27.         }
  28.  
  29.     if (mode != 1) {
  30.         fprintf(stderr,"Keyboard not in direct mode\n");
  31.         exit(1);
  32.         }
  33.  
  34.     if (**argv == 'r')         /* reset console */
  35.         fd = open("/dev/console");
  36.     else
  37.         fd = 2;
  38.  
  39.    if (fd) {
  40.       name = ttyname(fd);
  41.        if (name) {
  42.          ioctl(fd,TIOCCONS,&one);
  43.          printf("Redirecting CONSOLE output to: %s\n",name);
  44.          exit(0);
  45.          }
  46.       }
  47.    }
  48.