//Mtxtbuf.bcpl
//	Last editted: 2 June 1981

external [
// OS
	Resets; Puts

// MASM
	@MBlock; BackUp

// MDISP
	Blink

// MMENU
	DoAction; DoTextAction
	EscInputText; EscAction; EscMBunion; EscMDFS; CRAction

// MCMD
	CmdAltMenuP

// Defined here
	ClearInText; TxtBNewChar; InputStream; InputTextBuffer
	TxtBufClearFlag
]

static[ TxtBufClearFlag = false; InputTextBuffer; InputStream
	semiF = false ]

manifest[
	bs = #10; del = #177;  Esc = #33
]

let ClearInText() be TxtBufClearFlag = true


and TxtBNewChar(Char) be
[	if (Char ge $a) & (Char le $z) then Char = Char & not 40B
	switchon Char into
	[
default:
	if Char > #176 then [ Blink(); return ]
	if TxtBufClearFlag then
	[ Resets(InputStream)
//Flush leading blanks
	  if Char eq $  then return
	]
	TxtBufClearFlag = false
	test semiF
	ifso
	[ if CmdAltMenuP ne 0 then [ Blink(); return ]
//Type ahead illegal during command execution beyond
//point at which another action is initiated
	  semiF = false; BackUp(InputStream)
	  DoTextAction(Char)
	]
	ifnot
	[ if Char le $Z-100B then [ DoTextAction(Char); return ]
 	  if Char eq $; then semiF = true
	  Puts(InputStream,Char); return
	]
	return

//Character erase
case bs:
case $A-100B:
	TxtBufClearFlag = false; semiF = false
	BackUp(InputStream); return	

//Line erase
case $Q-100B:
case del: semiF = false; Resets(InputStream); return

//Non-control action characters
case $):
case $=:
case $:: if TxtBufClearFlag then
	[ Resets(InputStream); TxtBufClearFlag = false
	]
	if (CmdAltMenuP ne 0) % semiF then [ Blink(); return ]
//CFile abort character
case $Z-100B:
//Always-active command abort character
case $C-100B: DoTextAction(Char); return

case $*n:
case Esc:
	Resets(InputStream)
	MBlock(InputTextBuffer,EscInputText,EscInputText!0 + 1)
	DoAction((Char eq Esc ? EscAction,CRAction),EscMBunion,EscMDFS)
	return

	]
]