Setting Up Termcap for Informix

Many of the Informix tools and applications (e.g. dbaccess, any 4GL apps that you've written) use CURSES to display their output and interface with the user. For CURSES to work, termcap must be installed.

Unfortunately, on many of the later versions of your favorite OS, termcap is now obsolete (which is not to say that nobody is using it but simply that, "we got bored supporting it, especially when we could be coming up with another cool-looking-but-essentially-useless skin for some really-hot-or-maybe-not-so-much app"). Lucky for us, a replacement for termcap exists in the form of a compatibility library for terminfo.

Under CentOS/RedHat/etc., you can install the compatibility library like this:

     su
     yum install compat-libtermcap

Under Ubuntu, you can install the compatibility library with:

     su
     apt-get install termcap-compat

Under Ubuntu, you may also want:

     apt-get install libncurses5-dev

Alternately, instead of using the terminfo compatibility library, Informix also comes with its own copy of termcap, which you can use from the Informix install library by setting the environment TERMCAP, like this:

     export TERMCAP=${INFORMIXDIR}/etc/termcap

if the INFORMIXDIR environment variable is set, or, depending on where you installed Informix, something like this:

     export TERMCAP=/usr/share/informix/etc/termcap

In many cases, we prefer to use our own version of TERMCAP which we got from an old version of RedHat and which we keep around just for running old, legacy stuff. As with the termcap file in the Informix install library, the TERMCAP environment is pointed at the old RedHat termcap file:

     export TERMCAP=/home/dbusr/termcap.OLDRH

Any of these approaches should work equally well. Or, so one would think. Unfortunately, if you choose the third approach and use an old RedHat termcap file, you may run into a little problem that Informix has with termcap entries that are chained. In a termcap file, chaining is done with the "tc=" parameter. The problem manifests itself when you run any of the Informix tools or 4GL apps with this error:

     Termcap entry too long
     Too many tc= indirections

Apparently, in the case of Informix, "Too many" means four (i.e. more than three). The vt100 entry in older RedHat termcap files has this problem, for example, while the vt200 and vt220 entry appears not to. The simple solution is to pick vt200 or some other entry that works.

However, it is possible to fix the problem with your favorite text editor. Open up /etc/termcap and look for something like this:

     vt100|vt100-am|dec vt100 (w/advanced video):\
             :5i:am:bs:ms:xn:xo:\
             :co#80:it#8:li#24:vt#3:\
                  .
                  .
                  .
             :us=\E[4m:tc=vt100+fnkeys:

If you follow the chain to the vt100+fnkeys entry you might see:

     vt100+fnkeys|dec vt100 numeric keypad:\
             :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
             :tc=vt100+pfkeys:

Following the chain to the vt100+pfkeys entry you might see:

     vt100+pfkeys|dec vt100 numeric keypad:\
             :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:

And, following the chain to the fourth vt100+keypad entry you might see:

     vt100+keypad|dec vt100 numeric keypad no fkeys:\
             :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:

Simply follow all of the indirections in the chain and smack them all together in the single vt100 entry, like this:

     vt100|vt100-am|dec vt100 (w/advanced video):\
             :5i:am:bs:ms:xn:xo:\
             :co#80:it#8:li#24:vt#3:\
                  .
                  .
                  .
             :us=\E[4m:\
             :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
             :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:\
             :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:

We have also noticed some strange behavior when connecting to later Linux systems (e.g. CentOS 6.4) via SSH only. If you use telnet, everything is fine. But, we all know we shouldn't use telnet (the world is an evil place, my friend) so we use SSH instead. If you do, you may find that somebody in kernel-land, or perhaps its SSH, is monkeying with the key codes that your terminal emulator is sending. Despite the fact the your terminal emulator correctly sends "\EOA", "\EOB", etc. for the cursor keys, cursor movement is broken.

You can figure out what is being received by Informix (and other apps, for that matter) by running:

     showkey -a

Type the broken keys on your terminal emulator and you'll see what codes are actually being sent. We're betting that someone is mapping:

     /EOA  -->  /E[A
     /EOB  -->  /E[B
     /EOC  -->  /E[C
     /EOD  -->  /E[D

These codes ain't stricly incorrect. They work fine with the vt200 termcap entry, for example. But they are wrong for vt100s. So, once again, you can pick the vt200 or vt220 entry or you can "fix" the vt100 entry. If you choose the later, it should look something like this:

     vt100|vt100-am|dec vt100 (w/advanced video):\
                  .
                  .
                  .
             :ku=\E[A:kd=\E[B:kr=\E[C:kl=\E[D:\
                  .
                  .
                  .

Whether you use the Informix-supplied termcap file or an older RedHat termcap file, you'll probably be faced with this problem either way. As for the terminfo compatibility library, its anybody's guess.