Subject: Changes to lpd to run if and of on remote printers
To: None <tech-misc@netbsd.org>
From: David Brownlee <abs@formula1.com>
List: tech-misc
Date: 08/28/2002 15:38:44
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--0-1436075781-1030544351=:21266
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-ID: <Pine.NEB.4.44.0208281538071.21266@moss.i.formula1.com>

	lpd has a '-r' option to run 'of' for remote printers, but it
	doesn't actually pass the contents of any files through it.

	We have another application here that means we want to run
	'if' in that same situation (-r passed).

	Complications:
	    - lpd has to send the size of the file across before its
	      contents, so to work the filter has to store the results
	      to a temporary file.
	    - Each file is sent separately so 'of' has to be run for each
	      entry, rather than once for everything sent (assuming I've
	      followed the logic correctly).

	I've come up with a set of patches that handles this - does
	anyone have any thought/objections/comments?

-- 
		David Brownlee/absolute          abs@formula1.com


--0-1436075781-1030544351=:21266
Content-Type: TEXT/PLAIN; charset=US-ASCII; name=diff
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.NEB.4.44.0208281538440.21266@moss.i.formula1.com>
Content-Description: 
Content-Disposition: attachment; filename=diff

SW5kZXg6IGxwZC9wcmludGpvYi5jDQo9PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
DQpSQ1MgZmlsZTogL2N2c3Jvb3QvYmFzZXNyYy91c3Iuc2Jpbi9scHIvbHBk
L3ByaW50am9iLmMsdg0KcmV0cmlldmluZyByZXZpc2lvbiAxLjM0DQpkaWZm
IC11IC1CIC1yMS4zNCBwcmludGpvYi5jDQotLS0gbHBkL3ByaW50am9iLmMJ
MjAwMi8wNy8xNCAxNToyODowMAkxLjM0DQorKysgbHBkL3ByaW50am9iLmMJ
MjAwMi8wOC8yOCAxNDozODowNw0KQEAgLTExNyw2ICsxMTcsNyBAQA0KIHN0
YXRpYyBjaGFyCXB4bGVuZ3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