]> git.donarmstrong.com Git - bin.git/blob - scan_stuff
add a VERBOSE flag to getmail
[bin.git] / scan_stuff
1 #!/usr/bin/perl
2 # scan_stuff scans papers
3 # and is released under the terms of the GNU GPL version 3, or any
4 # later version, at your option. See the file README and COPYING for
5 # more information.
6 # Copyright 2014 by Don Armstrong <don@donarmstrong.com>.
7
8
9 use warnings;
10 use strict;
11
12 use Getopt::Long;
13 use Pod::Usage;
14
15 =head1 NAME
16
17 scan_stuff - scans papers
18
19 =head1 SYNOPSIS
20
21 scan_stuff [options]
22
23  Options:
24    --debug, -d debugging level (Default 0)
25    --help, -h display this help
26    --man, -m display manual
27
28 =head1 OPTIONS
29
30 =over
31
32 =item B<--debug, -d>
33
34 Debug verbosity. (Default 0)
35
36 =item B<--help, -h>
37
38 Display brief usage information.
39
40 =item B<--man, -m>
41
42 Display this manual.
43
44 =back
45
46 =head1 EXAMPLES
47
48 scan_stuff
49
50 =cut
51
52
53 use vars qw($DEBUG);
54
55 my %options = (device          => 'fujitsu',
56                debug           => 0,
57                help            => 0,
58                man             => 0,
59                mode            => 'Gray'
60               );
61
62 GetOptions(\%options,
63            'duplex!',
64            'simplex!',
65            'mode=s',
66            'debug|d+','help|h|?','man|m');
67
68 pod2usage() if $options{help};
69 pod2usage({verbose=>2}) if $options{man};
70
71 $DEBUG = $options{debug};
72
73 my @USAGE_ERRORS;
74 my $use_duplex = 1;
75 if (exists $options{duplex} and exists $options{simplex} and
76     not ($options{duplex} xor $options{simplex})) {
77     push @USAGE_ERRORS,"Conflicting --duplex and --simplex options given";
78 }
79
80 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
81
82
83 if ((exists $options{duplex} and not $options{duplex}) or
84     (exists $options{simplex} and $options{simplex})) {
85     $use_duplex = 0;
86 }
87
88
89 use File::Find;
90
91 if (@ARGV) {
92     chdir($ARGV[0]);
93 }
94
95 my $last_num = 0;
96 find(sub { return if /^\./;
97            $File::Find::prune = 1 if -d $_;
98            if (/out_(\d+)_/) {
99                $last_num = $1 if $1 > $last_num;
100            }
101        }
102      ,'.');
103
104 $last_num++;
105
106 exec('scanimage','-d',$options{device},
107      '--source',$use_duplex?'ADF Duplex':'ADF Front','--mode',$options{mode},'--format','tiff',
108      '--batch=out_'.sprintf('%03d',$last_num).'_%03d.tif');
109
110 __END__
111
112
113
114