Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: bruhn@aie.wu-wien.ac.at (Peter Bruhn)
Subject: Re: postcript printing
Date: 1996/04/26	[thread overview]
Message-ID: <BRUHN.96Apr26101854@aie.wu-wien.ac.at> (raw)
In-Reply-To: 4livqh$aqe@hobbes.cc.uga.edu


> From: lebo@bscr.uga.edu (Richard Lebo)
> Newsgroups: comp.unix.osf.osf1
> Date: 23 Apr 1996 16:17:21 GMT
> Organization: University of Georgia, Athens, Ga
> Reply-To: lebo@bscr.uga.edu
> 
> In article <317BE371.655F@spectratek.co.uk>, John Stewart <john_stewart@spectratek.co.uk> writes:
> >How can I print ascii files from a DEC Alpha (3.2c OSF) over ethernet to 
> >a postscript ethernet printer. I assume you need to modify /etc/printcap 
> >but how ?
> >
> >Thanks in advance.
> >-- 
> >John Stewart	

We have a postscript eathernet printer and do all kind of printing
(PS, ASCII). Our /etc/printcap on all machines except exaia:

ps3|HP LJ4SiMX with TCP/IP card:\
        :lp=:\
        :rm=exaia:\
        :rp=ps3:\
        :mx#0:\
        :sd=/usr/spool/lpd/ps3:

/etc/printcap on exaia:

ps3|HP LJ4SiMX with TCP/IP card:\
        :lp=/dev/null:sd=/usr/spool/lpd/ps3:\
        :lf=/usr/adm/lpd-errs:if=/usr/local/etc/ps3.pl:\
        :af=/usr/adm/lpd-acct:sh:mx#0:rw:

/usr/local/etc/ps3.pl is:

#!/usr/local/bin/perl
#
# $Log: tcpfilt.pl,v $
# Revision 1.2  1993/10/29  14:04:36  harlan
# We are doing the network handling now ourself. tcpcat is no longer
# used.
# The connect to the printers socket is monitored and a message is
# written to a status file (There is no way to find out which one to
# use... so its hard coded.)
# Also some major cleanup was done.
#
# Revision 1.1.1.1  1993/10/07  17:20:40  harlan
# Initial Cvs Revision of GeNUTools
#
#Revision 1.4  1993/09/28  18:19:56  harlan
#put also manualfeed true into the psfile for Manual Feed
#
#Revision 1.3  1993/09/22  18:35:31  harlan
#tcpfilt if invoked with 'manual' in the program name will
#add ps code to invoke the Manual Feeder...
#
#Revision 1.2  1993/09/10  10:45:47  harlan
#*** empty log message ***
#
#Revision 1.1  1993/07/28  13:23:01  harlan
#Initial revision
#
#
#
# filter for printing on a network printer.
#
#
# Copyright (C) 1993 GeNUA mbH Muenchen Germany
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for educational, research, and non-profit purposes and
# without fee is hereby granted, provided that the above copyright
# notice appear in all copies and that both that copyright notice and
# this permission notice appear in supporting documentation, and that
# the name of GeNUA mbH not be used in advertising or publicity pertaining
# to distribution of the software without specific, written prior permission.
# Permission to incorporate this software into commercial products can be
# obtained from GeNUA mbH, 8000 Muenchen 83, Leoprechtingstr. 13, Germany
# The GeNUA mbH makes no  representations about the suitability
# of this software for any purpose.  It is provided "as is" without express
# or implied warranty.
#

# Configure this
# status file
$status = "/tmp/status";

# Printer port
$PORT = 9100;

# Printer name
$HOST = "137.208.51.161";

# DVI to ps converter as $dvips < dvifile
$dvips = "/usr/local/bin/dvips -q -f ";

# Ascii to ps converter as $a2ps < asciifile
$a2ps  = "/usr/local/lib/psf/hp4si6";

################################################################
# dont edit below this line
################################################################

# $debug = 1;
if ( $debug ) {
    close(STDERR);
    open(STDERR,">>/tmp/tcpfilt.log");
    select(STDERR); $| = 1;
    select(STDOUT);
}

&debug("ARGV: <@ARGV>");

$SIG{'INT'} = 'clean_up';
$ENV{'PATH'} .= "/usr/local/bin:/usr/contrib/bin";
$PROGRAM = $0;

$prolog = &prolog();

@l = unpack('CCCC',$l);
@l_dvi = (223,223,223,223);

################ read in the body
while ( $n = read(STDIN,$x,1000) ) {
    $f = substr($x,0,4) unless $f;
    $l = substr($x,-5);
    $body .= $x;
    $N += $n;
}

&debug("read: <$N> bytes");

################ find out what file type we have and print
if ( $f =~ /^\%\!/ ) {
    &debug("PS");
    # is postscript
    &write_out($prolog,$body,$N);
}
elsif ( join('',@l) eq join('',@l_dvi) ) {
    &debug("DVI");
    &filter($dvips);
    &write_out($prolog,$body,$N);
}
else {
    &debug("TEXT");
    &filter($a2ps);
    &write_out($prolog,$body,$N);
}

################################################################
# cleanup what ever files are left.
################################################################
sub clean_up {
    if ( -f $tmp ) {
	unlink ($tmp);
    }
    exit;
}

################################################################
# run a filter over the body
################################################################
sub filter {
    local($com) = @_;
    &debug("filter: <$com>");

    $tmp = "/tmp/tcpfilt$$_$$";
    open(TMP,">$tmp") || die "Could not open tmp file $tmp: $!\n";
    if ( syswrite(TMP,$body,$N) != $N ) {
	die "did not write everything: $!\n";
    }
    close TMP;

    $N = 0;
    $body = '';
    open(FILT,"$com <$tmp |");
    while ( $n = read(FILT,$x,1000) ) {
	$body .= $x;
	$N += $n;
    }
    close(FILT);
    unlink($tmp);
}

################################################################
# write to the socket.
################################################################
sub write_out {
    local($prolog,$body,$N) = @_;
    
    &debug("write_out: <$prolog> <$N>");

    &net_setup();

    &debug(" $$ : Connect ok!");

    &status("Ready and printing\n");

    print S $prolog;
    if ( syswrite(S,$body,$N) != $N ) {
	die "did not write everything: $!\n";
    }
    print S "\004"; 
    close(S) || die "Could not close socket: $!\n";
}

################################################################
# write out a status message
################################################################
sub status {
    local($s) = @_;
    open(STAT,">$status") ||
	die "Could not open status file <$status>: $!\n";
    print STAT "$s";
    close(STAT);
}

################################################################
# debug
################################################################
sub debug {
    local($what) = @_;
    print STDERR "DEBUG: $what\n" if $debug;
}

################################################################
# return a proper prolog, depending on the program name
################################################################
sub prolog {
    &debug("PROGRAM: <$PROGRAM>");
    
    local($val);

    local($sb) = "statusdict begin";

    local($ts) = "statusdict /settrayswitch known " .
	"{ $sb false settrayswitch end } if\n";
    
    if ( $PROGRAM =~ m,upper, ) {
	$val .= "statusdict /setpapertray known " . 
	"{ $sb 0 setpapertray end } if\n";
    }
    if ( $PROGRAM =~ m,lower, ) {
	$val .= "statusdict /setpapertray known " . 
	"{ $sb 1 setpapertray end } if\n";
    }
    else {
	$val .= "statusdict /setpapertray known " . 
	"{ $sb 0 setpapertray end } if\n";
    }
    if ( $PROGRAM =~ m,duplex, ) {
	$val .= "statusdict /setduplexmode known " . 
	"{ $sb true setduplexmode end } if\n";
    }
    if ( $PROGRAM =~ m,booklet, ) {
	$val .= "statusdict /setduplexmode known " . 
	"{ $sb true setduplexmode end } if\n";
	$val .= "statusdict /settumble known " . 
	"{ $sb true settumble end } if\n";
    }
    if ( $PROGRAM =~ m,manual, ) {
	$val .= "statusdict /ManualFeed true put\n";
	$val .= "statusdict /manualfeed true put\n";
    }

    return "%!\n$ts$val";
}

################################################################
# set up the sockets
################################################################
sub net_setup {
    &debug("net_setup: <@_>");

    local($name,$al,$proto,$aliases,$type,$len,$thataddr,$that,$port);
    local($proto,$sockaddr,$AF_INET,$SOCK_STREAM);

    $port = $PORT; # | 9900;
    $AF_INET = 2;
    $SOCK_STREAM = 1;
    
    $sockaddr = 'S n a4 x8';
    chop($name = `hostname`);
    &debug("Got my hostname: <$name>");


    ($name,$al,$proto) = getprotobyname('tcp');
    &debug("Got protobyname: <$name>, protocol = $proto");

    ($name,$aliases,$type,$len,$thataddr) = 
	gethostbyname($HOST);# || die "gethostbyname";

    ($a1,$a2,$a3,$a4) = unpack('C4', $thataddr);
    &debug("his sockaddr: af $AF_INET, port $port @ $a1.$a2.$a3.$a4");

    $that = pack($sockaddr,$AF_INET,$port,$thataddr);
    
    socket(S,$AF_INET,$SOCK_STREAM,$proto ) || die "socket: $!";

    while ( ! connect(S,$that) ) {
	close(S);
	&debug("Connect failed: $!");
	if ( $! =~ /Connection timed out/ || $! =~ /Bad file descriptor/ ) {
	    &status("Printer turned off. Waiting for power on!\n");
	    sleep(60);
	}
	else {
	    &status("Printer currently printing....\n");
	    sleep(5);
	}
	socket(S,$AF_INET,$SOCK_STREAM,$proto ) || die "socket: $!";
    }
    return 1;
}

################################################################
# Bit fiddling
################################################################
sub addBits {
    local($fh) = @_;
    vec($fileDescs,fileno($fh),1) = 1;
}

sub delBits {
    local($fh) = @_;
    vec($fileDescs,fileno($fh),1) = 0;
}


Hope this helps,
Peter
-- 
Peter Bruhn             | Department of Applied Computer Science
                        | University of Economics and Business Administration
                        | Augasse 2-6, A-1090 Vienna, Austria
bruhn@wu-wien.ac.at     | Phone: +43 1 31336 x5209 fax: x739
------------------------> Code fast, execute young, and leave a pretty core!



      parent reply	other threads:[~1996-04-26  4:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-22  4:00 postcript printing John Stewart
1996-04-23  4:00 ` Richard Lebo
1996-04-24  4:00   ` Dean Darlison
1996-04-25  4:00   ` William R. Pearson
1996-04-26  4:00   ` Peter Bruhn [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox