From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 14-JUN-1989 20:08
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Termcap to Termtable Conversion Program (1 of 3)

Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Wed, 14 JUN 89 15:45:16 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Wed, 14 Jun 89 15:18:27 PDT
Received: by ucbvax.Berkeley.EDU (5.61/1.36)
	id AA21219; Wed, 14 Jun 89 15:04:40 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 14 Jun 89 18:57:38 GMT
From: mtxinu!sybase!forrest%sybase.com@ucbvax.Berkeley.EDU
Organization: Sybase, Inc.
Subject: Termcap to Termtable Conversion Program (1 of 3)
Message-Id: <4669@sybase.sybase.com>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

The response to my offer of a termcap to termtable conversion
was overwhelming. So, I thought I'd just post it here. There will
be three postings, including this one. Please let me know if
you find any problems or bugs.

Jon Forrest
forrest@sybase.com

$! ................... Cut between dotted lines and save. ...................
$!...........................................................................
$! VAX/VMS archive file created by VMS_SHARE V06.10 7-FEB-1989.
$!
$! VMS_SHARE was written by James Gray (Gray:OSBUSouth@Xerox.COM) from
$! VMS_SHAR by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au).
$!
$! To unpack, simply save, concatinate all parts into one file and
$! execute (@) that file.
$!
$! This archive was created by user FORREST
$! on 30-MAR-1989 13:16:44.22.
$!
$! ATTENTION: To keep each article below 31 blocks (15872 bytes), this
$!            program has been transmitted in 3 parts.  You should
$!            concatenate ALL parts to ONE file and execute (@) that file.
$!
$! It contains the following 3 files:
$!        README.TC2TT
$!        TABLE.H
$!        TC2TT.C
$!
$!============================================================================
$ SET SYMBOL/SCOPE=( NOLOCAL, NOGLOBAL )
$ VERSION = F$GETSYI( "VERSION" )
$ IF VERSION .GES "V4.4" THEN GOTO VERSION_OK
$ WRITE SYS$OUTPUT "You are running VMS ''VERSION'; ", -
    "VMS_SHARE V06.10 7-FEB-1989 requires VMS V4.4 or higher."
$ EXIT 44 ! SS$_ABORT
$VERSION_OK:
$ GOTO START
$!
$UNPACK_FILE:
$ WRITE SYS$OUTPUT "Creating ''FILE_IS'"
$ DEFINE/USER_MODE SYS$OUTPUT NL:
$ EDIT/TPU/COMMAND=SYS$INPUT/NODISPLAY/OUTPUT='FILE_IS'/NOSECTION -
    VMS_SHARE_DUMMY.DUMMY
