/******************************************************************************
 * This file is part of a software distribution, which is furnished under the *
 * terms of a license.  Use of this software  by any means is subject to this *
 * license  and  signifies  the  acceptance of  the  licensing  terms  stated *
 * therein. Please see  the file LICENSE in the  top-level directory  of this *
 * software  distribution  for detailed copyright  disclaimers  and licensing *
 * terms.                                                                     *
 ******************************************************************************
 * Copryight (c) by Andreas S. Wetzel - All rights reserved.                  *
 ******************************************************************************/

/* $Id: vd_resize.c,v 1.2 2001/03/19 14:54:06 mickey Exp $ */

#include <vchat.h>
#include <if_telnet.h>
#include <proto_vchatd.h>

/********* Globals **********/

extern u_short tel_option[];

extern ED	*ed;
extern VP	vp;
extern VD	vd;
extern VTCAP	vtcap;

/*********** Code ***********/

void resize(void)
{
	SIZE *sz;

	static u_short depth = 0;

	int x =0;
	int tx = 0;
	int ty = 0;

	if(vd.resize_ok && his_state_is_will(TELOPT_NAWS) && !depth)
	{
		depth = 0xff;

		vlock(LOCK, (V_IO | V_TIMER));

		/*
		 * Now we don't give up, til
		 * the screen has an acceptable
		 * size.
		 */

		do
		{
			sz = getsize();

			vtcap.cols = sz->x;
			vtcap.rows = sz->y;

			if(vtcap.cols < 39 || vtcap.rows < 4)
			{
				if(vtcap.cols != tx || vtcap.rows != ty)
					x = 0;

				if(!x)
				{
					cls();
					printf(" Inefficient screensize (%dx%d)\r\n", vtcap.cols, vtcap.rows);
					printf("Resize window to at least\r\n");
					printf("          39 x 4\r\n");

					tx = vtcap.cols;
					ty = vtcap.rows;

					x = 0xff;
				}

				vsleep(0, 0x186A0);

				if(cmd_loop() == -1)
					exit(-1);
			}
		}
		while(vtcap.cols < 39 || vtcap.rows < 4);

		cls();

		alter_status(STAT_SIZE, "%dx%d ", vtcap.cols, vtcap.rows);

		scroll_reg(1, vtcap.rows - 2);

		if((ed->curpos - ed->margin) > vtcap.cols)
			ed->margin = (char *)(ed->curpos - vtcap.cols + 1);

		line_update();

		depth = 0;

		vlock(UNLOCK, (V_IO | V_TIMER));
	}
}


syntax highlighted by Code2HTML, v. 0.9.1