There is no standard way of getting a list of aliases for the

terminal. However, some applications such as telnet want to know this.
ncurses dumps the terminfo header into an undefined variable ttytype
and these applications then parse it to work out the aliases.
We should do the same for now, until a standard mechanism for getting
the information is available or the need for it goes away.
This commit is contained in:
roy 2011-10-05 10:46:08 +00:00
parent efb47b42e6
commit 62480e1c72
1 changed files with 44 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: curterm.c,v 1.7 2011/10/04 11:01:14 roy Exp $ */
/* $NetBSD: curterm.c,v 1.8 2011/10/05 10:46:08 roy Exp $ */
/*
* Copyright (c) 2009, 2011 The NetBSD Foundation, Inc.
@ -28,16 +28,29 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: curterm.c,v 1.7 2011/10/04 11:01:14 roy Exp $");
__RCSID("$NetBSD: curterm.c,v 1.8 2011/10/05 10:46:08 roy Exp $");
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <term_private.h>
#include <term.h>
#include <termios.h>
#include <stdio.h>
TERMINAL *cur_term;
/*
* There is no standard way of getting a list of aliases for the
* terminal. However, some applications such as telnet want to know this.
* ncurses dumps the terminfo header into an undefined variable ttytype
* and these applications then parse it to work out the aliases.
* We should do the same for now, until a standard mechanism for getting
* the information is available or the need for it goes away.
*/
#define NAMESIZE 256
char ttytype[NAMESIZE];
static const speed_t bauds[] = {
0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 2400, 4800, 9600,
19200, 38400, 57600, 115200, 230400, 460800, 921600
@ -67,6 +80,8 @@ TERMINAL *
set_curterm(TERMINAL *nterm)
{
TERMINAL *oterm;
size_t l, n;
char *p;
oterm = cur_term;
cur_term = nterm;
@ -81,6 +96,33 @@ set_curterm(TERMINAL *nterm)
PC = *pad_char;
_ti_setospeed(nterm);
ospeed = nterm->_ospeed;
p = ttytype;
l = sizeof(ttytype);
if ((n = strlcpy(p, nterm->name, l)) == strlen(p)) {
p += n;
l -= n;
*p++ = '|';
l--;
if (nterm->_alias &&
(n = strlcpy(p, nterm->_alias, l)) == strlen(p))
{
p += n;
l -= n;
*p++ = '|';
l--;
}
if (nterm->desc &&
(n = strlcpy(p, nterm->desc, l)) == strlen(p))
{
p += n;
l -= n;
*p++ = '|';
l--;
}
p--;
}
*p = '\0';
}
return oterm;