Quizzer

 view release on metacpan or  search on metacpan

exercises/compile-tcsh/tcsh-6.10.00/ed.screen.c  view on Meta::CPAN


	if (ioctl(SHIN, TIOCGWINSZ, (ioctl_t) &ws) != -1) {
	    if (ws.ws_col)
		*cols = ws.ws_col;
	    if (ws.ws_row)
		*lins = ws.ws_row;
	}
    }
# endif /* !lint */
#else /* TIOCGWINSZ */
# ifdef TIOCGSIZE
#  define KNOWsize
    {
	struct ttysize ts;	/* from Sun */

	if (ioctl(SHIN, TIOCGSIZE, (ioctl_t) &ts) != -1) {
	    if (ts.ts_cols)
		*cols = ts.ts_cols;
	    if (ts.ts_lines)
		*lins = ts.ts_lines;
	}
    }
# endif /* TIOCGSIZE */
#endif /* TIOCGWINSZ */

    return (Val(T_co) != *cols || Val(T_li) != *lins);
}

#endif /* SIGWINDOW */

void
ChangeSize(lins, cols)
    int     lins, cols;
{
    /*
     * Just in case
     */
    Val(T_co) = (cols < 2) ? 80 : cols;
    Val(T_li) = (lins < 1) ? 24 : lins;

#ifdef WINNT_NATIVE
      nt_set_size(lins,cols);
#endif /* WINNT_NATIVE */
#ifdef KNOWsize
    /*
     * We want to affect the environment only when we have a valid
     * setup, not when we get bad settings. Consider the following scenario:
     * We just logged in, and we have not initialized the editor yet.
     * We reset termcap with tset, and not $TERMCAP has the right
     * terminal size. But since the editor is not initialized yet, and
     * the kernel's notion of the terminal size might be wrong we arrive
     * here with lines = columns = 0. If we reset the environment we lose
     * our only chance to get the window size right.
     */
    if (Val(T_co) == cols && Val(T_li) == lins) {
	Char    buf[10];
	char   *tptr;

	if (getenv("COLUMNS")) {
	    (void) Itoa(Val(T_co), buf, 0, 0);
	    tsetenv(STRCOLUMNS, buf);
	}

	if (getenv("LINES")) {
	    (void) Itoa(Val(T_li), buf, 0, 0);
	    tsetenv(STRLINES, buf);
	}

	if ((tptr = getenv("TERMCAP")) != NULL) {
	    /* Leave 64 characters slop in case we enlarge the termcap string */
	    Char    termcap[1024+64], backup[1024+64], *ptr;
	    int     i;

	    ptr = str2short(tptr);
	    (void) Strncpy(termcap, ptr, 1024);
	    termcap[1023] = '\0';

	    /* update termcap string; first do columns */
	    buf[0] = 'c';
	    buf[1] = 'o';
	    buf[2] = '#';
	    buf[3] = '\0';
	    if ((ptr = Strstr(termcap, buf)) == NULL) {
		(void) Strcpy(backup, termcap);
	    }
	    else {
		i = (int) (ptr - termcap + Strlen(buf));
		(void) Strncpy(backup, termcap, (size_t) i);
		backup[i] = '\0';
		(void) Itoa(Val(T_co), buf, 0, 0);
		(void) Strcat(backup + i, buf);
		ptr = Strchr(ptr, ':');
		(void) Strcat(backup, ptr);
	    }

	    /* now do lines */
	    buf[0] = 'l';
	    buf[1] = 'i';
	    buf[2] = '#';
	    buf[3] = '\0';
	    if ((ptr = Strstr(backup, buf)) == NULL) {
		(void) Strcpy(termcap, backup);
	    }
	    else {
		i = (int) (ptr - backup + Strlen(buf));
		(void) Strncpy(termcap, backup, (size_t) i);
		termcap[i] = '\0';
		(void) Itoa(Val(T_li), buf, 0, 0);
		(void) Strcat(termcap, buf);
		ptr = Strchr(ptr, ':');
		(void) Strcat(termcap, ptr);
	    }
	    /*
	     * Chop the termcap string at 1024 characters to avoid core-dumps
	     * in the termcap routines
	     */
	    termcap[1023] = '\0';
	    tsetenv(STRTERMCAP, termcap);
	}
    }
#endif /* KNOWsize */

    ReBufferDisplay();		/* re-make display buffers */
    ClearDisp();
}



( run in 0.526 second using v1.01-cache-2.11-cpan-6aa56a78535 )