b_part := CREATE_BUFFER( "{Part}", GET_INFO( COMMAND_LINE, "file_name" ) )
; s_file_spec := GET_INFO( COMMAND_LINE, "output_file" ); SET( OUTPUT_FILE
, b_part, s_file_spec ); b_errors := CREATE_BUFFER( "{Errors}" ); i_errors 
:= 0; pat_beg_1 := ANCHOR & "-+-+-+ Beginning"; pat_beg_2 := LINE_BEGIN 
& "+-+-+-+ Beginning"; pat_end := ANCHOR & "+-+-+-+-+ End"; POSITION
( BEGINNING_OF( b_part ) ); LOOP EXITIF SEARCH( SPAN( ' ' )@r_trail 
& LINE_END, FORWARD) = 0; POSITION( r_trail ); ERASE( r_trail ); ENDLOOP
; POSITION( BEGINNING_OF( b_part ) ); i_append_line := 0; LOOP EXITIF MARK
( NONE ) = END_OF( b_part ); s_x := ERASE_CHARACTER( 1 )
; IF s_x = '+' THEN r_skip := SEARCH( pat_beg_1, FORWARD, EXACT ); IF r_skip 
<> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ERASE_LINE; ENDIF
; ENDIF; IF s_x = '-' THEN r_skip := SEARCH( pat_end, FORWARD, EXACT )
; IF r_skip <> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); m_skip 
:= MARK( NONE ); r_skip := SEARCH( pat_beg_2, FORWARD, EXACT ); IF r_skip 
<> 0 THEN POSITION( END_OF( r_skip ) ); MOVE_HORIZONTAL( -CURRENT_OFFSET )
; MOVE_VERTICAL( 1 ); MOVE_HORIZONTAL( -1 ); ELSE POSITION( END_OF( b_part 
) ); ENDIF; ERASE( CREATE_RANGE( m_skip, MARK( NONE ), NONE ) ); ENDIF; ENDIF
; IF s_x = 'V' THEN s_x := ''; IF i_append_line <> 0 THEN APPEND_LINE
; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF; i_append_line := 1
; MOVE_VERTICAL( 1 ); ENDIF; IF s_x = 'X' THEN s_x := ''; IF i_append_line 
<> 0 THEN APPEND_LINE; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF
; i_append_line := 0; MOVE_VERTICAL( 1 ); ENDIF; IF s_x <> '' THEN i_errors 
:= i_errors + 1; s_text := CURRENT_LINE; POSITION( b_errors ); COPY_TEXT
( "The following line could not be unpacked properly:" ); SPLIT_LINE
; COPY_TEXT( s_x ); COPY_TEXT( s_text ); POSITION( b_part ); MOVE_VERTICAL
( 1 ); ENDIF; ENDLOOP; POSITION( BEGINNING_OF( b_part ) ); LOOP r_x := SEARCH
( "`", FORWARD, EXACT ); EXITIF r_x = 0; POSITION( r_x ); ERASE_CHARACTER
( 1 ); COPY_TEXT( ASCII( INT( ERASE_CHARACTER( 3 ) ) ) ); ENDLOOP
; IF i_errors = 0 THEN SET( NO_WRITE, b_errors, ON ); ELSE POSITION
( BEGINNING_OF( b_errors ) ); COPY_TEXT( FAO
( "The following !UL errors were detected while unpacking !AS", i_errors
, s_file_spec ) ); SPLIT_LINE; SET( OUTPUT_FILE, b_errors, "SYS$COMMAND" )
; ENDIF; EXIT; 
$ DELETE VMS_SHARE_DUMMY.DUMMY;*
$ CHECKSUM 'FILE_IS
$ WRITE SYS$OUTPUT " CHECKSUM ", -
  F$ELEMENT( CHECKSUM_IS .EQ. CHECKSUM$CHECKSUM, ",", "failed!!,passed." )
