states.man: Escape backslashes in namerules and startrules examples.
[enscript.git] / scripts / sliceprint.in
1 #!@PERLPROG@
2 # -*- perl -*-
3 #
4 # Print documents with long lines.
5 # Copyright (c) 1996-1999 Markku Rossi
6 #
7 # Author: Markku Rossi <mtr@iki.fi>
8 #
9
10 #
11 # This file is part of GNU Enscript.
12 #
13 # Enscript is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
17 #
18 # Enscript is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with Enscript.  If not, see <http://www.gnu.org/licenses/>.
25 #
26
27 $enscript = "enscript";
28
29 $program = $0;
30 $program =~ s/.*\///g;
31
32 sub usage {
33     warn "Usage: $program [ENSCRIPT_OPTION]... [FILE]...\n";
34 }
35
36 # Handle arguments.
37 $args = "--extended-return-values";
38 $files = "";
39 while ($arg = shift(@ARGV)) {
40     if ($arg eq "--help") {
41         &usage;
42         exit 0;
43     } elsif ($arg eq "--version") {
44         warn "sliceprint 1.0\n";
45         exit 0;
46     } elsif ($arg =~ /^-p(.+)$/
47         || $arg =~ /^-o(.+)$/
48         || $arg =~ /^--output=(.+)$/) {
49         $output_file = $1;
50     } elsif ($arg eq "-p" || $arg eq "-o") {
51         $output_file = shift(@ARGV);
52     } elsif ($arg =~ /^-/) {
53         $args .= " $arg";
54     } else {
55         $files .= " $arg";
56     }
57 }
58
59 # Check if output file is "-".
60 if (defined($output_file) && $output_file eq "-") {
61     die "$program: output file can't be stdout\n";
62 }
63
64 $slice = 0;
65 while (1) {
66     $slice++;
67     if (defined($output_file)) {
68         $cmd = "$enscript" . $args . " --slice=$slice -p"
69             . $output_file . "." . $slice . " " . $files;
70     } else {
71         $cmd = "$enscript" . $args . " --slice=$slice" . $files;
72     }
73     print "printing slice $slice...\n";
74     $result = `$cmd 2>&1`;
75     if ($result !~ ".*lines were.*") {
76         last;
77     }
78 }