| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
debconf-escape - helper when working with debconf's escape capability |
| 6 |
|
| 7 |
=head1 SYNOPSIS |
| 8 |
|
| 9 |
debconf-escape -e < unescaped-text |
| 10 |
debconf-escape -u < escaped-text |
| 11 |
|
| 12 |
=head1 DESCRIPTION |
| 13 |
|
| 14 |
When debconf has the 'escape' capability set, it will expect commands |
| 15 |
you send it to have backslashes and newlines escaped (as C<\\> and C<\n> |
| 16 |
respectively) and will in turn escape backslashes and newlines in its |
| 17 |
replies. This can be used, for example, to substitute multi-line strings |
| 18 |
into templates, or to get multi-line extended descriptions reliably |
| 19 |
using C<METAGET>. |
| 20 |
|
| 21 |
=head1 SEE ALSO |
| 22 |
|
| 23 |
L<debconf-devel(7)> |
| 24 |
(available in the debconf-doc package) |
| 25 |
|
| 26 |
=cut |
| 27 |
|
| 28 |
use warnings; |
| 29 |
use strict; |
| 30 |
use Getopt::Long; |
| 31 |
|
| 32 |
use vars qw($escape $unescape); |
| 33 |
|
| 34 |
sub usage { |
| 35 |
print STDERR <<EOF; |
| 36 |
Usage: debconf-unescape -e|-u < input-text |
| 37 |
-e, --escape escape text |
| 38 |
-u, --unescape unescape text |
| 39 |
|
| 40 |
Exactly one of -e or -u must be used. |
| 41 |
EOF |
| 42 |
exit(1); |
| 43 |
} |
| 44 |
|
| 45 |
$escape=0; |
| 46 |
$unescape=0; |
| 47 |
|
| 48 |
GetOptions( |
| 49 |
"escape|e" => \$escape, |
| 50 |
"unescape|u" => \$unescape, |
| 51 |
) || usage(); |
| 52 |
|
| 53 |
if ($escape == $unescape) { |
| 54 |
usage(); |
| 55 |
} |
| 56 |
|
| 57 |
if ($escape) { |
| 58 |
while (<STDIN>) { |
| 59 |
s/\\/\\\\/g; |
| 60 |
s/\n/\\n/g; |
| 61 |
print; |
| 62 |
} |
| 63 |
} else { |
| 64 |
while (<STDIN>) { |
| 65 |
for (split /(\\.)/) { |
| 66 |
s/\\(.)/$1 eq "n" ? "\n" : $1/eg; |
| 67 |
print; |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
=head1 AUTHOR |
| 73 |
|
| 74 |
Colin Watson <[email protected]> |
| 75 |
|
| 76 |
=cut |