summaryrefslogtreecommitdiffstats
path: root/perl-install/printer
diff options
context:
space:
mode:
authorTill Kamppeter <tkamppeter@mandriva.com>2005-02-09 02:22:20 +0000
committerTill Kamppeter <tkamppeter@mandriva.com>2005-02-09 02:22:20 +0000
commit58551a88694dde4a93d04e7b45781b554a17b4c2 (patch)
tree01f4c4233a703db49d3672ccca34a47df41e4c8b /perl-install/printer
parent7d130d0e83bd8376ac737e8952c2c4097637344c (diff)
downloaddrakx-58551a88694dde4a93d04e7b45781b554a17b4c2.tar
drakx-58551a88694dde4a93d04e7b45781b554a17b4c2.tar.gz
drakx-58551a88694dde4a93d04e7b45781b554a17b4c2.tar.bz2
drakx-58551a88694dde4a93d04e7b45781b554a17b4c2.tar.xz
drakx-58551a88694dde4a93d04e7b45781b554a17b4c2.zip
Added subroutine to parse HPLIP device database XML file.
Diffstat (limited to 'perl-install/printer')
-rw-r--r--perl-install/printer/main.pm115
1 files changed, 115 insertions, 0 deletions
diff --git a/perl-install/printer/main.pm b/perl-install/printer/main.pm
index 3d78ebfbd..796a72e88 100644
--- a/perl-install/printer/main.pm
+++ b/perl-install/printer/main.pm
@@ -2238,6 +2238,121 @@ sub autodetectionentry_for_uri {
#
# ------------------------------------------------------------------
+sub read_hplip_db {
+
+ # Read the device database XML file which comes with the HPLIP
+ # package
+ open(my $F, "< $::prefix/usr/share/hplip/data/xml/models.xml") or
+ die "Could not read /usr/share/hplip/data/xml/models.xml\n";
+
+ my $entry = {};
+ my $inentry = 0;
+ my $inrX = 0;
+ my $incomment = 0;
+ my %hplipdevices;
+ local $_;
+ while (<$F>) {
+ chomp;
+ if ($incomment) {
+ # In a comment block, skip all except the end of the comment
+ if (m!^(.*?)-->(.*)$!) {
+ # End of comment, keep rest of line
+ $_ = $2;
+ $incomment = 0;
+ } else {
+ # Skip line
+ $_ = '';
+ }
+ } else {
+ while (m/^(.*?)<!--(.*?)-->(.*)$/) {
+ # Remove one-line comments
+ $_ = $1 . $3;
+ }
+ if (m/^(.*?)<!--(.*)$/) {
+ # Start of comment, keep the beginning of the line
+ $_ = $1;
+ $incomment = 1;
+ }
+ }
+ # Is there some non-comment part left in the line
+ if (m!\S!) {
+ if ($inentry) {
+ # We are inside a device entry
+ if ($inrX) {
+ # We are in one of the the device's <rX> sections,
+ # skip the section
+ if (m!^\s*</r\d+>\s*$!) {
+ # End of <rX> section
+ $inrX = 0;
+ }
+ } else {
+ if (m!^\s*<r\d+>\s*$!) {
+ # Start of <rX> section
+ $inrX = 1;
+ } elsif (m!^\s*</model>\s*$!) {
+ # End of device entry
+ $inentry = 0;
+ my $devidmodel;
+ if ($entry->{$devidmodel}) {
+ $devidmodel = $entry->{devidmodel};
+ $devidmodel =~ s/ /_/g;
+ } else {
+ $devidmodel = $entry->{model};
+ }
+ $hplipdevices{$devidmodel} = $entry;
+ $entry = {};
+ } elsif (m!^\s*<id>\s*([^<>]+)\s*</id>\s*$!) {
+ # Full ID string
+ my $idstr = $1;
+ $idstr =~ m!(MFG|MANUFACTURER):([^;]+);!i
+ and $entry->{devidmake} = $2;
+ $idstr =~ m!(MDL|MODEL):([^;]+);!i
+ and $entry->{devidmodel} = $2;
+ $idstr =~ m!(DES|DESCRIPTION):([^;]+);!i
+ and $entry->{deviddesc} = $2;
+ $idstr =~ m!(CMD|COMMAND\s*SET):([^;]+);!i
+ and $entry->{devidcmdset} = $2;
+ } elsif (m!^\s*<align type="(\d+)"/>\s*$!) {
+ # Head alignment type
+ $entry->{align} = $1;
+ } elsif (m!^\s*<clean type="(\d+)"/>\s*$!) {
+ # Head cleaning type
+ $entry->{clean} = $1;
+ } elsif (m!^\s*<color-cal type="(\d+)"/>\s*$!) {
+ # Color calibration type
+ $entry->{colorcal} = $1;
+ } elsif (m!^\s*<status type="(\d+)"/>\s*$!) {
+ # Status request type
+ $entry->{status} = $1;
+ } elsif (m!^\s*<scan type="(\d+)"/>\s*$!) {
+ # Scanner access type
+ $entry->{scan} = $1;
+ } elsif (m!^\s*<fax type="(\d+)"/>\s*$!) {
+ # Fax access type
+ $entry->{fax} = $1;
+ } elsif (m!^\s*<pcard type="(\d+)"/>\s*$!) {
+ # Memory card access type
+ $entry->{card} = $1;
+ } elsif (m!^\s*<copy type="(\d+)"/>\s*$!) {
+ # Copier access type
+ $entry->{copy} = $1;
+ }
+ }
+ } else {
+ # We are not in a printer entry
+ if (m!^\s*<\s*model\s+name=\"(\S+)\"\a*>\s*$!) {
+ $inentry = 1;
+ # HPLIP model ID
+ $entry->{model} = $1;
+ }
+ }
+ }
+ }
+ close $F;
+ return \%hplipdevices;
+}
+
+
sub configure_hpoj {
my ($device, @autodetected) = @_;