/*****************************************************************************

	ExeCtR()

	This function executes a control-R command.  The control-R command
sets TECO's radix,  which controls how ASCII strings are converted to/from
their binary representations.  The current radix is used by the backslash
command and whenever TECO encounters a string of digits in a command string.

*****************************************************************************/

#include "ZPort.h"		/* define portability identifiers */
#include "DefError.h"		/* define identifiers for error messages */
#include "DefTeco.h"		/* define general identifiers */

extern	VOID	ErrMsg();	/* display an error message */
extern	DEFAULT	GetNmA();	/* get numeric argument */
extern	DEFAULT	PushEx();	/* push onto expression stack */

EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	LONG	NArgmt;		/* numeric argument */
EXTERN	DEFAULT	Radix;		/* TECO's current radix, 2-36 */


DEFAULT ExeCtR()		/* execute a ^R (control-R) command */
{
#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1){DbgMsg();DbgDBf("ExeCtR: called.\015\012");DbgROf();}
#endif

	if (EStTop > EStBot)			/* if numeric argument */
		{
		if (GetNmA() == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeCtR: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
#if DEBUGGING
}
#endif
		if ((NArgmt != 8L) && (NArgmt != 10L) && (NArgmt != 16L))
			{
			ErrMsg(ERR_IRA);	/* illegal radix with ^R */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeCtR: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
			}
		Radix = (DEFAULT)NArgmt;
		}
	else
		if (PushEx((LONG)Radix, OPERAND) == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeCtR: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
#if DEBUGGING
}
#endif

#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeCtR: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
