home *** CD-ROM | disk | FTP | other *** search
- /* clearhint.c -- clear terminal status line
- Copyright (C) 1989 David MacKenzie
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- /* clearhint - clear terminal status line
-
- Usage: clearhint [-T terminal]
-
- David MacKenzie
- Latest revision: 08/15/89 */
-
- #include <stdio.h>
- #ifdef USG
- #include <termio.h>
- #else
- #include <sgtty.h>
- #endif
-
- char *getenv ();
- char *tgetstr ();
- void exit ();
-
- int tcputchar ();
- void getspeed ();
- void usage ();
-
- extern short ospeed; /* Output speed of stdout for tputs. */
- extern char PC; /* Pad character for tputs. */
-
- int
- main (argc, argv)
- int argc;
- char **argv;
- {
- extern char *optarg;
- extern int optind;
- char entry[1024]; /* Raw termcap entry. */
- char strings[80]; /* Extracted termcap strings. */
- char *term; /* Environment variable TERM. */
- char *next_string; /* Pointer into strings. */
- char *tc_ds; /* Disable status line string. */
- char *tc_pc; /* Pad character string. */
- int c; /* Option character. */
-
- term = getenv ("TERM");
- while ((c = getopt (argc, argv, "T:")) != EOF)
- if (c == 'T')
- term = optarg;
- else
- usage (argv[0]);
- if (optind != argc)
- usage (argv[0]);
-
- if (term == NULL)
- {
- fprintf (stderr,
- "%s: TERM environment variable is not defined\n", argv[0]);
- exit (1);
- }
-
- switch (tgetent (entry, term))
- {
- case 0:
- fprintf (stderr,
- "%s: Terminal type %s is unknown\n", argv[0], term);
- exit (1);
- case -1:
- fprintf (stderr,
- "%s: Cannot open terminal description database\n", argv[0]);
- exit (1);
- }
-
- getspeed ();
-
- next_string = strings;
- tc_pc = tgetstr ("pc", &next_string);
- PC = tc_pc ? *tc_pc : 0;
- tc_ds = tgetstr ("ds", &next_string);
- if (tc_ds)
- {
- tputs (tc_ds, 1, tcputchar);
- exit (0);
- }
- exit (1);
- /* NOTREACHED */
- }
-
- void
- getspeed ()
- {
- #ifdef USG
- struct termio tty_buffer;
-
- if (ioctl (1, TCGETA, &tty_buffer) != -1)
- ospeed = tty_buffer.c_cflag & CBAUD;
- #else
- struct sgttyb tty_buffer;
-
- if (gtty (1, &tty_buffer) != -1)
- ospeed = tty_buffer.sg_ospeed;
- #endif
- else
- ospeed = 0;
- }
-
- int
- tcputchar (c)
- int c;
- {
- putchar (c & 0x7f);
- return c;
- }
-
- void
- usage (program)
- char *program;
- {
- fprintf (stderr, "Usage: %s [-T terminal]\n", program);
- exit (1);
- }
-