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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
#!/usr/bin/env perl
#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
# Print configurator. Designed to be architecture and distribution independent.
#
# Copyright (C) 2000-2001 Ximian, Inc.
#
# Authors: Hans Petter Jansson <hpj@ximian.com>
# Michael Vogt <mvo@debian.org> (Debian Support)
# Arturo Espinosa <arturo@ximian.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
# Best viewed with 100 columns of width.
# Configuration files affected:
#
# /etc/resolv.conf
# /etc/host.conf
# /etc/hosts
# /etc/sysconfig/print
# /etc/rc.config
# /etc/smb.conf
# Running programs affected:
#
# smbd
# nmbd
# ifconfig: check current printers and activate/deactivate.
require "___scriptsdir___/general.pl";
require "___scriptsdir___/platform.pl";
require "___scriptsdir___/util.pl";
require "___scriptsdir___/file.pl";
require "___scriptsdir___/xml.pl";
require "___scriptsdir___/print.pl";
# Debug stuff
#$xst_prefix = "/tmp/y";
#open STDERR, ">/tmp/err";
# --- Tool information --- #
$name = "print";
$version = "0.1.0";
@platforms = ("redhat-6.0", "redhat-6.1", "redhat-6.2", "redhat-7.0",
"mandrake-7.2", "debian-2.2", "debian-woody");
$description =<<"end_of_description;";
Configures the lpr subsystem.
end_of_description;
$progress_max = 10;
# --- XML parsing ---
# Scan XML from standard input to an internal tree.
sub xml_parse
{
my ($tree, %hash);
# Scan XML to tree.
$tree = &xst_xml_scan;
# Walk the tree recursively and extract configuration parameters.
# This is the top level - find and enter the "print" tag.
while (@$tree)
{
if ($$tree[0] eq "print") { &xml_parse_print ($$tree[1], \%hash); }
shift @$tree;
shift @$tree;
}
return(\%hash);
}
# <print>...</print>
sub xml_parse_print
{
my $tree = $_[0];
my $hash = $_[1];
my %printer;
shift @$tree; # Skip attributes.
while (@$tree)
{
if ($$tree[0] eq "printer") { &xml_parse_printer ($$tree[1], \%printer); }
shift @$tree;
shift @$tree;
}
%$hash = %printer if scalar keys %printer;
}
# <printer>...</printer>
sub xml_parse_printer
{
my $tree = $_[0];
my $printer = $_[1];
my %hash, %section_hash;
my $dev;
shift @$tree;
while (@$tree)
{
$hash{$$tree[0]} = &xst_xml_get_pcdata ($$tree[1]);
# If get_pcdata returns an array instead of a scalar, we have
# a subsection to process.
if ( ref($hash{$$tree[0]}) eq "ARRAY" ) {
$hash{$$tree[0]} = &xml_parse_section($$tree[1]);
}
shift @$tree;
shift @$tree;
}
$dev = $hash{"name"};
$$printer{$dev} = \%hash;
}
sub xml_parse_section
{
my $tree = $_[0];
my %hash;
my $dev;
while (@$tree)
{
$hash{$$tree[0]} = &xst_xml_get_pcdata ($$tree[1]);
shift @$tree;
shift @$tree;
}
return \%hash;
}
# --- XML printing --- #
sub xml_print_section
{
}
sub xml_print_printer
{
my ($h, $spool) = @_;
my ($i, $val, $section);
&xst_xml_print_vspace ();
&xst_xml_print_line ("<printer>\n");
&xst_xml_enter ();
foreach $i (keys (%$h)) {
$val = &xst_xml_quote ($$h{$i});
&xst_xml_print_line ("<$i>$val</$i>\n");
}
&xst_xml_leave ();
&xst_xml_print_line ("</printer>\n");
}
sub xml_print
{
my $h = $_[0];
my ($i, $val);
&xst_xml_print_begin ();
foreach $i (keys (%$h)) {
&xml_print_printer ($$h{$i}, $i);
}
&xst_xml_print_end ();
}
# Top-level actions.
sub get
{
my $hash;
# print printer stuff
$hash = &xst_print_conf_get ();
&xst_end();
&xml_print ($hash);
}
sub set
{
my $hash;
$hash = &xml_parse ();
# check the success result of this.
&xst_print_conf_set ($hash);
&xst_end ();
}
# --- Filter config: XML in, XML out --- #
sub filter
{
my $hash;
$hash = &xml_parse ();
&xst_end ();
&xml_print ($hash);
}
# --- Main --- #
&xst_init ($name, $version, $description, @ARGV);
&xst_platform_ensure_supported (@platforms);
# Do our thing.
if ($xst_operation eq "get") { &get; }
elsif ($xst_operation eq "set") { &set; }
elsif ($xst_operation eq "filter") { &filter; }
|