[unix-pc.general] Changing window sizes on the unixpc

tkacik@rphroy.UUCP (Tom Tkacik) (06/14/88)

I have always disliked using the shell windows on my 7300, because when
I change its size programs such as vi,
which need to know the size of a window, no longer work.

I then came up with  rsz.  Rsz is a KSH alias defined as

$ alias rsz='TERMCAP=`sz`'

The quotes are critical!  Sz is the program listed below.
After using the mouse to change the size of a shell window, just type rsz
and vi will work in the newly sized window.

What sz does is to change the TERMCAP environment variable,
by getting the actual number of rows and columns in the current window,
and sticking them into TERMCAP.

Rsz is necessary because it is not possible to change the environment
of a parent process.

----
Tom Tkacik
tkacik@gmr.com

# # # # # # # cut on the dotted line # # # # # # #

/* sz - change the TERMCAP shell variable to match the window */
/*    requires a ksh alias rsz defined as                     */
/* alias rsz='TERMCAP=`sz`'                                   */
/*							      */
/* compile with:  cc -o sz sz.c                               */

#include <stdio.h>
#include <sys/window.h>
#include <string.h>

/* size of a standard font character in pixels */
#define  HEIGHT 12
#define  WIDTH  9

/* window structure */
  struct uwdata win;

/* to hold the new TERMCAP entry */
  char term[500];

main()
{
	int col, row, wn;
	char *s, *getenv();

     /* get the window info */
	ioctl(2, WIOCGETD, &win);
	col = win.uw_width / WIDTH;
	row = win.uw_height / HEIGHT;

     /* set window height and width to be exactly row by col */
	win.uw_width = col * WIDTH;
	win.uw_height = row * HEIGHT;
	ioctl(2, WIOCSETD, &win);

     /* get the original TERMCAP entry */
	s = getenv("TERMCAP");
	if(s != NULL)
		strcpy(term, s);
	else
		return; /* there is no TERMCAP entry */

     /* now update the TERMCAP entry with the */
     /*  new row and col                      */

     /* look for li# (the number of lines) */
	s = term;
	while((*s != '\0') && (strncmp(s, "li#", 3) != 0)) {
		s++;
	}
	if(*s != '\0') {
		s[3] = row / 10 + '0';
		s[4] = row % 10 + '0';
	}

     /* look for co# (the number of columns) */
	s = term;
	while((*s != '\0') && (strncmp(s, "co#", 3) != 0)) {
		s++;
	}
	if(*s != '\0') {
		s[3] = col / 10 + '0';
		s[4] = col % 10 + '0';
	}

	puts(term);
}