cvsdist 9435e6
--- foomatic-db-engine-3.0-20031217/foomatic-ppdload.in.ppdload	2003-12-19 15:26:40.360620848 +0000
cvsdist 9435e6
+++ foomatic-db-engine-3.0-20031217/foomatic-ppdload.in	2003-12-19 15:26:56.289725866 +0000
cvsdist 9435e6
@@ -0,0 +1,118 @@
cvsdist 9435e6
+#!@PERL@
cvsdist 9435e6
+
cvsdist 9435e6
+use Getopt::Std;
cvsdist 9435e6
+getopts("hdR:");
cvsdist 9435e6
+help() if $opt_h;
cvsdist 9435e6
+
cvsdist 9435e6
+use Foomatic::PPD;
cvsdist 9435e6
+use Foomatic::Defaults;
cvsdist 9435e6
+
cvsdist 9435e6
+my $file;
cvsdist 9435e6
+my $printer;
cvsdist 9435e6
+
cvsdist 9435e6
+if ($opt_R) { # Remove entry
cvsdist 9435e6
+    $printer = $opt_R;
cvsdist 9435e6
+} else { # Add entry
cvsdist 9435e6
+    $file = $ARGV[0];
cvsdist 9435e6
+    $printer = $ARGV[1];
cvsdist 9435e6
+}
cvsdist 9435e6
+
cvsdist 9435e6
+if (!$opt_R) { # Add entry
cvsdist 9435e6
+
cvsdist 9435e6
+    if (! -f "$libdir/db/source/printer/$printer.xml") {
cvsdist 9435e6
+	die "Printer $printer does not seem to exist in the database!\n";
cvsdist 9435e6
+    }
cvsdist 9435e6
+
cvsdist 9435e6
+    if (! -f $file) {
cvsdist 9435e6
+	die "The PPD file you specified, $file, does not seem to exist!\n";
cvsdist 9435e6
+    }
cvsdist 9435e6
+
cvsdist 9435e6
+    # Load the PPD
cvsdist 9435e6
+    my $p = new Foomatic::PPD $file, $printer;
cvsdist 9435e6
+
cvsdist 9435e6
+    if ($opt_d) {
cvsdist 9435e6
+	# Parser PPD structure dump
cvsdist 9435e6
+	use Data::Dumper;
cvsdist 9435e6
+	local $Data::Dumper::Purity=1;
cvsdist 9435e6
+	local $Data::Dumper::Indent=1;
cvsdist 9435e6
+	print Dumper($p);
cvsdist 9435e6
+    } else {
cvsdist 9435e6
+	# Normal behavior, save as various option files by ID
cvsdist 9435e6
+	my @opts = $p->foo_options();
cvsdist 9435e6
+	for (@opts) {
cvsdist 9435e6
+	    my ($id, $xml) = ($_->{'id'}, $_->{'xml'});
cvsdist 9435e6
+	    
cvsdist 9435e6
+	    my $ofile = "$libdir/db/source/opt/$id.xml";
cvsdist 9435e6
+	    open TMP, ">$ofile" or die "Cannot write $ofile!\n";
cvsdist 9435e6
+	    print STDERR "Writing $ofile\n";
cvsdist 9435e6
+	    print TMP join('',@{$xml});
cvsdist 9435e6
+	    close TMP;
cvsdist 9435e6
+	}
cvsdist 9435e6
+	
cvsdist 9435e6
+	# Add this printer to the ppd driver
cvsdist 9435e6
+
cvsdist 9435e6
+	# Read the driver entry file
cvsdist 9435e6
+	open PPDENTRY, "< $libdir/db/source/driver/ppd.xml" or
cvsdist 9435e6
+	    die "Cannot read $libdir/db/source/driver/ppd.xml!\n";
cvsdist 9435e6
+	print STDERR "Reading $libdir/db/source/driver/ppd.xml\n";
cvsdist 9435e6
+	$ppdentry = join('', <PPDENTRY>);
cvsdist 9435e6
+	close PPDENTRY;
cvsdist 9435e6
+	
cvsdist 9435e6
+	# Either we've got it already
cvsdist 9435e6
+	my $found =
cvsdist 9435e6
+	    ($ppdentry =~ m!<id>[\s\n]*printer/$printer[\s\n]*</id>!s);
cvsdist 9435e6
+	
cvsdist 9435e6
+	# Or we need to append a new item and write the file
cvsdist 9435e6
+	if (! $found) {
cvsdist 9435e6
+	    $ppdentry =~ s!^(\s*)</printers>!$1  <printer>\n$1    <id>printer/$printer</id>\n$1  </printer>\n$1</printers>!m;
cvsdist 9435e6
+	    open PPDENTRY, "> $libdir/db/source/driver/ppd.xml" or
cvsdist 9435e6
+		die "Cannot write $libdir/db/source/driver/ppd.xml!\n";
cvsdist 9435e6
+	    print STDERR "Writing $libdir/db/source/driver/ppd.xml\n";
cvsdist 9435e6
+	    print PPDENTRY $ppdentry;
cvsdist 9435e6
+	    close PPDENTRY;
cvsdist 9435e6
+	} else {
cvsdist 9435e6
+	    print STDERR "Printer $printer already registered as supported by the \"ppd\" driver!\n";
cvsdist 9435e6
+	}
cvsdist 9435e6
+    }
cvsdist 9435e6
+} else { # Remove entry
cvsdist 9435e6
+    # Read the driver entry file
cvsdist 9435e6
+    open PPDENTRY, "< $libdir/db/source/driver/ppd.xml" or
cvsdist 9435e6
+	die "Cannot read $libdir/db/source/driver/ppd.xml!\n";
cvsdist 9435e6
+    print STDERR "Reading $libdir/db/source/driver/ppd.xml\n";
cvsdist 9435e6
+    $ppdentry = join('', <PPDENTRY>);
cvsdist 9435e6
+    close PPDENTRY;
cvsdist 9435e6
+	
cvsdist 9435e6
+    # Do we have the requested entry?
cvsdist 9435e6
+    my $found =
cvsdist 9435e6
+	($ppdentry =~ m!<id>[\s\n]*printer/$printer[\s\n]*</id>!s);
cvsdist 9435e6
+    
cvsdist 9435e6
+    # Then we have to remove it and to write the file
cvsdist 9435e6
+    if ($found) {
cvsdist 9435e6
+	$ppdentry =~ s!\n+\s*<printer>[\s\n]*<id>printer/$printer</id>[\s\n]*</printer>\s*\n+!\n!sg;
cvsdist 9435e6
+	open PPDENTRY, "> $libdir/db/source/driver/ppd.xml" or
cvsdist 9435e6
+	    die "Cannot write $libdir/db/source/driver/ppd.xml!\n";
cvsdist 9435e6
+	print STDERR "Writing $libdir/db/source/driver/ppd.xml\n";
cvsdist 9435e6
+	print PPDENTRY $ppdentry;
cvsdist 9435e6
+	close PPDENTRY;
cvsdist 9435e6
+    } else {
cvsdist 9435e6
+	print STDERR "Printer $printer not registered as supported by the \"ppd\" driver!\n";
cvsdist 9435e6
+    }
cvsdist 9435e6
+    # Remove the option entries
cvsdist 9435e6
+    system("rm -f $libdir/db/source/opt/ppd-${printer}-*.xml");
cvsdist 9435e6
+}
cvsdist 9435e6
+
cvsdist 9435e6
+exit(0);
cvsdist 9435e6
+
cvsdist 9435e6
+sub help {
cvsdist 9435e6
+    select STDERR;
cvsdist 9435e6
+    print "\n";
cvsdist 9435e6
+    print "Usage: foomatic-ppdload filename.ppd printer-id\n";
cvsdist 9435e6
+    print "       foomatic-ppdload -R printer-id\n";
cvsdist 9435e6
+    print "\n";
cvsdist 9435e6
+    print "       The first form adds the printer with the ID printer-id\n";
cvsdist 9435e6
+    print "       and the PPD file filename.ppd to the \"ppd\" driver,\n";
cvsdist 9435e6
+    print "       the second form removes the printer with the ID\n";
cvsdist 9435e6
+    print "       printer-id from the \"ppd\" driver.\n";
cvsdist 9435e6
+    print "\n";
cvsdist 9435e6
+    exit(1);
cvsdist 9435e6
+}
cvsdist 9435e6
--- foomatic-db-engine-3.0-20031217/foomatic-ppdload.8.in.ppdload	2003-12-19 15:26:45.290034426 +0000
cvsdist 9435e6
+++ foomatic-db-engine-3.0-20031217/foomatic-ppdload.8.in	2003-12-19 15:26:56.034756198 +0000
cvsdist 9435e6
@@ -0,0 +1,47 @@
cvsdist 9435e6
+.\" This -*- nroff -*- source file is part of foomatic.
cvsdist 9435e6
+.\"
cvsdist 9435e6
+.TH FOOMATIC-PPDLOAD 8 "2001-05-07" "Foomatic Project"
cvsdist 9435e6
+.SH NAME
cvsdist 9435e6
+foomatic-ppdload \- <put a short description here>
cvsdist 9435e6
+.SH SYNOPSIS
cvsdist 9435e6
+.B foomatic-ppdload \-h
cvsdist 9435e6
+
cvsdist 9435e6
+.B foomatic-ppdload
cvsdist 9435e6
+\fIfilename.ppd printer-id\fR
cvsdist 9435e6
+
cvsdist 9435e6
+.B foomatic-ppdload \-R
cvsdist 9435e6
+\fIprinter-id\fR
cvsdist 9435e6
+
cvsdist 9435e6
+.SH DESCRIPTION
cvsdist 9435e6
+.B foomatic-ppdload
cvsdist 9435e6
+takes a ppd filename and a printer ID as arguments.  It
cvsdist 9435e6
+parses a PPD file and writes option data into the foomatic database
cvsdist 9435e6
+for use with the foomatic "ppd" driver and that printer.
cvsdist 9435e6
+
cvsdist 9435e6
+With the \fB-R\fR option you can remove a printer from the "ppd"
cvsdist 9435e6
+driver, and with \fB-h\fR a short help text is shown.
cvsdist 9435e6
+
cvsdist 9435e6
+Right now, it will handle Boolean and PickOne options that go in the
cvsdist 9435e6
+Prolog, DocumentSetup, or PageSetup spots.  Also, PPD interoption
cvsdist 9435e6
+constraints (not to be confused with foomatic option to printer and
cvsdist 9435e6
+driver mapping constraints) are not supported by foomatic.  And of
cvsdist 9435e6
+course, the interesting color and font information from the PPD has
cvsdist 9435e6
+no place in the current foomatic schema.  All this will change over
cvsdist 9435e6
+time.
cvsdist 9435e6
+
cvsdist 9435e6
+
cvsdist 9435e6
+.\".SH SEE ALSO
cvsdist 9435e6
+.\".IR foomatic-XXX (1),
cvsdist 9435e6
+
cvsdist 9435e6
+.SH EXIT STATUS
cvsdist 9435e6
+.B foomatic-ppdload
cvsdist 9435e6
+returns ...
cvsdist 9435e6
+
cvsdist 9435e6
+.SH AUTHOR
cvsdist 9435e6
+Manfred Wassmann <\fImanolo@NCC-1701.B.Shuttle.de\fR> for the foomatic
cvsdist 9435e6
+project using output from the associated binary.
cvsdist 9435e6
+
cvsdist 9435e6
+.SH BUGS
cvsdist 9435e6
+There are several limitations, but it's an interesting experiment.
cvsdist 9435e6
+
cvsdist 9435e6
+Please send bug reports to foomatic-devel@linuxprinting.org.
cvsdist 9435e6
--- foomatic-db-engine-3.0-20031217/configure.in.ppdload	2003-12-19 15:27:03.188905120 +0000
cvsdist 9435e6
+++ foomatic-db-engine-3.0-20031217/configure.in	2003-12-19 15:27:21.165766554 +0000
cvsdist 9435e6
@@ -280,7 +280,7 @@
cvsdist 9435e6
 foomatic-configure foomatic-printjob foomatic-kitload
