home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 503a.lha / Print.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1991-05-05  |  13.2 KB  |  476 lines

  1. /***************************************************************************/
  2. /*                              PrintDJ                                    */
  3. /*                                                                         */
  4. /* This program has been designed specifically for use with the HP Deskjet */
  5. /* 500. Use with other printers will require modification of the command   */
  6. /* codes and perhaps a modification of some special features.              */
  7. /*                                                                         */
  8. /* This program is designed to allow the printing of normal ASCII files.   */
  9. /* Control codes are written to the parallel device to allow access to     */
  10. /* special features.  The file itself is written to the print device to    */
  11. /* support ANSI control codes in documents.                                */
  12. /*                                                                         */
  13. /* You may include a file name when on the command line when the program   */
  14. /* is started. If so, you are immediately taken to a parameters screen     */
  15. /* where you may select the desired print attributes. If no file name is   */
  16. /* supplied upon startup, the ARP file requester will be used to allow you */
  17. /* to select the desired file. When used in this way, the sequence is      */
  18. /* repeated until no file is requested. Default print parameters may be    */
  19. /* saved. They will be stored in the s: device in a file called            */
  20. /* DJ500Print.config.                                                      */
  21. /*                                                                         */
  22. /* The program assumes that the REXXARPLIB has already been defined to     */
  23. /* ARexx.                                                                  */
  24. /*                                                                         */
  25. /* Only one filename will be recognized on the command line.               */
  26. /*                                                                         */
  27. /* Version 1.1 represents changes to support the DeskJet 500.              */
  28. /*             A modification was also made so that if a filename is       */
  29. /*             specified on the command line, that file is printed and     */
  30. /*             the program automatically exits.                            */
  31. /*                                                                         */
  32. /* Copyright: Bill Raecke 08/89 and 04/91                                  */
  33. /* Permission granted for non-commercial distribution                      */
  34. /***************************************************************************/
  35.  
  36. arg inputfile
  37.  
  38. startfile = 0
  39. dirname = ""
  40. file = ""
  41. directory = ""
  42.  
  43.  
  44. /* These are the printer control codes */
  45. /* They are sent directly to the parallel port */
  46.  
  47. topofpage    = "&l0H"
  48. topmargin    = "&l5E"
  49. setorient.1  = "&l0O"
  50. setorient.2  = "&l1O"
  51. setcset      = "(10U"
  52. setsub       = "(s0u"
  53. setspace.1   = "0p"
  54. setspace.2   = "1p"
  55. setpitch.1   = "12"
  56. setpitch.2   = "10"
  57. setpitch.3   = "16"
  58. setpitch.4   = "20"
  59. setpitch.5   = ""
  60. setstyle.1   = "0s"
  61. setstyle.2   = "1s"
  62. setfont.1    = "6T"      /* LtrGothic */
  63. setfont.2    = "3T"      /* Courier */
  64. setfont.3    = "3T"      /* Courier */
  65. setfont.4    = "3T"      /* Courier */
  66. setfont.5    = "4101T"   /* CG Times */
  67. setLPI.1     = "&l6D"   /* 6 LPI */
  68. setLPI.2     = "&l7D"   /* 7 LPI */
  69. setLPI.3     = "&l8D"   /* 8 LPI */
  70. setLPI.4     = "&l12D"  /* 12 LPI */
  71. setqual.1    = "(s1Q"
  72. setqual.2    = "(s2Q"
  73. setmargin1   = "&a"
  74. setmargin2   = "L"           /* Margin size is inserted between 1 and 2 */
  75. carriage     = '0D'X
  76. thisarg      = 0
  77.  
  78.  
  79. /* These are the default print settings */
  80. /* They are used when no default file is found */
  81.  
  82. orient = 1                /* 1 is Portrait - 2 is Landscape */
  83. font = 1                  /* 1 is Ltr12 - 2 is Cour 10  - 3 is Cour 16 */
  84.                           /* 4 is Cour 20 - 5 is Times 12 */
  85. style = 1                 /* 1 is Normal - 2 is Italic */
  86. quality = 2               /* 1 is Draft - 2 is Letter */
  87. filewidth = 80
  88. lines = 1                 /* 1 is 6 LPI, 2 is 7 LPI, 3 is 8 LPI and 4 is 12 */
  89. spacing = 1               /* set to 2 if the default is Times */
  90. points = 12               /* set to 6 if 12 LPI is the default */
  91.  
  92. dummy = filelist("s:DJ500Print.config",,F,E) /* Do defaults exist? */
  93. if dummy = 1 then
  94.    do
  95.       call open('defaultfile','s:DJ500Print.config','R')
  96.       orient = readln('defaultfile')
  97.       font = readln('defaultfile')
  98.       style = readln('defaultfile')
  99.       quality = readln('defaultfile')
  100.       filewidth = readln('defaultfile')
  101.       lines =  readln('defaultfile')
  102.       spacing = readln('defaultfile')
  103.       points = readln('defaultfile')
  104.       call close('defaultfile')
  105.    end
  106.  
  107. firsttime = 1
  108.  
  109. do forever
  110.    if filesupplied = 1 & firsttime = 0 then leave
  111.    call dofile
  112.    if file = "" then leave
  113.    firsttime = 0
  114.    call startwindow
  115.    call resetorient
  116.    call resetfont
  117.    call resetstyle
  118.    call resetqual
  119.    call resetlines
  120.    thisarg = ""
  121.    do until thisarg = "file"
  122.       call getsettings
  123.    end
  124.    thisarg = ""
  125.    call closewindow(prtcntl)
  126.    call printersetup
  127.    call printfile
  128.    call resetfile
  129. end
  130.  
  131. call closeport(prtport)
  132. if startfile = 1 then call CloseWindow(prtcntl)
  133. exit
  134.  
  135.  
  136. resetorient:
  137. orientset. = "OFF"
  138. orientset.orient = "ON"
  139. call setgadget(prtcntl,"portrait",orientset.1)
  140. call setgadget(prtcntl,"landscape",orientset.2)
  141. return()
  142.  
  143.  
  144. resetfont:
  145. fontset. = "OFF"
  146. fontset.font = "ON"
  147. call setgadget(prtcntl,"l12",fontset.1)
  148. call setgadget(prtcntl,"c10",fontset.2)
  149. call setgadget(prtcntl,"c16",fontset.3)
  150. call setgadget(prtcntl,"c20",fontset.4)
  151. call setgadget(prtcntl,"t12",fontset.5)
  152. return()
  153.  
  154.  
  155. resetstyle:
  156. styleset. = "OFF"
  157. styleset.style = "ON"
  158. call setgadget(prtcntl,"normal",styleset.1)
  159. call setgadget(prtcntl,"italic",styleset.2)
  160. return()
  161.  
  162.  
  163. resetqual:
  164. qualset. = "OFF"
  165. qualset.quality = "ON"
  166. call setgadget(prtcntl,"draft",qualset.1)
  167. call setgadget(prtcntl,"ltr",qualset.2)
  168. return()
  169.  
  170.  
  171. resetlines:
  172. lineset. = "OFF"
  173. lineset.lines = "ON"
  174. call setgadget(prtcntl,"lpi6",lineset.1)
  175. call setgadget(prtcntl,"lpi7",lineset.2)
  176. call setgadget(prtcntl,"lpi8",lineset.3)
  177. call setgadget(prtcntl,"lpi12",lineset.4)
  178. return()
  179.  
  180.  
  181. resetfile:
  182. inputfile = directory
  183. if right(inputfile,1) ~= ":" then
  184.    if right(inputfile,1) ~= "/" then
  185.       inputfile = inputfile || "/"
  186. return()
  187.  
  188.  
  189. startwindow:
  190. address AREXX "'call createhost("prtcntl","prtport")'"
  191. address command "c:WaitForPort" prtcntl
  192. call openport(prtport)
  193.  
  194. idcmp = 'GADGETUP'
  195. flags = 'WINDOWDRAG+WINDOWDEPTH+BACKFILL'
  196. WindowText = "              ORIENTATION\\\LTR GOTH        COURIER        CG TIMES"
  197. WindowText = WindowText || "\\\       STYLE                QUALITY\\\   DOCUMENT WIDTH         LINES/INCH"
  198.  
  199. call OpenWindow(prtcntl,100,25,360,150,idcmp,flags," Print Control Screen ")
  200.  
  201. call windowtext(prtcntl,WindowText)
  202. call addgadget(prtcntl,50,30,"portrait"," Portrait  ","%d")
  203. call addgadget(prtcntl,210,30,"landscape"," Landscape ","%d")
  204.  
  205. call addgadget(prtcntl,35,57,"l12"," 12 ","%d")
  206. call addgadget(prtcntl,115,57,"c10"," 10 ","%d")
  207. call addgadget(prtcntl,160,57,"c16"," 16 ","%d")
  208. call addgadget(prtcntl,205,57,"c20"," 20 ","%d")
  209. call addgadget(prtcntl,280,57,"t12"," Pr ","%d")
  210.  
  211. call addgadget(prtcntl,20,83,"normal"," Normal ","%d")
  212. call addgadget(prtcntl,100,83,"italic"," Italic ","%d")
  213. call addgadget(prtcntl,205,83,"ltr","  LTR  ","%d")
  214. call addgadget(prtcntl,275,83,"draft"," DRAFT ","%d")
  215.  
  216. call addgadget(prtcntl,75,110,"docwidth",filewidth,"%g",50)
  217. call addgadget(prtcntl,190,110,"lpi6"," 6 ","%d")
  218. call addgadget(prtcntl,230,110,"lpi7"," 7 ","%d")
  219. call addgadget(prtcntl,270,110,"lpi8"," 8 ","%d")
  220. call addgadget(prtcntl,310,110,"lpi12","12 ","%d")
  221.  
  222. call addgadget(prtcntl,200,130,"file", "   PRINT FILE   ","%d")
  223. call addgadget(prtcntl,30,130,"defaults"," SAVE DEFAULTS  ","%d")
  224.  
  225. return()
  226.  
  227.  
  228. getsettings:
  229. call waitpkt(prtport)
  230. p = getpkt(prtport)
  231. if p ~== NULL() & p ~= 0 then
  232.    do
  233.       thisarg = getarg(p)
  234.       t = reply(p, 0)
  235.    end
  236. select
  237.    when thisarg="portrait" then
  238.       do
  239.          orient = 1
  240.          call resetorient
  241.       end
  242.    when thisarg="landscape" then
  243.       do
  244.          orient = 2
  245.          call resetorient
  246.          if font = 1 | font = 5 then
  247.             do
  248.                font = 2
  249.                call resetfont
  250.             end
  251.          if style = 2 then
  252.             do
  253.                style = 1
  254.                call resetstyle
  255.             end
  256.          if lines = 2 then
  257.             do
  258.                lines = 1
  259.                call resetlines
  260.             end
  261.       end
  262.    when thisarg="l12" then
  263.       do
  264.          if orient ~= 2 then
  265.          do
  266.             font = 1
  267.             call resetfont
  268.             spacing = 1
  269.          end
  270.       end
  271.    when thisarg="c10" then
  272.       do
  273.          font = 2
  274.          call resetfont
  275.          spacing = 1
  276.       end
  277.    when thisarg="c16" then
  278.       do
  279.          font = 3
  280.          call resetfont
  281.          spacing = 1
  282.          if style = 2 then
  283.          do
  284.             style = 1
  285.             call resetstyle
  286.          end
  287.       end
  288.    when thisarg="c20" then
  289.       do
  290.          font = 4
  291.          call resetfont
  292.          spacing = 1
  293.       end
  294.    when thisarg="t12" then
  295.       do
  296.          if orient ~= 2 then
  297.          do
  298.             font = 5
  299.             call resetfont
  300.             spacing = 2
  301.          end
  302.       end
  303.    when thisarg="normal" then
  304.       do
  305.          style = 1
  306.          call resetstyle
  307.       end
  308.    when thisarg="italic" then
  309.       do
  310.          if orient ~= 2 & font ~= 3 then
  311.          do
  312.             style = 2
  313.             call resetstyle
  314.          end
  315.       end
  316.    when thisarg="ltr" then
  317.       do
  318.          quality = 2
  319.          call resetqual
  320.       end
  321.    when thisarg="draft" then
  322.       do
  323.          quality = 1
  324.          call resetqual
  325.       end
  326.    when thisarg="lpi6" then
  327.       do
  328.          lines = 1
  329.          call resetlines
  330.          points = 12
  331.       end
  332.    when thisarg="lpi7" then
  333.       if orient =1 then
  334.       do
  335.          lines = 2
  336.          call resetlines
  337.          points = 12
  338.       end
  339.    when thisarg="lpi8" then
  340.       do
  341.          lines = 3
  342.          call resetlines
  343.          points = 12
  344.       end
  345.    when thisarg="lpi12" then
  346.       do
  347.          lines = 4
  348.          call resetlines
  349.          points = 6
  350.       end
  351.    when thisarg="file" then nop
  352.    when thisarg="defaults" then
  353.       do
  354.          call open('defaultfile','s:DJ500Print.config','W')
  355.          call writeln('defaultfile',orient)
  356.          call writeln('defaultfile',font)
  357.          call writeln('defaultfile',style)
  358.          call writeln('defaultfile',quality)
  359.          call writeln('defaultfile',filewidth)
  360.          call writeln('defaultfile',lines)
  361.          call writeln('defaultfile',spacing)
  362.          call writeln('defaultfile',points)
  363.          call close('defaultfile')
  364.       end
  365.    otherwise
  366.       if datatype(thisarg) = "NUM" then
  367.          filewidth = thisarg
  368. end
  369. return()
  370.  
  371.  
  372.  
  373. dofile:
  374. if inputfile ~= "" then             /* Check to see if a filename was sent */
  375.    do
  376.       call dirname                  /* Determine directory name */
  377.       call filename                 /* Determine file name */
  378.       if file ~= "" then            /* Was there a filename? */
  379.          do
  380.             filesupplied = 1
  381.             ret = filelist(inputfile,,F,E) /* Does the file exist? */
  382.             if ret = 0 then
  383.                file = ""
  384.          end
  385.    end
  386. if file = "" then
  387.    do
  388.       inputfile = getfile(90,35,directory,file,"Select File To Print",)
  389.       call dirname
  390.       call filename
  391.    end
  392. return()
  393.  
  394.  
  395. dirname:
  396. directorypos = lastpos("/",inputfile)
  397. if directorypos = 0 then
  398.    do
  399.       directorypos = lastpos(":",inputfile)
  400.       if directorypos = 0 then
  401.           directory = ""
  402.       else
  403.           directory = left(inputfile,directorypos)
  404.    end
  405. else
  406.    directory = left(inputfile,directorypos-1)
  407. return()
  408.  
  409.  
  410. filename:
  411. reslength = length(inputfile)
  412. file = right(inputfile,reslength-directorypos)
  413. return()
  414.  
  415.  
  416. printersetup:
  417. prtstrng = ""
  418. prtstrng = setorient.orient || setcset || setsub || setspace.spacing
  419. prtstrng = prtstrng || setpitch.font || "h" || points || "v" || setstyle.style
  420. prtstrng = prtstrng || setfont.font || setqual.quality || setLPI.lines
  421. prtstrng = prtstrng || "&l2A&l120P&l1L"
  422.  
  423. if font = 5 then
  424.    characters = 12
  425. else
  426.    characters = value(setpitch.font)
  427.  
  428. if orient = 1 then
  429.    printerwidth = characters * 8
  430. else
  431.    printerwidth = characters * 10
  432.  
  433. leftmargin = (printerwidth - filewidth) % 2
  434. if sign(leftmargin) = -1 then leftmargin = 0
  435.  
  436. prtstrng = prtstrng || setmargin1 || leftmargin || setmargin2
  437.  
  438. if orient = 1 then
  439.    do
  440.       if lines = 1 then linesperpage = 57
  441.       if lines = 2 then linesperpage = 66
  442.       if lines = 3 then linesperpage = 76
  443.       if lines = 4 then linesperpage = 114
  444.    end
  445. else
  446.    do
  447.       if lines = 1 then linesperpage = 45
  448.       if lines = 3 then linesperpage = 60
  449.       if lines = 4 then linesperpage = 87
  450.    end
  451.  
  452. prtstrng = prtstrng || topmargin || "&l" || linesperpage || "F"
  453. prtstrng = prtstrng || topofpage
  454. call checkprnt
  455. call open('par','PAR:','W')   /* Send control codes via parallel port */
  456. call writeln('par',prtstrng)
  457. call close('par')
  458. return()
  459.  
  460.  
  461. printfile:
  462. address command "type > prt:" inputfile
  463. return()
  464.  
  465.  
  466. checkprnt:
  467. checkdev = showlist('d','printer.device')
  468. if checkdev = 0 then
  469.    do
  470.       call open('prt','PRT:','W')   /* Open print device now to avoid reset
  471.                                        after control codes are sent */ 
  472.       call writeln('prt',' ')
  473.       call close('prt')
  474.    end
  475. return()
  476.