summaryrefslogtreecommitdiff
path: root/tools/epson2usb.pl
blob: 6d542d7b46567a5d396c3c1a33ed1af0e40d4323 (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
#!/usr/bin/perl -w

# Creates an USB device list from the description file
#
# epson2usb.pl doc/descriptions/epson2.desc
#
# Copyright (C) 2010 Tower Technologies
# Author: Alessandro Zummo <a.zummo@towertech.it>
#
# This file is part of the SANE package.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, version 2.

use strict;
use warnings;

	my %ids;
	my @models;
	my $i = 0;

	while (<>) {

		my $flip = /^:model/ ... /^$/;

		$models[$i]{$1} = $2
			if /^:(\w+)\s+(.+)/;

		$i++
			if $flip =~ /E0$/;
	}

	foreach my $m (@models) {

		next unless defined $m->{'usbid'};
		next if $m->{'status'} eq ':unsupported';

#		print $m->{'model'} , "\n";
#		print "-", $m->{'usbid'} , "-\n";

		next unless $m->{'usbid'} =~ /"0x04b8"\s+"(0x[[:xdigit:]]+)"/;

		my $id = $1;

#		print $id, "\n";

		$id =~ s/0x0/0x/;

		$m->{'model'} =~ s/;.+$//;
		$m->{'model'} =~ s/\"//g;
		$m->{'model'} =~ s/\s+$//;

		push(@{$ids{$id}}, $m->{'model'});
	}

	foreach (sort keys %ids) {
		print '  ', $_, ', /* ';
		print join(', ', @{$ids{$_}});
		print " */\n";
	}