2
0

apr_rename.pl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use ExtUtils::MakeMaker qw(prompt);
  4. use File::Find;
  5. my $just_check = @ARGV ? $ARGV[0] eq '-c' : 0;
  6. shift if $just_check;
  7. my $dir = shift || '.';
  8. my %names;
  9. my $prefix = 'apr_';
  10. while (<DATA>) {
  11. chomp;
  12. my($old, $new) = grep { s/^$prefix//o } split;
  13. next unless $old and $new;
  14. $names{$old} = $new;
  15. }
  16. my $pattern = join '|', keys %names;
  17. #print "replacement pattern=$pattern\n";
  18. find sub {
  19. chomp;
  20. return unless /\.[ch]$/;
  21. my $file = "$File::Find::dir/$_";
  22. print "looking in $file\n";
  23. replace($_, !$just_check);
  24. }, $dir;
  25. sub replace {
  26. my($file, $replace) = @_;
  27. local *IN, *OUT;
  28. my @lines;
  29. my $found = 0;
  30. open IN, $file or die "open $file: $!";
  31. while (<IN>) {
  32. for (m/[^_\"]*$prefix($pattern)\b/og) {
  33. $found++;
  34. print " $file:$. apr_$_ -> apr_$names{$_}\n";
  35. }
  36. push @lines, $_ if $replace;
  37. }
  38. close IN;
  39. return unless $found and $replace;
  40. # my $ans = prompt("replace?", 'y');
  41. # return unless $ans =~ /^y/i;
  42. open OUT, ">$file" or die "open $file: $!";
  43. for (@lines) {
  44. unless (/^\#include/) {
  45. s/([^_\"]*$prefix)($pattern)\b/$1$names{$2}/og;
  46. }
  47. print OUT $_;
  48. }
  49. close OUT;
  50. }
  51. __DATA__
  52. apr_time_t:
  53. apr_implode_gmt apr_time_exp_gmt_get
  54. apr_socket_t:
  55. apr_close_socket apr_socket_close
  56. apr_create_socket apr_socket_create
  57. apr_get_sockaddr apr_socket_addr_get
  58. apr_get_socketdata apr_socket_data_get
  59. apr_set_socketdata apr_socket_data_set
  60. apr_shutdown apr_socket_shutdown
  61. apr_bind apr_socket_bind
  62. apr_listen apr_socket_listen
  63. apr_accept apr_socket_accept
  64. apr_connect apr_socket_connect
  65. apr_send apr_socket_send
  66. apr_sendv apr_socket_sendv
  67. apr_sendto apr_socket_sendto
  68. apr_recvfrom apr_socket_recvfrom
  69. apr_sendfile apr_socket_sendfile
  70. apr_recv apr_socket_recv
  71. apr_filepath_*:
  72. apr_filename_of_pathname apr_filepath_name_get
  73. apr_gid_t:
  74. apr_get_groupid apr_gid_get
  75. apr_get_groupname apr_gid_name_get
  76. apr_group_name_get apr_gid_name_get
  77. apr_compare_groups apr_gid_compare
  78. apr_uid_t:
  79. apr_get_home_directory apr_uid_homepath_get
  80. apr_get_userid apr_uid_get
  81. apr_current_userid apr_uid_current
  82. apr_compare_users apr_uid_compare
  83. apr_get_username apr_uid_name_get
  84. apr_compare_users apr_uid_compare