Problem with make buildworld with existing terminfo database

From: Dan Hulme <d_at_diefree.com>
Date: Tue, 16 Dec 2003 00:09:40 -0800
The compilation of [/usr/src/usr.sbin/sysinstall] depends on a small
program called "rtermcap".  The program is used to generate a file
called "makedevs.c" from several termcap entries (ansi, xterm, cons25,
etc.).

rtermcap, in turn, relies on a c call (ncurses) to "tgetent," which
checks for a termcap entry, and fills a buffer with the terminal
information.  On closer inspection, however, "tgetent" is also capable
of using terminfo, and in fact prefers terminfo over termcap (if the
terminal exists in terminfo, it will never check termcap--perhaps this
behavior can be changed in ncurses, but I'm not sure it should be).
Unfortunately, it acts a little differently when using terminfo:

[man curs_termcap]
The tgetent routine loads the entry for name.  It returns 1 on success,
0 if there is no such entry, and -1 if the terminfo database could  not
be found.  The emulation ignores the buffer pointer bp.

So, in the event that a terminfo database is present, tgetent will use
it, and will not fill the buffer.  However, the Makefile in
[/usr/src/usr.sbin/sysinstall] relies on the buffer being filled, so it
can use this data to create the arrays in makedevs.c.  There is no
detection of this issue currently, and the compilation of sysinstall
fails with the following message(s), due to the arrays being empty:

makedevs.c:4: error: syntax error before ',' token
makedevs.c:7: error: syntax error before ',' token
makedevs.c:10: error: syntax error before ',' token
makedevs.c:13: error: syntax error before ',' token
makedevs.c:16: error: syntax error before ',' token
makedevs.c:19: error: syntax error before ',' token
makedevs.c:22: error: syntax error before ',' token
makedevs.c:25: error: syntax error before ',' token
makedevs.c:28: error: syntax error before ',' token
makedevs.c:31: error: syntax error before ',' token

I happen to have a terminfo database installed in
[/usr/share/misc/terminfo].  It really is just a symlink to
[/usr/compat/linux/usr/share/terminfo].  Therefore, my build failed, and
didn't give me any helpful information when it did so.  After tracking
down the culprit scripts, I still didn't know what was wrong, because I
didn't understand how ncurses deals with terminfo/termcap. Now that I
understand it, I think that something should be changed to deal with
this possibility.

Currently, the workaround is to remove/move the terminfo database during
the build.  Possible solutions to the problem might include prebuilding
makedevs.c (the termcap file hasn't changed in quite a long time), or
manually pulling the data using cgetent.  I have written a short program
to replace rtermcap.c which has identical output, but is terminfo safe
(in other words it loads from termcap even if terminfo exists):

#include <stdlib.h>

int main(int argc, char**argv)
{
   char * files[]={ "/etc/termcap" };
   char * tbuf;
   char * buf;
   char * c;
   char d;
   int i;
   if (argc < 2)
     return 1;
   i=cgetent(&tbuf, files, argv[1]);
   for (c = tbuf; *c != 0; c++) {
     if(*c != '\t' && (*c != 58 || d != 58)) {
       printf("%c", *c);
       d = *c;
     }
   }
   cgetclose();
   return 0;
}

I suggest that this code replace rtermcap.c, or some other solution be
found, so that having a terminfo database installed doesn't break the
build.  This code strips tabs and avoids duplicate colons (:), to have
the same output as tgetent (which does not appear to strip spaces).

I did "make makedevs.c" on this code as well as the original, and the
output is identical.  If there is a terminfo database installed at
[/usr/share/misc/terminfo] (or in root's profile), this code gives
identical output, but the original code creates an uncompileable
makedevs.c.

-Dan

Please CC any responses to d_at_diefree.com, as I am not subscribed.
Received on Mon Dec 15 2003 - 23:08:07 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:34 UTC