.; PPORT.CMD dumps a file to your printer port, after setting
.; your screen width and the horizontal pitch on your printer.
.; Note that it may have trouble with files that are heavily
.; tabbed. 

.; Initialize:

	.ENABLE SUBSTITUTION
	.SETS MCR ""
	.IF <CLI> <> "MCR"	.SETS MCR ""
	.SETN NJUNK 33
	.SETS ESCAPE "'NJUNK%V'"
	.SETS CSI ESCAPE+"["
	.SETN OLDWID <TICWID>
	'MCR'SET /BUF=TI:255.

.; Table to translate line length into pitch control character:

	.SETS PITCH "5555555555555555555555555555555555555555"
	.SETS PITCH PITCH+"66666666888888888888888888"
	.SETS PITCH PITCH+"000000000000002222222222222222"
	.SETS PITCH PITCH+"444444444444444444444444444444444444"

.; Table to translate line length into screen width:

	.SETS SCREEN "llllllllllllllllllllllllllllllllllllllll"
	.SETS SCREEN SCREEN+"lllllllllllllllllllllllllllllllll"
	.SETS SCREEN SCREEN+"lllllllhhhhhhhhhhhhhhhhhhhhhhhhhh"
	.SETS SCREEN SCREEN+"hhhhhhhhhhhhhhhhhhhhhhhhhh"

.; Main (and only) loop:

.LOOP:
	.ASKS FILE What file shall I print
	.IF FILE = ""	.GOTO EXIT

.; Get the record size to use as line length:

	.OPENR 'FILE'
	.PARSE <FILATR> "," RTYP RATT RSIZ JUNK
	.CLOSE

.; Extract proper characters from pitch and screen arrays:

	.SETS SCRCHR SCREEN['RSIZ'.:'RSIZ'.]
	.SETS PITCHR PITCH['RSIZ'.:'RSIZ'.]

.; Set screen width, turn on printer, and set printer pitch:

	.DISABLE DISPLAY
	;'CSI'?3'SCRCHR''CSI'5i'CSI''PITCHR'w

.; Print the file:

	.ENABLE QUIET
	'MCR'PIP TI:='FILE'
	.DISABLE QUIET

.; Restore printer pitch, turn off printer port, and restore
.; screen width by the same flakey algorithm EDT uses: 

	.SETS SCRCHR SCREEN[OLDWID:OLDWID]
	;'CSI'w''CSI'4i'CSI'?3'SCRCHR'
	.ENABLE DISPLAY
	.GOTO LOOP

.; All done:

.EXIT:	'MCR'SET /BUF=TI:'OLDWID%D'.
	.EXIT
