home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume8 / hint / part02 / clearhint.c next >
Encoding:
C/C++ Source or Header  |  1989-08-24  |  2.9 KB  |  134 lines

  1. /* clearhint.c -- clear terminal status line
  2.    Copyright (C) 1989 David MacKenzie
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 1, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  17.  
  18. /* clearhint - clear terminal status line
  19.  
  20.    Usage: clearhint [-T terminal]
  21.  
  22.    David MacKenzie
  23.    Latest revision: 08/15/89 */
  24.  
  25. #include <stdio.h>
  26. #ifdef USG
  27. #include <termio.h>
  28. #else
  29. #include <sgtty.h>
  30. #endif
  31.  
  32. char *getenv ();
  33. char *tgetstr ();
  34. void exit ();
  35.  
  36. int tcputchar ();
  37. void getspeed ();
  38. void usage ();
  39.  
  40. extern short ospeed;        /* Output speed of stdout for tputs. */
  41. extern char PC;            /* Pad character for tputs. */
  42.  
  43. int
  44. main (argc, argv)
  45.      int argc;
  46.      char **argv;
  47. {
  48.   extern char *optarg;
  49.   extern int optind;
  50.   char entry[1024];        /* Raw termcap entry. */
  51.   char strings[80];        /* Extracted termcap strings. */
  52.   char *term;            /* Environment variable TERM. */
  53.   char *next_string;        /* Pointer into strings. */
  54.   char *tc_ds;            /* Disable status line string. */
  55.   char *tc_pc;            /* Pad character string. */
  56.   int c;            /* Option character. */
  57.  
  58.   term = getenv ("TERM");
  59.   while ((c = getopt (argc, argv, "T:")) != EOF)
  60.     if (c == 'T')
  61.       term = optarg;
  62.     else
  63.       usage (argv[0]);
  64.   if (optind != argc)
  65.     usage (argv[0]);
  66.  
  67.   if (term == NULL)
  68.     {
  69.       fprintf (stderr,
  70.            "%s: TERM environment variable is not defined\n", argv[0]);
  71.       exit (1);
  72.     }
  73.  
  74.   switch (tgetent (entry, term))
  75.     {
  76.     case 0:
  77.       fprintf (stderr,
  78.            "%s: Terminal type %s is unknown\n", argv[0], term);
  79.       exit (1);
  80.     case -1:
  81.       fprintf (stderr,
  82.            "%s: Cannot open terminal description database\n", argv[0]);
  83.       exit (1);
  84.     }
  85.  
  86.   getspeed ();
  87.  
  88.   next_string = strings;
  89.   tc_pc = tgetstr ("pc", &next_string);
  90.   PC = tc_pc ? *tc_pc : 0;
  91.   tc_ds = tgetstr ("ds", &next_string);
  92.   if (tc_ds)
  93.     {
  94.       tputs (tc_ds, 1, tcputchar);
  95.       exit (0);
  96.     }
  97.   exit (1);
  98.   /* NOTREACHED */
  99. }
  100.  
  101. void
  102. getspeed ()
  103. {
  104. #ifdef USG
  105.   struct termio tty_buffer;
  106.  
  107.   if (ioctl (1, TCGETA, &tty_buffer) != -1)
  108.     ospeed = tty_buffer.c_cflag & CBAUD;
  109. #else
  110.   struct sgttyb tty_buffer;
  111.  
  112.   if (gtty (1, &tty_buffer) != -1)
  113.     ospeed = tty_buffer.sg_ospeed;
  114. #endif
  115.   else
  116.     ospeed = 0;
  117. }
  118.  
  119. int
  120. tcputchar (c)
  121.      int c;
  122. {
  123.   putchar (c & 0x7f);
  124.   return c;
  125. }
  126.  
  127. void
  128. usage (program)
  129.      char *program;
  130. {
  131.   fprintf (stderr, "Usage: %s [-T terminal]\n", program);
  132.   exit (1);
  133. }
  134.