Tim Waugh c6c2bc
diff -up foomatic-db-engine-3.0-20080710/configure.ac.ppdload foomatic-db-engine-3.0-20080710/configure.ac
Tim Waugh c6c2bc
--- foomatic-db-engine-3.0-20080710/configure.ac.ppdload	2008-09-02 13:31:19.000000000 +0100
Tim Waugh c6c2bc
+++ foomatic-db-engine-3.0-20080710/configure.ac	2008-09-02 13:31:19.000000000 +0100
Tim Waugh c6c2bc
@@ -295,7 +295,7 @@ AC_OUTPUT(Makefile makeDefaults makeMan
Tim Waugh c6c2bc
 foomatic-configure foomatic-printjob foomatic-kitload
Tim Waugh c6c2bc
 foomatic-ppdfile foomatic-preferred-driver foomatic-cleanupdrivers
Tim Waugh c6c2bc
 foomatic-getpjloptions foomatic-addpjloptions
Tim Waugh c6c2bc
-foomatic-compiledb foomatic-fix-xml
Tim Waugh c6c2bc
+foomatic-compiledb foomatic-fix-xml foomatic-ppdload
Tim Waugh c6c2bc
 foomatic-nonumericalids foomatic-replaceoldprinterids
Tim Waugh c6c2bc
 foomatic-ppd-options foomatic-printermap-to-gutenprint-xml
Tim Waugh c6c2bc
 foomatic-extract-text foomatic-searchprinter
Tim Waugh c6c2bc
diff -up /dev/null foomatic-db-engine-3.0-20080710/foomatic-ppdload.8.in
Tim Waugh c6c2bc
--- /dev/null	2008-09-02 08:50:58.290000634 +0100
Tim Waugh c6c2bc
+++ foomatic-db-engine-3.0-20080710/foomatic-ppdload.8.in	2008-09-02 13:31:19.000000000 +0100
Tim Waugh c6c2bc
@@ -0,0 +1,47 @@
Tim Waugh c6c2bc
+.\" This -*- nroff -*- source file is part of foomatic.
Tim Waugh c6c2bc
+.\"
Tim Waugh c6c2bc
+.TH FOOMATIC-PPDLOAD 8 "2001-05-07" "Foomatic Project"
Tim Waugh c6c2bc
+.SH NAME
Tim Waugh c6c2bc
+foomatic-ppdload \- <put a short description here>
Tim Waugh c6c2bc
+.SH SYNOPSIS
Tim Waugh c6c2bc
+.B foomatic-ppdload \-h
Tim Waugh c6c2bc
+
Tim Waugh c6c2bc
+.B foomatic-ppdload
Tim Waugh c6c2bc
+\fIfilename.ppd printer-id\fR
Tim Waugh c6c2bc
+
Tim Waugh c6c2bc
+.B foomatic-ppdload \-R
Tim Waugh c6c2bc
+\fIprinter-id\fR
Tim Waugh c6c2bc
+
Tim Waugh c6c2bc
+.SH DESCRIPTION
Tim Waugh c6c2bc
+.B foomatic-ppdload
Tim Waugh c6c2bc
+takes a ppd filename and a printer ID as arguments.  It
Tim Waugh c6c2bc
+parses a PPD file and writes option data into the foomatic database
Tim Waugh c6c2bc
+for use with the foomatic "ppd" driver and that printer.
Tim Waugh c6c2bc
+
Tim Waugh c6c2bc
+With the \fB-R\fR option you can remove a printer from the "ppd"
Tim Waugh c6c2bc
+driver, and with \fB-h\fR a short help text is shown.
Tim Waugh c6c2bc
+
Tim Waugh c6c2bc
+Right now, it will handle Boolean and PickOne options that go in the
Tim Waugh c6c2bc
+Prolog, DocumentSetup, or PageSetup spots.  Also, PPD interoption
Tim Waugh c6c2bc
+constraints (not to be confused with foomatic option to printer and
Tim Waugh c6c2bc
+driver mapping constraints) are not supported by foomatic.  And of
Tim Waugh c6c2bc
+course, the interesting color and font information from the PPD has
Tim Waugh c6c2bc
+no place in the current foomatic schema.  All this will change over
Tim Waugh c6c2bc
+time.
Tim Waugh c6c2bc
+
Tim Waugh c6c2bc
+
Tim Waugh c6c2bc
+.\".SH SEE ALSO
Tim Waugh c6c2bc
+.\".IR foomatic-XXX (1),
Tim Waugh c6c2bc
+
Tim Waugh c6c2bc
+.SH EXIT STATUS
Tim Waugh c6c2bc
+.B foomatic-ppdload
Tim Waugh c6c2bc
+returns ...
Tim Waugh c6c2bc
+
Tim Waugh c6c2bc
+.SH AUTHOR
Tim Waugh c6c2bc
+Manfred Wassmann <\fImanolo@NCC-1701.B.Shuttle.de\fR> for the foomatic
Tim Waugh c6c2bc
+project using output from the associated binary.
Tim Waugh c6c2bc
+
Tim Waugh c6c2bc
+.SH BUGS
Tim Waugh c6c2bc
+There are several limitations, but it's an interesting experiment.
Tim Waugh c6c2bc
+
Tim Waugh c6c2bc
+Please send bug reports to foomatic-devel@linuxprinting.org.
Tim Waugh c6c2bc
diff -up /dev/null foomatic-db-engine-3.0-20080710/foomatic-ppdload.in
Tim Waugh c6c2bc
--- /dev/null	2008-09-02 08:50:58.290000634 +0100
Tim Waugh c6c2bc
+++ foomatic-db-engine-3.0-20080710/foomatic-ppdload.in	2008-09-02 13:31:19.000000000 +0100
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
+}
Tim Waugh c6c2bc
diff -up foomatic-db-engine-3.0-20080710/Makefile.in.ppdload foomatic-db-engine-3.0-20080710/Makefile.in
Tim Waugh c6c2bc
--- foomatic-db-engine-3.0-20080710/Makefile.in.ppdload	2008-07-10 08:20:10.000000000 +0100
Tim Waugh c6c2bc
+++ foomatic-db-engine-3.0-20080710/Makefile.in	2008-09-02 13:31:19.000000000 +0100
Tim Waugh c6c2bc
@@ -147,6 +147,7 @@ AC_OUTPUT_FILES:=Makefile makeDefaults m
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 \
Tim Waugh c6c2bc
 	foomatic-ppd-options foomatic-printermap-to-gutenprint-xml \
Tim Waugh c6c2bc
 	foomatic-extract-text foomatic-searchprinter
Tim Waugh c6c2bc
@@ -158,7 +159,7 @@ BINFILES:=foomatic-printjob foomatic-con
Tim Waugh c6c2bc
 	foomatic-ppd-options foomatic-searchprinter
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 \
Tim Waugh c6c2bc
 	foomatic-nonumericalids foomatic-replaceoldprinterids \