$ RETURN
$!
$START: 
$ FILE_IS = "README.TC2TT"
$ CHECKSUM_IS = 55353196
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
XThis is the beta test version of a program that attempts to convert a
XUnix "termcap" file into a VMS TERMTABLE.TXT file. Two output files
Xare produced, a file called TERMTABLE.TXT containing SMG equivalents
Xof what was found in termcap, and a file called ERRLOG. containing
Xinformation about things TC2TT wasn't able to do. It is important
Xthat ERRLOG. be examined after running TC2TT to see what happened.
XDEC recommends, and I concur, that only terminals actually in use
Xat a site be kept in TERMTABLE.TXT. This requires that someone
Xedit TERMTABLE.TXT before the SMGBLDTRM program is run.
X
XThe task of converting termcap into TERMTABLE.TXT is made difficult by
Xseveral factors.
X
X1) There is no real standard for termcap files. In the process
Xof writing this program I have found termcap entries that don't
Xfollow the TERMCAP(5) manual page. My guess is that such entries
Xare fixed when the terminal with the errant entry
Xappears at the site. This program makes an attempt to diagnose
Xabnormal entries but no claim is made that this effort will
Xalways succeed.
X
X2) Although the VMS documentation does a reasonable job at explaining
Xthe contents of a TERMTABLE.TXT file, several key areas are ignored.
XFor example, DEC doesn't allow '-' or '+' characters in terminal names
Xalthough I couldn't find any specific mention of this restriction.
XSince these characters are used in many places in termcap something
Xhad to be done. My choice was to convert the '-' to '_' and to
Xconvert '+' into the string 'plus'. I hope this is the right thing
Xto do.
X
X3) More serious is the fact that strings in TERMTABLE.TXT can't be
Xlonger than 128 characters isn't documentated. This is a problem
Xbecause also not documented is the fact that if a string capability
Xappears more than once in a terminal description, the second string
Xdefinition is appended to the first definition. In the termcap file
XI used to test TC2TT there are several termcap entries that result
Xin more than one INIT_STRING capability, with a total length of over
X128 characters. Such problems show up as a "expression too complex"
Xerror message from SMGBLDTRM. This problem could be solved by keeping
Xtrack of whether a capability has already been used and, if so, ignoring
Xany subsequent usage.
X
X4) Termcap and curses assume a top left origin of (0,0) whereas
XSMG uses (1,1). Given that DEC VTxxx family terminals also use
Xa (1,1) origin this isn't too surprising. Termcap handles this
Xproblem by using the "%i" construct, which adds 1 to both the line
Xand column values being sent to the terminal. In order to work with
Xterminals with (0,0) origins, SMG entries must subtract 1 from the`032
Xline and column values sent to terminals. This is why some entries
Xin the TERMTABLE.TXT file produced by TC2TT have SET_CURSOR_ABS
Xstrings containing expressions with -1.
X
X5) In many cases DEC ignores capabilities that are expressed in termcap.
XIn these cases TC2TT outputs a message into the errorlog file.
XOne good example is the "%2d" type of construct in termcap.
XThis is used, for example, when an integer is being sent to a terminal.
XApparently, some terminals only want to receive 2 digits, and
Xno more. Although the SYS$FAO system service allows constructs
Xsuch as !2UL, the SMGBLDTRM program generates a XXX error message.
X
X6) One very annoying problem is that SMGBLDTRM tries to parse strings
Xin all string capabilities. This sometimes causes a problem with
XINIT_STRING capabilities containing any of the arithmetic expression
Xcharacters. The end result of this is that any such string`032
Xis seen as an overly complex expression by SMGBLDTRM.
XTo avoid this I insert the escape character '_' in front
Xof any such characters.
X
XTC2TT doesn't handle single termcap capabilities that extend over lines
Xyet. The best example of this is the entry for tvi950-style terminals.
XThis will be fixed in the next release. For the time being, edit
Xyour termcap file to keep all multi-line capabilities on one line.
X
XAnother problem is that I have done very little to verify that
Xthe output of TC2TT is correct. Most terminals at my disposal
Xare some variant of ANSI-compatible. I don't have access to any of the
Xolder, more bizarre terminals so I have no idea if TC2TT-generated
Xdefinition really work. Please keep me informed about this.
X
XRestrictions:
X
XTC2TT doesn't support the %n, %D, %>, and %B cursor addressing modes.
XWarning are written to errlog. if these are used. If these modes
Xare actually needed I'll consider adding them.
X
XNo check is made to insure that strings are no longer than 256
Xcharacters, which is the maximum allowed by the 'ex/vi' editor.
XThe requirements of this editor govern the sizes of termcap.
X
XOnly one level of indirection is supported for the "tc" capability.
X
XGiven all these conditions, I recommend that you use this first
Xversion of TC2TT as an imperfect tool. You may find problems.
XIf you find that SMGBLDTRM doesn't accept a line generated
Xby TC2TT, look at the termcap file you used for input. In my experience
X99% of such problems are caused by errors in the termcap file. If
Xthis is the case, edit your TERMTABLE.TXT file to remove all entries that
Xaren't acceptable to SMGBLDTRM. If you believe you've found a bug
Xplease send me both the entry from the termcap file that caused
Xthe error and the output generated by SMGBLDTRM. (Please don't send me
Xthe whole termcap file).
X
XI would like to know about any problems you find. It is my goal
Xto improve TC2TT to the point where it handles all but the most
Xobstinate termcap entries. The next version will incorporate any
Xbug fixes resulting from this beta release as well as a true
Xman page.
X
XJon Forrest
XFORREST@SYBASE.COM
X`123pacbell,pyramid,sun,`123uunet,ucbvax`125!mtxinu`125!sybase!forrest
X415-596-3422
$ GOSUB UNPACK_FILE

