// I N I T	QINIT2.SR

get "BRAVO.DF";
get "HEAP.DF";
get "DISPLAY.DF";
get "CHAR.DF";
get "GINN.DF"; // **

// Incoming Procedures

external [
	movec
	insertlf
	settabs
	stperm
	getfont
	errhlt
	initfontwidth
	markcc
	setlf
	stsize
	cpvisible
// ** GYPSY added:
	insertparas
	makemenuitems
	makeunpointabledoc
	lastparacp
	];

// Incoming Statics

external [
	vdevtype
	xleftmargstd
	xrightmargstd
	selaux
	selarg
	selmain
	cursorstate
	vcpadjusteq
	rgpctb
	rgmaccp
	dnlf
	macdoc
	rgcfn
	cpscrt
	rgdirty
	rgdlfirst
	rgdllast
	rgdoc
	rgcpfdispl
	rghpused
	rgupdate
	rgcpfirst
	rgcpfirstnew
	rgcplast
	rgcplastnew
	rgxlast
	rgxlastnew
	rgxfirst
	rgxfirstnew
	rgul
	rgpbm
	rgpbmnew
	rgyfirst
	rgylast
	rgmaxdl
	mpdldcb
	dcb
	vdcbblack
	cdcb
	cnrgul
	heightstd
	fontstd
	macdl
	macww
	rgccomp
	rgcdlblank
	sbstate
	sbtermesc
	rgccstd
	rgcpfirstinl
	rgxtab
	mpfunsb
	rgfont
	rgrgcc
	vsncompact
	vbetwixt
	widthblave
	widthblmin
// ** GYPSY ADDED:
	selection
	rgpara
	rgpage
	rgpagenum
	rgreadonly
	rgspec
	rgprogram
	rgchoppage
	rgulnew
	rgmenu
	mdoc
	sphp // %%
// ** END GYPSY ADDITIONS
	];

// Outgoing Procedures

external [
	qinitselect;
	qinitbravocom;
	qinitdoc;
	qinitdisplay;
	qinitformat;
// **
	qinitmenu
	qsetupmenu
	];

// Outgoing Statics

external [
// ** GYPSY ADDED:
	menumessage
	nmenuitems
	vmenumessage
	vdprinteron
	sbpast
	rgview
// ** END GYPSY ADDITIONS
	]; 

// Local Statics

static [
// ** GYPSY ADDED:
	menumessage
	nmenuitems
	vmenumessage
	vdprinteron
	sbpast
	rgview
// ** END GYPSY ADDITIONS
	];

// I N I T S E L E C T
// SPE catalogue no.

