home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / text / interlea / 548 < prev    next >
Encoding:
Text File  |  1992-07-21  |  6.6 KB  |  187 lines

  1. Path: sparky!uunet!darwin.sura.net!gatech!purdue!hsdndev!news.cs.umb.edu!ram
  2. From: ram@cs.umb.edu (Robert Morris)
  3. Newsgroups: comp.text.interleaf
  4. Subject: Re: Printers (was Interleaf to .ps conversion
  5. Message-ID: <RAM.92Jul21090745@ra.cs.umb.edu>
  6. Date: 21 Jul 92 14:07:45 GMT
  7. References: <1992Jul16.171637.10467@draco.macsch.com>
  8.     <1992Jul16.203026.19994@engr.latech.edu>
  9.     <1992Jul17.211204.29826@draco.macsch.com>
  10. Sender: news@cs.umb.edu (USENET News System)
  11. Reply-To: ram@cs.umb.edu
  12. Organization: University of Massachusetts at Boston
  13. Lines: 172
  14.  
  15. In article <1992Jul17.211204.29826@draco.macsch.com> todd@draco.macsch.com (Todd C. Williams) writes:
  16.  
  17.   >Path: news.cs.umb.edu!hsdndev!wupost!usc!sdd.hp.com!swrinde!elroy.jpl.nasa.gov!nntp-server.caltech.edu!draco.macsch.com!todd
  18.   >From: todd@draco.macsch.com (Todd C. Williams)
  19.   >Newsgroups: comp.text.interleaf
  20.   >Date: 17 Jul 92 21:12:04 GMT
  21.   >References: <1992Jul16.171637.10467@draco.macsch.com><1992Jul16.203026.19994@engr.latech.edu>
  22.  
  23.   >In article <1992Jul16.203026.19994@engr.latech.edu> dan@engr.latech.edu writes:
  24.     >>I have several printers defined to Interleaf for various areas of
  25.     >>our network.  ...the problem is that printers that are not
  26.     >>actually available for a particular host that Interleaf is running on
  27.     >>still show up in the menus, they don't work, but they still appear.
  28.     >>Am I doing something wrong?
  29.  
  30.   >No.
  31.  
  32.     >>It seems to me that the menu's
  33.     >>should only contain entries for those printers defined to the
  34.     >>workstation Interleaf is running on. 
  35.  
  36.   >That would require more work out of the Interleaf software.
  37.  
  38.  
  39. Not that much.
  40.  
  41. You can change the printer popup menu with print-set-popups. It takes
  42. as arguments the network names of the printers you want on your menu.
  43. Possibly you don't actually want all the printers anyway, just the
  44. ones near you if you have a lot. In this case, the simplest call is
  45. something like
  46.     (print-set-popups "printer1" "printer2" "printer3")
  47. where printerN are the network names, as many as you want.
  48. This means that you have to change your list any time the network list
  49. changes (you will provoke a lisp error if you mention a printer not in
  50. your network printer list). So if you really want everything, you have
  51. to get ileaf's idea of the network names, Unix's idea of the network
  52. names, intersect them and apply print-set-popups to the intersection.
  53.  
  54. The code below will do that. Probably the printcap parsing can be
  55. improved. System V printing can probably get the printer names by
  56. executing an appropriate "ls" from lisp. I have no clue about other
  57. kinds of network printing, but I suppose each OS must have
  58. some way to get the network printer names.
  59.  
  60. If you want to reset your printer popups to the entire list, do
  61.    (apply #'print-set-popups 
  62.       (mapcar #'(lambda (printer) (getf printer :netname)) *printers*))
  63.  
  64. or simply 
  65.     (apply #'print-set-popups (get-ileaf-printer-list))
  66. if you have loaded my lisp.
  67.  
  68. Any of these solutions can be put in your profile, or for
  69. slightly more maintainability, in a separate lisp file in your profile
  70. cabinet.
  71.  
  72.  
  73.  
  74.  
  75. Bob Morris
  76. ram@cs.umb.edu
  77.  
  78. lisp follows on next page.
  79.  
  80.  
  81. (lisp-set-implementation "Interleaf Lisp" "2.0")
  82.  
  83. ;;Copyright 1992
  84. ;;Robert A. Morris
  85. ;;40 Groveland Street
  86. ;;Newton MA 02166
  87. ;;
  88. ;;Permission is granted to copy, use or modify this program
  89. ;;for any purpose except sale provided that this notice remains
  90. ;;with the copy and that source code is provided with the copy.
  91.  
  92. ;; Module name: printerselect
  93. ;; Purpose: Reduce printer popup to hosts available
  94. ;; from the current host. 
  95. ;;
  96. ;; Notes: This code assumes a Berkeley Unix spooling system
  97. ;; Additional notes at end
  98.  
  99. ;; Audit:
  100. ;; DD-MON-YY USERNAME        COMMENT
  101. ;; 20-07-92  ram@cs.umb.edu    initial implementation
  102.  
  103. ;; Put this lisp in a file named printers.lsp in your profile
  104. ;;
  105. ;; Additional comments at end
  106.  
  107. (defvar printerselect-version 1)
  108.  
  109. (defun get-ileaf-printer-list ()
  110.   "Return list of networks names of printers presently known to ileaf"
  111.   (mapcar #'(lambda (printer) (getf printer :netname)) *printers*))
  112.  
  113. (defun get-network-printer-list ()
  114.   "Return list of Berkely unix printer names from termcap file"
  115. ;; This is the unpleasant part. System V may be easier, since
  116. ;; printer names come from the file system entries
  117. ;;
  118. ;;     Printer names are uniquely determined (?) by strings which
  119. ;; 1. are in a line not beginning with whitespace or #
  120. ;; 2. are terminated by | or :
  121. ;;
  122. ;; Probably there is some simpler way to parse the termcap lines
  123. ;; but I don't know all the Lisp string handling capability. Suggestions
  124. ;; welcome.
  125.  
  126.   (let* ((istream (open "/etc/printcap" :input))
  127.      line names)
  128.      (while (not (eql 'eof (setq line (read-line istream))))
  129.       (when (and (> (length line) 0)
  130.          (not (member (char line 0) '(#\# #\\t #\ ))))
  131.         (setq names (append (get-printer-names line) names)))
  132.     names)))
  133.  
  134. (defun get-printer-names (line)
  135.   "Parse a Berkeley printcap string LINE assumed to have printer names and
  136. return a list of those names as strings"
  137.   ;; strip trailing "\" from the line
  138.   (setq line (string-right-trim "#\\" line))
  139.   (let (namelist delim name)
  140.     (while (> (length line) 0)                ;find first "|" or ":"
  141.       (when (not (setq delim (position '#\| line)))
  142.         (setq delim (position '#\: line))) ;should handle failure here too
  143.       (setq 
  144.        name (subseq line 0 delim)
  145.        namelist (cons name namelist)
  146.        line (subseq line (1+ delim))))
  147.     namelist))
  148.  
  149. (defun intersection (l1 l2)
  150. "Return intersection of lists L1 L2 of strings"
  151. ;;Hey this is in Common Lisp. Interleaf should provide it, and
  152. ;;better than this one...
  153.   (let (intersection item)
  154.     (while l1
  155.       (when (member  (setq item (pop l1)) l2 #'string-equal)
  156.       (push item intersection)))
  157.     intersection))
  158.  
  159. (defun set-my-printers (network-list ileaf-list)
  160.   "Set the list of printers to the intersection of 
  161. NETWORK-LIST and ILEAF-LIST so only printers accessible from
  162. this host are seen on the printer menu"
  163.   (when *printers*
  164.     (apply #'print-set-popups  (intersection network-list ileaf-list))))
  165.  
  166.  
  167. (set-my-printers (get-network-printer-list) (get-ileaf-printer-list))
  168.  
  169.  
  170.  
  171. ;; Comments
  172. ;;If you really only want a small collection of printers, do
  173. ;;    (print-set-popups NAME*) 
  174. ;;where NAME's are the strings naming the printers
  175. ;;you want to see. 
  176.  
  177. ;;If you want to avoid errors should you name printers
  178. ;;which don't exist, try an appropriate modification of
  179. ;;    (let ( (my-list '("printer1" "printer2")))
  180. ;;         (set-my-printers my-list (get-ileaf-printer-list)))
  181.  
  182. ;; To reset the printers to the original list do
  183. ;;    (apply #'print-set-popups (get-ileaf-printer-list))
  184.  
  185. ;; Putting calls to such things in your Custom->NoSelection cabinet
  186. ;; might make their use easier
  187.