Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!uw-beaver!ssc-vax!uvicctr!tholm From: tholm@uvicctr.UUCP (Terrence W. Holm) Newsgroups: comp.os.minix Subject: termcap(3) fixes Message-ID: <411@uvicctr.UUCP> Date: 17 May 88 23:08:51 GMT Reply-To: tholm@uvicctr.UUCP (Terrence W. Holm) Organization: University of Victoria, Victoria B.C. Canada Lines: 187 EFTH Minix report #9 - May 1988 - termcap(3) fixes Following are some fixes for the termcap(3) supplied with Minix 1.2a. The earlier version will get confused if $TERMCAP is defined, but $TERM is not the same as the current terminal. The terminal name was not compared correctly. Also the ^x escapes were incorrect. We have also made a "man" page for the Minix termcap(3). echo x - termcap.fix gres '^X' '' > termcap.fix << '/' X9a10,17 X> X> /* efth 1988-Apr-29 X> X> - Correct when TERM != name and TERMCAP is defined [tgetent] X> - Correct the comparison for the terminal name [tgetent] X> - Correct the value of ^x escapes [tgetstr] X> */ X> X44,52c52,64 X< if ((file = getenv("TERMCAP")) != (char *) NULL) { X< if (*file != '/' && X< (cp = getenv("TERM")) != NULL && strcmp(name, cp) == 0) { X< (void) strcpy(bp, file); X< return(1); X< } X< } else X< file = "/etc/termcap"; X< /* If TERM is NULL and TERMCAP is defined, then won't work (EFTH) */ X--- X> X> /* Fixed problem: If TERM != name and TERMCAP was defined, */ X> /* then should look in /etc/termcap, but didn't. (efth) */ X> X> if ( (file = getenv("TERMCAP")) == NULL ) X> file = "/etc/termcap"; X> else if ( *file != '/' ) X> if ( (cp = getenv("TERM")) != NULL && strcmp( name, cp ) == 0 ) { X> strcpy( bp, file ); X> return( 1 ); X> } else X> file = "/etc/termcap"; X> X56c68,73 X< while (fgets(bp, 1024, fp) != NULL) { X--- X> X> while (fgets(bp, 1024, fp) != NULL) { X> /* Read in the rest of the definition now (efth) */ X> while (*(cp = &bp[strlen(bp) - 2]) == '\\') X> fgets(cp, 1024, fp); X> X62,64c79,81 X< if (strncmp(name, cp, len) == 0) { X< while (*(cp = &bp[strlen(bp) - 2]) == '\\') X< fgets(cp, 1024, fp); X--- X> X> /* Make sure "name" matches exactly (efth) */ X> if (strncmp(name, cp, len) == 0 && cp[len] == '|') { X162c179 X< **area = *++cp - 'A'; X--- X> **area = *++cp - '@'; /* fix (efth)*/ / echo x - termcap.3 gres '^X' '' > termcap.3 << '/' XNAME X termcap(3) - routines to read the termcap file X XSYNOPSIS X int tgetent( buffer, name ) X char buffer[ 1024 ]; X char *name; X X int tgetflag( entry ) X char *entry; X X int tgetnum( entry ) X char *entry; X X char *tgetstr( entry, p ) X char *entry; X char **p; X X char *tgoto( cm_string, column, line ) X char *cm_string; X int column; X int line; X X tputs( string, count, Putchar ) X char *string; X int count; X void (*Putchar)(); X XDESCRIPTION X To read a termcap description into memory, use tgetent(). X The capabilities of the terminal "name" will be copied X to the "buffer". This buffer is used by tgetflag(), tgetnum() X and tgetstr(). X X This routine checks the $TERMCAP string in the environment, X using the following algorithm, X X if ( $TERMCAP is undefined ) then X search file /etc/termcap for "name" X X else if ( $TERMCAP starts with a '/' ) then X search file $TERMCAP for "name" X X else if ( $TERM = "name" ) then X use $TERMCAP as the termcap X X else X search file /etc/termcap for "name" X X Note this means that when $TERM is changed $TERMCAP must be X either updated or removed, see tset(1). X X On successful completion tgetent() returns 1. If it can not X open the termcap file then -1 is returned. If there is no X description for "name" then 0 is returned. X X READING ENTRIES X X To check for the presence of an entry in a description, use X tgetflag(). This routine returns 1 if the capability is X present, 0 if not and -1 for invalid calls. X X The "co" and "li" entries have a numeric value. A numeric X entry is read by tgetnum(). If the entry is not specified X then -1 is returned. X X Most entries are strings, and are read by tgetstr(). If X the requested entry is found, then it is copied to **p. X *p is incremented by the size of the entry. A pointer to X the start of the string is returned if successful, NULL X is returned if the entry was not found. X X GENERATING OUTPUT X X To position a cursor on the screen the routine tgoto() is X used. This takes the "cm" string and a column and line X number, and forms a string which can be sent to the terminal X by using tputs(). If tgoto() encounters a problem, then the X returned string is "OOPS". There are some special format X commands recognized by tgoto(), see termcap(4) for details. X X All strings returned by tgetstr() or tgoto() should be X output using tputs(). This performs the appropriate padding X for different terminals under various Unix systems. X For Minix, tputs() simply calls "Putchar()" for each X character in "string". X X NOTES X X XTABS should be off while using termcap(3). X X See termcap(4) for a complete description of the termcap X entries and the escape codes available for use within strings. X X XFILES X /etc/termcap The termcap entries X XSEE ALSO X termcap(1), tset(1), termcap(4) X XBUGS X tgetent() only checks the second terminal name in a description. X X tgoto() does not use BC or UP to avoid unpleasant characters. X X tgoto() is missing some format commands, including "%r". X X tputs() does not do padding under Minix. / -------------------------------------------------------------------- Edwin L. Froese (in London for the month) Terrence W. Holm {uw-beaver,ubc-cs}!uvicctr!sirius!tholm