let qinitselect(alloc) be
[
// ** GYPSY changed selections:
selection = alloc(sell);
selaux = alloc(sell);
selarg = alloc(sell);
selection >> SEL.type = snone;
selaux >> SEL.type = snone;
selarg >> SEL.type = snone;
selection >> SEL.ulmode = 1;
selaux >> SEL.ulmode = 2;
selarg >> SEL.ulmode = 0;
selmain = selection
selaux >> SEL.ulmodewas = 0 ;
selaux >> SEL.ulcpfirstoff = -2 ;
selection >> SEL.ulmodewas = 0 ;
selection >> SEL.ulcpfirstoff = -2 ;
// ** END GYPSY changes

sbpast = alloc(25);
sbpast ! 0 = 0;
cursorstate = -1

// ** GYPSY deleted rgsbcom stuff

] 
// I N I T B R A V O C O M 
// catalogue no. 
and qinitbravocom( ) be
[
// ** GYPSY deleted createdoce's and doctxcurrent (buffer stuff)

// ** GYPSY changed 0 to 1:
vcpadjusteq = 1;

// ** GYPSY DELETED tsread and tstoflush and ccommand

] 
// I N I T D O C
// catalogue no.
and qinitdoc(alloc) be
[
rgpara = alloc(maxdoc) // **
movec(rgpara,rgpara+maxdoc-1,0) // **
rgpage = alloc(maxdoc) // **
movec(rgpage,rgpage+maxdoc-1,0) // **
rgpagenum = alloc(maxdoc) // **
movec(rgpagenum,rgpagenum+maxdoc-1,0) // **
rgreadonly = alloc(maxdoc) // **
movec(rgreadonly,rgreadonly+maxdoc-1,0) // **
rgspec = alloc(maxdoc) // **
movec(rgspec,rgspec+maxdoc-1,0) // **
rgprogram = alloc(maxdoc) // **
movec(rgprogram,rgprogram+maxdoc-1,0) // **
rgview = alloc(maxdoc) // **
movec(rgview,rgview+maxdoc-1,0) // **
rgchoppage = alloc(maxdoc) // **
movec(rgchoppage,rgchoppage+maxdoc-1,0) // **
rgpctb = alloc(maxdoc);
rgmaccp = alloc(maxdoc);
dnlf = alloc(maxlf);
movec(dnlf,dnlf+maxlf-1,0);
macdoc = 0;
movec(rgpctb,rgpctb+maxdoc-1,-1);
rgcfn = alloc(maxfn);
movec(rgcfn,rgcfn+maxfn-1,0);
cpscrt = 0;
rgdirty = alloc(maxww);
movec(rgdirty,rgdirty+maxww-1,0);
] 

// I N I T D I S P L A Y

and qinitdisplay(alloc) be
[
rgdlfirst = alloc(maxww);
rgdllast = alloc(maxww);
rgdoc = alloc(maxww);
rgcpfdispl = alloc(maxww);
rghpused = alloc(maxww);
movec(rghpused,rghpused+maxww-1,0);
sphp = alloc(maxsphp); // %%
movec(sphp,sphp+maxsphp-1,0); // %%

rgupdate = alloc(maxww);

rgcpfirst = alloc(maxdl);
rgcpfirstnew = alloc(maxdl);
rgcplast = alloc(maxdl);
rgcplastnew = alloc(maxdl);
rgxlast = alloc(maxdl);
movec(rgxlast,rgxlast+maxdl-1,-1);
rgxlastnew = alloc(maxdl);
rgxfirst = alloc(maxdl);
movec(rgxfirst,rgxfirst+maxdl-1,xleftmargstd);
rgxfirstnew = alloc(maxdl);
rgul = alloc(maxdl);
movec(rgul,rgul+maxdl-1,uloff);

// ** GYPSY ADDED:
rgulnew = alloc(maxdl);
movec(rgulnew,rgulnew+maxdl-1,uloff);
// ** END GYPSY ADDITIONS

rgpbm = alloc(maxdl);
movec(rgpbm,rgpbm+maxdl-1,0);
rgpbmnew = alloc(maxdl);
rgyfirst = alloc(maxww);
rgylast = alloc(maxww);
rgmaxdl = alloc(maxww);
mpdldcb = alloc(maxdl);
dcb = alloc(maxcdcb*dcbl+1);
vdcbblack = alloc(5);
if vdcbblack << odd then 
	vdcbblack = vdcbblack+1
vdcbblack ! 0 = 0;
vdcbblack ! 1 = #40000;
vdcbblack ! 2 = 0;
vdcbblack ! 3 = 303;
if dcb << odd then dcb = dcb+1;
cdcb = 0;
cnrgul = 0;
heightstd = fontstd ! 0;

macdl = inidl;
macww = 0;

movec(rgcpfirst,rgcpfirst+maxdl-1,0);
cnrgul = 0;

rgccomp = alloc(maxww);
movec(rgccomp,rgccomp+maxww-1,0);
rgcdlblank = alloc(maxww);
movec(rgcdlblank,rgcdlblank+maxww-1,0);
sbstate = alloc(35);
sbtermesc = alloc(15);
] // end qinitdisplay

