// sendmsg.sr


get "BRAVO1.DF"
get "NEWMSG.DF"


// Outgoing Procedures

external	[
	MufopConcat
//	FopiFromMufop
	FopFromMufop
	]


// Outgoing Statics

// external


// Incoming Procedures

external	[
	SiPutCache
	vcache
	move
	errhlta
	]


// Incoming Statics

external	[
	mpIffFfp
	]


// Local Statics

// static


// Local Structures

structure	OD:
	[
	ogHigher	byte
	ogLower	byte
	]


// Local Manifests

// manifest


// M U F O P   C O N C A T

let MufopConcat(mufop, pufopNew, cwMax, fUndo) = valof
[
let iffNew = pufopNew>>UFOP.iff
let ffpNew = mpIffFfp ! iffNew
let cwUfopNew = ffpNew<<FFP.carg + 1
let cwMufop = mufop>>MUFOP.cw
if not fUndo & pufopNew>>UFOP.fIncrement then
	[
	let cwMufopNew = cwMufop + cwUfopNew
	if cwMufopNew ge cwMax then errhlta(207)
	move(pufopNew, mufop+cwMufop, cwUfopNew)
	mufop>>MUFOP.cw = cwMufopNew
	resultis mufop
	]
let mpiffod = table
	[
	#0 lshift 8	+ #0	// iffTrailer
	#0 lshift 8	+ #1	// iffVisibuf
	#0 lshift 8	+ #1	// iffUl
	#0 lshift 8	+ #0	// iffVanish
	#0 lshift 8	+ #1	// iffBold
	#0 lshift 8	+ #1	// iffItalic
	#0 lshift 8	+ #1	// iffExt
	#0 lshift 8	+ #1	// iffVisible
	#0 lshift 8	+ #1	// iffFun
	#0 lshift 8	+ #1	// iffSuper

	#0 lshift 8	+ #2	// iffXrightmarg
	#0 lshift 8	+ #4	// iffXleftmarg
	#0 lshift 8	+ #4	// iffXleftmargf
	#0 lshift 8	+ #2	// iffProcYpos
	#0 lshift 8	+ #2	// iffLdln
	#0 lshift 8	+ #2	// iffLdhdr
	#0 lshift 8	+ #10	// iffRj
	#0 lshift 8	+ #10	// iffCenter

	#1 lshift 8	+ #1	// iffProcClr
	#0 lshift 8	+ #2	// iffProcUp
	#0 lshift 8	+ #2	// iffProcDown
	#0 lshift 8	+ #2	// iffProcDxtb
	#0 lshift 8	+ #2	// iffProcXtb

	#10 lshift 8	+ #10	// iffRjCenter
	#1 lshift 8	+ #1	// iffProcSameLooks
	#16 lshift 8	+ #2	// iffProcSamePar
	#4 lshift 8	+ #4	// iffProcLeftmarg
	#0 lshift 8	+ #2	// iffProcColumn
	#0 lshift 8	+ #2	// iffControl
	#0 lshift 8	+ #2	// iffYkeep
	#0 lshift 8	+ #1	// iffSub

	#0 lshift 8	+ #1	// iffOvstrike
	#0 lshift 8	+ #0	// iffTc

//	#0 lshift 8	+ #20	// iffUppercase
//	#0 lshift 8	+ #20	// iffLowercase
//	#20 lshift 8	+ #20	// iffCase
//	#0 lshift 8	+ #2	// iffProcTable
	]
let ogHigher = (mpiffod ! iffNew)<<OD.ogHigher
let pufop = mufop + 1
let pufopTo = pufop
let pufopMac = mufop + cwMufop
while pufop ls pufopMac do
	[
	let iff = pufop>>UFOP.iff
	let ffp = mpIffFfp ! iff
	let cwUfop = ffp<<FFP.carg + 1
	let fSkip = valof
		[
		test iff eq iffNew ifso
			[
			unless ffpNew<<FFP.fArgDep do
				resultis true
			resultis pufopNew>>UFOP.ffv eq pufop>>UFOP.ffv
			]
		ifnot	resultis (ogHigher & mpiffod ! iff) ne 0
		]
	unless fSkip do
		[
		if pufop ne pufopTo then
			move(pufop, pufopTo, cwUfop)
		pufopTo = pufopTo + cwUfop
		]
	pufop = pufop + cwUfop
	]
let cwMufopNew = pufopTo - mufop + (fUndo ? 0, cwUfopNew)
if cwMufopNew ge cwMax then errhlta(207)
unless fUndo do
	move(pufopNew, pufopTo, cwUfopNew)
mufop>>MUFOP.cw = cwMufopNew
resultis mufop
] // end MufopConcat


// F O P I   F R O M   M U F O P
//
// and FopiFromMufop(mufop) = SiPutCache(vcache, mufop)
// end FopiFromMufop


// F O P   F R O M   M U F O P

and FopFromMufop(mufop) = valof
[
if mufop>>MUFOP.cw eq 1 then
	resultis fopNil
if mufop>>MUFOP.cw eq 2 then
	resultis mufop ! 1
let fop = 0
// fop<<FOP.fopi = FopiFromMufop(mufop)
fop<<FOP.fopi = SiPutCache(vcache, mufop)
fop<<FOP.fIndirect = true
resultis fop
] // end FopFromMufop