Exemplo n.º 1
0
/*
 * Set window size if not set already, but update our copy of the values if the
 * size was set.
 */
void
set_window_size(int fd, short *high, short *wide)
{
    STRUCT_WINSIZE win;
    (void) ioctl(fd, IOCTL_GET_WINSIZE, &win);
    if (WINSIZE_ROWS(win) == 0 &&
	WINSIZE_COLS(win) == 0) {
	if (*high > 0 && *wide > 0) {
	    WINSIZE_ROWS(win) = (unsigned short) *high;
	    WINSIZE_COLS(win) = (unsigned short) *wide;
	    (void) ioctl(fd, IOCTL_SET_WINSIZE, &win);
	}
    } else if (WINSIZE_ROWS(win) > 0 &&
	       WINSIZE_COLS(win) > 0) {
	*high = (short) WINSIZE_ROWS(win);
	*wide = (short) WINSIZE_COLS(win);
    }
}
Exemplo n.º 2
0
static void _nc_get_screensize(int *linep, int *colp)
/* Obtain lines/columns values from the environment and/or terminfo entry */
{
char	*rows, *cols, *p;
long	l;

	/* figure out the size of the screen */
	T(("screen size: terminfo lines = %d columns = %d", lines, columns));

	if (!_use_env)
	{
	    *linep = (int)lines;
	    *colp  = (int)columns;
	}
	else	/* usually want to query LINES and COLUMNS from environment */
	{
	    *linep = *colp = 0;

	    /* first, look for environment variables */
	    if ((rows = getenv("LINES")) != 0) {
		l = strtol(rows, &p, 10);
		if (p != rows && *p == '\0' && l != LONG_MIN && l <= INT_MAX)
		    *linep = (int)l;
	    }
	    if ((cols = getenv("COLUMNS")) != 0) {
		l = strtol(cols, &p, 10);
		if (p != cols && *p == '\0' && l != LONG_MIN && l <= INT_MAX)
		    *colp = (int)l;
	    }
	    T(("screen size: environment LINES = %d COLUMNS = %d",*linep,*colp));

#if HAVE_SIZECHANGE
	    /* if that didn't work, maybe we can try asking the OS */
	    if (*linep <= 0 || *colp <= 0)
	    {
		if (isatty(cur_term->Filedes))
		{
		    STRUCT_WINSIZE size;

		    errno = 0;
		    do {
			if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0
				&& errno != EINTR)
			    goto failure;
		    } while
			(errno == EINTR);

		    *linep = WINSIZE_ROWS(size);
		    *colp  = WINSIZE_COLS(size);
		}
		/* FALLTHRU */
	    failure:;
	    }
#endif /* HAVE_SIZECHANGE */

	    /* if we can't get dynamic info about the size, use static */
	    if (*linep <= 0 || *colp <= 0)
		if (lines > 0 && columns > 0)
		{
		    *linep = (int)lines;
		    *colp  = (int)columns;
		}

	    /* the ultimate fallback, assume fixed 24x80 size */
	    if (*linep <= 0 || *colp <= 0)
	    {
		*linep = 24;
		*colp  = 80;
	    }

	    /*
	     * Put the derived values back in the screen-size caps, so
	     * tigetnum() and tgetnum() will do the right thing.
	     */
	    lines   = (short)(*linep);
	    columns = (short)(*colp);
	}

	T(("screen size is %dx%d", *linep, *colp));

#ifdef init_tabs
	if (init_tabs != -1)
		TABSIZE = (int)init_tabs;
	else
