
/************************************************************************/
/*                                                                      */
/* Copyright (c) 1988 -                                                 */
/*     The Rector and Visitors of the University of Virginia            */
/*                                                                      */
/* This code may not be distributed further without permission          */
/*      from the University of Virginia.                                */
/* This code is distributed WITHOUT ANY WARRANTY.  No claims are        */
/*      made as to whether it serves any particular purpose or even     */
/*      works at all.                                                   */
/*                                                                      */
/************************************************************************/

#include <stdio.h>
#include "size.h"
#include "runtime.h"

extern DISPLAY _DISPLAY;

/*
 * RT_save_disp is called when a procedure or function name is passed as
 * a parameter.  RT_save_disp saves in a special struct the current display
 * (static scope environment), the entry point of the procedure or
 * function, and the current block level.
 */

DISPAREA *
RT_save_disp (entry_point, blklevel, dp)
	char *entry_point;
	int	blklevel;
	register DISPAREA *dp;
{
	register int i;
	dp->d_entrypt = entry_point;
	dp->d_level = blklevel;
	for (i = 2*blklevel+1; i > 1; i--)
		dp->d_save[i] = _DISPLAY[i];
	return(dp);
}

/*
 * RT_swap_disp is called when a procedural or functional parameter is
 * called. RT_swap_disp swaps the current display with a display that
 * was saved earlier by RT_save_disp and returns the entry point of the
 * functional parameter.  After the functional parameter returns,
 * RT_swap_disp is called again to restore the previous display.
 */

char *
RT_swap_disp(dp)
	register DISPAREA *dp;
{
	register char *temp;
	register int i;

	for (i = 2*dp->d_level+1; i > 1; i--)  {
		temp = dp->d_save[i];
		dp->d_save[i] = _DISPLAY[i];
		_DISPLAY[i] = temp;
	}
	return (dp->d_entrypt);
}
