2
0

apr_rename.pl 2.7 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 = 'fspr_';
  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:$. fspr_$_ -> fspr_$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. fspr_time_t:
  53. fspr_implode_gmt fspr_time_exp_gmt_get
  54. fspr_socket_t:
  55. fspr_close_socket fspr_socket_close
  56. fspr_create_socket fspr_socket_create
  57. fspr_get_sockaddr fspr_socket_addr_get
  58. fspr_get_socketdata fspr_socket_data_get
  59. fspr_set_socketdata fspr_socket_data_set
  60. fspr_shutdown fspr_socket_shutdown
  61. fspr_bind fspr_socket_bind
  62. fspr_listen fspr_socket_listen
  63. fspr_accept fspr_socket_accept
  64. fspr_connect fspr_socket_connect
  65. fspr_send fspr_socket_send
  66. fspr_sendv fspr_socket_sendv
  67. fspr_sendto fspr_socket_sendto
  68. fspr_recvfrom fspr_socket_recvfrom
  69. fspr_sendfile fspr_socket_sendfile
  70. fspr_recv fspr_socket_recv
  71. fspr_filepath_*:
  72. fspr_filename_of_pathname fspr_filepath_name_get
  73. fspr_gid_t:
  74. fspr_get_groupid fspr_gid_get
  75. fspr_get_groupname fspr_gid_name_get
  76. fspr_group_name_get fspr_gid_name_get
  77. fspr_compare_groups fspr_gid_compare
  78. fspr_uid_t:
  79. fspr_get_home_directory fspr_uid_homepath_get
  80. fspr_get_userid fspr_uid_get
  81. fspr_current_userid fspr_uid_current
  82. fspr_compare_users fspr_uid_compare
  83. fspr_get_username fspr_uid_name_get
  84. fspr_compare_users fspr_uid_compare