/* send.c: general send */
/* MCR>SEND taskname message */
#include <stdio.h>
#include <cx.h>
#define EFN 12
main(argc,argv)
int		argc;
char		**argv;
{extern int	esc_msk;
 char		ascii[7];
 struct rad50	task;
 int		buf[15];
 int		dsw;
 char		*p;
 char		*q;
 int		printf();
 esc_msk=0xFF;
 zero(ascii,6);
 strcpy(ascii,argv[1]);
 ascii[6]=0;
 if	(*ascii)
	{ascr50(6,ascii,&task);
	 zero(buf,30);
	 p = argv[2];
	 q = buf;
	 while	(*q++ = esc(&p))	p++;
	 wblock(buf,26,printf);
	 dsw = sdat(&task,buf,EFN);
	 printf("%s: sdat(%s)=%oo\n",*argv,ascii,dsw);
	 dsw = ustp(&task);
	 printf("%s: ustp(%s)=%oo\n",*argv,ascii,dsw);
	}
 ;
}

wblock(buf,len,pf)
char	*buf;
int	len;
int	(*pf)();
{int	max;
 int	i;
 while	(len)
	{max = len>8 ? 8 : len;
	 for	(i = 0; i<max; i++)	(*pf)("%2x",buf[i]&0xFF);
	 for	(; i<8; i++)		(*pf)("  ");
	 				(*pf)("\t");
	 for	(i=0; i<max; i++)
		{(*pf)(" ");
		 wchar(buf[i],pf);
		}
	 ;
					(*pf)("\n");
	 len -= max;
	 buf += max;
	}
 ;
}

wchar(c,pf)
char	c;
int	(*pf)();
{(*pf)(c&0x80?"'":" ");
 c &= 0x7F;
 if	(c<040)
	{c+=0100;
	 (*pf)("^");
	}
 else
	{(*pf)(" ");
	}
 ;
 (*pf)("%c",c);
}
