home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************/
- /* PrintDJ */
- /* */
- /* This program has been designed specifically for use with the HP Deskjet */
- /* 500. Use with other printers will require modification of the command */
- /* codes and perhaps a modification of some special features. */
- /* */
- /* This program is designed to allow the printing of normal ASCII files. */
- /* Control codes are written to the parallel device to allow access to */
- /* special features. The file itself is written to the print device to */
- /* support ANSI control codes in documents. */
- /* */
- /* You may include a file name when on the command line when the program */
- /* is started. If so, you are immediately taken to a parameters screen */
- /* where you may select the desired print attributes. If no file name is */
- /* supplied upon startup, the ARP file requester will be used to allow you */
- /* to select the desired file. When used in this way, the sequence is */
- /* repeated until no file is requested. Default print parameters may be */
- /* saved. They will be stored in the s: device in a file called */
- /* DJ500Print.config. */
- /* */
- /* The program assumes that the REXXARPLIB has already been defined to */
- /* ARexx. */
- /* */
- /* Only one filename will be recognized on the command line. */
- /* */
- /* Version 1.1 represents changes to support the DeskJet 500. */
- /* A modification was also made so that if a filename is */
- /* specified on the command line, that file is printed and */
- /* the program automatically exits. */
- /* */
- /* Copyright: Bill Raecke 08/89 and 04/91 */
- /* Permission granted for non-commercial distribution */
- /***************************************************************************/
-
- arg inputfile
-
- startfile = 0
- dirname = ""
- file = ""
- directory = ""
-
-
- /* These are the printer control codes */
- /* They are sent directly to the parallel port */
-
- topofpage = "&l0H"
- topmargin = "&l5E"
- setorient.1 = "&l0O"
- setorient.2 = "&l1O"
- setcset = "(10U"
- setsub = "(s0u"
- setspace.1 = "0p"
- setspace.2 = "1p"
- setpitch.1 = "12"
- setpitch.2 = "10"
- setpitch.3 = "16"
- setpitch.4 = "20"
- setpitch.5 = ""
- setstyle.1 = "0s"
- setstyle.2 = "1s"
- setfont.1 = "6T" /* LtrGothic */
- setfont.2 = "3T" /* Courier */
- setfont.3 = "3T" /* Courier */
- setfont.4 = "3T" /* Courier */
- setfont.5 = "4101T" /* CG Times */
- setLPI.1 = "&l6D" /* 6 LPI */
- setLPI.2 = "&l7D" /* 7 LPI */
- setLPI.3 = "&l8D" /* 8 LPI */
- setLPI.4 = "&l12D" /* 12 LPI */
- setqual.1 = "(s1Q"
- setqual.2 = "(s2Q"
- setmargin1 = "&a"
- setmargin2 = "L" /* Margin size is inserted between 1 and 2 */
- carriage = '0D'X
- thisarg = 0
-
-
- /* These are the default print settings */
- /* They are used when no default file is found */
-
- orient = 1 /* 1 is Portrait - 2 is Landscape */
- font = 1 /* 1 is Ltr12 - 2 is Cour 10 - 3 is Cour 16 */
- /* 4 is Cour 20 - 5 is Times 12 */
- style = 1 /* 1 is Normal - 2 is Italic */
- quality = 2 /* 1 is Draft - 2 is Letter */
- filewidth = 80
- lines = 1 /* 1 is 6 LPI, 2 is 7 LPI, 3 is 8 LPI and 4 is 12 */
- spacing = 1 /* set to 2 if the default is Times */
- points = 12 /* set to 6 if 12 LPI is the default */
-
- dummy = filelist("s:DJ500Print.config",,F,E) /* Do defaults exist? */
- if dummy = 1 then
- do
- call open('defaultfile','s:DJ500Print.config','R')
- orient = readln('defaultfile')
- font = readln('defaultfile')
- style = readln('defaultfile')
- quality = readln('defaultfile')
- filewidth = readln('defaultfile')
- lines = readln('defaultfile')
- spacing = readln('defaultfile')
- points = readln('defaultfile')
- call close('defaultfile')
- end
-
- firsttime = 1
-
- do forever
- if filesupplied = 1 & firsttime = 0 then leave
- call dofile
- if file = "" then leave
- firsttime = 0
- call startwindow
- call resetorient
- call resetfont
- call resetstyle
- call resetqual
- call resetlines
- thisarg = ""
- do until thisarg = "file"
- call getsettings
- end
- thisarg = ""
- call closewindow(prtcntl)
- call printersetup
- call printfile
- call resetfile
- end
-
- call closeport(prtport)
- if startfile = 1 then call CloseWindow(prtcntl)
- exit
-
-
- resetorient:
- orientset. = "OFF"
- orientset.orient = "ON"
- call setgadget(prtcntl,"portrait",orientset.1)
- call setgadget(prtcntl,"landscape",orientset.2)
- return()
-
-
- resetfont:
- fontset. = "OFF"
- fontset.font = "ON"
- call setgadget(prtcntl,"l12",fontset.1)
- call setgadget(prtcntl,"c10",fontset.2)
- call setgadget(prtcntl,"c16",fontset.3)
- call setgadget(prtcntl,"c20",fontset.4)
- call setgadget(prtcntl,"t12",fontset.5)
- return()
-
-
- resetstyle:
- styleset. = "OFF"
- styleset.style = "ON"
- call setgadget(prtcntl,"normal",styleset.1)
- call setgadget(prtcntl,"italic",styleset.2)
- return()
-
-
- resetqual:
- qualset. = "OFF"
- qualset.quality = "ON"
- call setgadget(prtcntl,"draft",qualset.1)
- call setgadget(prtcntl,"ltr",qualset.2)
- return()
-
-
- resetlines:
- lineset. = "OFF"
- lineset.lines = "ON"
- call setgadget(prtcntl,"lpi6",lineset.1)
- call setgadget(prtcntl,"lpi7",lineset.2)
- call setgadget(prtcntl,"lpi8",lineset.3)
- call setgadget(prtcntl,"lpi12",lineset.4)
- return()
-
-
- resetfile:
- inputfile = directory
- if right(inputfile,1) ~= ":" then
- if right(inputfile,1) ~= "/" then
- inputfile = inputfile || "/"
- return()
-
-
- startwindow:
- address AREXX "'call createhost("prtcntl","prtport")'"
- address command "c:WaitForPort" prtcntl
- call openport(prtport)
-
- idcmp = 'GADGETUP'
- flags = 'WINDOWDRAG+WINDOWDEPTH+BACKFILL'
- WindowText = " ORIENTATION\\\LTR GOTH COURIER CG TIMES"
- WindowText = WindowText || "\\\ STYLE QUALITY\\\ DOCUMENT WIDTH LINES/INCH"
-
- call OpenWindow(prtcntl,100,25,360,150,idcmp,flags," Print Control Screen ")
-
- call windowtext(prtcntl,WindowText)
- call addgadget(prtcntl,50,30,"portrait"," Portrait ","%d")
- call addgadget(prtcntl,210,30,"landscape"," Landscape ","%d")
-
- call addgadget(prtcntl,35,57,"l12"," 12 ","%d")
- call addgadget(prtcntl,115,57,"c10"," 10 ","%d")
- call addgadget(prtcntl,160,57,"c16"," 16 ","%d")
- call addgadget(prtcntl,205,57,"c20"," 20 ","%d")
- call addgadget(prtcntl,280,57,"t12"," Pr ","%d")
-
- call addgadget(prtcntl,20,83,"normal"," Normal ","%d")
- call addgadget(prtcntl,100,83,"italic"," Italic ","%d")
- call addgadget(prtcntl,205,83,"ltr"," LTR ","%d")
- call addgadget(prtcntl,275,83,"draft"," DRAFT ","%d")
-
- call addgadget(prtcntl,75,110,"docwidth",filewidth,"%g",50)
- call addgadget(prtcntl,190,110,"lpi6"," 6 ","%d")
- call addgadget(prtcntl,230,110,"lpi7"," 7 ","%d")
- call addgadget(prtcntl,270,110,"lpi8"," 8 ","%d")
- call addgadget(prtcntl,310,110,"lpi12","12 ","%d")
-
- call addgadget(prtcntl,200,130,"file", " PRINT FILE ","%d")
- call addgadget(prtcntl,30,130,"defaults"," SAVE DEFAULTS ","%d")
-
- return()
-
-
- getsettings:
- call waitpkt(prtport)
- p = getpkt(prtport)
- if p ~== NULL() & p ~= 0 then
- do
- thisarg = getarg(p)
- t = reply(p, 0)
- end
- select
- when thisarg="portrait" then
- do
- orient = 1
- call resetorient
- end
- when thisarg="landscape" then
- do
- orient = 2
- call resetorient
- if font = 1 | font = 5 then
- do
- font = 2
- call resetfont
- end
- if style = 2 then
- do
- style = 1
- call resetstyle
- end
- if lines = 2 then
- do
- lines = 1
- call resetlines
- end
- end
- when thisarg="l12" then
- do
- if orient ~= 2 then
- do
- font = 1
- call resetfont
- spacing = 1
- end
- end
- when thisarg="c10" then
- do
- font = 2
- call resetfont
- spacing = 1
- end
- when thisarg="c16" then
- do
- font = 3
- call resetfont
- spacing = 1
- if style = 2 then
- do
- style = 1
- call resetstyle
- end
- end
- when thisarg="c20" then
- do
- font = 4
- call resetfont
- spacing = 1
- end
- when thisarg="t12" then
- do
- if orient ~= 2 then
- do
- font = 5
- call resetfont
- spacing = 2
- end
- end
- when thisarg="normal" then
- do
- style = 1
- call resetstyle
- end
- when thisarg="italic" then
- do
- if orient ~= 2 & font ~= 3 then
- do
- style = 2
- call resetstyle
- end
- end
- when thisarg="ltr" then
- do
- quality = 2
- call resetqual
- end
- when thisarg="draft" then
- do
- quality = 1
- call resetqual
- end
- when thisarg="lpi6" then
- do
- lines = 1
- call resetlines
- points = 12
- end
- when thisarg="lpi7" then
- if orient =1 then
- do
- lines = 2
- call resetlines
- points = 12
- end
- when thisarg="lpi8" then
- do
- lines = 3
- call resetlines
- points = 12
- end
- when thisarg="lpi12" then
- do
- lines = 4
- call resetlines
- points = 6
- end
- when thisarg="file" then nop
- when thisarg="defaults" then
- do
- call open('defaultfile','s:DJ500Print.config','W')
- call writeln('defaultfile',orient)
- call writeln('defaultfile',font)
- call writeln('defaultfile',style)
- call writeln('defaultfile',quality)
- call writeln('defaultfile',filewidth)
- call writeln('defaultfile',lines)
- call writeln('defaultfile',spacing)
- call writeln('defaultfile',points)
- call close('defaultfile')
- end
- otherwise
- if datatype(thisarg) = "NUM" then
- filewidth = thisarg
- end
- return()
-
-
-
- dofile:
- if inputfile ~= "" then /* Check to see if a filename was sent */
- do
- call dirname /* Determine directory name */
- call filename /* Determine file name */
- if file ~= "" then /* Was there a filename? */
- do
- filesupplied = 1
- ret = filelist(inputfile,,F,E) /* Does the file exist? */
- if ret = 0 then
- file = ""
- end
- end
- if file = "" then
- do
- inputfile = getfile(90,35,directory,file,"Select File To Print",)
- call dirname
- call filename
- end
- return()
-
-
- dirname:
- directorypos = lastpos("/",inputfile)
- if directorypos = 0 then
- do
- directorypos = lastpos(":",inputfile)
- if directorypos = 0 then
- directory = ""
- else
- directory = left(inputfile,directorypos)
- end
- else
- directory = left(inputfile,directorypos-1)
- return()
-
-
- filename:
- reslength = length(inputfile)
- file = right(inputfile,reslength-directorypos)
- return()
-
-
- printersetup:
- prtstrng = ""
- prtstrng = setorient.orient || setcset || setsub || setspace.spacing
- prtstrng = prtstrng || setpitch.font || "h" || points || "v" || setstyle.style
- prtstrng = prtstrng || setfont.font || setqual.quality || setLPI.lines
- prtstrng = prtstrng || "&l2A&l120P&l1L"
-
- if font = 5 then
- characters = 12
- else
- characters = value(setpitch.font)
-
- if orient = 1 then
- printerwidth = characters * 8
- else
- printerwidth = characters * 10
-
- leftmargin = (printerwidth - filewidth) % 2
- if sign(leftmargin) = -1 then leftmargin = 0
-
- prtstrng = prtstrng || setmargin1 || leftmargin || setmargin2
-
- if orient = 1 then
- do
- if lines = 1 then linesperpage = 57
- if lines = 2 then linesperpage = 66
- if lines = 3 then linesperpage = 76
- if lines = 4 then linesperpage = 114
- end
- else
- do
- if lines = 1 then linesperpage = 45
- if lines = 3 then linesperpage = 60
- if lines = 4 then linesperpage = 87
- end
-
- prtstrng = prtstrng || topmargin || "&l" || linesperpage || "F"
- prtstrng = prtstrng || topofpage
- call checkprnt
- call open('par','PAR:','W') /* Send control codes via parallel port */
- call writeln('par',prtstrng)
- call close('par')
- return()
-
-
- printfile:
- address command "type > prt:" inputfile
- return()
-
-
- checkprnt:
- checkdev = showlist('d','printer.device')
- if checkdev = 0 then
- do
- call open('prt','PRT:','W') /* Open print device now to avoid reset
- after control codes are sent */
- call writeln('prt',' ')
- call close('prt')
- end
- return()
-