Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sunybcs!rutgers!devon!paul From: paul@devon.lns.pa.us (Paul Sutcliffe Jr.) Newsgroups: comp.unix.xenix Subject: Re: Xenix clear screen function.. Summary: Using printf() just won't do Message-ID: <1990Feb15.234804.26734@devon.lns.pa.us> Date: 15 Feb 90 23:48:04 GMT References: <153@mnopltd.UUCP> <4185@helios.TAMU.EDU> <25CFA32B.1493@marob.masa.com> <251@microm.UUCP> <873@jetsun.WEITEK.COM> Reply-To: paul@devon.LNS.PA.US (Paul Sutcliffe Jr.) Organization: Devon Computer Services, Lancaster, PA Lines: 80 In article <873@jetsun.WEITEK.COM> brothers@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@devon.lns.pa.us | If life's a bitch, then UUCP: ...!rutgers!devon!paul | we must be her puppies.