"Fossies" - the Fresh Open Source Software Archive

Member "foomatic-db-engine-4.0-20221101/foomatic-cleanupdrivers.in" (1 Nov 2022, 1364 Bytes) of package /linux/misc/foomatic-db-engine-4.0-20221101.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!@PERL@
    2 # -*- perl -*-
    3 
    4 # This is foomatic-cleanupdrivers. It removes all driver XML files
    5 # which have an empty command line. So one can avoid that "unusable"
    6 # printer/driver combos are shown in frontends. This program also runs
    7 # when Foomatic is not installed.
    8 
    9 use Foomatic::Defaults;
   10 if ($#ARGV > -1) {
   11     $libdir = $ARGV[0];
   12 } elsif ($ENV{FOOMATICDB}) {
   13     $libdir = $ENV{FOOMATICDB};
   14 } elsif (!$libdir) {
   15     $libdir = "/usr/share/foomatic";
   16 }
   17 
   18 # Read out the program name with which we were called, but discard the path
   19 $0 =~ m!/([^/]+)\s*$!;
   20 $progname = $1;
   21 
   22 # Read the directory with the driver's XML entries
   23 opendir DRIVERDIR, "$libdir/db/source/driver" ||
   24     die "Cannot open driver XML directory!\n";
   25 my $driver;
   26 while ($driver = readdir(DRIVERDIR)) {
   27     open DRIVERENTRY, "< $libdir/db/source/driver/$driver" || die "   Database entry for the driver $driver cannot be read!\n";
   28     my @driverentryfield = <DRIVERENTRY>;
   29     close DRIVERENTRY;
   30     my $driverentry = join ('', @driverentryfield);
   31     next unless $driverentry;
   32     if (($driverentry =~ m!<prototype>\s*</prototype>!sg) ||
   33 	($driverentry =~ m!<prototype\s*/\s*>!sg) ||
   34 	($driverentry !~ m!<prototype[>/\s]!sg)) {
   35 	unlink("$libdir/db/source/driver/$driver") ||
   36 	    die "Cannot delete $driver!\n";
   37 	print "$driver has an empty command line, deleted!\n";
   38     }
   39 }
   40 closedir DRIVERDIR;