cull_options 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. our %short_no_arg;
  7. our %short_with_num;
  8. our %long_opt = (
  9. 'no-i-r' => 0,
  10. 'fake-super' => 0,
  11. 'log-file' => 3,
  12. );
  13. our $last_long_opt;
  14. open(IN, '../options.c') or die "Unable to open ../options.c: $!\n";
  15. while (<IN>) {
  16. if (/\Qargstr[x++]\E = '([^.ie])'/) {
  17. $short_no_arg{$1} = 1;
  18. undef $last_long_opt;
  19. } elsif (/\Qasprintf(\E[^,]+, "-([a-zA-Z0-9])\%l?[ud]"/) {
  20. $short_with_num{$1} = 1;
  21. undef $last_long_opt;
  22. } elsif (/\Qargs[ac++]\E = "--([^"=]+)"/) {
  23. $last_long_opt = $1;
  24. $long_opt{$1} = 0;
  25. } elsif (defined($last_long_opt)
  26. && /\Qargs[ac++]\E = ([^["\s]+);/ && $1 ne 'dest_option') {
  27. $long_opt{$last_long_opt} = 2;
  28. undef $last_long_opt;
  29. } elsif (/dest_option = "--([^"]+)"/) {
  30. $long_opt{$1} = 2;
  31. undef $last_long_opt;
  32. } elsif (/\Qasprintf(\E[^,]+, "--([^"=]+)=/ || /\Qargs[ac++]\E = "--([^"=]+)=/) {
  33. $long_opt{$1} = 1;
  34. undef $last_long_opt;
  35. }
  36. }
  37. close IN;
  38. my $short_no_arg = join('', sort keys %short_no_arg);
  39. my $short_with_num = join('', sort keys %short_with_num);
  40. print <<EOT;
  41. # These options are the only options that rsync might send to the server,
  42. # and only in the option format that the stock rsync produces.
  43. # To disable a short-named option, add its letter to this string:
  44. our \$short_disabled = 's';
  45. our \$short_no_arg = '$short_no_arg'; # DO NOT REMOVE ANY
  46. our \$short_with_num = '$short_with_num'; # DO NOT REMOVE ANY
  47. # To disable a long-named option, change its value to a -1. The values mean:
  48. # 0 = the option has no arg; 1 = the arg doesn't need any checking; 2 = only
  49. # check the arg when receiving; and 3 = always check the arg.
  50. our \%long_opt = (
  51. EOT
  52. foreach my $opt (sort keys %long_opt) {
  53. my $val = $long_opt{$opt};
  54. $val = 1 if $opt =~ /^(max-|min-)/;
  55. $val = 3 if $opt eq 'files-from';
  56. $val = '$ro ? -1 : ' . $val if $opt =~ /^remove-/;
  57. print " '$opt' => $val,\n";
  58. }
  59. print ");\n\n";