Codebase list foomatic-filters / fb1799c
New d/ppd-doc-extractor; refresh d/copyright Jörg Frings-Fürst 2 years ago
6 changed file(s) with 202 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
00 foomatic-filters for Debian
11 ---------------------------
2
3 At /usr/share/doc/foomatic-filters/examples you can found a new
4 ppd-doc-extractor. Thanks to Alexander Zangerl <az@debian.org>.
5
6 -- Jörg Frings-Fürst <debian@jff.email> Thu, 24 Feb 2022 08:07:44 +0100
27
38 Note that the structure of the OpenPrinting (foomatic) printer
49 configuration system in Debian (and upstream) has changed from the 2.0
33 - Fix error on handling text filter.
44 * New debian/patches/0120-Disable_option_docs.patch (Closes: #1004417)
55 - Disable not available option docs.
6 * New debian/ppd-doc-extractor installed at
7 /usr/share/doc/foomatic-filters/examples.
8 Thanks to Alexander Zangerl <az@debian.org>
9 * debian/copyright:
10 - Add year 2022 to myself.
11 - New paragraph for debian/ppd-doc-extractor.
612
713 -- Jörg Frings-Fürst <debian@jff.email> Thu, 24 Feb 2022 08:07:44 +0100
814
2222
2323 Files: debian/*
2424 Copyright: 2003 Chris Lawrence <lawrencc@debian.org>
25 2014-2021 Jörg Frings-Fürst <debian@jff.email>
25 2014-2022 Jörg Frings-Fürst <debian@jff.email>
2626 License: GPL-2.0+
27
28 Files: debian/ppd-doc-extractor
29 Copyright: 2022 Alexander Zangerl <az@snafu.priv.at>
30 License: GPL-2.0
2731
2832 License: GPL-2.0+
2933 This program is free software; you can redistribute it
00 filter.conf
1 debian/ppd-doc-extractor
00 Description: Disable not available option docs
11 Author: Jörg Frings-Fürst <debian@jff.email>
22 Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1004417
3 Forwarded: no
3 Forwarded: not-needed
44 Last-Update: 2022-02-24
55 ---
66 This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
0 #!/usr/bin/perl
1 # $Id$
2 #
3 # File: ppd-doc-extractor
4 # Date: 27 Jan 2022 16:28:17
5 # Author: Alexander Zangerl <az@snafu.priv.at>
6 #
7 # Abstract:
8 # very minimal recreation of the PPD documentation extractor
9 # of foomatic-rip 3.x (which you got with foomatic-rip -o docs), which
10 # is not part of the rewritten 4.x versions despite the documentation's
11 # claims and the broken option code that doesn't reject what it cannot
12 # handle.
13 #
14 # copyright (c) 2022 Alexander Zangerl <az@snafu.priv.at>
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License version 2
18 # as published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 use strict;
29 use File::Slurp;
30 use Data::Dumper;
31
32 my ($ppdfile,@a2ps) = @ARGV;
33 die "usage: $0 <ppdfile> [a2ps args]\n
34 no a2ps args: print to stdout
35 automatically added: --center-title, --footer\n\n" if (!-f $ppdfile);
36
37 my @stuff = read_file($ppdfile);
38
39 # parse everything but massage and handle just the relevant parts
40 my (%x, $curopengroup);
41 for (my $i = 0; $i <= $#stuff; ++$i)
42 {
43 my $line = $stuff[$i];
44 $line =~ s/\r\n$//; # de-dos
45 chomp $line;
46
47 my ($key, $value, $option, $xlatoption);
48
49 next if ($line =~ /^(\*%.*)?$/ or $line eq "*End");
50 if ($line =~ /^\*([^:]+):\s*(.+)\s*$/)
51 {
52 ($key, $value) = ($1,$2);
53 if ($key =~ /^(\S+)\s+(.+)$/)
54 {
55 $key = $1;
56 $option = $2;
57
58 if ($option =~ m!^([^/]+)/(.+)$!)
59 {
60 ($option,$xlatoption) = ($1,$2);
61 undef $xlatoption if ($xlatoption eq $option); # unnecessary ones
62 }
63 }
64 # invocationvalue and quotedvalue allow continuation
65 if ($value =~ /^"([^"]+)"\s*$/)
66 {
67 $value = $1;
68 }
69 elsif ($value =~ /^"([^"]*)*$/)
70 {
71 $value = $1;
72 while ((my $nextline = $stuff[++$i]) !~ /"/)
73 {
74 $value .= $nextline;
75 }
76 if ($stuff[$i] =~ /^([^"]+)"\s*$/)
77 {
78 $value .= $1;
79 }
80 }
81
82 # orderdependency is laid out extraspecially stupidly
83 if ($key =~ /^(NonUI)?OrderDependency$/)
84 {
85 $key = "OrderDependency"; # we lump these together
86 my ($num,$dontcare,$appliesto) = split(/\s+/,$value);
87 ($option = $appliesto) =~ s/^\*//;
88 $value = $num;
89 }
90 # want the options under openui w/o fluff
91 elsif ($key eq "OpenUI")
92 {
93 $option =~ s/^\*//;
94 }
95 # another instance of shitty structural layout
96 elsif ($key eq "OpenGroup")
97 {
98 if ($value =~ m!^\s*(\S+)/(.+)$!)
99 {
100 ($option,$xlatoption) = ($1,$2);
101 }
102 else
103 {
104 $xlatoption = $option = $value;
105 }
106 $curopengroup = $value = $option;
107 }
108 elsif ($key eq "CloseGroup")
109 {
110 undef $curopengroup;
111 }
112
113 if (defined $option)
114 {
115 # for option entries add a sequence number for sorting - simply use the line number
116 $x{$key}->{$option} = { xlat => $xlatoption,
117 value => $value,
118 sequence => $i,
119 ingroup => $curopengroup, };
120
121 }
122 else
123 {
124 $x{$key} = $value;
125 }
126 }
127 else
128 {
129 die "unrecognized line nr. $i\n";
130 }
131 }
132
133 # print Dumper(\%x);
134
135 if (@a2ps)
136 {
137 push @a2ps, ("--center-title=Documentation for $x{ModelName}","--footer=");
138
139 # lazy me: just duping the pipe fd...
140 open(P, "|-", "a2ps", @a2ps) or die "cannot pipe to a2ps: $!\n";
141 open(STDOUT, ">&", \*P) or die "cannot dup: $!\n";
142 }
143
144 print qq|
145 Invocation summary for $x{ModelName}:
146 Command line: lpr [-Z opt=value, opt=value...] [lpr options] <file>
147
148 List of available options:\n\n|;
149
150 # meh...orderdependency is not in all ppds or all sections :-(
151 my $odep = $x{OrderDependency};
152 my @onames = sort { $odep->{$a}->{ingroup} cmp $odep->{$a}->{ingroup}
153 || $odep->{$a}->{sequence} <=> $odep->{$b}->{sequence}
154 || $odep->{$a}->{value} <=> $odep->{$b}->{value}
155 || $x{OpenUI}->{$a}->{sequence} <=> $x{OpenUI}->{$b}->{sequence} } keys %{$x{OpenUI}};
156
157 for my $oname (@onames)
158 {
159 my $label = $x{OpenUI}->{$oname}->{xlat} // $oname;
160 my $type = $x{OpenUI}->{$oname}->{value} // "Unknown";
161
162 # one choice is no choice
163 next if ($type eq "PickOne" && keys %{$x{$oname}} == 1);
164
165 my $this = $x{$oname};
166 my $example = (keys %$this)[0];
167 my $sectionname = $x{OpenGroup}->{$this->{$example}->{ingroup}}->{xlat};
168 my $sectionlabel = $sectionname ? " Section: $sectionname\n":"";
169
170 print "Option '$oname': $label\n$sectionlabel Type: $type\n Choices:\n";
171 for my $choice (sort { $this->{$a}->{sequence} <=> $this->{$b}->{sequence} } keys %$this)
172 {
173 my $choicelabel = $x{$oname}->{$choice}->{xlat};
174 print " o '$choice'".($choicelabel? ": $choicelabel":"")."\n";
175 }
176 print " Default: ".$x{"Default$oname"}."\n Example: -Z $oname=$example\n\n";
177 }
178
179 if (@a2ps)
180 {
181 close(STDOUT);
182 close(P);
183 }