[comp.os.minix] tset

tholm@uvicctr.UUCP (Terrence W. Holm) (06/02/88)

EFTH Minix report #16  - June 1988 -  a minimal tset(1)


This is an implementation of a minimal tset(1) that we wrote
for Minix. Please consider this a public domain program.

This tset(1) is only used to find the default device type for
log-in's to different ports.

Note: You must have termcap(3) and ttyname(3) to compile tset(1).
A "man" page is included.

echo x - tset.1
gres '^X' '' > tset.1 << '/'
XNAME
X    tset(1)		- setup the TERM environment variable
X
XSYNOPSIS
X    eval `tset  [ device_type ]`
X
XDESCRIPTION
X    This command is generally used in a ".profile" script
X    with no arguments. In this case tset(1) uses the name
X    of the current port and looks in "/etc/ttytype" to find
X    the default device type for the port. It will return a
X    "TERM=..." definition for export. Put the following in
X    your ".profile" script:
X
X		eval `tset`
X
X    If the optional "device_type" is supplied then tset(1)
X    will generate a "TERM=device_type" string. However, to 
X    change the current device type it is easier to simply
X    type the "TERM=..." parameter yourself.
X
X    Tset(1) checks to make sure the device has a description
X    in "/etc/termcap".
X
X    The command stty(1) should be used to set the terminal
X    characteristics, for example the "line kill" character.
X
XFILES
X    /etc/termcap	definitions for termcap(3)
X    /etc/ttytype 	device type at each port
X
XSEE ALSO
X    stty(1), environ(4), termcap(4), ttytype(4)
/
echo x - ttytype.4
gres '^X' '' > ttytype.4 << '/'
XNAME
X    ttytype(4)		- mapping from terminal ports to type
X
XSYNOPSIS
X    /etc/ttytype
X
XDESCRIPTION
X    This file contains one line for each terminal port.
X    The format is: device type, a space and then the port
X    name (without the "/dev/" prefix), for example:
X
X	minix tty0
X	vt100 tty1
X
X    The tset(1) command uses this file to map a port
X    name into the appropriate default device descriptor.
X
XSEE ALSO
X    tset(1), ttys(4)
/
echo x - tset.c
gres '^X' '' > tset.c << '/'
X/****************************************************************/
X/*								*/
X/*	tset(1)							*/
X/*								*/
X/*		Setup the $TERM environment variable.		*/
X/*								*/
X/****************************************************************/
X/*   origination	  1988-May-6		 T. Holm	*/
X/****************************************************************/
X
X
X
X#include <stdio.h>
X
X
X#define  LINE_LENGTH  40	/* Max length in /etc/ttytype	*/
X#define  TC_BUFFER  1024	/* Size of termcap(3) buffer	*/
X
X
XFILE *fopen();
Xchar *ttyname();
Xchar *index();
Xchar *getenv();
X
X
X
X
X
X/****************************************************************/
X/*								*/
X/*	eval `tset  [ device_type ]`				*/
X/*								*/
X/*	"device_type" is the new name for $TERM. If no		*/
X/*	type is supplied then /etc/ttytype is scanned for	*/
X/*	the current port.					*/
X/*								*/
X/*	This program returns the string:			*/
X/*								*/
X/*		TERM= . . .					*/
X/*								*/
X/****************************************************************/
X/*								*/
X/*	Login(1) sets a default for $TERM, so for logging-in	*/
X/*	to any terminal place the following in ".profile":	*/
X/*								*/
X/*		eval `tset`					*/
X/*								*/
X/*	To change $TERM during a session:			*/
X/*								*/
X/*		eval `tset device_type`				*/
X/*								*/
X/****************************************************************/
X
X
X
Xmain( argc, argv )
X  int   argc;
X  char *argv[];
X
X  {
X  char *name;
X  FILE *f;
X  char  line[ LINE_LENGTH ];
X
X
X  if ( argc > 2 )
X    {
X    fprintf( stderr, "Usage:  %s  [ device_type ]\n", argv[0] );
X    exit( 1 );
X    }
X  
X  if ( argc == 2 )
X    {
X    Find_Termcap( argv[1] );
X    exit( 0 );
X    }
X
X
X  /*  No terminal name supplied, so use the current device	*/
X
X  if ( (name = ttyname( 0 )) == NULL )
X    Error( "Can not determine the user's terminal" );
X
X  name += 5;        	/*  Chop off "/dev/" part		*/
X 
X
X  /*  Look up the default terminal type in /etc/ttytype		*/
X
X  if ( (f = fopen( "/etc/ttytype", "r" )) == NULL )
X    Error( "Can not open /etc/ttytype" );
X
X  while ( fgets( line, LINE_LENGTH, f ) != NULL )
X    {
X    char *space = index( line, ' ' );
X
X    line[ strlen(line) - 1 ] = '\0';	/*  Remove '\n'		*/
X
X    if ( strcmp( space+1, name ) == 0 )
X      {
X      *space = '\0';
X      Find_Termcap( line );
X      exit( 0 );
X      }
X    }
X
X  Error( "Can not find your terminal in /etc/ttytype" );
X  }
X
X
X
XFind_Termcap( terminal )
X  char *terminal;
X
X  {
X  char termcap[ TC_BUFFER ];
X
X  if ( tgetent( termcap, terminal ) != 1 )
X    Error( "No termcap for your terminal type" );
X
X  /*  In real Unix the $TERMCAP would also be returned here  */
X
X  printf( "TERM=%s;\n", terminal );
X  }
X
X
X
XError( msg )
X  char *msg;
X
X  {
X  fprintf( stderr, "tset: %s\n", msg );
X  exit( 1 );
X  }
/
--------------------------------------------------------------------
               Edwin L. Froese
                  uw-beaver!ubc-cs!mprg!handel!froese

               Terrence W. Holm
                  {uw-beaver,ubc-cs}!uvicctr!sirius!tholm