
#include	"sysdef.h"


#define	then
#define	CTRLZ	032
#define	CR	015
#define	ESC	033
#define	LF	012
#define	RUB	0177

static char rubout[] = "\010\040\010" ;

readmacro()
{
	extern int macsize[],maccurrent ;
	extern char *mapmacro() ;

	ceol24() ;
	macsize[maccurrent] = lgetbin(mapmacro(maccurrent),"Macro text ? ") ;
	goback() ;
	return( macsize[maccurrent] ) ;
}

lgetdef(s,p,d)
char *s,*p ;
register char *d ;
{
	register int len ;
	register char *cp ;

	if ( (len = lgetbin(s,p)) != 0 )
	  then	return(len) ;
	  else	{
		cp = s ;
		for (len=0; *d != '\0';len++) *cp++ = *d++ ;
		putbin("\015",1) ;
		lkill() ;
		if ( len ) then putbin(s,len) ;
		return(len) ;
		}
}
		


lgetbin(s,p)
char *p ;
register char *s;
{
	register char ch ;
	register int  i,j ;
	char *save ;

	i = 0 ;
	save = s ;
	putbin("\015",1) ;
	putbin(p,0) ;
	while ( i < 63 ) {
	  if ( (ch = getc()) == CTRLZ || ch == CR ) then break ;
	  if ( ch == RUB )
		then	{
			if (i > 0)
			  then	{
				s-- ;
				i-- ;
				if ( *s < CTRLZ )
				  then putbin(rubout,0) ;
				putbin(rubout,0) ;
				}
			}
		else	{
			*s++ = ch ;
			echoch(ch) ;
			i++ ;
			}			
	}
	*s = '\0' ;
	return(i) ;
}			


static getc()
{
	register char ch ;
	while ( ( ch = getbin() ) == LF ) ;
	return(ch) ;
}

static echoch( ch )
register char ch ;
{
	char tempch ;

	tempch = ch ;
	if ( ch == ESC )
	  then	putbin("$",1) ;
	  else
	    if ( ch > CTRLZ )
	      then putbin(&tempch,1) ;
	      else {
		putbin("^",1) ;
		tempch = ch | 0100 ;
		putbin(&tempch,1) ;
		} ;
}
