3 ############################################################################
5 # url-pattern-translator
7 # Filters Privoxy action files and changes old-school URL patterns to
8 # use extended regular expressions for the host as well.
10 # While it works good enough to satisfy the regression tests in
11 # default.action.master, it isn't perfect and you should double-check
12 # the output and keep backups of your old action files.
16 # url-pattern-translator.pl old.action > new.action
18 # Only convert your files once, or, as RoboCop used to say,
19 # there will be... trouble.
21 # $Id: url-pattern-translator.pl,v 1.3 2009/01/13 17:01:04 fabiankeil Exp $
23 # Copyright (c) 2008 Fabian Keil <fk@fabiankeil.de>
25 # Permission to use, copy, modify, and distribute this software for any
26 # purpose with or without fee is hereby granted, provided that the above
27 # copyright notice and this permission notice appear in all copies.
29 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
30 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
31 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
32 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
33 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
34 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
35 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
37 ############################################################################
44 print $message . "\n";
47 sub convert_host_pattern ($) {
48 my $host_pattern = shift;
49 my $hp = $host_pattern;
56 # XXX: This is somewhat ugly and while it's
57 # the equivalent pattern in most cases
58 # \. should be good enough.
65 # Match-all syntax has changed ...
68 # Extended host patterns are right-anchored by default
69 $hp =~ s@\.$@(\..*)?@;
71 # Literal dots have to be escaped
72 $hp =~ s@((?<!\\)\.[^*])@\\$1@g;
74 # Match single character with a dot.
75 $hp =~ s@(?<!\))\?@.@g;
80 sub looks_interesting($) {
82 my $type_to_skip = undef;
86 $type_to_skip = "comment";
88 } elsif (/[{}]/ or /\\$/) {
90 $type_to_skip = "action settings";
94 $type_to_skip = "whitespace";
96 } elsif (m@^\s*TAG:@) {
98 $type_to_skip = "tag patttern";
100 } elsif (m@^[^/]*=@) {
102 $type_to_skip = "macro or version definition";
104 } elsif (m@^\s*standard\.@) {
106 $type_to_skip = "predefined settings";
110 #p("Skipping " . $type_to_skip . ": " . $_) if defined $type_to_skip;
112 return not defined $type_to_skip;
122 if (looks_interesting($_)) {
123 if (m@^([^/]+)(/.*)$@) {
126 $host = convert_host_pattern($host);
129 elsif (m@^([^/]*)$@) {
131 $host = convert_host_pattern($host);