diff --text -r -N -u oki4linux-2.0/src/README.oki4daemon oki4linux-2.0-hacked/src/README.oki4daemon --- oki4linux-2.0/src/README.oki4daemon Wed Dec 31 19:00:00 1969 +++ oki4linux-2.0-hacked/src/README.oki4daemon Sun Oct 29 19:00:08 2000 @@ -0,0 +1,37 @@ +Oki4drv daemon +============== + +I've written a little Perl program which runs as a daemon and +eliminates some of the awkwardness of this driver. + +Basically, you twiddle oki4daemon to know about the proper paths, then +run it. It will background itself, then create and monitor a named +pipe called /dev/oki4drv (or whatever you told it). + +Once oki4daemon is running, /dev/oki4drv accepts Postscript. In LPD, +for example, you could set lp=/dev/oki4drv and be all set... + + +Option setting +-------------- + +You can prepend lines of the form + +%FAKEOKI foo=bar + +to the job to control the various options. I've configured oki4drv in +Foomatic to know about these option values, so between this and +Foomatic, you can use oki4drv cleanly under CUPS, LPD, or PDQ. Or at +least that's the theory ;) + + +Also included in this patch are fixes to oki4drv itself; it was not +invoking Ghostscript with -dSAFER, and it didn't call getopt properly +for its own -w (paperweight) option. + +http://www.linuxprinting.org/download/printing/ +http://www.linuxprinting.org/show_driver.cgi?driver=oki4drv + +-- +Grant Taylor +http://www.linuxprinting.org/ \ No newline at end of file diff --text -r -N -u oki4linux-2.0/src/main.c oki4linux-2.0-hacked/src/main.c --- oki4linux-2.0/src/main.c Mon Jul 31 19:23:16 2000 +++ oki4linux-2.0-hacked/src/main.c Sun Oct 29 18:43:33 2000 @@ -465,7 +465,7 @@ */ static char *compose_gs_command(char *name, int size_index) { - char *chunk1 = "/usr/bin/gs -q -dNOPAUSE -dBATCH -sDEVICE=bit -r600x600 -sPAPERSIZE="; + char *chunk1 = "/usr/bin/gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bit -r600x600 -sPAPERSIZE="; char *chunk2 = " -sOutputFile=- -q "; char *result; @@ -538,7 +538,7 @@ /* Parse command line options. */ - while ((c = getopt(argc, argv, "gmd:s:vVo:")) != -1) + while ((c = getopt(argc, argv, "gmw:d:s:vVo:")) != -1) switch (c) { case 'v': puts("This is oki4drv, version " VERSION "."); diff --text -r -N -u oki4linux-2.0/src/oki4daemon oki4linux-2.0-hacked/src/oki4daemon --- oki4linux-2.0/src/oki4daemon Wed Dec 31 19:00:00 1969 +++ oki4linux-2.0-hacked/src/oki4daemon Sun Oct 29 18:46:45 2000 @@ -0,0 +1,187 @@ +#! /usr/bin/perl + +# Simple named pipe daemon for oki4drv. + +# The idea: we read jobs from a named pipe in the filesystem. We +# simply pipe them into oki4drv. We define a job format like this: + +# %FAKEOKI option=foo +# %FAKEOKI option=bar +# %! +# .... + +# This is handy in that I can put the %FAKEOKI clauses in as ps/gs +# args in Foomatic, or anyone else can trivially handle this in any +# other system. + +# Available options are not really documented; just read the code +# below... + +# If not in path +my $oki4drv = '/usr/local/sbin/oki4drv'; + +# contents of 8min.rip from distribution. You could use immediate.rip. +my $sleepstring = '%-98765XBb%-98765X'; + +use Getopt::Std; +getopts('f:o:h'); +help_and_die() if $opt_h; + +my $device = '/dev/lp0'; +$device = $opt_o if $opt_o; + +# Step 1: mkfifo + +my $fifo = '/dev/oki4drv'; +$fifo = $opt_f if ($opt_f); + +if (! -p $fifo) { + system("mkfifo $fifo 0600") == 0 + or die "Unable to make named pipe $fifo"; +} + +# Step 1.5: dissociate, daemonize, &c... + +# TODO: Connect stderr/stdout to logger or something similar, and/or +# provide suitable die handler... + +fork and exit; + +use Sys::Syslog qw(:DEFAULT setlogsock); +setlogsock('unix'); # change to 'inet' for network logging +openlog ('oki4daemon', 'pid,cons,ndelay', 'lpr') + or die 'Unable to open syslog'; + +$SIG{__DIE__} = sub { + die @_ if $^S; + syslog 'err', @_; +}; + +sub death { + syslog 'notice', "Oki4daemon for $fifo exiting on signal"; + unlink "/var/run/oki4daemon"; + exit (0); +} + +$SIG{HUP} = \&death; +$SIG{INT} = \&death; +$SIG{QUIT} = \&death; + +close STDERR; +close STDOUT; +close STDIN; + +open RUN, ">/var/run/oki4daemon" + or die "Cannon open /var/run/oki4daemon"; +print RUN $$, "\n"; +close RUN; + +syslog 'notice', "Oki4drv daemon running on fifo $fifo"; + +while(1) { + + # First, make sure the printer is set to suspend properly... + open LPDEV, "> $device" + or die "Cannot open $device to write sleepstring"; + print LPDEV $sleepstring; + close LPDEV + or die "Cannot close $device after writing sleepstring"; + + # Now wait for jobs... + open FIFO, "< $fifo" + or die "Unable to open named pipe $fifo"; + + my ($papersize, $darkness, $paperweight, $graphics, $manual); + + # override default in oki4drv + $papersize = 'letter'; + + # Step 2: read beginning of job, until no @FAKEOKI options + my $firstline; + do { + $firstline = ; + + # could be options + if ($firstline =~ m!^\%FAKEOKI ([^=]+)=([^=]+)$!) { + my ($opt, $val) = ($1, $2); + chomp $val; + + if ($opt eq 'PAPERSIZE') { + if ($papersize eq 'a4' + or $papersize eq 'a5' + or $papersize eq 'a6' + or $papersize eq 'b5' + or $papersize eq 'letter' + or $papersize eq 'legal') { + + # kosher papersize + $papersize = $val; + } else { + syslog 'warn', "Bad papersize $val"; + } + } elsif ($opt eq 'DARKNESS') { + if ($val <= 2 and $val >= -2) { + $darkness = sprintf("%d", $val); + } else { + syslog 'warn', "Bad darkness $val"; + } + } elsif ($opt eq 'PAPERWEIGHT') { + if ($val <= 2 and $val >= -2) { + $paperweight = sprintf("%d", $val); + } else { + syslog 'warn', "Bad weight $val"; + } + } elsif ($opt eq 'GRAPHICS') { + if ($val eq 'ON') { + $graphics = 1; + } + } elsif ($opt eq 'MANUALFEED') { + if ($val eq 'ON') { + $manual = 1; + } + } + } + } until ($firstline !~ m%^\%FAKEOKI%); + + # Step 3: run oki4drv + my $okicommand = + sprintf('%s%s%s%s%s%s%s -', + $oki4drv, + " -o $device", + defined($manual) ? ' -m' : '', + defined($graphics) ? ' -g' : '', + defined($papersize) ? " -s $papersize" : '', + defined($paperweight) ? " -w $paperweight" : '', + defined($darkness) ? " -d $darkness" : ''); + + # print STDERR "running '$okicommand'\n"; + + open OKIDRV, "|$okicommand" + or die "Unable to run '$okicommand'"; + + # Step 4: stuff job into oki4drv + + my $linect = 1; + + print OKIDRV $firstline; + while () { + print OKIDRV $_; + $linect++; + } + + sleep 5; + close OKIDRV; + # should do: or die "Error closing '$okicommand'"; + # ...but this makes the daemon die for bad jobs + + # Repeat... + close FIFO; + sleep 5; + +} + + +sub help_and_die { + print STDERR "Usage $0 [-f fifo_path] [-o device_path]\n"; + exit(1); +} diff --text -r -N -u oki4linux-2.0/src/oki4daemon.init oki4linux-2.0-hacked/src/oki4daemon.init --- oki4linux-2.0/src/oki4daemon.init Wed Dec 31 19:00:00 1969 +++ oki4linux-2.0-hacked/src/oki4daemon.init Sun Oct 29 17:33:26 2000 @@ -0,0 +1,30 @@ +#!/bin/sh + +PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin +DAEMON=/usr/local/sbin/oki4daemon +PIDFILE=/var/spool/lpd/lpd.lock + +test -x $DAEMON -a -x /usr/local/sbin/oki4drv || exit 0 + +case "$1" in + start) + echo -n "Starting Oki4 Daemon: oki4daemon" + $DAEMON # any arguments? + echo "." + ;; + stop) + echo -n "Stopping Oki4 Daemon: oki4daemon" + PID=`cat $PIDFILE` + kill -INT $PID 2>/dev/null + echo "." + ;; + force-reload|restart) + $0 stop + $0 start + ;; + *) + echo "Usage: /etc/init.d/oki4daemon {start|stop|restart|force-reload}" + exit 1 +esac + +exit 0