From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 11-OCT-1989 18:09
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Re: terminal type

Received: From EQL.Caltech.Edu ([131.215.139.240]) by CRVAX.SRI.COM with TCP; Wed, 11 OCT 89 14:30:16 PDT
Date:     Wed, 11 Oct 89 14:30:01 PDT
From: rankin@EQL.Caltech.Edu (Pat Rankin)
Message-Id: <891011142920.20200194@EQL.Caltech.Edu>
Subject:  Re: terminal type
To: j3gum%mkvax1%msus1.bitnet@EQL.Caltech.Edu
Cc: info-vax@sri.com

>
>           I'm writing a DCL procedure that must have the terminal type
>      as a character string (ie. "VT100").  Currently I'm using
>      f$getdvi(f$getjpi(f$pid(CONTEXT),"TERMINAL"),"DEVTYPE") to return
>      the terminals integer equivalent.  I'm taking this number using
>      nested IFs and converting it to the number to the correct
>      terminal type.  Code follows:
 [...]
>      Question:
>         Is there an easier way to accomplish this goal using DCL or
>      Fortran, Pascal, Modula, GCC or Macro procedures.

     Several people have pointed out various methods, including
combinations of f$locate()+f$extract() or f$element().  The better way,
SMG$INIT_TERM_TABLE_BY_TYPE() was also demonstrated, but it requires
that an image be invoked.

     We run a program at boot time that creates a logical name table
containing entries that are 'supported'.  It includes the standard DEC
terminals and a few we've added to TERMTABLE for SMG use.  The table
contains a pair of logical names for each type, allowing easy numeric
to string name conversion and vice versa.

$ show trans/table=smg_support vt102          !name to number
  VT102 = "98"  (SMG_SUPPORT_TABLE)
$ show trans/table=smg_support tt_type_98     !number to name
  TT_TYPE_98 = "VT102"  (SMG_SUPPORT_TABLE)

     The logical names allow this DCL to accomplish what you want:

$ devtype = f$getdvi(terminal,"DEVTYPE")
$ term = f$trnlnm("TT_TYPE_''devtype'","SMG_SUPPORT")
$ if term .eqs. "" then  term = "Unknown"

     The following Fortran program was developed under VMS V4.7A and
still runs as is under V5.2.  I see no reason why it wouldn't work for
V4.5 as well.  I consider it unfinished--it runs in 'system' mode but it
would be nice to have a 'user' mode too--but is sufficient to our needs,
so I doubt if I'll do any more with it.  It creates a shareable logical
name table called SMG_SUPPORT_TABLE and also a logical name SMG_SUPPORT
pointing to that table.  Privileges are required, as noted in the code.

$ create SMG_Support.For
$DECK
      PROGRAM SMG_Support_Logicals
        !
        !                                               Pat Rankin, 12/88
        !   Check all possible terminal type codes (0..255) for
        !   SMG defined terminals and create logical names for them
        !   to allow easy DCL determination of supported terminals.
        !
        !   Intended to be run during system boot;
        !   SYSNAM & SYSPRV privileges required.
        !
        !   Individual users can support additional terminals via their
        !   process, job, or group tables by defining additional logical
        !   names and re-defining SMG_SUPPORT.
        !   $ define/job term$tabloc dev:[dir]  !as per vms doc
        !   $ define/job TT_TYPE_222 "adm3a"    !number corresponding to
        !   $ define/job "adm3a" "222"          ! termtype must be determined
        !   $ define/table=lnm$process_directory smg_support -
        !                                        lnm$job,smg_support_table
        !
        implicit none
        INCLUDE '($LNMdef)/nolist'      !logical name defs
        INCLUDE '($PSLdef)/nolist'      !processor status longword (modes)
        CHARACTER *(*)  sMG_SUPPORT,  sMG_SUPPORT_TABLE,
     &                  pARENT_TABLE,  tT_PREFIX
        PARAMETER     ( sMG_SUPPORT = 'SMG_SUPPORT',    !indirect table access
     &                  sMG_SUPPORT_TABLE = 'SMG_SUPPORT_TABLE',
     &                  pARENT_TABLE = 'LNM$SYSTEM_DIRECTORY',
     &                  tT_PREFIX = 'TT_TYPE_' )        !logical name prefix
        PARAMETER       tBL_QUOTA = 4096,               !relatively small
     &                  tBL_MODE  = PSL$C_EXEC,
     &                  tBL_ATTR  = LNM$M_NO_ALIAS
     &                         .OR. LNM$M_CREATE_IF,
     &                  tBL_PROT  = 'EE44'x !(world:r,group:r,own:rwd,sys:rwd)
C
        CHARACTER  *16  tname,  lname
        INTEGER *2      tlen,  llen
        INTEGER *4      dev_type,  trmtab,  sts
        INTEGER *4      SYS$CRELNT,  LIB$SET_LOGICAL,
     &                  SMG$INIT_TERM_TABLE_BY_TYPE
C
C         $ create/name_table smg_support_table /parent='system'/exec -
C            /attributes=(noalias,share)/prot=(s:rwd,o:rwd,g:r,w:r)/quota=4096
        sts = SYS$CRELNT( tBL_ATTR, ,, tBL_QUOTA, tBL_PROT,
     &                   sMG_SUPPORT_TABLE, pARENT_TABLE, tBL_MODE)
D       type '(X,A,Z8.8)', '$crelnt = ', sts
        IF ( .NOT. sts )  CALL EXIT( sts)
C
C         $ define/table='parent' smg_support smg_support_table
        sts = LIB$SET_LOGICAL( sMG_SUPPORT, sMG_SUPPORT_TABLE,
     &                        pARENT_TABLE)
C
        trmtab = 0
        DO dev_type = 0, 255
            sts = SMG$INIT_TERM_TABLE_BY_TYPE( dev_type, trmtab, tname)
            IF ( sts ) THEN
C             'device_type' represents a supported terminal called "''tname'"
                CALL STR$TRIM( tname, tname, tlen)      !determine length
                CALL SYS$FAO( '!AS!UB', llen, lname,    !format number
     &                       tT_PREFIX, %VAL(dev_type))
C
C                 $ define/table=smg_support TT_TYPE_'nn' "''device_name'"
                sts = LIB$SET_LOGICAL( lname(:llen), tname(:tlen),
     &                                sMG_SUPPORT)
D               type '(Z9.8,X,3A)', sts, lname(:llen),' = ',tname(:tlen)
C
C                 $ define/table=smg_support "''device_name'" "''nn'"
                sts = LIB$SET_LOGICAL( tname(:tlen),
     &                                lname(LEN(tT_PREFIX)+1:llen),
     &                                sMG_SUPPORT)
            END IF !dev_type ok
        END DO !next dev_type
C
        CALL SMG$DEL_TERM_TABLE()
D       pause '...'
        !
      END !of SMG_Support_Logicals
$EOD
$ fortran SMG_Support
$ link SMG_Support      !(no special options necessary)

     Hope this is of some use.

                                Pat Rankin
                                Calif. State Legislature
                 Internet:  rankin@eql.Caltech.EDU
              SPAN/HEPnet:  EQL::RANKIN  (EQL==5.970)
                   Bitnet:  rankin%eql@CITiago.bitnet

