- Make sure that the command contained the '.' arg at the end of the
[rsync/rsync.git] / support / cull_options
1 #!/usr/bin/perl
2 # This script outputs some perl code that parses all possible options
3 # that the code in options.c might send to the server.  This perl code
4 # is included in the rrsync script.
5 use strict;
6 no strict 'refs';
7
8 our(%short_no_arg, %short_with_num);
9 our(%long_no_arg, %long_before_arg, %long_with_arg);
10 our $last_long_opt;
11
12 open(IN, '../options.c') or die "Unable to open ../options.c: $!\n";
13
14 while (<IN>) {
15     if (/\Qargstr[x++]\E = '(.)'/) {
16         $short_no_arg{$1} = 1;
17         undef $last_long_opt;
18     } elsif (/\Qasprintf(\E[^,]+, "-([a-zA-Z0-9])\%l?[ud]"/) {
19         $short_with_num{$1} = 1;
20         undef $last_long_opt;
21     } elsif (/\Qargs[ac++]\E = "--([^"=]+)"/) {
22         $last_long_opt = $1;
23         $long_no_arg{$1} = 1;
24     } elsif (defined($last_long_opt)
25         && /\Qargs[ac++]\E = ([^["\s]+);/ && $1 ne 'dest_option') {
26         delete $long_no_arg{$last_long_opt};
27         $long_before_arg{$last_long_opt} = 1;
28         undef $last_long_opt;
29     } elsif (/dest_option = "--([^"])"/) {
30         $long_before_arg{$1} = 1;
31         undef $last_long_opt;
32     } elsif (/\Qasprintf(\E[^,]+, "--([^"=]+)=/ || /\Qargs[ac++]\E = "--([^"=]+)=/) {
33         $long_with_arg{$1} = 1;
34         undef $last_long_opt;
35     }
36 }
37 close IN;
38
39 print "\n",
40     "# These options are the only options that rsync might send to the\n",
41     "# server, and only in the arg styles that the stock rsync produces.\n",
42     "our \$short_no_arg = '", sort(keys %short_no_arg), "';\n",
43     "our \$short_with_num = '", sort(keys %short_with_num), "';\n",
44     "# To disable a short-named option, add its letter to this string:\n",
45     "our \$short_disabled = '';\n",
46     "# To disable a long-named option, change its value to a 0.  A value of -1\n",
47     "# means the arg doesn't need checking, a 2 means only check when receiving.\n";
48
49 foreach my $name (qw( long_no_arg long_with_arg long_before_arg )) {
50     $_ = "our \%$name = (\n  '" . join("' => 1,\n  '", sort keys %$name) . "' => 1,\n);\n";
51     if ($name eq 'long_before_arg') {
52         s/ 1,/ 2,/g;
53         s/('files-from' =>) 2,/$1 1,/;
54         s/('max-.* =>) 2,/$1 -1,/g;
55     } else {
56         s/ 1,/ -1,/g;
57         s/('files-from' =>) -1,/$1 1,/;
58     }
59     s/('remove-.* =>) (-?\d),/$1 \$ro ? 0 : $2,/g;
60     print;
61 }
62
63 print "\n";