* $Source: /u1/X/xterm/RCS/resize.c,v $
* $Header: resize.c,v 10.101 86/12/02 10:35:30 swick Exp $
static char *rcsid_resize_c
= "$Header: resize.c,v 10.101 86/12/02 10:35:30 swick Exp $";
#include <X/mit-copyright.h>
/* Copyright Massachusetts Institute of Technology 1984 */
static char sccs_id
[] = "@(#)resize.c\tX10/6.6B\t12/26/86";
char *emuname
[EMULATIONS
] = {
char *getsize
[EMULATIONS
] = {
"\0337\033[r\033[999;999H\033[6n",
char *getwsize
[EMULATIONS
] = {
char *restore
[EMULATIONS
] = {
char *setsize
[EMULATIONS
] = {
char *size
[EMULATIONS
] = {
char sunname
[] = "sunsize";
char *wsize
[EMULATIONS
] = {
char *strindex (), *index (), *rindex();
resets termcap string to reflect current screen size
register char *ptr
, *env
;
register int emu
= VT100
;
if(ptr
= rindex(myname
= argv
[0], '/'))
if(strcmp(myname
, sunname
) == 0)
for(argv
++, argc
-- ; argc
> 0 && **argv
== '-' ; argv
++, argc
--) {
case 's': /* Sun emulation */
Usage(); /* Never returns */
case 'u': /* Bourne (Unix) shell */
Usage(); /* Never returns */
"%s: Can't set window size under %s emulation\n",
if(!checkdigits(argv
[0]) || !checkdigits(argv
[1]))
Usage(); /* Never returns */
Usage(); /* Never returns */
if((ttyfp
= fopen("/dev/tty", "r+")) == NULL
) {
fprintf(stderr
, "%s: Can't open /dev/tty\n", myname
);
if((env
= getenv("TERMCAP")) && *env
)
if(!(env
= getenv("TERM")) || !*env
) {
setname
= "TERM=xterm;\n";
else setname
= "setenv TERM xterm;\n";
if(tgetent (termcap
, env
) <= 0) {
fprintf(stderr
, "%s: Can't get entry \"%s\"\n",
ioctl (tty
, TIOCGETP
, &sgorig
);
ioctl (tty
, TIOCSETP
, &sg
);
sprintf (buf
, setsize
[emu
], argv
[0], argv
[1]);
write(tty
, buf
, strlen(buf
));
write(tty
, getsize
[emu
], strlen(getsize
[emu
]));
readstring(ttyfp
, buf
, size
[emu
]);
if(sscanf (buf
, size
[emu
], &rows
, &cols
) != 2) {
fprintf(stderr
, "%s: Can't get rows and columns\r\n", myname
);
write(tty
, restore
[emu
], strlen(restore
[emu
]));
/* finally, set the tty's window size */
if (ioctl (tty
, TIOCGSIZE
, &ts
) != -1) {
ioctl (tty
, TIOCSSIZE
, &ts
);
/* finally, set the tty's window size */
/* get the window size in pixels */
write (tty
, getwsize
[emu
], strlen (getwsize
[emu
]));
readstring(ttyfp
, buf
, wsize
[emu
]);
if(sscanf (buf
, wsize
[emu
], &ws
.ws_xpixel
, &ws
.ws_ypixel
) != 2) {
fprintf(stderr
, "%s: Can't get window size\r\n", myname
);
ioctl (tty
, TIOCSWINSZ
, &ws
);
} else if (ioctl (tty
, TIOCGWINSZ
, &ws
) != -1) {
/* we don't have any way of directly finding out
the current height & width of the window in pixels. We try
our best by computing the font height and width from the "old"
struct winsize values, and multiplying by these ratios...*/
ws
.ws_xpixel
= cols
* (ws
.ws_xpixel
/ ws
.ws_col
);
ws
.ws_ypixel
= rows
* (ws
.ws_ypixel
/ ws
.ws_row
);
ioctl (tty
, TIOCSWINSZ
, &ws
);
ioctl (tty
, TIOCSETP
, &sgorig
);
signal(SIGQUIT
, SIG_DFL
);
signal(SIGTERM
, SIG_DFL
);
/* update termcap string */
if ((ptr
= strindex (termcap
, "co#")) == NULL
) {
fprintf(stderr
, "%s: No `co#'\n", myname
);
strncpy (newtc
, termcap
, ptr
- termcap
+ 3);
sprintf (newtc
+ strlen (newtc
), "%d", cols
);
if ((ptr
= strindex (newtc
, "li#")) == NULL
) {
fprintf(stderr
, "%s: No `li#'\n", myname
);
strncpy (termcap
, newtc
, ptr
- newtc
+ 3);
sprintf (termcap
+ ((int) ptr
- (int) newtc
+ 3), "%d", rows
);
printf ("%sTERMCAP='%s'\n",
else printf ("set noglob;\n%ssetenv TERMCAP '%s';\nunset noglob;\n",
returns a pointer to the first occurrence of s2 in s1, or NULL if there are
while ((s3
= index (s1
, *s2
)) != NULL
)
if (strncmp (s3
, s2
, strlen (s2
)) == 0) return (s3
);
signal(SIGALRM
, timeout
);
bzero((char *)&it
, sizeof(struct itimerval
));
it
.it_value
.tv_sec
= TIMEOUT
;
setitimer(ITIMER_REAL
, &it
, (struct itimerval
*)NULL
);
if((*buf
++ = getc(fp
)) != *str
) {
fprintf(stderr
, "%s: unknown character, exiting.\r\n", myname
);
last
= str
[i
= strlen(str
) - 1];
while((*buf
++ = getc(fp
)) != last
);
bzero((char *)&it
, sizeof(struct itimerval
));
setitimer(ITIMER_REAL
, &it
, (struct itimerval
*)NULL
);
fprintf(stderr
, strcmp(myname
, sunname
) == 0 ?
"Usage: %s [rows cols]\n" :
"Usage: %s [-u] [-s [rows cols]]\n", myname
);
fprintf(stderr
, "%s: Time out occurred\r\n", myname
);
ioctl (tty
, TIOCSETP
, &sgorig
);