cvsdist 9435e6
 foomatic-ppdfile foomatic-preferred-driver foomatic-cleanupdrivers
cvsdist 9435e6
 foomatic-getpjloptions foomatic-addpjloptions
cvsdist 9435e6
-foomatic-compiledb foomatic-fix-xml
cvsdist 9435e6
+foomatic-compiledb foomatic-fix-xml foomatic-ppdload
cvsdist 9435e6
 foomatic-nonumericalids foomatic-replaceoldprinterids
cvsdist 9435e6
 foomatic-ppd-options
cvsdist 9435e6
 )
cvsdist 9435e6
--- foomatic-db-engine-3.0-20031217/Makefile.in.ppdload	2003-12-19 15:27:25.217284580 +0000
cvsdist 9435e6
+++ foomatic-db-engine-3.0-20031217/Makefile.in	2003-12-19 15:28:09.349034667 +0000
cvsdist 9435e6
@@ -145,6 +145,7 @@
cvsdist 9435e6
 	foomatic-kitload foomatic-ppdfile foomatic-preferred-driver \
cvsdist 9435e6
 	foomatic-cleanupdrivers foomatic-getpjloptions \
cvsdist 9435e6
 	foomatic-addpjloptions foomatic-compiledb foomatic-fix-xml \
cvsdist 9435e6
+	foomatic-ppdload \
cvsdist 9435e6
 	foomatic-nonumericalids foomatic-replaceoldprinterids \
cvsdist 9435e6
 	foomatic-ppd-options
cvsdist 9435e6
 
cvsdist 9435e6
@@ -155,7 +156,7 @@
cvsdist 9435e6
 	foomatic-ppd-options
cvsdist 9435e6
 
cvsdist 9435e6
 # Administrative commands, only useful for admins
cvsdist 9435e6
-SBINFILES:=foomatic-kitload \
cvsdist 9435e6
+SBINFILES:=foomatic-kitload foomatic-ppdload \
cvsdist 9435e6
 	foomatic-getpjloptions foomatic-addpjloptions \
cvsdist 9435e6
 	foomatic-preferred-driver foomatic-fix-xml \
cvsdist 9435e6
 	foomatic-nonumericalids foomatic-replaceoldprinterids