/* $XTermId: resize.c,v 1.144 2020/06/03 00:26:23 tom Exp $ */
/*
* Copyright 2003-2018,2020 by Thomas E. Dickey
*
* All Rights Reserved
*
* 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, 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 LISTED COPYRIGHT HOLDER(S) 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.
*
*
* Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
*
* All Rights Reserved
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of Digital Equipment
* Corporation not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior permission.
*
*
* DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
* DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/*
* Some OS's may want to use both, like SCO for example. We catch here anyone
* who hasn't decided what they want.
*/
#if !defined(USE_TERMCAP) && !defined(USE_TERMINFO)
#define USE_TERMINFO
#endif
#ifdef USE_TERMCAP
static void
print_termcap(const char *termcap)
{
int ch;
putchar('\'');
while ((ch = *termcap++) != '\0') {
switch (ch & 0xff) {
case 127: /* undo bug in GNU termcap */
printf("^?");
break;
case '\'': /* must escape anyway (unlikely) */
/* FALLTHRU */
case '!': /* must escape for SunOS csh */
putchar('\\');
/* FALLTHRU */
default:
putchar(ch);
break;
}
}
putchar('\'');
}
#endif /* USE_TERMCAP */
static int
checkdigits(char *str)
{
while (*str) {
if (!isdigit(CharOf(*str)))
return (0);
str++;
}
return (1);
}
static void
readstring(FILE *fp, char *buf, const char *str)
{
int last, c;
#if !defined(USG) && !defined(__minix)
/* What is the advantage of setitimer() over alarm()? */
struct itimerval it;
#endif
myname = x_basename(argv[0]);
if (strcmp(myname, sunname) == 0)
emu = SUN;
for (argv++, argc--; argc > 0 && **argv == '-'; argv++, argc--) {
switch ((*argv)[1]) {
case 's': /* Sun emulation */
if (emu == SUN)
Usage(); /* Never returns */
emu = SUN;
break;
case 'u': /* Bourne (Unix) shell */
shell_type = SHELL_BOURNE;
break;
case 'c': /* C shell */
shell_type = SHELL_C;
break;
case 'v':
printf("%s\n", xtermVersion());
exit(EXIT_SUCCESS);
default:
Usage(); /* Never returns */
}
}
if (SHELL_UNKNOWN == shell_type) {
/* Find out what kind of shell this user is running.
* This is the same algorithm that xterm uses.
*/
if ((ptr = x_getenv("SHELL")) == NULL) {
uid_t uid = getuid();
struct passwd pw;
if (x_getpwuid(uid, &pw)) {
(void) x_getlogin(uid, &pw);
}
if (!OkPasswd(&pw)
|| *(ptr = pw.pw_shell) == 0) {
/* this is the same default that xterm uses */
ptr = x_strdup("/bin/sh");
}
}
shell = x_basename(ptr);
/* now that we know, what kind is it? */
for (i = 0; shell_list[i].name; i++) {
if (!strcmp(shell_list[i].name, shell)) {
break;
}
}
shell_type = shell_list[i].type;
}
if (argc == 2) {
if (!setsize[emu]) {
fprintf(stderr,
"%s: Can't set window size under %s emulation\n",
myname, emuname[emu]);
exit(EXIT_FAILURE);
}
if (!checkdigits(argv[0]) || !checkdigits(argv[1])) {
Usage(); /* Never returns */
}
} else if (argc != 0) {
Usage(); /* Never returns */
}
#ifdef CANT_OPEN_DEV_TTY
if ((name_of_tty = ttyname(fileno(stderr))) == NULL)
#endif
name_of_tty = x_strdup("/dev/tty");