// S E L . S R --- GSEL.SR getvch now bumps vcp **

get "BRAVO.DF";
get "CHAR.DF";
// Incoming Procedures

external [
	getvch;
	stput;
	ugt;
	ult;
	setlf;
	errhlt;
	PUTS;
	outnum;
	GETS;
	innum;
	ENDOFS;
	];

// Incoming Statics

external [
	vdoc;
	vcp;
	vchremain;
	outstream;
	cominstream;
	rgmaccp
	rgdoc
	];

// Outgoing Procedures

external [
	readsel;
	seltolf;
	stputlf;
	setsel;
	invalidatesel;
	selectwholeww
	selectwholedoc
	selectsel
	];

// 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;
vchremain = 0;
for i = 0  to maxi-1 do
	[ stput(sb,i,getvch( ))
	lasti = i;
	if vcp gr cplast then // **
		break;
	] 
sb >> lh = lasti+1;
] // end readsel

// S E T S E L
//
and setsel(sel,cpfirst,cplast) be
[ sel >> SEL.cpfirst = cpfirst;
sel >> SEL.cplast = cplast;
sel >> SEL.xfirst = -1;
sel >> SEL.xlast = -1;
] 
// I N V A L I D A T E S E L
//
and invalidatesel(sel) be
[ sel >> SEL.xfirst = -1;
sel >> SEL.xlast = -1;
] 

// S E L E C T W H O L E D O C
// 
and selectwholedoc(sel,doc) be
[ sel >> SEL.doc = doc;
sel >> SEL.type = schar;
sel >> SEL.cpfirst = 0;
sel >> SEL.xfirst = -1;
sel >> SEL.cplast = rgmaccp ! doc-1;
sel >> SEL.xlast = -1;
] 
// S E L E C T W H O L E W W 
//
and selectwholeww(sel,ww)be
[ selectwholedoc(sel,rgdoc ! ww)
sel >> SEL.ww = ww;
] 

// SE L E C T S E L
//
and selectsel(sel, ww, cpfirst, cplast ; numargs N) be
[
sel >> SEL.doc = rgdoc ! ww;
sel >> SEL.xfirst = -1;
sel >> SEL.xlast = -1;
sel >> SEL.ww = ww;
sel >> SEL.cpfirst = cpfirst;
sel >> SEL.cplast = N eq 4?cplast, cpfirst-1;
]