#endif /* init_tabs */
		TABSIZE = 8;
	T(("TABSIZE = %d", TABSIZE));

}
Exemplo n.º 3
0
static void
_nc_get_screensize(int *linep, int *colp)
/* Obtain lines/columns values from the environment and/or terminfo entry */
{
    /* figure out the size of the screen */
    T(("screen size: terminfo lines = %d columns = %d", lines, columns));

    if (!_use_env) {
	*linep = (int) lines;
	*colp = (int) columns;
    } else {			/* usually want to query LINES and COLUMNS from environment */
	int value;

	*linep = *colp = 0;

	/* first, look for environment variables */
	if ((value = _nc_getenv_num("LINES")) > 0) {
	    *linep = value;
	}
	if ((value = _nc_getenv_num("COLUMNS")) > 0) {
	    *colp = value;
	}
	T(("screen size: environment LINES = %d COLUMNS = %d", *linep, *colp));

#ifdef __EMX__
	if (*linep <= 0 || *colp <= 0) {
	    int screendata[2];
	    _scrsize(screendata);
	    *colp = screendata[0];
	    *linep = screendata[1];
	    T(("EMX screen size: environment LINES = %d COLUMNS = %d",
	       *linep, *colp));
	}
#endif
#if HAVE_SIZECHANGE
	/* if that didn't work, maybe we can try asking the OS */
	if (*linep <= 0 || *colp <= 0) {
	    if (isatty(cur_term->Filedes)) {
		STRUCT_WINSIZE size;

		errno = 0;
		do {
		    if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0
			&& errno != EINTR)
			goto failure;
		} while
		    (errno == EINTR);

		/*
		 * Solaris lets users override either dimension with an
		 * environment variable.
		 */
		if (*linep <= 0)
		    *linep = WINSIZE_ROWS(size);
		if (*colp <= 0)
		    *colp = WINSIZE_COLS(size);
	    }
	    /* FALLTHRU */
	  failure:;
	}
#endif /* HAVE_SIZECHANGE */

	/* if we can't get dynamic info about the size, use static */
	if (*linep <= 0) {
	    *linep = (int) lines;
	}
	if (*colp <= 0) {
	    *colp = (int) columns;
	}

	/* the ultimate fallback, assume fixed 24x80 size */
	if (*linep <= 0) {
	    *linep = 24;
	}
	if (*colp <= 0) {
	    *colp = 80;
	}

	/*
	 * Put the derived values back in the screen-size caps, so
	 * tigetnum() and tgetnum() will do the right thing.
	 */
	lines = (short) (*linep);
	columns = (short) (*colp);
    }

    T(("screen size is %dx%d", *linep, *colp));

    if (VALID_NUMERIC(init_tabs))
	TABSIZE = (int) init_tabs;
    else
	TABSIZE = 8;
    T(("TABSIZE = %d", TABSIZE));

}
Exemplo n.º 4
0
int
main(int argc, char **argv)
{
    int ch, noinit, noset, quiet, Sflag, sflag, showterm;
    const char *p;
    const char *ttype;

    obsolete(argv);
    noinit = noset = quiet = Sflag = sflag = showterm = 0;
    while ((ch = getopt(argc, argv, "a:cd:e:Ii:k:m:np:qQSrsVw")) != -1) {
	switch (ch) {
	case 'c':		/* set control-chars */
	    opt_c = TRUE;
	    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;
	case 'q':		/* display term only */
	    noset = 1;
	    break;
	case 'r':		/* display term on stderr */
	    showterm = 1;
	    break;
	case 'S':		/* OBSOLETE: output TERM & TERMCAP */
	    Sflag = 1;
	    break;
	case 's':		/* output TERM set command */
	    sflag = 1;
	    break;
	case 'V':		/* print curses-version */
	    puts(curses_version());
	    ExitProgram(EXIT_SUCCESS);
	case 'w':		/* set window-size */
	    opt_w = TRUE;
	    break;
	case '?':
	default:
	    usage();
	}
    }

    _nc_progname = _nc_rootname(*argv);
    argc -= optind;
    argv += optind;

    if (argc > 1)
	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
    ospeed = (NCURSES_OSPEED) cfgetospeed(&mode);
#else
    ospeed = (NCURSES_OSPEED) mode.sg_ospeed;
#endif

    if (!strcmp(_nc_progname, PROG_RESET)) {
	isreset = TRUE;
	reset_mode();
    }

    ttype = get_termcap_entry(*argv);

    if (!noset) {
	tcolumns = columns;
	tlines = lines;

#if HAVE_SIZECHANGE
	if (opt_w) {
	    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 &&
		tlines > 0 && tcolumns > 0) {
		WINSIZE_ROWS(win) = tlines;
		WINSIZE_COLS(win) = tcolumns;
		(void) ioctl(STDERR_FILENO, IOCTL_SET_WINSIZE, &win);
	    }
	}
#endif
	if (opt_c) {
	    set_control_chars();
	    set_conversions();

	    if (!noinit)
		set_init();

	    /* Set the modes if they've changed. */
	    if (memcmp(&mode, &oldmode, sizeof(mode))) {
		SET_TTY(STDERR_FILENO, &mode);
	    }
	}
    }

    /* Get the terminal name from the entry. */
    ttype = _nc_first_name(cur_term->type.term_names);

    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.
	 */
#ifdef TERMIOS
	if (!quiet) {
	    report("Erase", VERASE, CERASE);
	    report("Kill", VKILL, CKILL);
	    report("Interrupt", VINTR, CINTR);
	}
#endif
    }

    if (Sflag)
	err("The -S option is not supported under terminfo.");

    if (sflag) {
	int len;
	char *var;
	char *leaf;
	/*
	 * Figure out what shell we're using.  A hack, we look for an
	 * environmental variable SHELL ending in "csh".
	 */
	if ((var = getenv("SHELL")) != 0
	    && ((len = (int) strlen(leaf = _nc_basename(var))) >= 3)
	    && !strcmp(leaf + len - 3, "csh"))
	    p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n";
	else
	    p = "TERM=%s;\n";
	(void) printf(p, ttype);
    }

    ExitProgram(EXIT_SUCCESS);
}