// sel.sr 

get "BRAVO1.DF";
get "CHAR.DF";
get "MSG.DF";
get "display.DF";
get "DOC.DF";
get "SELECT.DF";

// Incoming Procedures

external [
	clearbuf		//temporary hack
	getvch;
	stput;
	ugt;
	ult;
	setlp;
	errhlt;
	outnum;
	innum;
	bravochar;
	outsel;
	waitbug;
	nobug;
	findfield;
	invalidatedisplay;
	deletea;
	insertlp;
	findlppc;
	setpcsiz;
	inserta;
	deletelp;
	binsearcha;
	setfield;
	establishpc;
	msgtomi;
	mctomsg;
	combinemsg;
	mitomsg;
	cpfc;
	move;
	];

// Incoming Statics

external [
	tsstream;
	vdoc;
	vcp;
	vchremain;
	outstream;
	tsread;
	cominstream;
	tscorrect;
	rgmaccp;
	pctb;
	mppccp;
	rgpctb;
	ppcd;
	vmapstatus;
	vpc;
	mpWwWwd;
	macww
	];

// Outgoing Procedures

external [
	readsel;
	seltobuf;
	bufferize;
//	clearbuf - this is now called ClearBuf and resides in buffer.sr
//	by edict of Carol 6/3/76
	setsel;
	invalidatesel;
	selectwholedoc;
	selectwholeww;
	];

// Outgoing Statics

external [
	i;
	selarg;
	selmain;
	selaux;
	vsel;
	];

// Local Statics

static [
	i;
	selarg;
	selmain;
	selaux;
	vsel;
	];
// R E A D S E L
// catalogue no. = 126
let readsel(sb,doc,cpfirst,cplast,maxi) be
[ let lasti = nil;
sb ! 0 = 0;
vdoc = doc;
vcp = cpfirst;
vmapstatus = statusblind;
for i = 0  to maxi-1 do
	[ stput(sb,i,getvch( ))
	lasti = i;
	if ugt(vcp,cplast) then
		break;
	] 
sb >> lh = lasti+1;
] // end readsel

// S E T S E L
//
and setsel(sel,cpfirst,cplast) be
[ if sel >> SEL.type eq sph then sel >> SEL.type = schar;
sel >> SEL.cpfirst = cpfirst;
sel >> SEL.cplast = cplast;
sel >> SEL.xdfirst = -1;
sel >> SEL.xdlast = -1;
move(lv sel >> SEL.cpfirst,lv sel >> SEL.cpfirstorig,4)
// ** ↑↑↑ ** sel >> SEL.cpfirstorig = cpfirst;
// sel >> SEL.cplastorig = cplast;
// sel >> SEL.xdfirstorig = -1;
// sel >> SEL.xdlastorig = -1;
] 
// I N V A L I D A T E S E L
//
and invalidatesel(sel) be
[ sel >> SEL.xdfirst = -1;
sel >> SEL.xdlast = -1;
] 
// S E L E C T W H O L E D O C
// 
and selectwholedoc(sel,doc) be
[ let wwOfDoc = 0
for ww = 1 to macww-1 do
	if (mpWwWwd ! ww) >> WWD.doc eq doc then
		wwOfDoc = ww
if wwOfDoc eq 0 then return
sel >> SEL.doc = doc;
sel >> SEL.type = schar;
sel >> SEL.ww = wwOfDoc;
sel >> SEL.cpfirst = 0;
sel >> SEL.xdfirst = -1;
sel >> SEL.cplast = rgmaccp ! doc-1;
sel >> SEL.xdlast = -1;
] 
// S E L E C T W H O L E W W 
//
and selectwholeww(sel,ww)be
[ selectwholedoc(sel,(mpWwWwd ! ww)>>WWD.doc)
sel >> SEL.ww = ww;
]