;;; -*- Midas -*- code to use SYSENG;FORMAT reasonably

irp x,,[a,b,c,d,e,j]y,,[1,2,3,4,5,16]
	ifndef format"x, format"x==:<ifdef x,[x] .else [y]>
termin

.insrt dsk:syseng;format >

format"outstr:
	ifxe.	format"j,<-1,,0>
	  .call [setz ? sixbit 'siot' ? format"j ? format"a ? setz format"b]
	   .lose %lssys
	  ret
	endif.
	do.
	  sojl	format"b,endlp.
	  ildb	format"c,format"a
	  idpb	format"c,format"j
	  loop.
	enddo.
	ret

define	format	outdes,&string&,args
	call [	saveac [format"a,format"b,format"c,format"d,format"e,format"j]
		ifg <outdes>,{
			move format"j,<outdes>
			push p,[[movem format"j,<outdes> ? popj p,]]
		} .else ifg <<outdes>+20>, movei format"j,-<outdes>
		irp x,y,[args]
			push p,x
			ifb [y] movni format"c,<.irpcnt+1>
		termin
		hrroi	format"a,[ascii string]
		movei	format"b,.length string
		jrst	format"format]
termin
