This is the release 0.4 of magic-filter for BSD lpd.

Copyright
=========
    
(C) Brian McCauley 1993.  Distributed under the terms of the GNU
General Public License. You must not modify or distubute this package
until you have obtained a copy of the GNU GPL and accepted its terms.

Disclaimer
==========

It would be highly unlikely that is package could damage your system
but if it does - you've got the source you should have spotted it!

Abstract
========

This package allows what appears to lpd as a single filter take any
number of different file formats and automatically perform the right
filtering on each, provided that they can be distiguished by the
`file' command. This overcomes the limit introduced by the predefined
set of available file types supported by lpd and alows greater
lazyness when using lpr. It also allows you to save space in your
spool queue by compressing files. If the compressed files are on your
disk use the -s switch on lpr to save even more space.

Installation
============

The package can be installed anywhere but I keep it in:

/usr/local/lib/magic-filter/*

The exception to this is rewind-stdin which must be compiled and moved
(or linked) into /bin, /usr/bin or /usr/local/bin. (If you fail to to
this magic-filter will still work but it will always create temporary
files).

Edit /usr/etc/printcap to call the apporopriate magic filter for each
filter. You don't have to install magic-filer as all of a printer's
filters if you don't want to. Here's my printcap file - I trust you
get the idea.

lp|Epson FX-80:lp=/dev/lp1:sd=/usr/spool/lp1:sh:mx#0:pw#80:px#80:\
	:cf=/usr/local/lib/magic-filter/lp.cf:\
	:gf=/usr/local/lib/magic-filter/lp.gf:\
	:rf=/usr/local/lib/magic-filter/lp.rf:\
	:vf=/usr/local/lib/magic-filter/lp.vf:\
	:tf=/usr/local/lib/magic-filter/lp.tf:\
	:nf=/usr/local/lib/magic-filter/lp.nf:\
	:df=/usr/local/lib/magic-filter/lp.df:\
	:if=/usr/local/lib/magic-filter/lp.if:

Never install a magic filter as `of' (see printing-HOWTO for reason).

The basic magic-filter, lp.if, will allow lpr to handle compressed
text files. Check what your `file' command generates for the various
compression formats and edit the config file accoringly.

If you have more than one type of local printer you should create
additional sets of symlinks to magic-filter replacing lp with the name
of the printer. (If you have mutliple printers of the same type they
could share a filter set.)

If you already had a any filters you may chooese to edit their names
into the config file. By default lp.if will use `text-filter' which
will insert a carrage return at the end of each line. To suppress this
use `lpr -l'. It will also insert a formfeed at the end of each page.
As an added feature `lpr -l -i' is misused to print a file without CR
or FF added.

There is also an example setup for filter lp.df that I use to allow
`lpr -d' to handle DVI, PostScript and texinfo files. (In fact the
actual filters in sample-filters/ are not strictly part of this
package since they are printer specific. For details on writing
filters see the Linux printing-HOWTO or the lpd manual.

To create new magic filters
===========================

Run the `file' command on a few specimen files, check that it can
identify them and note down output it generates for each type.

Obtain non-magic filters for _your_ printer for each file type you
want to process. These must be filters that lpd *could* use to drive
*your* printer in the absence of the magic-filter package. (Note: you
don't need separate filters for compressed file formats).

Edit the config file for your filter to reflect the locations and
selection criteria of the non-magic filters.

Prefilters
==========

If magic filter detects a compressed file it passes through a
pre-filter and then back into magic-filter. Prefilters should only be
used to cope with file compression/encryption formats.

Non-piping filters
==================

Occasionally some of your non-magic lpd filters may not be filters in
the usual Unix sense, in that they require their standard input be
rewindable. This problem is commonly found in filters based on
dvips. This can cause problems as magic-filter tries to avoid large
temporary files by using pipes. To avoid this, test your filters thus:

cat suitable-small-file | filter-in-question >/dev/lp1
filter-in-question >/dev/lp1 <suitable-small-file

If neither of these works your filter probably insists on some of it's
command line parameters so RTM(printcap) and try again.  If the first
of these fails but the second works then your filter insists that its
stdin be a file so set the nopipe flag in the config file when
selecting the filter in question.

GZIP and texinfo magic
=======================

My /etc/magic lacked an entried for gzip and texinfo so I stuck this
on the end:

0	byte		037		gzip compressed file
#
0	string		\\input\ texinfo	TeXinfo source

I've not tested it much - it may give false positives or false
negatives but its better than nothing.

BASH
====

These scripts are written in bash and assume /bin/bash is linked to
your copy of bash.

If you don't have bash you may have to make some edits - notably I
suspect (although I don't know) that ${0##*/} will not be understood
by borne shell. You can replace:
  ${0##*/}
..with..
  `basename $0`
and
  ${0%/*}/
..with..
  `dirname $0`

You will also have to make your config script not use wildcard pattern
matching in the case constuct.

There may be other problems that I don't know about since I only have
bash.

Bugs
====

It's only as good as /etc/magic.

Error reporting could be better.

Tempfiles could hit the filename length limit on the Minix fs. 

When attempting to identify a decompressed file only the first 1kb is
passed to `file', this could cause problems.
        
This package may introduce some security holes. If you find any and
see how to plug them let me know.
         
Please E-mail bug reports and suggestions to me:

    \\   ( )   No Bullshit!   | Email: B.A.McCauley@bham.ac.uk
 .  _\\__[oo       from       | Voice: +44 21 471 3789 (home)
.__/  \\ /\@  /~)  /~[   /\/[ |        +44 21 627 2171 (work)
.  l___\\    /~~) /~~[  /   [ |   Fax: +44 21 627 2175 (work)
 # ll  l\\  ~~~~ ~   ~ ~    ~ | Snail: 197 Harborne Lane, B29 6SS, UK
###LL  LL\\ (Brian McCauley)  |  ICBM: 52.5N 1.9W

* The name PostScript is owned by Adobe (for all the good that does
them).

** The ``No Bullshit!'' device is not a registered trade mark but
perhaps it should be :-).
