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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
#!/usr/bin/env perl
#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
# /* Functions for on-the-fly commentary on a tool's work. */
#
# Copyright (C) 2000-2001 Ximian, Inc.
#
# Authors: Hans Petter Jansson <hpj@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.
$SCRIPTSDIR = "@scriptsdir@";
if ($SCRIPTSDIR =~ /^@scriptsdir[@]/)
{
$SCRIPTSDIR = ".";
$DOTIN = ".in";
}
require "$SCRIPTSDIR/general.pl$DOTIN";
# --- Progress printing --- #
$gst_progress_current = 0; # Compat with old $progress_max use.
$gst_progress_last_percentage = 0;
sub gst_progress
{
my $prc = $_[0];
# /* Don't go backwards. */
$prc = $gst_progress_last_percentage if ($prc < $gst_progress_last_percentage);
# /* Don't go above 99%. */
$prc = 99 if ($prc >= 100);
if ($gst_progress && (int $prc > int $gst_progress_last_percentage))
{
&gst_report ("progress", $prc);
$gst_progress_last_percentage = $prc;
}
}
sub gst_progress_begin
{
&gst_progress (0);
}
sub gst_progress_end
{
&gst_progress (99);
}
sub gst_print_progress # Compat with old $progress_max use.
{
my $prc;
$gst_progress_current++;
&gst_progress (($gst_progress_current * 100) / $progress_max);
}
# --- Report printing --- #
sub gst_report_begin
{
my ($tool) = @_;
&gst_report ("begin");
&gst_report_enter ();
&gst_progress_begin ();
}
sub gst_report_end
{
&gst_progress_end ();
&gst_report_leave ();
&gst_report ("end");
}
sub gst_report_set_threshold
{
$gst_report_threshold = $_[0];
}
sub gst_report_enter
{
# This has been trivialized because it is not working
# correctly at the moment and is causing some trouble.
# /* We'll probably replace this with something smarter */
# (like a detail-level value in the report hash)
# when the report strings are used at the gui-level again.
# $gst_report_level ++;
$gst_report_level = 0;
}
sub gst_report_leave
{
# $gst_report_level --;
$gst_report_level = 0;
}
# Escapes a report using the report line format.
sub gst_report_escape
{
my ($args) = @_;
my ($arg);
foreach $arg (@$args)
{
$arg =~ s/\\/\\\\/g;
$arg =~ s/::/\\::/g;
}
}
$gst_report_level = 0;
$gst_report_started = 0;
# Just to trap these errors with the debugger easily.
sub gst_report_stderr
{
my ($major, $key, $res) = @_;
print STDERR "$gst_name - $major::${key}::$res";
}
sub gst_report
{
my (@args) = @_;
my ($key, $major, $minor, $str, $format, $res);
my $report_message = &gst_report_table ();
&gst_report_escape (\@args);
$key = shift @args;
if (! (exists $$report_message{$key}))
{
&gst_report ("report_minor_unk", $key);
return;
}
($major, $str) = @{$$report_message{$key}};
if (! (exists $gst_report_valid_majors{$major}))
{
&gst_report ("report_major_unk", $major, join ("::", $key, @args));
return;
}
$gst_report_started = 1 if !$gst_report_started && $key eq "begin" && $major eq "sys";
# Verbose (--verbose) output is human-readable only.
$format = "$str\n";
$res = sprintf ($format, @args);
if ($gst_do_verbose ||
$major eq "error" ||
$major eq "debug")
{
&gst_report_stderr ($major, $key, $res);
}
if ($key ne "progress")
{
return if ($gst_report_level >= $gst_report_threshold || !$gst_report_started);
}
# Report (--report) output is machine-readable.
if ($gst_do_report)
{
print STDOUT join ("::", $major, $key, $str, @args) . "\n";
}
&gst_debug_print_indented_string ($gst_report_level, "report $major:$key: $res");
}
# Internal
{
my $report_table = \%gst_report_message;
sub gst_report_table
{
my $table = shift @_;
if ($table) # Add
{
foreach my $key (keys %$table)
{
$$report_table{$key} = $$table{$key} unless exists $$report_table{$key};
}
}
else # Get
{
return $report_table;
}
}
}
# This disables reporting.
&gst_report_set_threshold (0);
%gst_report_valid_majors = (
"sys" => 1,
"error" => 1,
"warn" => 1,
"info" => 1,
"debug" => 1
);
%gst_report_message =
(
"begin" => ["sys", "Start of work report."],
"end" => ["sys", "End of work report."],
"progress" => ["sys", "%d"],
"compat" => ["info", "%s."],
"report_major_unk" => ["error", "Unknown major [%s] in report [%s]."],
"report_minor_unk" => ["error", "Unknown minor [%s]."],
"directive_run" => ["info", "Running directive [%s] with args [%s]."],
"directive_unsup" => ["error", "Directive [%s] not supported."],
"directive_invalid" => ["error", "Directive [%s] structure has wrong format."],
"directive_badargs" => ["error", "Directive [%s] requires exactly [%s] args in [%s]."],
"directive_lowargs" => ["error", "Directive [%s] requires at least [%s] args in [%s]."],
"platform_unsup" => ["error", "Your platform [%s] is not supported."],
"platform_undet" => ["error", "Unable to determine host platform."],
"platform_success" => ["sys", "Configuring for platform [%s] (%s)."],
"platform_no_table" => ["error", "No parse/replace table for platform [%s]."],
"xml_unexp_tag" => ["error", "Unexpected tag [%s]."],
"xml_unexp_arg" => ["error", "Unexpected argument [%s] to tag [%s]."],
"file_copy_failed" => ["debug", "Could not copy file [%s] to [%s]."],
"file_open_read_failed" => ["warn", "Could not open [%s] for reading."],
"file_open_read_success" => ["info", "Reading options from [%s]."],
"file_open_write_failed" => ["error", "Failed to write to [%s]."],
"file_open_write_create" => ["warn", "Could not find [%s] for writing. Creating [%s]."],
"file_open_write_success" => ["info", "Writing to [%s]."],
"file_run_pipe_failed" => ["warn", "Failed to pipe command [%s] for reading."],
"file_run_pipe_success" => ["info", "Piping command [%s] for reading."],
"file_run" => ["info", "Running command [%s]."],
"file_create_path" => ["info", "Directory [%s] created."],
"file_backup_rotate" => ["info", "Backup directory [%s] was rotated."],
"file_backup_success" => ["info", "Saved backup for [%s]."],
"file_open_filter_failed" => ["warn", "No file to patch: [%s]."],
"file_open_filter_create" => ["warn", "Could not find [%s] for patching. Creating [%s]."],
"file_open_filter_success" => ["info", "Found [%s]. Patching [%s]."],
"file_buffer_load" => ["info", "Loading file [%s] to buffer."],
"file_buffer_save" => ["info", "Saving buffer to file [%s]."],
"file_remove" => ["info", "Removing file [%s]."],
"file_locate_tool_success" => ["info", "Found tool [%s]."],
"file_locate_tool_failed" => ["warn", "Couldn't find tool [%s]."],
"parse_table" => ["info", "Parsing option [%s]."],
"parse_trivial" => ["info", "Trivialy passing [%s]."],
"parse_split" => ["info", "Getting option [%s] from [%s]."],
"parse_split_hash" => ["info", "Getting configuration from [%s]."],
"parse_split_hash_cont" => ["info", "Getting configuration from [%s]."],
"parse_sh" => ["info", "Getting shell option [%s] from [%s]."],
"parse_kw" => ["info", "Getting keyword [%s] from [%s]."],
"parse_line_first" => ["info", "Getting information from [%s]."],
"parse_chat" => ["info", "Getting chat information from [%s]."],
"parse_ini" => ["info", "Getting option [%s] from [%s], section [%s]."],
"parse_ifaces_str" => ["info", "Getting option [%s] from interface [%s]."],
"parse_ifaces_kw" => ["info", "Getting keyword [%s] from interface [%s]."],
"parse_ifaces_kw_strange" => ["warn", "Keyword for interface [%s] in [%s] had unexpected value."],
"replace_split" => ["info", "Replacing key [%s] in [%s]."],
"replace_sh" => ["info", "Replacing shell var [%s] in [%s]."],
"replace_kw" => ["info", "Replacing keyword [%s] in [%s]."],
"replace_line_first" => ["info", "Replacing contents of file [%s]."],
"replace_chat" => ["info", "Replacing values in [%s]."],
"replace_ini" => ["info", "Replacing variable [%s] in section [%s] of [%s]."],
"replace_del_ini_sect" => ["info", "Removing section [%s] from [%s]."],
"replace_ifaces_str" => ["info", "Replacing option [%s] from interface [%s]."],
"replace_ifaces_kw" => ["info", "Replacing keyword [%s] from interface [%s]."],
"service_status_running" => ["info", "Service [%s] is running."],
"service_status_stopped" => ["info", "Service [%s] is stopped."],
"service_sysv_unsupported" => ["info", "No SystemV support for platform [%s]."],
"service_sysv_not_found" => ["warn", "Could not find SystemV scripts for service [%s]."],
"service_sysv_no_runlevel" => ["warn", "Could not find SystemV runlevel [%s] directory [%s]."],
"service_sysv_remove_link" => ["info", "Removed SystemV link [%s]."],
"service_sysv_add_link" => ["info", "Created SystemV link [%s]."],
"service_sysv_op_unk" => ["error", "Unknown initd operation [%s]."],
"service_sysv_op_success" => ["info", "Service [%s] %s."],
"service_sysv_op_failed" => ["warn", "Service [%s] could not be %s."],
"network_dialing_get" => ["info", "Loading ISP configurations."],
"network_iface_active_get" => ["info", "Finding active interfaces."],
"network_iface_is_active" => ["info", "Checking if interface [%s] is active."],
"network_hostname_set" => ["info", "Setting hostname to [%s]."],
"network_dialing_set" => ["info", "Saving ISP configurations."],
"network_remove_pap" => ["info", "Removing entry [%s] from [%s]."],
"network_iface_set" => ["info", "Configuring interface [%s]."],
"network_iface_activate" => ["info", "Activating interface [%s]."],
"network_iface_deactivate" => ["info", "Deactivating interface [%s]."],
"network_ifaces_set" => ["info", "Setting up interfaces."],
"network_get_pap_passwd" => ["info", "Getting PAP/CHAP password for [%s] from [%s]."],
"network_get_ppp_option" => ["info", "Getting option [%s] from [%s]."],
"network_set_ppp_option" => ["info", "Setting option [%s] in [%s]."],
"network_set_ppp_connect" => ["info", "Setting connect option in [%s]."],
"network_get_ppp_unsup" => ["info", "Getting additional options from [%s]."],
"network_set_ppp_unsup" => ["info", "Setting additional options in [%s]."],
"network_bootproto_unsup" => ["warn", "Boot method [%s] for interface [%s] not supported."],
"network_get_remote" => ["info", "Getting remote address for interface [%s]."],
"network_set_remote" => ["info", "Setting remote address for interface [%s]."],
"network_ensure_lo" => ["info", "Ensuring loopback interface configuration."],
"filesys_mount" => ["info", "Mounting [%s] on [%s]."],
"filesys_mount_failed" => ["warn", "Failed to mount [%s] on [%s]."],
"filesys_unmount" => ["info", "Unmounting [%s] from [%s]."],
"filesys_unmount_failed" => ["warn", "Failed to unmount [%s] from [%s]."],
"boot_lilo_failed" => ["warn", "Failed to run lilo."],
"boot_lilo_success" => ["info", "Succesfully executed lilo."],
"boot_conf_read_failed" => ["error", "Failed to open boot configuration file [%s]."],
"boot_grub_convert_failed" => ["error", "Conversion of [%s] failed."],
"sfdisk_failed" => ["error", "Could not run sfdisk."],
"disks_fstab_add" => ["info", "Adding [%s] to fstab."],
"disks_partition_probe" => ["info", "Looking for partitions on [%s]."],
"disks_size_query" => ["info", "Querying size of [%s]."],
"disks_mount" => ["info", "Mounting [%s]."],
"disks_umount" => ["info", "Unmounting [%s]."],
"disks_mount_error" => ["error", "Could not find mount tools. No mounting done."],
"memory_swap_found" => ["info", "Found swap entry [%s]."],
"memory_swap_probe" => ["info", "Looking for swap entries."],
"print_no_printtool" => ["warn", "No printtool setup in directory [%s]."],
"time_timezone_scan" => ["info", "Scanning timezones."],
"time_timezone_cmp" => ["info", "Scanning timezones: [%s]."],
"time_timezone_set" => ["info", "Setting timezone as [%s]."],
"time_localtime_set" => ["info", "Setting local time as [%s]."]
);
1;
|