1999-08-24 01:06:48 +00:00
|
|
|
/****************************************************************************
|
2014-03-01 00:40:26 +00:00
|
|
|
* Copyright (c) 1998-2012,2013 Free Software Foundation, Inc. *
|
1999-08-24 01:06:48 +00:00
|
|
|
* *
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a *
|
|
|
|
* copy of this software and associated documentation files (the *
|
|
|
|
* "Software"), to deal in the Software without restriction, including *
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish, *
|
|
|
|
* distribute, distribute with modifications, sublicense, and/or sell *
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is *
|
|
|
|
* furnished to do so, subject to the following conditions: *
|
|
|
|
* *
|
|
|
|
* The above copyright notice and this permission notice shall be included *
|
|
|
|
* in all copies or substantial portions of the Software. *
|
|
|
|
* *
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
|
|
|
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
|
|
* *
|
|
|
|
* Except as contained in this notice, the name(s) of the above copyright *
|
|
|
|
* holders shall not be used in advertising or otherwise to promote the *
|
|
|
|
* sale, use or other dealings in this Software without prior written *
|
|
|
|
* authorization. *
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
|
|
|
|
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
|
2007-01-20 07:32:02 +00:00
|
|
|
* and: Thomas E. Dickey 1996-on *
|
1999-08-24 01:06:48 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-02-28 19:18:07 +00:00
|
|
|
/*
|
|
|
|
* Notes:
|
|
|
|
* The initial adaptation from 4.4BSD Lite sources in September 1995 used 686
|
|
|
|
* lines from that version, and made changes/additions for 150 lines. There
|
|
|
|
* was no reformatting, so with/without ignoring whitespace, the amount of
|
|
|
|
* change is the same.
|
|
|
|
*
|
|
|
|
* Comparing with current (2009) source, excluding this comment:
|
|
|
|
* a) 209 lines match identically to the 4.4BSD Lite sources, with 771 lines
|
|
|
|
* changed/added.
|
|
|
|
* a) Ignoring whitespace, the current version still uses 516 lines from the
|
|
|
|
* 4.4BSD Lite sources, with 402 lines changed/added.
|
|
|
|
*
|
|
|
|
* Raymond's original comment on this follows...
|
|
|
|
*/
|
|
|
|
|
1999-08-24 01:06:48 +00:00
|
|
|
/*
|
|
|
|
* tset.c - terminal initialization utility
|
|
|
|
*
|
|
|
|
* This code was mostly swiped from 4.4BSD tset, with some obsolescent
|
|
|
|
* cruft removed and substantial portions rewritten. A Regents of the
|
|
|
|
* University of California copyright applies to some portions of the
|
|
|
|
* code, and is reproduced below:
|
|
|
|
*/
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1980, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2014-02-28 19:18:07 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1999-08-24 01:06:48 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2007-12-30 11:08:14 +00:00
|
|
|
#define USE_LIBTINFO
|
1999-08-24 01:06:48 +00:00
|
|
|
#define __INTERNAL_CAPS_VISIBLE /* we need to see has_hardware_tabs */
|
|
|
|
#include <progs.priv.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <termcap.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#if HAVE_GETTTYNAM && HAVE_TTYENT_H
|
|
|
|
#include <ttyent.h>
|
|
|
|
#endif
|
|
|
|
#ifdef NeXT
|
|
|
|
char *ttyname(int fd);
|
|
|
|
#endif
|
|
|
|
|
2008-11-09 14:08:54 +00:00
|
|
|
#if HAVE_SIZECHANGE
|
|
|
|
# if !defined(sun) || !TERMIOS
|
|
|
|
# if HAVE_SYS_IOCTL_H
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
# endif
|
|
|
|
# endif
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NEED_PTEM_H
|
|
|
|
/* they neglected to define struct winsize in termios.h -- it's only
|
|
|
|
in termio.h */
|
2002-05-21 05:30:25 +00:00
|
|
|
#include <sys/stream.h>
|
|
|
|
#include <sys/ptem.h>
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <dump_entry.h>
|
2000-10-11 07:31:01 +00:00
|
|
|
#include <transform.h>
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2014-03-01 00:40:26 +00:00
|
|
|
MODULE_ID("$Id: tset.c,v 1.93 2013/12/15 01:05:56 tom Exp $")
|
2008-11-09 14:08:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS,
|
|
|
|
* Solaris, IRIX) define TIOCGWINSZ and struct winsize.
|
|
|
|
*/
|
|
|
|
#ifdef TIOCGSIZE
|
|
|
|
# define IOCTL_GET_WINSIZE TIOCGSIZE
|
|
|
|
# define IOCTL_SET_WINSIZE TIOCSSIZE
|
|
|
|
# define STRUCT_WINSIZE struct ttysize
|
|
|
|
# define WINSIZE_ROWS(n) n.ts_lines
|
|
|
|
# define WINSIZE_COLS(n) n.ts_cols
|
|
|
|
#else
|
|
|
|
# ifdef TIOCGWINSZ
|
|
|
|
# define IOCTL_GET_WINSIZE TIOCGWINSZ
|
|
|
|
# define IOCTL_SET_WINSIZE TIOCSWINSZ
|
|
|
|
# define STRUCT_WINSIZE struct winsize
|
|
|
|
# define WINSIZE_ROWS(n) n.ws_row
|
|
|
|
# define WINSIZE_COLS(n) n.ws_col
|
|
|
|
# endif
|
|
|
|
#endif
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2014-02-28 19:18:07 +00:00
|
|
|
#ifndef environ
|
1999-08-24 01:06:48 +00:00
|
|
|
extern char **environ;
|
2014-02-28 19:18:07 +00:00
|
|
|
#endif
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
#undef CTRL
|
|
|
|
#define CTRL(x) ((x) & 0x1f)
|
|
|
|
|
2014-03-01 00:40:26 +00:00
|
|
|
static void failed(const char *) GCC_NORETURN;
|
|
|
|
static void exit_error(void) GCC_NORETURN;
|
|
|
|
static void err(const char *,...) GCC_NORETURN;
|
|
|
|
|
1999-08-24 01:06:48 +00:00
|
|
|
const char *_nc_progname = "tset";
|
|
|
|
|
2002-05-21 05:30:25 +00:00
|
|
|
static TTY mode, oldmode, original;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2007-01-20 07:32:02 +00:00
|
|
|
static bool opt_c; /* set control-chars */
|
|
|
|
static bool opt_w; /* set window-size */
|
|
|
|
|
2002-05-21 05:30:25 +00:00
|
|
|
static bool can_restore = FALSE;
|
2000-10-11 07:31:01 +00:00
|
|
|
static bool isreset = FALSE; /* invoked as reset */
|
2000-07-03 09:24:12 +00:00
|
|
|
static int terasechar = -1; /* new erase character */
|
|
|
|
static int intrchar = -1; /* new interrupt character */
|
|
|
|
static int tkillchar = -1; /* new kill character */
|
2014-03-01 00:40:26 +00:00
|
|
|
|
|
|
|
#if HAVE_SIZECHANGE
|
2000-07-03 09:24:12 +00:00
|
|
|
static int tlines, tcolumns; /* window size */
|
2014-03-01 00:40:26 +00:00
|
|
|
#endif
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2002-05-21 05:30:25 +00:00
|
|
|
#define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c))
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
static int
|
2000-07-03 09:24:12 +00:00
|
|
|
CaselessCmp(const char *a, const char *b)
|
|
|
|
{ /* strcasecmp isn't portable */
|
|
|
|
while (*a && *b) {
|
|
|
|
int cmp = LOWERCASE(*a) - LOWERCASE(*b);
|
|
|
|
if (cmp != 0)
|
|
|
|
break;
|
|
|
|
a++, b++;
|
|
|
|
}
|
|
|
|
return LOWERCASE(*a) - LOWERCASE(*b);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
2002-05-21 05:30:25 +00:00
|
|
|
static void
|
|
|
|
exit_error(void)
|
|
|
|
{
|
|
|
|
if (can_restore)
|
|
|
|
SET_TTY(STDERR_FILENO, &original);
|
|
|
|
(void) fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
2007-01-20 07:32:02 +00:00
|
|
|
ExitProgram(EXIT_FAILURE);
|
2002-05-21 05:30:25 +00:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
1999-08-24 01:06:48 +00:00
|
|
|
static void
|
2000-07-03 09:24:12 +00:00
|
|
|
err(const char *fmt,...)
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2007-01-20 07:32:02 +00:00
|
|
|
(void) fprintf(stderr, "%s: ", _nc_progname);
|
2000-07-03 09:24:12 +00:00
|
|
|
(void) vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
2002-05-21 05:30:25 +00:00
|
|
|
exit_error();
|
2000-07-03 09:24:12 +00:00
|
|
|
/* NOTREACHED */
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
failed(const char *msg)
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
char temp[BUFSIZ];
|
2014-03-01 00:40:26 +00:00
|
|
|
size_t len = strlen(_nc_progname) + 2;
|
2007-01-20 07:32:02 +00:00
|
|
|
|
2008-11-09 14:08:54 +00:00
|
|
|
if ((int) len < (int) sizeof(temp) - 12) {
|
2014-03-01 00:40:26 +00:00
|
|
|
_nc_STRCPY(temp, _nc_progname, sizeof(temp));
|
|
|
|
_nc_STRCAT(temp, ": ", sizeof(temp));
|
2007-01-20 07:32:02 +00:00
|
|
|
} else {
|
2014-03-01 00:40:26 +00:00
|
|
|
_nc_STRCPY(temp, "tset: ", sizeof(temp));
|
2007-01-20 07:32:02 +00:00
|
|
|
}
|
|
|
|
perror(strncat(temp, msg, sizeof(temp) - strlen(temp) - 2));
|
2002-05-21 05:30:25 +00:00
|
|
|
exit_error();
|
2000-07-03 09:24:12 +00:00
|
|
|
/* NOTREACHED */
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cat(char *file)
|
|
|
|
{
|
2002-05-21 05:30:25 +00:00
|
|
|
FILE *fp;
|
|
|
|
size_t nr;
|
2000-07-03 09:24:12 +00:00
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
2002-05-21 05:30:25 +00:00
|
|
|
if ((fp = fopen(file, "r")) == 0)
|
2000-07-03 09:24:12 +00:00
|
|
|
failed(file);
|
|
|
|
|
2002-05-21 05:30:25 +00:00
|
|
|
while ((nr = fread(buf, sizeof(char), sizeof(buf), fp)) != 0)
|
|
|
|
if (fwrite(buf, sizeof(char), nr, stderr) != nr)
|
|
|
|
failed("write to stderr");
|
|
|
|
fclose(fp);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
outc(int c)
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
return putc(c, stderr);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Prompt the user for a terminal type. */
|
|
|
|
static const char *
|
|
|
|
askuser(const char *dflt)
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
static char answer[256];
|
|
|
|
char *p;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
/* We can get recalled; if so, don't continue uselessly. */
|
2007-01-20 07:32:02 +00:00
|
|
|
clearerr(stdin);
|
2000-07-03 09:24:12 +00:00
|
|
|
if (feof(stdin) || ferror(stdin)) {
|
|
|
|
(void) fprintf(stderr, "\n");
|
2002-05-21 05:30:25 +00:00
|
|
|
exit_error();
|
|
|
|
/* NOTREACHED */
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
if (dflt)
|
|
|
|
(void) fprintf(stderr, "Terminal type? [%s] ", dflt);
|
|
|
|
else
|
|
|
|
(void) fprintf(stderr, "Terminal type? ");
|
|
|
|
(void) fflush(stderr);
|
|
|
|
|
|
|
|
if (fgets(answer, sizeof(answer), stdin) == 0) {
|
|
|
|
if (dflt == 0) {
|
2002-05-21 05:30:25 +00:00
|
|
|
exit_error();
|
|
|
|
/* NOTREACHED */
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
|
|
|
return (dflt);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if ((p = strchr(answer, '\n')) != 0)
|
|
|
|
*p = '\0';
|
|
|
|
if (answer[0])
|
|
|
|
return (answer);
|
|
|
|
if (dflt != 0)
|
|
|
|
return (dflt);
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Mapping logic begins here
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/* Baud rate conditionals for mapping. */
|
|
|
|
#define GT 0x01
|
|
|
|
#define EQ 0x02
|
|
|
|
#define LT 0x04
|
|
|
|
#define NOT 0x08
|
|
|
|
#define GE (GT | EQ)
|
|
|
|
#define LE (LT | EQ)
|
|
|
|
|
|
|
|
typedef struct map {
|
2000-07-03 09:24:12 +00:00
|
|
|
struct map *next; /* Linked list of maps. */
|
|
|
|
const char *porttype; /* Port type, or "" for any. */
|
|
|
|
const char *type; /* Terminal type to select. */
|
|
|
|
int conditional; /* Baud rate conditionals bitmask. */
|
2000-10-11 07:31:01 +00:00
|
|
|
int speed; /* Baud rate to compare against. */
|
1999-08-24 01:06:48 +00:00
|
|
|
} MAP;
|
|
|
|
|
|
|
|
static MAP *cur, *maplist;
|
|
|
|
|
|
|
|
typedef struct speeds {
|
2000-07-03 09:24:12 +00:00
|
|
|
const char *string;
|
|
|
|
int speed;
|
1999-08-24 01:06:48 +00:00
|
|
|
} SPEEDS;
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
static const SPEEDS speeds[] =
|
|
|
|
{
|
|
|
|
{"0", B0},
|
|
|
|
{"50", B50},
|
|
|
|
{"75", B75},
|
|
|
|
{"110", B110},
|
|
|
|
{"134", B134},
|
|
|
|
{"134.5", B134},
|
|
|
|
{"150", B150},
|
|
|
|
{"200", B200},
|
|
|
|
{"300", B300},
|
|
|
|
{"600", B600},
|
|
|
|
{"1200", B1200},
|
|
|
|
{"1800", B1800},
|
|
|
|
{"2400", B2400},
|
|
|
|
{"4800", B4800},
|
|
|
|
{"9600", B9600},
|
2000-10-11 07:31:01 +00:00
|
|
|
/* sgttyb may define up to this point */
|
|
|
|
#ifdef B19200
|
2000-07-03 09:24:12 +00:00
|
|
|
{"19200", B19200},
|
2000-10-11 07:31:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B38400
|
2000-07-03 09:24:12 +00:00
|
|
|
{"38400", B38400},
|
2000-10-11 07:31:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B19200
|
2000-07-03 09:24:12 +00:00
|
|
|
{"19200", B19200},
|
2000-10-11 07:31:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B38400
|
2000-07-03 09:24:12 +00:00
|
|
|
{"38400", B38400},
|
2000-10-11 07:31:01 +00:00
|
|
|
#endif
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef B19200
|
2000-07-03 09:24:12 +00:00
|
|
|
{"19200", B19200},
|
1999-08-24 01:06:48 +00:00
|
|
|
#else
|
|
|
|
#ifdef EXTA
|
2000-07-03 09:24:12 +00:00
|
|
|
{"19200", EXTA},
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef B38400
|
2000-07-03 09:24:12 +00:00
|
|
|
{"38400", B38400},
|
1999-08-24 01:06:48 +00:00
|
|
|
#else
|
|
|
|
#ifdef EXTB
|
2000-07-03 09:24:12 +00:00
|
|
|
{"38400", EXTB},
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef B57600
|
2000-07-03 09:24:12 +00:00
|
|
|
{"57600", B57600},
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B115200
|
2000-07-03 09:24:12 +00:00
|
|
|
{"115200", B115200},
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B230400
|
2000-07-03 09:24:12 +00:00
|
|
|
{"230400", B230400},
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B460800
|
2000-07-03 09:24:12 +00:00
|
|
|
{"460800", B460800},
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
{(char *) 0, 0}
|
1999-08-24 01:06:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
tbaudrate(char *rate)
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
const SPEEDS *sp;
|
|
|
|
int found = FALSE;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
/* The baudrate number can be preceded by a 'B', which is ignored. */
|
|
|
|
if (*rate == 'B')
|
|
|
|
++rate;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
for (sp = speeds; sp->string; ++sp) {
|
|
|
|
if (!CaselessCmp(rate, sp->string)) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
err("unknown baud rate %s", rate);
|
|
|
|
return (sp->speed);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Syntax for -m:
|
|
|
|
* [port-type][test baudrate]:terminal-type
|
|
|
|
* The baud rate tests are: >, <, @, =, !
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
add_mapping(const char *port, char *arg)
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
MAP *mapp;
|
|
|
|
char *copy, *p;
|
|
|
|
const char *termp;
|
|
|
|
char *base = 0;
|
|
|
|
|
|
|
|
copy = strdup(arg);
|
2014-02-28 19:18:07 +00:00
|
|
|
mapp = typeMalloc(MAP, 1);
|
2000-07-03 09:24:12 +00:00
|
|
|
if (copy == 0 || mapp == 0)
|
|
|
|
failed("malloc");
|
2014-02-28 19:18:07 +00:00
|
|
|
|
|
|
|
assert(copy != 0);
|
|
|
|
assert(mapp != 0);
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
mapp->next = 0;
|
|
|
|
if (maplist == 0)
|
|
|
|
cur = maplist = mapp;
|
|
|
|
else {
|
|
|
|
cur->next = mapp;
|
|
|
|
cur = mapp;
|
|
|
|
}
|
|
|
|
|
|
|
|
mapp->porttype = arg;
|
|
|
|
mapp->conditional = 0;
|
|
|
|
|
|
|
|
arg = strpbrk(arg, "><@=!:");
|
|
|
|
|
|
|
|
if (arg == 0) { /* [?]term */
|
|
|
|
mapp->type = mapp->porttype;
|
|
|
|
mapp->porttype = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg == mapp->porttype) /* [><@=! baud]:term */
|
|
|
|
termp = mapp->porttype = 0;
|
|
|
|
else
|
|
|
|
termp = base = arg;
|
|
|
|
|
|
|
|
for (;; ++arg) { /* Optional conditionals. */
|
|
|
|
switch (*arg) {
|
|
|
|
case '<':
|
|
|
|
if (mapp->conditional & GT)
|
1999-08-24 01:06:48 +00:00
|
|
|
goto badmopt;
|
2000-07-03 09:24:12 +00:00
|
|
|
mapp->conditional |= LT;
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
if (mapp->conditional & LT)
|
|
|
|
goto badmopt;
|
|
|
|
mapp->conditional |= GT;
|
|
|
|
break;
|
|
|
|
case '@':
|
|
|
|
case '=': /* Not documented. */
|
|
|
|
mapp->conditional |= EQ;
|
|
|
|
break;
|
|
|
|
case '!':
|
|
|
|
mapp->conditional |= NOT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto next;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
next:
|
|
|
|
if (*arg == ':') {
|
|
|
|
if (mapp->conditional)
|
|
|
|
goto badmopt;
|
|
|
|
++arg;
|
|
|
|
} else { /* Optional baudrate. */
|
|
|
|
arg = strchr(p = arg, ':');
|
|
|
|
if (arg == 0)
|
|
|
|
goto badmopt;
|
|
|
|
*arg++ = '\0';
|
|
|
|
mapp->speed = tbaudrate(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
mapp->type = arg;
|
|
|
|
|
|
|
|
/* Terminate porttype, if specified. */
|
|
|
|
if (termp != 0)
|
|
|
|
*base = '\0';
|
|
|
|
|
|
|
|
/* If a NOT conditional, reverse the test. */
|
|
|
|
if (mapp->conditional & NOT)
|
|
|
|
mapp->conditional = ~mapp->conditional & (EQ | GT | LT);
|
|
|
|
|
|
|
|
/* If user specified a port with an option flag, set it. */
|
2008-11-09 14:08:54 +00:00
|
|
|
done:
|
|
|
|
if (port) {
|
|
|
|
if (mapp->porttype) {
|
|
|
|
badmopt:
|
|
|
|
err("illegal -m option format: %s", copy);
|
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
mapp->porttype = port;
|
|
|
|
}
|
2008-11-09 14:08:54 +00:00
|
|
|
free(copy);
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef MAPDEBUG
|
2000-07-03 09:24:12 +00:00
|
|
|
(void) printf("port: %s\n", mapp->porttype ? mapp->porttype : "ANY");
|
|
|
|
(void) printf("type: %s\n", mapp->type);
|
|
|
|
(void) printf("conditional: ");
|
|
|
|
p = "";
|
|
|
|
if (mapp->conditional & GT) {
|
|
|
|
(void) printf("GT");
|
|
|
|
p = "/";
|
|
|
|
}
|
|
|
|
if (mapp->conditional & EQ) {
|
|
|
|
(void) printf("%sEQ", p);
|
|
|
|
p = "/";
|
|
|
|
}
|
|
|
|
if (mapp->conditional & LT)
|
|
|
|
(void) printf("%sLT", p);
|
|
|
|
(void) printf("\nspeed: %d\n", mapp->speed);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the type of terminal to use for a port of type 'type', as specified
|
|
|
|
* by the first applicable mapping in 'map'. If no mappings apply, return
|
|
|
|
* 'type'.
|
|
|
|
*/
|
|
|
|
static const char *
|
|
|
|
mapped(const char *type)
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
MAP *mapp;
|
|
|
|
int match;
|
|
|
|
|
|
|
|
for (mapp = maplist; mapp; mapp = mapp->next)
|
|
|
|
if (mapp->porttype == 0 || !strcmp(mapp->porttype, type)) {
|
|
|
|
switch (mapp->conditional) {
|
|
|
|
case 0: /* No test specified. */
|
|
|
|
match = TRUE;
|
|
|
|
break;
|
|
|
|
case EQ:
|
2014-03-01 00:40:26 +00:00
|
|
|
match = ((int) ospeed == mapp->speed);
|
2000-07-03 09:24:12 +00:00
|
|
|
break;
|
|
|
|
case GE:
|
2014-03-01 00:40:26 +00:00
|
|
|
match = ((int) ospeed >= mapp->speed);
|
2000-07-03 09:24:12 +00:00
|
|
|
break;
|
|
|
|
case GT:
|
2014-03-01 00:40:26 +00:00
|
|
|
match = ((int) ospeed > mapp->speed);
|
2000-07-03 09:24:12 +00:00
|
|
|
break;
|
|
|
|
case LE:
|
2014-03-01 00:40:26 +00:00
|
|
|
match = ((int) ospeed <= mapp->speed);
|
2000-07-03 09:24:12 +00:00
|
|
|
break;
|
|
|
|
case LT:
|
2014-03-01 00:40:26 +00:00
|
|
|
match = ((int) ospeed < mapp->speed);
|
2000-07-03 09:24:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
match = FALSE;
|
|
|
|
}
|
|
|
|
if (match)
|
|
|
|
return (mapp->type);
|
|
|
|
}
|
|
|
|
/* No match found; return given type. */
|
|
|
|
return (type);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Entry fetching
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out what kind of terminal we're dealing with, and then read in
|
|
|
|
* its termcap entry.
|
|
|
|
*/
|
|
|
|
static const char *
|
|
|
|
get_termcap_entry(char *userarg)
|
|
|
|
{
|
2001-05-17 08:21:06 +00:00
|
|
|
int errret;
|
2000-07-03 09:24:12 +00:00
|
|
|
char *p;
|
|
|
|
const char *ttype;
|
1999-08-24 01:06:48 +00:00
|
|
|
#if HAVE_GETTTYNAM
|
2000-07-03 09:24:12 +00:00
|
|
|
struct ttyent *t;
|
1999-08-24 01:06:48 +00:00
|
|
|
#else
|
2000-07-03 09:24:12 +00:00
|
|
|
FILE *fp;
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
char *ttypath;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if (userarg) {
|
|
|
|
ttype = userarg;
|
|
|
|
goto found;
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
/* Try the environment. */
|
|
|
|
if ((ttype = getenv("TERM")) != 0)
|
|
|
|
goto map;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if ((ttypath = ttyname(STDERR_FILENO)) != 0) {
|
2000-10-11 07:31:01 +00:00
|
|
|
p = _nc_basename(ttypath);
|
1999-08-24 01:06:48 +00:00
|
|
|
#if HAVE_GETTTYNAM
|
2000-07-03 09:24:12 +00:00
|
|
|
/*
|
|
|
|
* We have the 4.3BSD library call getttynam(3); that means
|
|
|
|
* there's an /etc/ttys to look up device-to-type mappings in.
|
|
|
|
* Try ttyname(3); check for dialup or other mapping.
|
|
|
|
*/
|
|
|
|
if ((t = getttynam(p))) {
|
|
|
|
ttype = t->ty_type;
|
|
|
|
goto map;
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
#else
|
2000-07-03 09:24:12 +00:00
|
|
|
if ((fp = fopen("/etc/ttytype", "r")) != 0
|
|
|
|
|| (fp = fopen("/etc/ttys", "r")) != 0) {
|
|
|
|
char buffer[BUFSIZ];
|
|
|
|
char *s, *t, *d;
|
|
|
|
|
|
|
|
while (fgets(buffer, sizeof(buffer) - 1, fp) != 0) {
|
|
|
|
for (s = buffer, t = d = 0; *s; s++) {
|
2002-05-21 05:30:25 +00:00
|
|
|
if (isspace(UChar(*s)))
|
2000-07-03 09:24:12 +00:00
|
|
|
*s = '\0';
|
|
|
|
else if (t == 0)
|
|
|
|
t = s;
|
|
|
|
else if (d == 0 && s != buffer && s[-1] == '\0')
|
|
|
|
d = s;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
if (t != 0 && d != 0 && !strcmp(d, p)) {
|
|
|
|
ttype = strdup(t);
|
|
|
|
fclose(fp);
|
|
|
|
goto map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
#endif /* HAVE_GETTTYNAM */
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
/* If still undefined, use "unknown". */
|
|
|
|
ttype = "unknown";
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
map:ttype = mapped(ttype);
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
/*
|
|
|
|
* If not a path, remove TERMCAP from the environment so we get a
|
|
|
|
* real entry from /etc/termcap. This prevents us from being fooled
|
|
|
|
* by out of date stuff in the environment.
|
|
|
|
*/
|
2014-03-01 00:40:26 +00:00
|
|
|
found:
|
|
|
|
if ((p = getenv("TERMCAP")) != 0 && !_nc_is_abs_path(p)) {
|
2000-07-03 09:24:12 +00:00
|
|
|
/* 'unsetenv("TERMCAP")' is not portable.
|
|
|
|
* The 'environ' array is better.
|
1999-08-24 01:06:48 +00:00
|
|
|
*/
|
2000-07-03 09:24:12 +00:00
|
|
|
int n;
|
|
|
|
for (n = 0; environ[n] != 0; n++) {
|
2014-03-01 00:40:26 +00:00
|
|
|
if (!strncmp("TERMCAP=", environ[n], (size_t) 8)) {
|
2000-07-03 09:24:12 +00:00
|
|
|
while ((environ[n] = environ[n + 1]) != 0) {
|
|
|
|
n++;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ttype now contains a pointer to the type of the terminal.
|
|
|
|
* If the first character is '?', ask the user.
|
|
|
|
*/
|
|
|
|
if (ttype[0] == '?') {
|
|
|
|
if (ttype[1] != '\0')
|
|
|
|
ttype = askuser(ttype + 1);
|
|
|
|
else
|
|
|
|
ttype = askuser(0);
|
|
|
|
}
|
|
|
|
/* Find the terminfo entry. If it doesn't exist, ask the user. */
|
2001-05-17 08:21:06 +00:00
|
|
|
while (setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO, &errret)
|
|
|
|
!= OK) {
|
2000-07-03 09:24:12 +00:00
|
|
|
if (errret == 0) {
|
2007-01-20 07:32:02 +00:00
|
|
|
(void) fprintf(stderr, "%s: unknown terminal type %s\n",
|
|
|
|
_nc_progname, ttype);
|
2000-07-03 09:24:12 +00:00
|
|
|
ttype = 0;
|
|
|
|
} else {
|
|
|
|
(void) fprintf(stderr,
|
2007-01-20 07:32:02 +00:00
|
|
|
"%s: can't initialize terminal type %s (error %d)\n",
|
|
|
|
_nc_progname, ttype, errret);
|
2000-07-03 09:24:12 +00:00
|
|
|
ttype = 0;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
ttype = askuser(ttype);
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
#if BROKEN_LINKER
|
2000-07-03 09:24:12 +00:00
|
|
|
tgetflag("am"); /* force lib_termcap.o to be linked for 'ospeed' */
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
return (ttype);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Mode-setting logic
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/* some BSD systems have these built in, some systems are missing
|
2007-01-20 07:32:02 +00:00
|
|
|
* one or more definitions. The safest solution is to override unless the
|
|
|
|
* commonly-altered ones are defined.
|
1999-08-24 01:06:48 +00:00
|
|
|
*/
|
2007-01-20 07:32:02 +00:00
|
|
|
#if !(defined(CERASE) && defined(CINTR) && defined(CKILL) && defined(CQUIT))
|
1999-08-24 01:06:48 +00:00
|
|
|
#undef CEOF
|
|
|
|
#undef CERASE
|
|
|
|
#undef CINTR
|
|
|
|
#undef CKILL
|
|
|
|
#undef CLNEXT
|
|
|
|
#undef CRPRNT
|
|
|
|
#undef CQUIT
|
|
|
|
#undef CSTART
|
|
|
|
#undef CSTOP
|
|
|
|
#undef CSUSP
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
/* control-character defaults */
|
2007-01-20 07:32:02 +00:00
|
|
|
#ifndef CEOF
|
1999-08-24 01:06:48 +00:00
|
|
|
#define CEOF CTRL('D')
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CERASE
|
1999-08-24 01:06:48 +00:00
|
|
|
#define CERASE CTRL('H')
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CINTR
|
1999-08-24 01:06:48 +00:00
|
|
|
#define CINTR 127 /* ^? */
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CKILL
|
1999-08-24 01:06:48 +00:00
|
|
|
#define CKILL CTRL('U')
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CLNEXT
|
1999-08-24 01:06:48 +00:00
|
|
|
#define CLNEXT CTRL('v')
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CRPRNT
|
1999-08-24 01:06:48 +00:00
|
|
|
#define CRPRNT CTRL('r')
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CQUIT
|
1999-08-24 01:06:48 +00:00
|
|
|
#define CQUIT CTRL('\\')
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CSTART
|
1999-08-24 01:06:48 +00:00
|
|
|
#define CSTART CTRL('Q')
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CSTOP
|
1999-08-24 01:06:48 +00:00
|
|
|
#define CSTOP CTRL('S')
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CSUSP
|
1999-08-24 01:06:48 +00:00
|
|
|
#define CSUSP CTRL('Z')
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_POSIX_VDISABLE)
|
|
|
|
#define DISABLED(val) (((_POSIX_VDISABLE != -1) \
|
|
|
|
&& ((val) == _POSIX_VDISABLE)) \
|
|
|
|
|| ((val) <= 0))
|
|
|
|
#else
|
|
|
|
#define DISABLED(val) ((int)(val) <= 0)
|
|
|
|
#endif
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2007-01-20 07:32:02 +00:00
|
|
|
#define CHK(val, dft) (DISABLED(val) ? dft : val)
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
static bool set_tabs(void);
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the terminal mode bits to a sensible state. Very useful after
|
|
|
|
* a child program dies in raw mode.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
reset_mode(void)
|
|
|
|
{
|
|
|
|
#ifdef TERMIOS
|
2000-07-03 09:24:12 +00:00
|
|
|
tcgetattr(STDERR_FILENO, &mode);
|
1999-08-24 01:06:48 +00:00
|
|
|
#else
|
2000-07-03 09:24:12 +00:00
|
|
|
stty(STDERR_FILENO, &mode);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TERMIOS
|
|
|
|
#if defined(VDISCARD) && defined(CDISCARD)
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cc[VDISCARD] = CHK(mode.c_cc[VDISCARD], CDISCARD);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CEOF);
|
|
|
|
mode.c_cc[VERASE] = CHK(mode.c_cc[VERASE], CERASE);
|
1999-08-24 01:06:48 +00:00
|
|
|
#if defined(VFLUSH) && defined(CFLUSH)
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cc[VFLUSH] = CHK(mode.c_cc[VFLUSH], CFLUSH);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cc[VINTR] = CHK(mode.c_cc[VINTR], CINTR);
|
|
|
|
mode.c_cc[VKILL] = CHK(mode.c_cc[VKILL], CKILL);
|
1999-08-24 01:06:48 +00:00
|
|
|
#if defined(VLNEXT) && defined(CLNEXT)
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cc[VLNEXT] = CHK(mode.c_cc[VLNEXT], CLNEXT);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CQUIT);
|
1999-08-24 01:06:48 +00:00
|
|
|
#if defined(VREPRINT) && defined(CRPRNT)
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cc[VREPRINT] = CHK(mode.c_cc[VREPRINT], CRPRNT);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#if defined(VSTART) && defined(CSTART)
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cc[VSTART] = CHK(mode.c_cc[VSTART], CSTART);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#if defined(VSTOP) && defined(CSTOP)
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cc[VSTOP] = CHK(mode.c_cc[VSTOP], CSTOP);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#if defined(VSUSP) && defined(CSUSP)
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cc[VSUSP] = CHK(mode.c_cc[VSUSP], CSUSP);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#if defined(VWERASE) && defined(CWERASE)
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cc[VWERASE] = CHK(mode.c_cc[VWERASE], CWERASE);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
|
2014-03-01 00:40:26 +00:00
|
|
|
mode.c_iflag &= ~((unsigned) (IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef IUCLC
|
2014-03-01 00:40:26 +00:00
|
|
|
| IUCLC
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef IXANY
|
2014-03-01 00:40:26 +00:00
|
|
|
| IXANY
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2014-03-01 00:40:26 +00:00
|
|
|
| IXOFF));
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_iflag |= (BRKINT | IGNPAR | ICRNL | IXON
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef IMAXBEL
|
2000-10-11 07:31:01 +00:00
|
|
|
| IMAXBEL
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
);
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2014-03-01 00:40:26 +00:00
|
|
|
mode.c_oflag &= ~((unsigned) (0
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef OLCUC
|
2014-03-01 00:40:26 +00:00
|
|
|
| OLCUC
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OCRNL
|
2014-03-01 00:40:26 +00:00
|
|
|
| OCRNL
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ONOCR
|
2014-03-01 00:40:26 +00:00
|
|
|
| ONOCR
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ONLRET
|
2014-03-01 00:40:26 +00:00
|
|
|
| ONLRET
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OFILL
|
2014-03-01 00:40:26 +00:00
|
|
|
| OFILL
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OFDEL
|
2014-03-01 00:40:26 +00:00
|
|
|
| OFDEL
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef NLDLY
|
2014-03-01 00:40:26 +00:00
|
|
|
| NLDLY
|
2007-12-30 11:08:14 +00:00
|
|
|
#endif
|
2008-11-09 14:08:54 +00:00
|
|
|
#ifdef CRDLY
|
2014-03-01 00:40:26 +00:00
|
|
|
| CRDLY
|
2007-12-30 11:08:14 +00:00
|
|
|
#endif
|
2008-11-09 14:08:54 +00:00
|
|
|
#ifdef TABDLY
|
2014-03-01 00:40:26 +00:00
|
|
|
| TABDLY
|
2007-12-30 11:08:14 +00:00
|
|
|
#endif
|
2008-11-09 14:08:54 +00:00
|
|
|
#ifdef BSDLY
|
2014-03-01 00:40:26 +00:00
|
|
|
| BSDLY
|
2007-12-30 11:08:14 +00:00
|
|
|
#endif
|
2008-11-09 14:08:54 +00:00
|
|
|
#ifdef VTDLY
|
2014-03-01 00:40:26 +00:00
|
|
|
| VTDLY
|
2007-12-30 11:08:14 +00:00
|
|
|
#endif
|
|
|
|
#ifdef FFDLY
|
2014-03-01 00:40:26 +00:00
|
|
|
| FFDLY
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2014-03-01 00:40:26 +00:00
|
|
|
));
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_oflag |= (OPOST
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef ONLCR
|
2000-10-11 07:31:01 +00:00
|
|
|
| ONLCR
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
);
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2014-03-01 00:40:26 +00:00
|
|
|
mode.c_cflag &= ~((unsigned) (CSIZE | CSTOPB | PARENB | PARODD | CLOCAL));
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_cflag |= (CS8 | CREAD);
|
2014-03-01 00:40:26 +00:00
|
|
|
mode.c_lflag &= ~((unsigned) (ECHONL | NOFLSH
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef TOSTOP
|
2014-03-01 00:40:26 +00:00
|
|
|
| TOSTOP
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ECHOPTR
|
2014-03-01 00:40:26 +00:00
|
|
|
| ECHOPRT
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XCASE
|
2014-03-01 00:40:26 +00:00
|
|
|
| XCASE
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2014-03-01 00:40:26 +00:00
|
|
|
));
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef ECHOCTL
|
2000-10-11 07:31:01 +00:00
|
|
|
| ECHOCTL
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ECHOKE
|
2000-10-11 07:31:01 +00:00
|
|
|
| ECHOKE
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-21 05:30:25 +00:00
|
|
|
SET_TTY(STDERR_FILENO, &mode);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns a "good" value for the erase character. This is loosely based on
|
|
|
|
* the BSD4.4 logic.
|
|
|
|
*/
|
2000-10-11 07:31:01 +00:00
|
|
|
#ifdef TERMIOS
|
1999-08-24 01:06:48 +00:00
|
|
|
static int
|
|
|
|
default_erase(void)
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
int result;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if (over_strike
|
|
|
|
&& key_backspace != 0
|
|
|
|
&& strlen(key_backspace) == 1)
|
|
|
|
result = key_backspace[0];
|
|
|
|
else
|
|
|
|
result = CERASE;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
return result;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-10-11 07:31:01 +00:00
|
|
|
#endif
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the values of the erase, interrupt, and kill characters in 'mode'.
|
|
|
|
*
|
|
|
|
* SVr4 tset (e.g., Solaris 2.5) only modifies the intr, quit or erase
|
|
|
|
* characters if they're unset, or if we specify them as options. This differs
|
|
|
|
* from BSD 4.4 tset, which always sets erase.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_control_chars(void)
|
|
|
|
{
|
|
|
|
#ifdef TERMIOS
|
2014-03-01 00:40:26 +00:00
|
|
|
if (DISABLED(mode.c_cc[VERASE]) || terasechar >= 0) {
|
|
|
|
mode.c_cc[VERASE] = UChar((terasechar >= 0)
|
|
|
|
? terasechar
|
|
|
|
: default_erase());
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2014-03-01 00:40:26 +00:00
|
|
|
if (DISABLED(mode.c_cc[VINTR]) || intrchar >= 0) {
|
|
|
|
mode.c_cc[VINTR] = UChar((intrchar >= 0)
|
|
|
|
? intrchar
|
|
|
|
: CINTR);
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2014-03-01 00:40:26 +00:00
|
|
|
if (DISABLED(mode.c_cc[VKILL]) || tkillchar >= 0) {
|
|
|
|
mode.c_cc[VKILL] = UChar((tkillchar >= 0)
|
|
|
|
? tkillchar
|
|
|
|
: CKILL);
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up various conversions in 'mode', including parity, tabs, returns,
|
|
|
|
* echo, and case, according to the termcap entry. If the program we're
|
|
|
|
* running was named with a leading upper-case character, map external
|
|
|
|
* uppercase to internal lowercase.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_conversions(void)
|
|
|
|
{
|
|
|
|
#ifdef __OBSOLETE__
|
2000-07-03 09:24:12 +00:00
|
|
|
/*
|
|
|
|
* Conversion logic for some *really* ancient terminal glitches,
|
|
|
|
* not supported in terminfo. Left here for succeeding generations
|
|
|
|
* to marvel at.
|
|
|
|
*/
|
|
|
|
if (tgetflag("UC")) {
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef IUCLC
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_iflag |= IUCLC;
|
|
|
|
mode.c_oflag |= OLCUC;
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
} else if (tgetflag("LC")) {
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef IUCLC
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_iflag &= ~IUCLC;
|
|
|
|
mode.c_oflag &= ~OLCUC;
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
|
|
|
mode.c_iflag &= ~(PARMRK | INPCK);
|
|
|
|
mode.c_lflag |= ICANON;
|
|
|
|
if (tgetflag("EP")) {
|
|
|
|
mode.c_cflag |= PARENB;
|
|
|
|
mode.c_cflag &= ~PARODD;
|
|
|
|
}
|
|
|
|
if (tgetflag("OP")) {
|
|
|
|
mode.c_cflag |= PARENB;
|
|
|
|
mode.c_cflag |= PARODD;
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif /* __OBSOLETE__ */
|
|
|
|
|
|
|
|
#ifdef TERMIOS
|
|
|
|
#ifdef ONLCR
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_oflag |= ONLCR;
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_iflag |= ICRNL;
|
|
|
|
mode.c_lflag |= ECHO;
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef OXTABS
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_oflag |= OXTABS;
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif /* OXTABS */
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
/* test used to be tgetflag("NL") */
|
|
|
|
if (newline != (char *) 0 && newline[0] == '\n' && !newline[1]) {
|
|
|
|
/* Newline, not linefeed. */
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef ONLCR
|
2014-03-01 00:40:26 +00:00
|
|
|
mode.c_oflag &= ~((unsigned) ONLCR);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2014-03-01 00:40:26 +00:00
|
|
|
mode.c_iflag &= ~((unsigned) ICRNL);
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
#ifdef __OBSOLETE__
|
2000-07-03 09:24:12 +00:00
|
|
|
if (tgetflag("HD")) /* Half duplex. */
|
|
|
|
mode.c_lflag &= ~ECHO;
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif /* __OBSOLETE__ */
|
|
|
|
#ifdef OXTABS
|
2000-07-03 09:24:12 +00:00
|
|
|
/* test used to be tgetflag("pt") */
|
|
|
|
if (has_hardware_tabs) /* Print tabs. */
|
|
|
|
mode.c_oflag &= ~OXTABS;
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif /* OXTABS */
|
2000-07-03 09:24:12 +00:00
|
|
|
mode.c_lflag |= (ECHOE | ECHOK);
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Output startup string. */
|
|
|
|
static void
|
|
|
|
set_init(void)
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
char *p;
|
|
|
|
bool settle;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
#ifdef __OBSOLETE__
|
2000-07-03 09:24:12 +00:00
|
|
|
if (pad_char != (char *) 0) /* Get/set pad character. */
|
|
|
|
PC = pad_char[0];
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif /* OBSOLETE */
|
|
|
|
|
|
|
|
#ifdef TAB3
|
2000-07-03 09:24:12 +00:00
|
|
|
if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) {
|
|
|
|
oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET);
|
2002-05-21 05:30:25 +00:00
|
|
|
SET_TTY(STDERR_FILENO, &oldmode);
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
settle = set_tabs();
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if (isreset) {
|
|
|
|
if ((p = reset_1string) != 0) {
|
|
|
|
tputs(p, 0, outc);
|
|
|
|
settle = TRUE;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
if ((p = reset_2string) != 0) {
|
|
|
|
tputs(p, 0, outc);
|
|
|
|
settle = TRUE;
|
|
|
|
}
|
|
|
|
/* What about rf, rs3, as per terminfo man page? */
|
|
|
|
/* also might be nice to send rmacs, rmul, rmm */
|
|
|
|
if ((p = reset_file) != 0
|
|
|
|
|| (p = init_file) != 0) {
|
|
|
|
cat(p);
|
|
|
|
settle = TRUE;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (settle) {
|
|
|
|
(void) putc('\r', stderr);
|
|
|
|
(void) fflush(stderr);
|
|
|
|
(void) napms(1000); /* Settle the terminal. */
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the hardware tabs on the terminal, using the ct (clear all tabs),
|
|
|
|
* st (set one tab) and ch (horizontal cursor addressing) capabilities.
|
|
|
|
* This is done before if and is, so they can patch in case we blow this.
|
|
|
|
* Return TRUE if we set any tab stops, FALSE if not.
|
|
|
|
*/
|
|
|
|
static bool
|
2007-01-20 07:32:02 +00:00
|
|
|
set_tabs(void)
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
if (set_tab && clear_all_tabs) {
|
|
|
|
int c;
|
2014-03-01 00:40:26 +00:00
|
|
|
int lim =
|
|
|
|
#if HAVE_SIZECHANGE
|
|
|
|
tcolumns
|
|
|
|
#else
|
|
|
|
columns
|
|
|
|
#endif
|
|
|
|
;
|
2000-07-03 09:24:12 +00:00
|
|
|
|
|
|
|
(void) putc('\r', stderr); /* Force to left margin. */
|
|
|
|
tputs(clear_all_tabs, 0, outc);
|
|
|
|
|
2014-03-01 00:40:26 +00:00
|
|
|
for (c = 8; c < lim; c += 8) {
|
2000-07-03 09:24:12 +00:00
|
|
|
/* Get to the right column. In BSD tset, this
|
|
|
|
* used to try a bunch of half-clever things
|
|
|
|
* with cup and hpa, for an average saving of
|
|
|
|
* somewhat less than two character times per
|
2007-01-20 07:32:02 +00:00
|
|
|
* tab stop, less than .01 sec at 2400cps. We
|
2000-07-03 09:24:12 +00:00
|
|
|
* lost all this cruft because it seemed to be
|
|
|
|
* introducing some odd bugs.
|
2007-01-20 07:32:02 +00:00
|
|
|
* -----------12345678----------- */
|
2000-07-03 09:24:12 +00:00
|
|
|
(void) fputs(" ", stderr);
|
|
|
|
tputs(set_tab, 0, outc);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
putc('\r', stderr);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
return (FALSE);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Main sequence
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the user if a control key has been changed from the default value.
|
|
|
|
*/
|
2000-10-11 07:31:01 +00:00
|
|
|
#ifdef TERMIOS
|
1999-08-24 01:06:48 +00:00
|
|
|
static void
|
|
|
|
report(const char *name, int which, unsigned def)
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
unsigned older, newer;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
newer = mode.c_cc[which];
|
|
|
|
older = oldmode.c_cc[which];
|
|
|
|
|
|
|
|
if (older == newer && older == def)
|
|
|
|
return;
|
|
|
|
|
|
|
|
(void) fprintf(stderr, "%s %s ", name, older == newer ? "is" : "set to");
|
|
|
|
|
2007-01-20 07:32:02 +00:00
|
|
|
if (DISABLED(newer))
|
|
|
|
(void) fprintf(stderr, "undef.\n");
|
2000-07-03 09:24:12 +00:00
|
|
|
/*
|
|
|
|
* Check 'delete' before 'backspace', since the key_backspace value
|
|
|
|
* is ambiguous.
|
|
|
|
*/
|
2007-01-20 07:32:02 +00:00
|
|
|
else if (newer == 0177)
|
2000-07-03 09:24:12 +00:00
|
|
|
(void) fprintf(stderr, "delete.\n");
|
|
|
|
else if ((p = key_backspace) != 0
|
2000-10-11 07:31:01 +00:00
|
|
|
&& newer == (unsigned char) p[0]
|
|
|
|
&& p[1] == '\0')
|
2000-07-03 09:24:12 +00:00
|
|
|
(void) fprintf(stderr, "backspace.\n");
|
|
|
|
else if (newer < 040) {
|
|
|
|
newer ^= 0100;
|
2007-01-20 07:32:02 +00:00
|
|
|
(void) fprintf(stderr, "control-%c (^%c).\n", UChar(newer), UChar(newer));
|
2000-07-03 09:24:12 +00:00
|
|
|
} else
|
2007-01-20 07:32:02 +00:00
|
|
|
(void) fprintf(stderr, "%c.\n", UChar(newer));
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-10-11 07:31:01 +00:00
|
|
|
#endif
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert the obsolete argument forms into something that getopt can handle.
|
|
|
|
* This means that -e, -i and -k get default arguments supplied for them.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
obsolete(char **argv)
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
for (; *argv; ++argv) {
|
|
|
|
char *parm = argv[0];
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if (parm[0] == '-' && parm[1] == '\0') {
|
|
|
|
argv[0] = strdup("-q");
|
|
|
|
continue;
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if ((parm[0] != '-')
|
|
|
|
|| (argv[1] && argv[1][0] != '-')
|
|
|
|
|| (parm[1] != 'e' && parm[1] != 'i' && parm[1] != 'k')
|
|
|
|
|| (parm[2] != '\0'))
|
|
|
|
continue;
|
|
|
|
switch (argv[0][1]) {
|
|
|
|
case 'e':
|
|
|
|
argv[0] = strdup("-e^H");
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
argv[0] = strdup("-i^C");
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
argv[0] = strdup("-k^U");
|
|
|
|
break;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-01-20 07:32:02 +00:00
|
|
|
usage(void)
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2007-01-20 07:32:02 +00:00
|
|
|
static const char *tbl[] =
|
|
|
|
{
|
|
|
|
""
|
|
|
|
,"Options:"
|
|
|
|
," -c set control characters"
|
|
|
|
," -e ch erase character"
|
|
|
|
," -I no initialization strings"
|
|
|
|
," -i ch interrupt character"
|
|
|
|
," -k ch kill character"
|
|
|
|
," -m mapping map identifier to type"
|
|
|
|
," -Q do not output control key settings"
|
|
|
|
," -r display term on stderr"
|
|
|
|
," -s output TERM set command"
|
|
|
|
," -V print curses-version"
|
|
|
|
," -w set window-size"
|
|
|
|
};
|
|
|
|
unsigned n;
|
|
|
|
(void) fprintf(stderr, "Usage: %s [options] [terminal]\n", _nc_progname);
|
|
|
|
for (n = 0; n < sizeof(tbl) / sizeof(tbl[0]); ++n)
|
|
|
|
fprintf(stderr, "%s\n", tbl[n]);
|
2002-05-21 05:30:25 +00:00
|
|
|
exit_error();
|
|
|
|
/* NOTREACHED */
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
static char
|
|
|
|
arg_to_char(void)
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2008-11-09 14:08:54 +00:00
|
|
|
return (char) ((optarg[0] == '^' && optarg[1] != '\0')
|
|
|
|
? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1]))
|
|
|
|
: optarg[0]);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
int ch, noinit, noset, quiet, Sflag, sflag, showterm;
|
|
|
|
const char *p;
|
|
|
|
const char *ttype;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
obsolete(argv);
|
|
|
|
noinit = noset = quiet = Sflag = sflag = showterm = 0;
|
2007-12-30 11:08:14 +00:00
|
|
|
while ((ch = getopt(argc, argv, "a:cd:e:Ii:k:m:np:qQSrsVw")) != -1) {
|
2000-07-03 09:24:12 +00:00
|
|
|
switch (ch) {
|
2007-01-20 07:32:02 +00:00
|
|
|
case 'c': /* set control-chars */
|
|
|
|
opt_c = TRUE;
|
2000-07-03 09:24:12 +00:00
|
|
|
break;
|
|
|
|
case 'a': /* OBSOLETE: map identifier to type */
|
|
|
|
add_mapping("arpanet", optarg);
|
|
|
|
break;
|
|
|
|
case 'd': /* OBSOLETE: map identifier to type */
|
|
|
|
add_mapping("dialup", optarg);
|
|
|
|
break;
|
|
|
|
case 'e': /* erase character */
|
|
|
|
terasechar = arg_to_char();
|
|
|
|
break;
|
|
|
|
case 'I': /* no initialization strings */
|
|
|
|
noinit = 1;
|
|
|
|
break;
|
|
|
|
case 'i': /* interrupt character */
|
|
|
|
intrchar = arg_to_char();
|
|
|
|
break;
|
|
|
|
case 'k': /* kill character */
|
|
|
|
tkillchar = arg_to_char();
|
|
|
|
break;
|
|
|
|
case 'm': /* map identifier to type */
|
|
|
|
add_mapping(0, optarg);
|
|
|
|
break;
|
|
|
|
case 'n': /* OBSOLETE: set new tty driver */
|
|
|
|
break;
|
|
|
|
case 'p': /* OBSOLETE: map identifier to type */
|
|
|
|
add_mapping("plugboard", optarg);
|
|
|
|
break;
|
|
|
|
case 'Q': /* don't output control key settings */
|
|
|
|
quiet = 1;
|
|
|
|
break;
|
2007-01-20 07:32:02 +00:00
|
|
|
case 'q': /* display term only */
|
|
|
|
noset = 1;
|
2000-07-03 09:24:12 +00:00
|
|
|
break;
|
|
|
|
case 'r': /* display term on stderr */
|
|
|
|
showterm = 1;
|
|
|
|
break;
|
2007-01-20 07:32:02 +00:00
|
|
|
case 'S': /* OBSOLETE: output TERM & TERMCAP */
|
|
|
|
Sflag = 1;
|
|
|
|
break;
|
2000-07-03 09:24:12 +00:00
|
|
|
case 's': /* output TERM set command */
|
|
|
|
sflag = 1;
|
|
|
|
break;
|
2007-01-20 07:32:02 +00:00
|
|
|
case 'V': /* print curses-version */
|
2000-10-11 07:31:01 +00:00
|
|
|
puts(curses_version());
|
2007-01-20 07:32:02 +00:00
|
|
|
ExitProgram(EXIT_SUCCESS);
|
|
|
|
case 'w': /* set window-size */
|
|
|
|
opt_w = TRUE;
|
|
|
|
break;
|
2000-07-03 09:24:12 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
2007-01-20 07:32:02 +00:00
|
|
|
usage();
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
2007-01-20 07:32:02 +00:00
|
|
|
|
|
|
|
_nc_progname = _nc_rootname(*argv);
|
2000-07-03 09:24:12 +00:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if (argc > 1)
|
2007-01-20 07:32:02 +00:00
|
|
|
usage();
|
|
|
|
|
|
|
|
if (!opt_c && !opt_w)
|
|
|
|
opt_c = opt_w = TRUE;
|
|
|
|
|
|
|
|
if (GET_TTY(STDERR_FILENO, &mode) < 0)
|
|
|
|
failed("standard error");
|
|
|
|
can_restore = TRUE;
|
|
|
|
original = oldmode = mode;
|
|
|
|
#ifdef TERMIOS
|
2008-11-09 14:08:54 +00:00
|
|
|
ospeed = (NCURSES_OSPEED) cfgetospeed(&mode);
|
2007-01-20 07:32:02 +00:00
|
|
|
#else
|
2008-11-09 14:08:54 +00:00
|
|
|
ospeed = (NCURSES_OSPEED) mode.sg_ospeed;
|
2007-01-20 07:32:02 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-28 19:18:07 +00:00
|
|
|
if (same_program(_nc_progname, PROG_RESET)) {
|
2007-01-20 07:32:02 +00:00
|
|
|
isreset = TRUE;
|
|
|
|
reset_mode();
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2014-02-28 19:18:07 +00:00
|
|
|
(void) get_termcap_entry(*argv);
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if (!noset) {
|
2014-03-01 00:40:26 +00:00
|
|
|
#if HAVE_SIZECHANGE
|
2000-07-03 09:24:12 +00:00
|
|
|
tcolumns = columns;
|
|
|
|
tlines = lines;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2007-01-20 07:32:02 +00:00
|
|
|
if (opt_w) {
|
2008-11-09 14:08:54 +00:00
|
|
|
STRUCT_WINSIZE win;
|
|
|
|
/* Set window size if not set already */
|
|
|
|
(void) ioctl(STDERR_FILENO, IOCTL_GET_WINSIZE, &win);
|
|
|
|
if (WINSIZE_ROWS(win) == 0 &&
|
|
|
|
WINSIZE_COLS(win) == 0 &&
|
2007-01-20 07:32:02 +00:00
|
|
|
tlines > 0 && tcolumns > 0) {
|
2008-11-09 14:08:54 +00:00
|
|
|
WINSIZE_ROWS(win) = tlines;
|
|
|
|
WINSIZE_COLS(win) = tcolumns;
|
|
|
|
(void) ioctl(STDERR_FILENO, IOCTL_SET_WINSIZE, &win);
|
2007-01-20 07:32:02 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
#endif
|
2007-01-20 07:32:02 +00:00
|
|
|
if (opt_c) {
|
|
|
|
set_control_chars();
|
|
|
|
set_conversions();
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2007-01-20 07:32:02 +00:00
|
|
|
if (!noinit)
|
|
|
|
set_init();
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2007-01-20 07:32:02 +00:00
|
|
|
/* Set the modes if they've changed. */
|
|
|
|
if (memcmp(&mode, &oldmode, sizeof(mode))) {
|
|
|
|
SET_TTY(STDERR_FILENO, &mode);
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
/* Get the terminal name from the entry. */
|
|
|
|
ttype = _nc_first_name(cur_term->type.term_names);
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if (noset)
|
|
|
|
(void) printf("%s\n", ttype);
|
|
|
|
else {
|
|
|
|
if (showterm)
|
|
|
|
(void) fprintf(stderr, "Terminal type is %s.\n", ttype);
|
|
|
|
/*
|
|
|
|
* If erase, kill and interrupt characters could have been
|
|
|
|
* modified and not -Q, display the changes.
|
|
|
|
*/
|
2000-10-11 07:31:01 +00:00
|
|
|
#ifdef TERMIOS
|
2000-07-03 09:24:12 +00:00
|
|
|
if (!quiet) {
|
|
|
|
report("Erase", VERASE, CERASE);
|
2007-01-20 07:32:02 +00:00
|
|
|
report("Kill", VKILL, CKILL);
|
|
|
|
report("Interrupt", VINTR, CINTR);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-10-11 07:31:01 +00:00
|
|
|
#endif
|
2000-07-03 09:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Sflag)
|
|
|
|
err("The -S option is not supported under terminfo.");
|
|
|
|
|
|
|
|
if (sflag) {
|
2007-01-20 07:32:02 +00:00
|
|
|
int len;
|
|
|
|
char *var;
|
|
|
|
char *leaf;
|
2000-07-03 09:24:12 +00:00
|
|
|
/*
|
|
|
|
* Figure out what shell we're using. A hack, we look for an
|
|
|
|
* environmental variable SHELL ending in "csh".
|
|
|
|
*/
|
2007-01-20 07:32:02 +00:00
|
|
|
if ((var = getenv("SHELL")) != 0
|
2008-11-09 14:08:54 +00:00
|
|
|
&& ((len = (int) strlen(leaf = _nc_basename(var))) >= 3)
|
2007-01-20 07:32:02 +00:00
|
|
|
&& !strcmp(leaf + len - 3, "csh"))
|
2000-07-03 09:24:12 +00:00
|
|
|
p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n";
|
|
|
|
else
|
|
|
|
p = "TERM=%s;\n";
|
|
|
|
(void) printf(p, ttype);
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2007-01-20 07:32:02 +00:00
|
|
|
ExitProgram(EXIT_SUCCESS);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|