/* worker.tsk: I will bend a region, and emit status */
/* I am a dummy for the many servers a terminal barnacle might use */
/* I would typically be called by SDRC$ */
/* I do no typeout unless ERROR - TT: will belong to barnacle, not me */
/* I will try to receive a packet, to pacify RSX, because I may be SDRC$ed */

/***********************************************************************\
*									*
*	Behold the most magic hack: sleep() does $$flsh to stdout	*
*	and sdterr. $$flsh decides that both these venerable		*
*	channels need a newline, so attempts WVB vfc='$' of "".		*
*	This attempt at terminal access causes a wait since the		*
*	invoking task has attached the terminal. We choose to set	*
*	VF$NOS bit (IO_NOS for C programmers) which tells $$flsh	*
*	not to mess with this line-feed business.			*
*									*
\***********************************************************************/

#include <stdio.h>
#include <cx.h>
#include <wdbdf.h>
#include <rdbdf.h>
#include <algol68.h>

int $$narg=1;

struct	wdb	w;
struct	rdb	r;
unsigned	dsw;
int		packet[15];		/* receive data packet		*/
long		tsknam;			/* name of a task (rad50)	*/

#define RNM "region"			/* region name			*/
#define APR (4)				/* which APR we use for region	*/

int	x;

main()
BEGIN
	tsknam = 0;			/* don't care where we receive from */
	dsw = rcvd(&tsknam,&packet);
	stderr -> _flag |= IO_NOS;	/* turn pesky LF handling off	*/
	stdout -> _flag |= IO_NOS;	/* turn pesky LF handling off	*/
	sleep(1);
	ascr50(6,RNM,&r.r_gnam);
	r.r_gsts = RS_RED | RS_WRT; 	/* don't really need write access */
	r.r_gpro = 0;
	r.r_gsiz = 0;
	r.r_gid  = 0;			/* trust NOBODY			*/
	dsw = atrg(&r);
	IF	(dsw!=IS_SUC)
	THEN	error("\7atrg:dsw=%oo",dsw);
	FI
	w.w_nrid = r.r_gid;
	w.w_nlen = 0;			/* exec tells me how long it is	*/
	w.w_noff = 0;			/* no 25-bit addresses today	*/
	w.w_nsts = WS_WRT | WS_MAP;	/* but we could use 25bits	*/
	w.w_napr = APR;
	w.w_nsiz = (8192/64);		/* 1 APR please			*/
	dsw = craw(&w);
	IF	(dsw!=IS_SUC)
	THEN	error("\7craw:dsw=%oo",dsw);
	FI
	sscanf(w.w_nbas,"%d",&x);
	sprintf(w.w_nbas,"%d",x+1);
	exst(x);
END

/* end: worker.c */
