There is this program on the Stratus FTP site called set_terminal_type.cobol.
It actually queried the terminal that you were connected to and tried to
determine what terminal you were on, based upon the response.  It had a few
problems: (1) it only had a few types that it knew/cared about and these were
all Stratus terminals, (2) it didn't even have all the Stratus types (or at
least the version I had didn't) (3) it was written in COBOL (yuk).

set_terminal_type.pl1 tries to remedy there problems.  Firstly, it is written
in wonderful VOS pl/1 and most importantly, it uses a tin/table file to
specify the terminals, the inquiry strings, and the expected responses.

The program has the display form:

 ------------------------------ set_terminal_type -----------------------------
 stt:         stt.table
 -wait_timer: 3

where:

stt is the path of the stt table.  The default is stt.table in the current dir.

-wait_timer is the expected time to wait for a response

In addition,

-raw is a secret switch that displays the response from the terminal.

The format of the tin file is:

declare  1  stt                    based,
            2  inq                 char(32), /* query character string     */
            2  pref                char(32) varying,
                                             /* identifiying prefix        */
            2  default             char(32) varying,
                                             /* default term type          */
            2  type_off            bin(15),  /* type location              */
            2  type_len            bin(15),  /* type length                */
            2  parms(5),
               3  name             char(32) varying,
                                             /* parameter to display       */
               3  offset           bin(15),  /* parm location              */
               3  len              bin(15),  /* parm length                */
            2  cmd                 char(300) varying;
                                             /* cmd to execute for this trm*/

where 

inq is the string that is sent to the terminal.

pref is the initial substring that is looked for in the response.  This may
not be the name or type of the terminal, but just something to identify the
response.

default is the default to use for the terminal.

type_off is the location in the response where the actual type to be used is.
If this is -1, then the default is used.

type_len is the length of the terminal type in the response.

parms are informational fields that are extracted from the response and
printed on the terminal after the terminal type has been established.

cmd is a command to execute once set_terminal_type has set the terminal type

The stt.table file is indexed based on the content of inq.  This groups
together all the terminals with a common inquiry.  That inquiry is only sent
once.  Then the common terminals that use that inquiry are searched based upon
a match of the response to the pref.  The order that they are searched is the
order they are in the file, even though they would have the same key (what is
in inq).  Thus, if two terminal share an initial substring in the pref, then
always put the longest one first in the tin file.

See the example stt.tin file for example of how to use the parms.  The purpose
of the cmd field is to execute a command after the terminal type has been set.
For example, I utilize the kermit ttp and K95.  If I detect that I am logging
in to a kermit terminal, I will call 'set_terminal_parameters -setup 132x42'
to resize the terminal.