// I N I T F O R M A T 
// catalogue no.
and qinitformat(alloc) be
[ rgccstd = alloc(256);
movec(rgccstd,rgccstd+255,0);
rgcpfirstinl = alloc(maxdl);
// ** rgfsfdispl = alloc(maxww);
// ** movec(rgfsfdispl,rgfsfdispl+maxww-1,0);
rgxtab = alloc(maxtab+1);
// ** rgfsdef = alloc(maxfun);
// ** movec(rgfsdef,rgfsdef+maxfun-1,0);
mpfunsb = alloc(maxfun);
movec(mpfunsb,mpfunsb+maxfun-1,0);
rgfont = alloc(maxfun);
movec(rgfont,rgfont+maxfun-1,0);
rgrgcc = alloc(maxfun);
movec(rgrgcc,rgrgcc+maxfun-1,0);
rgrgcc ! 0 = rgccstd;
// ** rgfsesc = alloc(maxww);
// ** movec(rgfsesc,rgfsesc+maxww-1,0);
// ** rgfs = alloc(maxdl);
// ** movec(rgfs,rgfs+maxdl-1,0);
// ** rgfsnew = alloc(maxdl);
// ** movec(rgfsnew,rgfsnew+maxdl-1,0);
// ** rgfsfirstinl = rgfsnew;

mpfunsb ! 0 = stperm("FONT.0", alloc);
mpfunsb ! 1 = stperm("FONT.1", alloc);
mpfunsb ! 2 = stperm("FONT.2", alloc);

// ** GYPSY changed:
fontstd = getfont(1);
if fontstd eq -1 then errhlt("NF1");
// ** END GYPSY CHANGE

// ** GYPSY ADDED:
vsncompact = 0;
// ** END GYPSY ADDITION

initfontwidth(fontstd,rgccstd);

// ** GYPSY changed:
markcc(rgccstd,#60,#71,0); // digits
markcc(rgccstd,#141,#172,0); // a-z
markcc(rgccstd,#101,#132,0); // A-Z
markcc(rgccstd,$',$',0); // ' 
markcc(rgccstd,#177,#377,1);
markcc(rgccstd,#0,#40,1); // ** space is special in GYPSY
markcc(rgccstd,chsp,chsp,2);
markcc(rgccstd,chcr,chcr,2);
markcc(rgccstd,chtab,chtab,2);
// ** END GYPSY CHANGE

vsncompact = 0;
vbetwixt = 0;
// $$[
vdevtype = devalto
widthblave = widthspave
widthblmin = widthspmin
xleftmargstd = altolmarg
xrightmargstd = altormarg
settabs(tabchstd)
// $$]

// ** GYPSY got rid of vfs stuff and fnts stuff
] 

// ** GYPSY deleted com.cm stuff and macro stuff

and qinitmenu(alloc) be 
	[
	rgmenu = alloc(maxmitems)
	rgmenu!mquit = stperm("Quit",alloc)
	rgmenu!mdirectory = stperm("Drafts",alloc) // %%
	rgmenu!mdrawer = stperm("Folders",alloc) // %%
	rgmenu!mcancel = stperm("Cancel",alloc)
	rgmenu!mfile = stperm("File",alloc)
	rgmenu!mprint = stperm("Printer",alloc)
	rgmenu!mfetch = stperm("Fetch",alloc)
	rgmenu!mscan = stperm("Scan",alloc)
	rgmenu!msubstitute = stperm("Substitute",alloc)
	rgmenu!mall = stperm("All", alloc)
	rgmenu!mdocument = stperm("Document", alloc)
	rgmenu!mturnto = stperm("Find", alloc)
	rgmenu!madd = stperm("Insert", alloc)
	rgmenu!mcreate = stperm("Create", alloc)
	rgmenu!mmake = stperm("Copy", alloc)
// $$[
	rgmenu!mput = stperm("Put", alloc)
	rgmenu!mdouble = stperm("Double", alloc)
	rgmenu!mheadings = stperm("Headings", alloc)
	rgmenu!mpagenums = stperm("Page", alloc)
	rgmenu!mrepaginate = stperm("Repaginate", alloc)
	rgmenu!mstart = stperm("Start", alloc)
	rgmenu!mstop = stperm("Stop", alloc)
	rgmenu!mcassette = stperm("Cassette", alloc)
	rgmenu!mwrite = stperm("Write", alloc)
// $$]

// %% Changed all below for 2-line menu
	menumessage = alloc(maxmenumessages)
	menumessage!mmnodoc =
 		stperm(" *T*T*T*T*TFolders    Quit *T*C", alloc)
	menumessage!mmdir   =
 		stperm(" *T*T*T*T*TFolders    Quit   Document *T*C", alloc)
	menumessage!mmnodocnocab =
 		stperm(" *T*T*T*T*T           Quit *T*C", alloc)
	menumessage!mmdirnocab   =
 		stperm(" *T*T*T*T*T           Quit   Document *T*C", alloc)
	menumessage!mmdirty =
 		stperm(" *T*T*T*T*TCancel     File *T*C", alloc)
// $$[
	menumessage!mmclean =
 		stperm(" *T*T*T*T*TDrafts    Printer  Cassette *T*C", alloc)
	menumessage!mmprint = 	stperm(
" *T*T*T*T*TStop       Start*CDouble spacing | Page numbers | Repaginate *T*C", alloc)
	menumessage!mmstop =	stperm(" *T*T*T*T*TStop *T*C", alloc)

	menumessage!mmcassette =
				stperm(" *T*T*T*T*TStop       Start *T*C", alloc)
	menumessage!mmnull  =	stperm("  *T*C", alloc)
// $$]

	nmenuitems = alloc(maxmenumessages)
	nmenuitems!mmnodoc	= 2 // %%
	nmenuitems!mmdir	= 3 // %%
	nmenuitems!mmnodocnocab	= 1 // %%
	nmenuitems!mmdirnocab	= 2 // %%
	nmenuitems!mmdirty	= 2
// $$[
	nmenuitems!mmclean	= 3
	nmenuitems!mmprint	= 5
	nmenuitems!mmstop	= 1
	nmenuitems!mmcassette	= 2
// $$]
	nmenuitems!mmnull 	= 0
	]

and qsetupmenu() be
[
let m1 = menumessage ! mmnodocnocab // %%
let m2 = " Scan for {"
let m3 = " } *TAll  Substitute {"
let m4 = " } for {"
let m5 = " }"
insertparas(mdoc, 0, mdoc, 0, 0)
insertlf(mdoc, lastparacp(mdoc)-2, lfmenu, idmenu1,100);
insertlf(mdoc, lastparacp(mdoc)-2, lfmenu, idmenu2, 26);
insertlf(mdoc, lastparacp(mdoc)-2, lfmenu, idmenu3, 26);
insertlf(mdoc, lastparacp(mdoc)-2, lfmenu, idmenu4, 26);
insertlf(mdoc, lastparacp(mdoc)-2, lfmenu, idmenu5, 26);
setlf(lfmenu, idmenu1, m1);
setlf(lfmenu, idmenu2, m2);
setlf(lfmenu, idmenu3, m3);
setlf(lfmenu, idmenu4, m4);
setlf(lfmenu, idmenu5, m5);
let rr = makeunpointabledoc(mdoc, 4)
rr ! 1 = stsize(m1)-1 + stsize(m2)-1 -1
rr ! 2 = rr ! 1 + 1
rr ! 3 = rr ! 2 + stsize(m3)-1 -1
rr ! 4 = rr ! 3 + 1
rr ! 5 = rr ! 4 + stsize(m4)-1 -1
rr ! 6 = rr ! 5 + 1
makemenuitems(mdoc, 0, 4) // %%Quit, Scan, Substitute, and All
cpvisible(1,0)
vmenumessage = 1
]