$ FILE_IS = "TABLE.H"
$ CHECKSUM_IS = 442098433
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X#define STR`0090
X#define BOOL`0091
X#define NUM`0092
X
Xstruct table_item
X`123
X`009int type;
X`009char *unix_name;
X`009char *vms_name;
X`125 table[] =
X`123
XSTR,`009"CC",`009"",
XSTR,`009"ae",`009"END_ALTERNATE_CHAR",
XSTR,`009"al",`009"",
XBOOL,`009"am",`009"AUTO_MARGIN",
XSTR,`009"as",`009"BEGIN_ALTERNATE_CHAR",
XSTR,`009"bc",`009"",
XSTR,`009"bl",`009"",
XBOOL,`009"bs",`009"",
XSTR,`009"bt",`009"",
XBOOL,`009"bw",`009"",
XSTR,`009"cd",`009"ERASE_TO_END_DISPLAY",
XSTR,`009"ce",`009"ERASE_TO_END_LINE",
XSTR,`009"ch",`009"CURSOR_RIGHT",
XSTR,`009"cl",`009"ERASE_WHOLE_DISPLAY",
XSTR,`009"cm",`009"SET_CURSOR_ABS",
XNUM,`009"co",`009"COLUMNS",
XSTR,`009"cr",`009"",
XSTR,`009"cs",`009"SET_SCROLL_REGION",
XSTR,`009"ct",`009"",
XSTR,`009"cv",`009"",
XNUM,`009"dB",`009"",
XNUM,`009"dC",`009"CR_FILL",
XNUM,`009"dF",`009"LF_FILL",
XNUM,`009"dN",`009"",
XNUM,`009"dT",`009"",
XBOOL,`009"da",`009"",
XBOOL,`009"db",`009"",
XSTR,`009"dc",`009"DELETE_CHAR",
XSTR,`009"dl",`009"DELETE_LINE",
XSTR,`009"dm",`009"BEGIN_DELETE_MODE",
XSTR,`009"do",`009"CURSOR_DOWN",
XSTR,`009"ed",`009"END_DELETE_MODE",
XSTR,`009"ei",`009"END_INSERT_MODE",
XSTR,`009"eo",`009"",
XSTR,`009"ff",`009"",
XBOOL,`009"hc",`009"",
XSTR,`009"hd",`009"",
XSTR,`009"ho",`009"HOME",
XSTR,`009"hu",`009"",
XSTR,`009"hz",`009"",
XSTR,`009"ic",`009"INSERT_CHAR",
XSTR,`009"if",`009"",
XSTR,`009"im",`009"BEGIN_INSERT_MODE",
XBOOL,`009"in",`009"INSERT_MODE_NULLS",
XSTR,`009"ip",`009"INSERT_PAD",
XSTR,`009"is",`009"INIT_STRING",
XSTR,`009"k0",`009"",
XSTR,`009"k1",`009"",
XSTR,`009"k2",`009"",
XSTR,`009"k3",`009"",
XSTR,`009"k4",`009"",
XSTR,`009"k5",`009"",
XSTR,`009"k6",`009"",
XSTR,`009"k7",`009"",
XSTR,`009"k8",`009"",
XSTR,`009"k9",`009"",
XSTR,`009"kb",`009"KEY_BACKSPACE",
XSTR,`009"kd",`009"",
XSTR,`009"ke",`009"SET_NUMERIC_KEYPAD",
XSTR,`009"kh",`009"",
XSTR,`009"kl",`009"KEY_LEFT_ARROW",
XNUM,`009"kn",`009"",
XSTR,`009"ko",`009"",
XSTR,`009"kr",`009"KEY_RIGHT_ARROW",
XSTR,`009"ks",`009"SET_APPLICATION_KEYPAD",
XSTR,`009"ku",`009"KEY_UP_ARROW",
XSTR,`009"l0",`009"",
XSTR,`009"l1",`009"",
XSTR,`009"l2",`009"",
XSTR,`009"l3",`009"",
XSTR,`009"l4",`009"",
XSTR,`009"l5",`009"",
XSTR,`009"l6",`009"",
XSTR,`009"l7",`009"",
XSTR,`009"l8",`009"",
XSTR,`009"l9",`009"",
XSTR,`009"le",`009"",
XNUM,`009"li",`009"ROWS",
XSTR,`009"ll",`009"",
XSTR,`009"ma",`009"",
XSTR,`009"mb",`009"",
XSTR,`009"md",`009"",
XSTR,`009"me",`009"",
XSTR,`009"mh",`009"",
XBOOL,`009"mi",`009"",
XSTR,`009"ml",`009"",
XSTR,`009"mr",`009"",
XBOOL,`009"ms",`009"",
XSTR,`009"mu",`009"",
XBOOL,`009"nc",`009"",
XSTR,`009"nd",`009"",
XSTR,`009"nl",`009"NEWLINE_CHAR",
XBOOL,`009"ns",`009"NO_SCROLL",
XBOOL,`009"os",`009"OVERSTRIKE",
XSTR,`009"pc",`009"PAD_CHAR",
XBOOL,`009"pt",`009"PHYSICAL_TABS",
XSTR,`009"rf",`009"",
XSTR,`009"rs",`009"",
XSTR,`009"se",`009"END_BOLD",
XSTR,`009"sf",`009"SCROLL_FORWARD",
XNUM,`009"sg",`009"",
XSTR,`009"so",`009"BEGIN_BOLD",
XSTR,`009"sr",`009"SCROLL_REVERSE",
XSTR,`009"st",`009"",
XSTR,`009"ta",`009"TAB_CHAR",
XSTR,`009"tc",`009"",
XSTR,`009"te",`009"RESTORE_CURSOR",
XSTR,`009"ti",`009"SAVE_CURSOR",
XSTR,`009"uc",`009"UNDERLINE_CHAR",
XSTR,`009"ue",`009"END_UNDERSCORE",
XNUM,`009"ug",`009"",
XBOOL,`009"ul",`009"UNDERLINE",
XSTR,`009"up",`009"CURSOR_UP",
XSTR,`009"us",`009"BEGIN_UNDERSCORE",
XSTR,`009"vb",`009"",
XSTR,`009"ve",`009"",
XSTR,`009"vs",`009"",
XNUM,`009"vt",`009"",
XBOOL,`009"xb",`009"",
XBOOL,`009"xn",`009"IGNORE_NEWLINE",
XBOOL,`009"xr",`009"",
XBOOL,`009"xs",`009"NO_ERASE",
XBOOL,`009"xt",`009""
X`125;
$ GOSUB UNPACK_FILE

$ FILE_IS = "TC2TT.C"
$ CHECKSUM_IS = 16860395
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X
X`009TC2TT Version 0.1 - Converts Unix (*tm) termcap files into VMS (*tm)
X`009TERMTABLE.TXT files. See accompanying README.TC2TT for more
X`009information.
X
X`009This program may not be sold. Otherwise it is in the public
X`009domain.
X
X`009Compile and link this program like any other Vax C program.
X`009It requires no special linking parameters.
X
X`009Jon Forrest
X`009Lawrence Berkeley Lab
X`009FORREST@LBL.GOV
X`009ucbvax!lbl-csam!ux1!forrest
X
X*/
X
X#include <stdio.h>
X#include <string.h>
X#include <ctype.h>
X#include "table.h"
X
X#ifdef VMS
X#define TERMCAP`009`009"termcap."
X#define ERRLOG`009`009"errlog."
X#else
X#define TERMCAP`009`009"termcap"
X#define ERRLOG`009`009"errlog"
X#endif
X
X#define LINE_LEN`009256
X#define TERMNAME_LEN`00964`009`009/* max len of terminal name */
X#define`009LONGNAME`0092`009`009/* long terminal name */
X#define EOL`009`009((char *)1)
X#define NO_TC`009`0090
X#define`009TC`009`0091
X#define`009FOUND`009`0091
X
X/*
X** The following two lines are global only because of a bug in the
X** VMS Debugger in VMS 4.7 which doesn't allow local character arrays to be
X** examined.
X*/
X
Xchar input_line1[LINE_LEN];
Xchar input_line2[LINE_LEN];
Xchar term_name[TERMNAME_LEN];`009`009/* official name of current terminal */
XFILE *ifp, *ofp, *efp;
XFILE *tcfp = NULL;
Xint do_end = 0;`009`009`009`009/* don't output END 1st time */
X
Xmain()
X`123
X
X`009if ((ifp = fopen(TERMCAP,"r")) == NULL)
X`009`123
X`009`009perror(TERMCAP);
X`009`009exit(1);
-+-+-+-+-+ End of part 1 +-+-+-+-+-
Jon Forrest
forrest@sybase.com
{pacbell,sun,{uunet,ucbvax}!mtxinu}!sybase!forrest
415-596-3422

