/*
 *	StartDVIprint.sd
 *
 * This is a small hack to run DVIprint from ShowDVI.
 *
NOTES:
 *
 * You must have set the printer name in ENV:DVIprint for this to
 * work, or the default (generic) printer will be used.
 *
 * 'TeX:bin/DVIprint' is used to find DVIprint. Otherwise it would
 * have to be in your RexxMast path...
 *
 */

LF = '0A'X


ADDRESS COMMAND 'version >nil: exec.library 36'
IF RC ~= 0 THEN CONWINDOW = "CON:20/30/430/100/DVIprint--Output"
	   ELSE CONWINDOW = "CON:20/30/430/100/DVIprint--Output/AUTO/CLOSE/WAIT/SCREENShowDVI-PubScr"


OPTIONS RESULTS

getfile
loadedfile = RESULT
getdir
loadeddir = RESULT
getpage
page = RESULT

IF RIGHT(loadeddir,1)~='/' & RIGHT(loadeddir,1)~=':' THEN
	loadeddir = loadeddir||'/'

IF upper(right(loadedfile,4)) ~= ".DVI" THEN
	loadedfile = loadedfile||".dvi"

IF loadedfile = "" | ~exists(loadeddir||loadedfile) THEN DO
	Message "Which file should I print?"
	EXIT
	END

IF show('P','dviprint') THEN DO
	Message "DVIprint is already running, please wait"
	EXIT
	END

/*hes: it would be nice to know how many pages the document has... */

okay2 "Print all pages with the predefined draft-modus?"
IF RESULT ~= 1 THEN 

  DO
	getnumber page "Print from page?"
	IF 0=RC THEN from = RESULT
		ELSE DO 
			Message "Print cancelled!"
			EXIT 0
		     END

	getnumber page "Print upto page?"
	IF 0=RC THEN to = RESULT
		ELSE DO 
			Message "Print cancelled!"
			EXIT 0
		     END

	okay2 "Should I print in draft mode?"
	IF RESULT = 1 THEN draft = "on"
		      ELSE draft = "off"


	str = "Should I start the print"||LF||"  of file '"loadedfile"'"LF||"  from page "from" to page "to||LF

	IF draft = "on" THEN str = str||"  in draft mode?"
			ELSE str = str||"  in HQ mode?"

	okay2 str
	IF RESULT = 0 THEN DO 
			      Message "Print cancelled!"
			      EXIT 0
			   END


	Message "calling DVIprint."

	ADDRESS COMMAND 'TeX:bin/DVIprint' ">"CONWINDOW" from "from" to "to" draft "draft loadeddir||loadedfile
	IF 0~= RC THEN Message "DVIprint failed."
  END

ELSE

  DO
	Message "calling DVIprint."

	ADDRESS COMMAND 'TeX:bin/DVIprint' ">"CONWINDOW " " loadeddir||loadedfile
	IF 0~= RC THEN Message "DVIprint failed."
  END

EXIT
