summaryrefslogtreecommitdiff
path: root/foomatic-searchprinter.in
blob: 747dc5e4232515c9dd8eded12f09a16c4a0b9c3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!@PERL@
# -*- Perl -*-

#
# This script searches for printers in the database. You can give the
# printer manufacturer and model names or the IEEE-1284 device ID of
# the printer. You will get one or more results sorted by how well they
# match. Exact metch of the model-identifying parts of the IEEE-1284 device ID
# counts highest. Run "foomatic-addpjloptions -h" to get help.
#
 
#
# Till Kamppeter (till.kamppeter@gmail.com)
#
# Copyright 2007 Till Kamppeter
#
# This software may be freely redistributed under the terms of the GNU
# General Public License (http://www.gnu.org/).
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
 
use strict;
use FileHandle;

sub usage(){
    print STDERR <<EOF;
Usage: foomatic-searchprinter [-mM] [-dD] <search term>
       foomatic-searchprinter -h

   <search term>: Manufacturer/model, separated by a space or a '|',
                  IEEE-1284 device ID, manufacturer, model, Foomatic
		  printer ID, or parts of any of the mentioned items

   -mM            Search mode:
                  M = 0: Match everything (default)
                  M = 1: No matches on only the manufacturer
                  M = 2: No matches on only the manufacturer or only the model
                  M = 3: Exact matches of device ID, make/model, or Foomatic ID
                         plus matches of the page description language in the
			 device ID to appropriate "Generic" printers
                  M = 4: Exact matches of device ID, make/model, or Foomatic ID
                         only
    
   -dD            Display results
                  D = 0: Everything
		  D = 1: Only best match class (default)
		  D = 2: Only best match

   -h             This help message

EOF

    exit(1);
}

# Read command line options
use Getopt::Std;
# Help
my $opt = {};
getopts("m:d:h",$opt) || usage();

# Show usage info
if ($opt->{h}) {
    usage();
}

# Options
my $mode = 0;
if (defined($opt->{m})) {
    $mode = $opt->{m};
    usage() if ($mode < 0) || ($mode > 4);
}

my $output = 1;
if (defined($opt->{d})) {
    $output = $opt->{d};
    usage() if ($output < 0) || ($output > 2);
}


# Search term
my $searchterm = join(' ', @ARGV);
usage() if !$searchterm;

use Foomatic::Defaults;
use Foomatic::DB;

my $db = new Foomatic::DB;

print join("\n", $db->find_printer($searchterm, $mode, $output)) . "\n";