/*
Which Printer V1.0 (c) 1998 A.Teichmann@gmx.net

Utility für Turboprint bei benutzung mehrerer Drucker...
*/

parse arg dat
dat =strip(dat)

IF ~EXISTS("libs:rexxreqtools.library") THEN DO
SAY "Brauche RexxReqTools.library"
EXIT
END
IF ~SHOW('libraries','rexxreqtools.library') THEN DO
CALL ADDLIB("rexxreqtools.library",0,-30)
END


nl="0a"x;zaehler=1
if dat="?" then call error
if dat="" then dat="env:whichprinter.dat"
if ~exists(dat) then dat="envarc:whichprinter.dat"
if ~exists(dat) then call error

call open(in,dat,"R")

buf=readln(in)
text=readln(in)
font=readln(in)
	pos=index(font,".")
	if pos=0 then call DATERROR
	size=substr(font,pos+1)
	if datatype(size)="CHAR" then size=8

	pos1=index(font,":") 
	if pos=0 then call DATERROR
	font=substr(font,pos1+1,pos-pos1-1)

	if ~exists("fonts:"font"/"size) then do
		 font="topaz"
		 size=8
		 end

titel="Whichprinter V1.0 (c)1999 A.Teichmann@gmx.net"



do forever
	buf=readln(in)
	if eof(in) then leave
	if substr(buf,1,3)="---" then call LOS
	end

call REQUESTER

address command "turboprint:turboprefs -q -c"tpconfig.wahl" -p1"
exit


LOS:
	do forever
	buf=readln(in)
	if eof(in) then leave
	call AUS
	end
	return

AUS:
	pos=index(buf,"[",1);if pos=0 then leave
	button.zaehler=strip(substr(buf,1,pos-1))

	pos1=index(buf,"]",pos+1);if pos1=0 then leave
	tpconfig.zaehler=strip(substr(buf,pos+1,pos1-pos-1))
	if ~exists("Turboprint:configs/"tpconfig.zaehler".tpc") then tpconfig.zaehler="_Default_" 

	pos2=index(buf,"[",pos1+1);if pos2=0 then leave	
	use.zaehler=strip(substr(buf,pos1+1,pos2-pos1-1))
	if index(use.zaehler,"USE")~=0 then use.zaehler="USE"
	if index(use.zaehler,"SAVE")~=0 then use.zaehler="SAVE"

	pos3=index(buf,"]",pos2+1);if pos3=0 then leave
	port.zaehler=strip(substr(buf,pos2+1,pos3-pos2-1))
	if datatype(port.zaehler)="CHAR" then port.zaehler=0 

	zaehler=zaehler+1
	return

ERROR:
	say "SYNTAX:"nl"whichprinter <Prefsfile>"
	exit
REQUESTER:
	buttons=""
	do i=1 to zaehler-1
		buttons=buttons"|"button.i
		end
	buttons=substr(buttons,2)

	CALL rtezrequest(Text,buttons,Titel,'rtez_flags = ezreqf_centertext' 'rt_font = '||FONT||'.font/'||SIZE)
	wahl=rtresult
	if wahl=0 then wahl=zaehler-1
	return


DATERROR:
	say "Fehler in DAT Datei"
	exit
