Xenix clear screen function..

Paul Sutcliffe Jr. paul at devon.lns.pa.us
Fri Feb 16 10:48:04 AEST 1990


In article <873 at jetsun.WEITEK.COM> brothers at jetsun.WEITEK.COM (bill brothers)
writes:
+---------
| >> On the console screen only, you can echo a Control-L to clear the screen
| >> and move the cursor home.
| >> 
| >> Alternatively, on the console and other ANSI terminals (vt100, vt220, ...)
| >> you can echo the 6 char sequence ESC [ H ESC [ J to clear the screen
| >> and move the cursor home.
| 
| The "right :*) way is using termcap/info"... Here is a bitty  pgm for
| that...
+---------

You're correct, the "right" way is termcap/terminfo.  However, you've
implemented it the *WRONG* *WAY* in your example:

+---------
| extern char *getenv();
| extern char *tgetstr();
| 
| main()
| {
| 	char buf[1024], a[1024], *area;
| 	area = a;
| 
| 	tgetent( buf, getenv("TERM") );
| 	printf("%s", tgetstr("cl", &area) );
| }
+---------
First, tgetstr doesn't decode any cursor addressing and/or padding
information defined in the termcap entry -- read the manual page!  
Second, you've used printf, which calls the whole stdio library
into your object, and which won't properly handle the padding returned
by tgetstr.  The string returned from tgetstr should be handed to
tputs() -- again, read the manual page!

Here's a *much better* solution; it doesn't use stdio, uses tgetstr
correctly, and even does proper error checking:

----- 8< ---------- 8< ---------- 8< ---------- 8< ---------- 8< -----
/*
 *	clear.c  -  clear crt screen
 *
 *	compile me by saying:  cc -O -s -o o clear clear.c -ltermlib
 */

#define	BUFSIZE	1024
#define	NULL	0

char	termcap[BUFSIZE], buffer[BUFSIZE];
int	outc();

main()
{
	char	*getenv(), *tgetstr();
	char	*term, *bptr;

	bptr = buffer;

	if ((term = getenv("TERM")) != (char *) NULL)
		if (tgetent(termcap, term) > 0)
			if (tgetstr("cl", &bptr) != (char *) NULL)
				tputs(buffer, 1, outc);
}

outc(ch)
char	ch;
{
	write(1, &ch, 1);	/* write ch on stdout */
}
----- 8< ---------- 8< ---------- 8< ---------- 8< ---------- 8< -----

Ghod, I even saw someone post a solution that used *curses*!  How big
was that binary anyway?

- paul

INTERNET:  paul at devon.lns.pa.us        |      If life's a bitch, then
UUCP:      ...!rutgers!devon!paul      |      we must be her puppies.



More information about the Comp.unix.xenix mailing list