📄 apr_rename.pl
字号:
#!/usr/bin/perl -wuse strict;use ExtUtils::MakeMaker qw(prompt);use File::Find;my $just_check = @ARGV ? $ARGV[0] eq '-c' : 0;shift if $just_check;my $dir = shift || '.';my %names;my $prefix = 'apr_';while (<DATA>) { chomp; my($old, $new) = grep { s/^$prefix//o } split; next unless $old and $new; $names{$old} = $new;}my $pattern = join '|', keys %names;#print "replacement pattern=$pattern\n";find sub { chomp; return unless /\.[ch]$/; my $file = "$File::Find::dir/$_"; print "looking in $file\n"; replace($_, !$just_check);}, $dir;sub replace { my($file, $replace) = @_; local *IN, *OUT; my @lines; my $found = 0; open IN, $file or die "open $file: $!"; while (<IN>) { for (m/[^_\"]*$prefix($pattern)\b/og) { $found++; print " $file:$. apr_$_ -> apr_$names{$_}\n"; } push @lines, $_ if $replace; } close IN; return unless $found and $replace;# my $ans = prompt("replace?", 'y');# return unless $ans =~ /^y/i; open OUT, ">$file" or die "open $file: $!"; for (@lines) { unless (/^\#include/) { s/([^_\"]*$prefix)($pattern)\b/$1$names{$2}/og; } print OUT $_; } close OUT;}__DATA__apr_time_t:apr_implode_gmt apr_time_exp_gmt_getapr_socket_t:apr_close_socket apr_socket_closeapr_create_socket apr_socket_createapr_get_sockaddr apr_socket_addr_getapr_get_socketdata apr_socket_data_getapr_set_socketdata apr_socket_data_setapr_shutdown apr_socket_shutdownapr_bind apr_socket_bindapr_listen apr_socket_listenapr_accept apr_socket_acceptapr_connect apr_socket_connectapr_send apr_socket_sendapr_sendv apr_socket_sendvapr_sendto apr_socket_sendtoapr_recvfrom apr_socket_recvfromapr_sendfile apr_socket_sendfileapr_recv apr_socket_recvapr_filepath_*:apr_filename_of_pathname apr_filepath_name_getapr_gid_t:apr_get_groupid apr_gid_getapr_get_groupname apr_gid_name_getapr_group_name_get apr_gid_name_getapr_compare_groups apr_gid_compareapr_uid_t:apr_get_home_directory apr_uid_homepath_getapr_get_userid apr_uid_getapr_current_userid apr_uid_currentapr_compare_users apr_uid_compareapr_get_username apr_uid_name_getapr_compare_users apr_uid_compare
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -