File cups-novell.pl of Package ncpfs

#!/usr/bin/perl -w

#
# CUPS backend for printing to Novel Netware printers
#
# Copyright (c) 2003 SuSE Linux AG, Nuernberg, Germany.
#
# Author: Jiri Srain <jsrain@suse.cz>, 2003
#

$scheme = "novell";

if (@ARGV == 0)
{

   print "network $scheme \"Unknown\" \"Novell netware printers\"\n";
   exit 0;
}

   
# in case of wrong number of arguments: print usage hint
if (@ARGV != 5 && @ARGV != 6)
{
   print << 'EOF'
Usage: novell job-id user title copies options [file]
       example for device-URI: 'novell://user:pass@host/queue'

Install a printqueue with 'lpadmin -p <novell-printer-name>
-v <novell://user:pass@host/queue> -E

EOF
;
   exit 1;
}

if (defined ($ARGV[5]))
{
    $file = $ARGV[5];
}
else
{
    $file = "-";
}

# get file to which the job is "printed" from device URI, so
# so that you can use this backend multiple times, for various
# "novell" printers...

$uri = $ENV{"DEVICE_URI"};

if ($uri =~ /$scheme:\/\/.*:.*@.*/)
{
   $user = $pass = $hostqueue = $uri;
   $user =~ s/$scheme:\/\/(.*):.*@.*/$1/;
   $pass =~ s/$scheme:\/\/.*:(.*)@.*/$1/;
   $hostqueue =~ s/$scheme:\/\/.*:.*@(.*)/$1/;
}
elsif ($uri =~ /#scheme:\/\/.*@.*/)
{
   $user = $hostqueue = $uri;
   $user =~ s/$scheme:\/\/(.*)@.*/$1/;
   $hostqueue =~ s/$scheme:\/\/.*@(.*)/$1/;
}
else
{
   $hostqueue = $uri;
   $hostqueue =~ s/$scheme:\/\/(.*)/$1/;
}

$host = $queue = $hostqueue;
$host =~ s/([^\/]*)\/.*/$1/;
$queue =~ s/[^\/]*\/(.*)/$1/;

my $cmdln = "nprint -S $host -q $queue";

if (defined ($user))
{
    $cmdln = "$cmdln -U $user";
}
if (defined ($pass))
{
    $cmdln = "$cmdln -P $pass";
}

$cmdln = "$cmdln $file >&2";

my $exit = system ($cmdln);
if ($exit != 0)
{
    print STDERR "ERROR: Error occurred while executing $cmdln";
}
exit $exit;
openSUSE Build Service is sponsored by