'on error resume next 'msgbox "All these settings are aviable till the browser restarted!",vbInformation,"ProxyShift" dim ws,pe,proxy,proxy1,proxycount,i,r const REGDIR="HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings" Set ws = WScript.CreateObject("WScript.Shell") readValues if pe=0 then if msgbox("Proxy is disabled, enable it?",vbYesNo,"ProxyShift")=vbYes then if proxy="" then proxy=InputBox("Input proxy server","ProxyShift") if proxy<> "" then ws.RegWrite REGDIR & "ProxyServer",proxy,"REG_SZ" ws.RegWrite REGDIR & "ProxyServer1",proxy,"REG_SZ" ws.RegWrite REGDIR & "ProxyCount","1","REG_SZ" end if else Call ChangeProxy end if ws.RegWrite REGDIR & "ProxyEnable",1,"REG_DWORD" msgbox "ProxyServer setted!",vbInformation,"ProxyShift" end if else r=msgbox("Proxy server list: " & vbcrlf & vbcrlf & get_Proxystr & vbcrlf & "Disable or change it?" & vbcrlf & vbcrlf & "[YES] for disable, [NO] for change",vbYesNoCancel,"ProxyShift") if r=vbYes then ws.RegWrite REGDIR & "ProxyEnable",0,"REG_DWORD" msgbox "Proxy disabled!",vbInformation,"ProxyShift" elseif r=vbNo then Call ChangeProxy msgbox "ProxyServer setted!",vbInformation,"ProxyShift" end if end if Function get_Proxystr dim proxystr proxystr="" proxy=ws.RegRead(REGDIR & "ProxyServer") proxycount=ws.RegRead(REGDIR & "ProxyCount") for i=1 to proxycount proxy1=ws.RegRead(REGDIR & "ProxyServer" & i) if proxy1 = "" then proxy1 = proxy proxystr=proxystr & i ". " & proxy1 if proxy1=proxy then proxystr = proxystr & " (DEFAULT)" proxystr=proxystr & vbcrlf next get_Proxystr=proxystr end Function sub ChangeProxy dim pindex r=msgbox("Proxy server list:" & vbcrlf & vbcrlf & get_Proxystr & vbcrlf & "Change the DEFAULT proxy server?" & vbcrlf & vbcrlf & "[YES] for change, [NO] for a new proxy server, [CANCEL] for use default", vbYesNoCancel,"ProxyShift") if r=vbYes then pindex=InputBox("Input proxy server index","ProxyShift") ws.RegWrite REGDIR & "ProxyServer",ws.RegRead(REGDIR & "ProxyServer" & pindex),"REG_SZ" msgbox "Proxy server " & pindex & " set as default!",vbInformation,"ProxyShift" elseif r=vbNo then dim newserver newserver=InputBox("Input a new proxy server:","ProxyShift") if newserver<>"" then ws.RegWrite REGDIR & "ProxyServer",newserver,"REG_SZ" ws.RegWrite REGDIR & "ProxyServer" & proxycount+1,newserver,"REG_SZ" ws.RegWrite REGDIR & "ProxyCount",proxycount+1,"REG_SZ" 'msgbox "ProxyServer setted!",vbInformation,"ProxyShift" end if end if end sub sub readValues on error resume next proxy=ws.RegRead(REGDIR & "ProxyServer") proxycount=ws.RegRead(REGDIR & "ProxyCount") if isnull(proxycount) or proxycount="" then ws.RegWrite REGDIR & "ProxyServer1",proxy,"REG_SZ" ws.RegWrite REGDIR & "ProxyCount","1","REG_SZ" end if proxycount=ws.RegRead(REGDIR & "ProxyCount") pe=ws.RegRead(REGDIR & "ProxyEnable") end sub
#!/usr/bin/perl -w # order templates, do NOT modify this annotation! ## #.<SELF>/#--<SELF>/#_<SELF>/pic_#/file_#/<SELF>.#/<SELF>_#// sub is_num{ $temp = shift; return ($temp=~/^d+$/); } sub is_inArray{ ($ele,@arr) = @_; foreach (@arr){ return 1 if($ele eq $_); } return 0; } sub lettersAdd{ my($letters, $step) = @_; my $last = unpack("C",substr($letters,-1,1)) + $step; if($last > 122){ if(length($letters)>1){ $str = lettersAdd(substr($letters, 0, length($letters)-1), 1).pack("C",$last-26); } else { $str = "a".pack("C",$last-26); } } else { $str = substr($letters, 0, length($letters)-1).pack("C",$last); } return $str; } sub print_line{ ($str) = @_; print " | $str"; print " " x (59-length($str)); print "|n"; } sub pathOf{ $f=shift; if($f=~/^(.*)/.+$/){ return "$1/"; } return "./"; } sub clashOf{ $f=shift; $p=pathOf($f); $f=~s/$p//; if($f=~/^(.*)..*$/){ return $1; } return $f; } sub extOf{ $f=shift; $p=pathOf($f); $f=~s/$p//; if($f=~/^.*.(.*)$/){ return $1; } return ""; } sub main_menu{ print " n"; print " +------------------------------------------------------------+n"; print " | MAIN MENU |n"; print " +------------------------------------------------------------+n"; print " | 1. Modify Whole File Name |n"; print " | 2. Replace |n"; print " | 3. Change With Order Name |n"; print " | 4. Add |n"; print " | 5. Delete |n"; print " | 6. Extended Functions |n"; print " | |n"; print " | U. Goto Previous Menu |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub whole{ print " n"; print " +------------------------------------------------------------+n"; print " | MODIFY WHOLE FILE NAME |n"; print " +------------------------------------------------------------+n"; print " | 1. Capitalize File Name |n"; print " | 2. Lowercase File Name |n"; print " | 3. Capitalize First Letter of Each Word of File Name |n"; print " | 4. Lowercase First Letter of Each Word of File Name |n"; print " | 5. Change File Name to |n"; print " | 6. Caplitalize Extension |n"; print " | 7. Lowercase Extension |n"; print " | 8. Change Extension to |n"; print " | |n"; print " | NOTE: File Name Does NOT Include Extension If Any |n"; print " | |n"; print " | U. Goto Previous Menu |n"; print " | M. Goto Main Menu |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub template{ print " n"; print " +------------------------------------------------------------+n"; print " | CHOOSE A ORDER TEMPLATE |n"; print " +------------------------------------------------------------+n"; print " | 1. Input A Template And Add It To The List |n"; print " | 2. Input A Template(Do Not Add To The List) |n"; for($i=0; $i<@ts; $i++){ print_line(($i+3).". ".$ts[$i]." "); } print " | |n"; print " | U. Goto Previous Menu |n"; print " | M. Goto Main Menu |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub get_pattern{ while(1){ print " >> Input a pattern: "; chomp ($the_p = <STDIN>); if($the_p =~ /^/(.+)/$/){ $the_p = $1; last; } else { print " !! The pattern is like [/txt/] .n"; } } return $the_p; } sub get_replace{ while(1){ print " >> Input a replace string: "; chomp ($the_p = <STDIN>); if($the_p =~ /^[^/]+$/){ last; } else { print " !! [/] is not allowed.n"; } } return $the_p; } sub input{ print " n"; print " +------------------------------------------------------------+n"; print " | INPUT FILES |n"; print " +------------------------------------------------------------+n"; print " | 1. Input A Path And A Filter |n"; print " | 2. Input Files Directly |n"; print " | |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub preview_or_apply{ print " n"; print " +------------------------------------------------------------+n"; print " | PREVIEW OR APPLY |n"; print " +------------------------------------------------------------+n"; print " | 1. Preview |n"; print " | 2. Apply |n"; print " | |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub help{ ($last_menu) = @_; print " n"; print " +------------------------------------------------------------+n"; print " | HELP |n"; print " +------------------------------------------------------------+n"; print " | INPUT FILES: |n"; print " | 1. Input A Path And A Filter |n"; print " | Input a path: |n"; print " | 1) path must exist |n"; print " | 2) path can be either relative or absolute |n"; print " | 3) enter directly for current directory |n"; print " | Input a filter: |n"; print " | 1) between // is a regular expression |n"; print " | 2) front ! means except files meet the given pattern |n"; print " | 3) enter directly for all the files |n"; print " | /.*.txt/ all .txt files |n"; print " | !/.*.txt/ all files but .txt |n"; print " | 2. Input Files Directly |n"; print " | 1) folder:foo1|foo2|foo3 |n"; print " | for file 'foo1' 'foo2' 'foo3' in the same 'folder' |n"; print " | 2) folder/foo1|folder/foo2|folder/foo3 |n"; print " | for the same |n"; print " | |n"; print " | MAIN MENU |n"; print " | 1. Modify Whole File Name |n"; print " | 1) extension treated as a separate part |n"; print " | 2) '/' is not allowed in file name and extension |n"; print " | 2. Replace |n"; print " | 1) replace pattern should be a regular expression |n"; print " | with '//' |n"; print " | 2) '/' is not allowed in replace string |n"; print " | e.g.: foo1,foo2,foo3 -> foo2,foo3,foo4 |n"; print " | pattern: /(d+)/ , replace string: ($1+1)."_" |n"; print " | then foo1,foo2,foo3 -> foo2_,foo3_,foo4_ |n"; print " | and then delete '_'(use function delete) |n"; print " | 3. Change With Order Name |n"; print " | 1) template |n"; print " | <SELF> represents file name (exclude extension) |n"; print " | # for digits or characters to replace, it's required |n"; print " | 2) the template will add to the list after you restart |n"; print " | this program if you choose this option |n"; print " | 3) regulation of order |n"; print " | 'a,b,c,d,e' |n"; print " | all can be omitted, the default value is '0,1,1,0,0' |n"; print " | a: start number or letter of order |n"; print " | b: number only, step of orde |n"; print " | c: maximal digit of number ignored if d set to 0 |n"; print " | d: 1, fill other digit 'a'(for letter) or '0'(for |n"; print " | number) if total digits less than maximum while |n"; print " | 0 does NOT |n"; print " | e: if letters capitalize them |n"; print " | 4. Add |n"; print " | Input position and string to add |n"; print " | 'pos/str' |n"; print " | pos: add position, e.g.: '0' for front ; |n"; print " | '1' for position between 1st and 2nd letter |n"; print " | '-1' between last letter and letter before it |n"; print " | str: string to add, '/' is not allowed |n"; print " | 5. Delete |n"; print " | 1) input a string to delete |n"; print " | 'foo' or 'foo/0' or 'foo/1' |n"; print " | 'foo' is an omitted form of 'foo/0' |n"; print " | '/0' means delete the first 'foo' in file name |n"; print " | '/1' means delete all 'foo' in file name |n"; print " | 2) input position and length to delete |n"; print " | 'pos/len' |n"; print " | pos is as the same as it in 'Add' menu |n"; print " | |n"; print " | !X !S. Goto Previous Menu |n"; print " | S. Save This Help to File 'smartrename.help' |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; if($_ eq "X"){ print "n"; exit; } elsif($_ eq "S"){ open(H, ">smartrename.help"); print H " n"; print H " +------------------------------------------------------------+n"; print H " | HELP |n"; print H " +------------------------------------------------------------+n"; print H " | INPUT FILES: |n"; print H " | 1. Input A Path And A Filter |n"; print H " | Input a path: |n"; print H " | 1) path must exist |n"; print H " | 2) path can be either relative or absolute |n"; print H " | 3) enter directly for current directory |n"; print H " | Input a filter: |n"; print H " | 1) between // is a regular expression |n"; print H " | 2) front ! means except files meet the given pattern |n"; print H " | 3) enter directly for all the files |n"; print H " | /.*.txt/ all .txt files |n"; print H " | !/.*.txt/ all files but .txt |n"; print H " | 2. Input Files Directly |n"; print H " | 1) folder:foo1|foo2|foo3 |n"; print H " | for file 'foo1' 'foo2' 'foo3' in the same 'folder' |n"; print H " | 2) folder/foo1|folder/foo2|folder/foo3 |n"; print H " | for the same |n"; print H " | |n"; print H " | MAIN MENU |n"; print H " | 1. Modify Whole File Name |n"; print H " | 1) extension treated as a separate part |n"; print H " | 2) '/' is not allowed in file name and extension |n"; print H " | 2. Replace |n"; print H " | 1) replace pattern should be a regular expression |n"; print H " | with '//' |n"; print H " | 2) '/' is not allowed in replace string |n"; print H " | e.g.: foo1,foo2,foo3 -> foo2,foo3,foo4 |n"; print H " | pattern: /(d+)/ , replace string: ($1+1)."_" |n"; print H " | then foo1,foo2,foo3 -> foo2_,foo3_,foo4_ |n"; print H " | and then delete '_'(use function delete) |n"; print H " | 3. Change With Order Name |n"; print H " | 1) template |n"; print H " | <SELF> represents file name (exclude extension) |n"; print H " | # for digits or characters to replace, it's required |n"; print H " | 2) the template will add to the list after you restart |n"; print H " | this program if you choose this option |n"; print H " | 3) regulation of order |n"; print H " | 'a,b,c,d,e' |n"; print H " | all can be omitted, the default value is '0,1,1,0,0' |n"; print H " | a: start number or letter of order |n"; print H " | b: number only, step of orde |n"; print H " | c: maximal digit of number ignored if d set to 0 |n"; print H " | d: 1, fill other digit 'a'(for letter) or '0'(for |n"; print H " | number) if total digits less than maximum while |n"; print H " | 0 does NOT |n"; print H " | e: if letters capitalize them |n"; print H " | 4. Add |n"; print H " | Input position and string to add |n"; print H " | 'pos/str' |n"; print H " | pos: add position, e.g.: '0' for front ; |n"; print H " | '1' for position between 1st and 2nd letter |n"; print H " | '-1' between last letter and letter before it |n"; print H " | str: string to add, '/' is not allowed |n"; print H " | 5. Delete |n"; print H " | 1) input a string to delete |n"; print H " | 'foo' or 'foo/0' or 'foo/1' |n"; print H " | 'foo' is an omitted form of 'foo/0' |n"; print H " | '/0' means delete the first 'foo' in file name |n"; print H " | '/1' means delete all 'foo' in file name |n"; print H " | 2) input position and length to delete |n"; print H " | 'pos/len' |n"; print H " | pos is as the same as it in 'Add' menu |n"; print H " | |n"; print H " +------------------------------------------------------------+n"; print H " n"; close(H); print " >> [smartrename.help] saved!n"; return $last_menu; } else { return $last_menu; } } sub deletion{ print " n"; print " +------------------------------------------------------------+n"; print " | DELETE OPTIONS |n"; print " +------------------------------------------------------------+n"; print " | 1. Input String to Delete |n"; print " | 2. Extended Deletion |n"; print " | |n"; print " | U. Goto Previous Menu |n"; print " | M. Goto Main Menu |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub extend{ print " n"; print " +------------------------------------------------------------+n"; print " | EXTENDED FUNCTIONS |n"; print " +------------------------------------------------------------+n"; print " | 1. Reverse English Characters Case |n"; print " | 2. Reverse Characters Order |n"; print " | 3. Lowercase Letter After Capital Letter One By One |n"; print " | Like: AaBbCcDdEeFf |n"; print " | 4. Capital Letter After Lowercase Letter One By One |n"; print " | Like: aAbBcCdDeEfF |n"; print " | 5. The 1st Choice Act On Extension |n"; print " | 6. The 2nd Choice Act On Extension |n"; print " | 7. The 3rd Choice Act On Extension |n"; print " | 8. The 4th Choice Act On Extension |n"; print " | |n"; print " | U. Goto Previous Menu |n"; print " | M. Goto Main Menu |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub get_delete_string{ while(1){ print " >> Input a string to delete: "; chomp ($_ = <STDIN>); if(/^[^/]+(?:/(?:0|1))?$/){ last; } else { print " !! [foo/0] to delete [foo] once while [foo/1] delete all.n"; } } return $_; } sub get_extended_deletion{ while(1){ print " >> Input position and length to delete: "; chomp ($_ = <STDIN>); if(/^d+/d+$/){ last; } else { print " !! [0/2] to delete the first 2 characters.n"; } } return $_; } sub get_menu{ ($menu) = @_; $ubound = $m_ubound{$menu}; @chars = split /,/, $m_chars{$menu}; while(1){ $choice = $menu; if(is_num $choice){ if($choice>=1 and $choice<=$ubound){ last; } else { print " !! Unknown choice.n"; } } else { if($choice eq "X" and is_inArray("X", @chars)){ print "n"; exit; } elsif($choice eq "H" and is_inArray("H", @chars)){ return get_menu(help($menu)); } elsif($choice eq "M" and is_inArray("M", @chars)) { return get_menu("main_menu"); } elsif($choice eq "U" and is_inArray("U", @chars)){ goto RESTART if($m_prev{$menu} eq "input"); goto REDO if($m_prev{$menu} eq "main_menu"); return get_menu($m_prev{$menu}); } else { print " !! Unknown choice.n"; } } } return $choice; } sub get_path{ while(1){ print " >> Input a path: "; $the_path = <STDIN>; chomp $the_path; return "./" if($the_path=~/^s*$/); # if no input, set path current directory if(-e $the_path and -d $the_path){ last; } else { print " !! Nonexistent path or non-directory path. n" } } return $the_path."/" if($the_path=~/^.*[^/]$/); return $the_path; } sub get_filter{ while(1){ print " >> Input a filter: "; $the_filter = <STDIN>; chomp $the_filter; if($the_filter=~/^!?/.+/$/){ last; } elsif($the_filter=~/^s*$/){ # for all the files $the_filter = "/^.*$/"; last; }else { print " !! The filter pattern is [!?/.+/] , e.g.:n"; print " !! [!/.*.txt/] for all but .txt files.n"; } } return $the_filter; } sub get_files{ REENTER:while(1){ print " >> Input files: "; $the_files = <STDIN>; chomp $the_files; ($the_path, $the_files) = ($the_files=~/^(?:(.+)s*:s*)?(.+)$/); if(!defined($the_files)){ print " !! Please check if [$_] exists, input sample: n"; print " !! [test:1.txt|2.txt] for 1.txt and 2.txt in directory;n"; print " !! [test/1.txt|test/2.txt] for the same.n"; next; } @the_filess = split /s*|s*/, $the_files; foreach (@the_filess){ if(defined($the_path)){$_ = "$the_path/$_";} if(!-e $_){ print " !! Please check if [$_] exists, input sample: n"; print " !! [test:1.txt|2.txt] for 1.txt and 2.txt in directory;n"; print " !! [test/1.txt|test/2.txt] for the same.n"; next REENTER; } } last; } return @the_filess; } sub get_if_apply{ while(1){ print " >> Apply(y) or discard(n) the results? "; $the_apply = <STDIN>; chomp $the_apply; if($the_apply eq "y" or $the_apply eq "n"){ last; } else { print " !! Input [y] or [n].n"; } } return $the_apply; } sub get_file_or_ext{ $flag = shift; $f = $flag ? "file name" : "extension"; while(1){ print " >> Input a new $f: "; $the_f = <STDIN>; chomp $the_f; if($the_f =~ /^[^/]+$/){ last; } else { print " !! [/] is not allowed in $f.n"; } } return $the_f; } sub get_input_template{ while(1){ print " >> Input a new template: "; chomp ($the_t = <STDIN>); if($the_t =~ /^[^/]*#[^/]*$/){ last; } else { print " !! [#] is required and [/] is not allowed.n"; } } return $the_t; } sub get_template{ $temp_choice = get_menu("template"); if($temp_choice == 1){ $temp = get_input_template; open(SELF, "$0"); @self_content = <SELF>; close(SELF); open(SELFBAK, ">$0.bak"); print SELFBAK @self_content; close(SELFBAK); foreach (@self_content){ if(/^## .+///){ s/////$temp///; } if(/^s+template => (d+),/){ s/($1)/$1+1/e; last; } } open(SELF, ">$0"); print SELF @self_content; close(SELF); } elsif ($temp_choice == 2){ $temp = get_input_template; } else { $temp = $ts[$temp_choice - 3]; } return $temp; } sub get_regular{ while(1){ print " >> Input A Regulation of Order: "; chomp ($_ = <STDIN>); if(/^(?:d+|[a-z]+)?(?:,d+)?(?:,d+)?(?:,(?:0|1))?(?:,(?:0|1))?$/){ last; } else { print " !! e.g.: [a,1,2,1,1] makes orders AA, AB, AC....n"; } } return $_; } sub get_add{ while(1){ print " >> Input position and string to add: "; chomp ($_ = <STDIN>); if(/^-?d+/[^/]+$/){ last; } else { print " !! e.g.: [0/foo] to add [foo] to the front.n"; } } return $_; } %m_ubound = ( input => 2, main_menu => 6, whole => 8, preview_or_apply =>2, template => 12, deletion => 2, extend => 8, ); %m_prev = ( main_menu => "input", whole => "main_menu", template => "main_menu", deletion => "main_menu", extend => "main_menu", ); %m_chars = ( input => "H,X", main_menu => "U,H,X", whole => "U,M,H,X", template => "U,M,H,X", deletion => "U,M,H,X", extend => "U,M,H,X", preview_or_apply => "H,X", ); open(SELF, $0); while(<SELF>){ chomp; if($_ =~ /^## (.+)///){ @ts = split ///, $1; last; } } close(SELF); RESTART: $input_menu = get_menu("input"); @files = (); %out_files = (); # get input files if($input_menu==1){ $path = &get_path; $filter = &get_filter; opendir(DIR, $path); while($file=readdir(DIR)){ if($filter=~/^!/(.+)/$/){ push @files,$path.$file if($file!~/$1/ and $file ne "." and $file ne ".."); } elsif($filter=~/^/(.+)/$/) { push @files,$path.$file if($file=~/$1/ and $file ne "." and $file ne ".."); } } closedir(DIR); } else { @files = &get_files; } print " n"; print " +------------------------------------------------------------+n"; print " | FILES TO RENAME |n"; print " +------------------------------------------------------------+n"; foreach (sort {lc($a) cmp lc($b) or $a <=> $b} @files){print_line($_);} print " +------------------------------------------------------------+n"; REDO: $main_input = get_menu("main_menu"); if($main_input==1){ $whole_choice = get_menu("whole"); if($whole_choice==1){ foreach (@files){ $out_files{$_} = pathOf($_).uc(clashOf($_)).((extOf($_) ne "")?".":"").extOf($_); } } elsif($whole_choice==2){ foreach (@files){ $out_files{$_} = pathOf($_).lc(clashOf($_)).((extOf($_) ne "")?".":"").extOf($_); } } elsif($whole_choice==3){ foreach (@files){ $out_files{$_} = pathOf($_).ucfirst(clashOf($_)).((extOf($_) ne "")?".":"").extOf($_); } } elsif($whole_choice==4){ foreach (@files){ $out_files{$_} = pathOf($_).lcfirst(clashOf($_)).((extOf($_) ne "")?".":"").extOf($_); } } elsif($whole_choice==5){ $file_name = get_file_or_ext(1); foreach (@files){ $out_files{$_} = pathOf($_).$file_name.((extOf($_) ne "")?".":"").extOf($_); } } elsif($whole_choice==6){ foreach (@files){ $out_files{$_} = pathOf($_).clashOf($_).((extOf($_) ne "")?".":"").uc(extOf($_)); } } elsif($whole_choice==7){ foreach (@files){ $out_files{$_} = pathOf($_).clashOf($_).((extOf($_) ne "")?".":"").lc(extOf($_)); } } elsif($whole_choice==8){ $file_name = get_file_or_ext(0); foreach (@files){ $out_files{$_} = pathOf($_).clashOf($_).((extOf($_) ne "")?".":"").((extOf($_) ne "")?$file_name:""); } } } elsif ($main_input== 2){ $pattern = get_pattern; $replace = get_replace; foreach (@files){ $file_name = clashOf($_).((extOf($_) ne "")?".":"").extOf($_); #$file_name =~ s/$pattern/($replace=~s/<(d+)>/$$1/g)/e; #eval('$file_name =~ s/$pattern/$replace/e;'); if($replace =~ /$/){ $file_name =~ s/$pattern/eval($replace)/e; } else { $file_name =~ s/$pattern/$replace/; } $out_files{$_} = pathOf($_).$file_name; } } elsif ($main_input==3){ $tmp = get_template; $reg = get_regular; ($start, $step, $len, $iffill, $ifcap) = ($reg =~ /^(d+|[a-z]+)?(?:,(d+))?(?:,(d+))?(?:,(0|1))?(?:,(0|1))?$/); $start = 0 if(!defined($start)); $step = 1 if(!defined($step)); $len = 1 if(!defined($len)); $iffill = 0 if(!defined($iffill)); $ifcap = 0 if(!defined($ifcap)); foreach (@files){ $tmp_clash = $tmp; $clash = clashOf($_); if($iffill){ if(length($start)<$len){ $start = sprintf(is_num($start)?"0":"a" x ($len-length($start))).$start; } } if(!is_num($start)){ if($ifcap) {$start = uc($start);} else {$start = lc($start);} } $tmp_clash =~ s/#/$start/g; $tmp_clash =~ s/<SELF>/$clash/g; $out_files{$_} = pathOf($_).$tmp_clash.((extOf($_) ne "")?".":"").extOf($_); if(is_num($start)){ $start += $step ; } else { $start = lettersAdd(lc($start), $step); } } } elsif ($main_input==4){ $add = get_add; ($pos, $str) = ($add =~ /^(-?d+)/([^/]+)$/); foreach (@files){ $clash = clashOf($_); substr($clash,$pos,0) = $str; $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } elsif ($main_input==5){ $delete = get_menu("deletion"); if($delete == 1){ $d_str = get_delete_string; ($delete_str, $delete_global) = ($d_str =~ /^([^/]+)(?:/(0|1))?$/); $delete_global = 0 if(!defined($delete_global)); foreach (@files){ $clash = clashOf($_); if($delete_global){ $clash =~ s/$delete_str//g; } else { $clash =~ s/$delete_str//; } $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } else { $d_ext = get_extended_deletion; ($d_pos,$d_len) = ($d_ext =~ /^(d+)/(d+)$/); foreach (@files){ $clash = clashOf($_); substr($clash,$d_pos,$d_len) = ""; $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } } else { $e_choice = get_menu("extend"); if($e_choice == 1){ foreach (@files){ $clash = clashOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); substr($clash,$i,1) = $c eq lc($c)?uc($c):lc($c); } $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } elsif ($e_choice == 2){ foreach (@files){ $clash = clashOf($_); $clash = reverse(split //,$clash); $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } elsif ($e_choice == 3){ foreach (@files){ my $first_cap = 1; $clash = clashOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); if(uc($c) ne lc($c)){ substr($clash,$i,1) = $first_cap?uc($c):lc($c); $first_cap = !$first_cap; } } $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } elsif ($e_choice == 4){ foreach (@files){ my $first_cap = 0; $clash = clashOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); if(uc($c) ne lc($c)){ substr($clash,$i,1) = $first_cap?uc($c):lc($c); $first_cap = !$first_cap; } } $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } elsif ($e_choice == 5){ foreach (@files){ $clash = clashOf($_).((extOf($_) ne "")?".":"").extOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); substr($clash,$i,1) = $c eq lc($c)?uc($c):lc($c); } $out_files{$_} = pathOf($_).$clash; } } elsif ($e_choice == 6){ foreach (@files){ $clash = clashOf($_).((extOf($_) ne "")?".":"").extOf($_); $clash = reverse(split //,$clash); $out_files{$_} = pathOf($_).$clash; } } elsif ($e_choice == 7){ foreach (@files){ my $first_cap = 1; $clash = clashOf($_).((extOf($_) ne "")?".":"").extOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); if(uc($c) ne lc($c)){ substr($clash,$i,1) = $first_cap?uc($c):lc($c); $first_cap = !$first_cap; } } $out_files{$_} = pathOf($_).$clash; } } else { foreach (@files){ my $first_cap = 0; $clash = clashOf($_).((extOf($_) ne "")?".":"").extOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); if(uc($c) ne lc($c)){ substr($clash,$i,1) = $first_cap?uc($c):lc($c); $first_cap = !$first_cap; } } $out_files{$_} = pathOf($_).$clash; } } } $app_input = get_menu("preview_or_apply"); if($app_input==1){ print "n"; print " +------------------------------------------------------------+n"; print " | RESULTS PREVIEW |n"; print " +------------------------------------------------------------+n"; foreach (sort {lc($a) cmp lc($b) or $a <=> $b} keys %out_files){ print " = [$_] => [$out_files{$_}]n"; } print " +------------------------------------------------------------+nn"; $app_choice = get_if_apply; if($app_choice eq "n"){ goto REDO; } } print "n"; print " +------------------------------------------------------------+n"; print " | RESULTS APPLYING |n"; print " +------------------------------------------------------------+n"; foreach (sort {lc($a) cmp lc($b) or $a <=> $b} keys %out_files){ if(!-e $out_files{$_} and rename($_,$out_files{$_})){ print " ~ "; } else { print " ! "; } print "[$_] => [$out_files{$_}]n"; } print " +------------------------------------------------------------+n"; print "n >> Done! n"; goto RESTART;
subject="审核通过!" body="<B>XXXXXX公司欢迎您。</B> " _ &"<B>您的用户名:111,密码:111</B> " _ &"<B>如果您有什么需求请您与我们联系。</B> " _ &"<B>顺颂商祺!</B> " _ &" " _ &"电话:010-XXXXXXXX / 传真:010-XXXXXXXX / 手机:13XXXXXXXX " _ &"网址:www.xxx.com / 邮箱:***@yahoo.com.cn" email="<A href="mailto:***@yahoo.com.cn">***@yahoo.com.cn</A>" Dim msg,SendMail Set msg = Server.Createobject("JMAIL.message") msg.silent = true msg.Logging = true msg.Charset = "gb2312" msg.MailServerUserName = "***" '输入smtp服务器验证登陆名 (邮局中任何一个用户的Email地址) msg.MailServerPassword = "******" '输入smtp服务器验证密码 (用户Email帐号对应的密码) msg.From = "<A href="mailto:***@yahoo.com.cn">***@yahoo.com.cn</A>" '发件人Email msg.FromName = "XXXX" '发件人姓名 msg.AddRecipient "<A href="mailto:***@163.com">***@163.com</A>" '收件人Email msg.Subject = subject '信件主题 'msg.Body = "邮件正文" '正文 msg.HTMLBody = body 'HTML正文 msg.ReturnReceipt=true msg.Send ("smtp."&right(email,instr(email,"@"))) 'smtp服务器地址(企业邮局地址) set msg = nothing if err then SendMail=err.description err.clear else SendMail="邮件发送成功!" end if Response.write SendMail
有时候总需要对一些pdb文件进行操作,特别是读数据,所以就写了这个库文件但是这个只是个比较粗略的,一时也不能补得很全,只是仅仅对ATOM的行进行了操作并进行了归类,其他的行暂时还没有进行操作,这些等到实际用到时,再进行补充吧 另外,关于atom_id和chain_id发现有些不是整型,因为在x-ray或者mnr测结构时无法确定而加的abcd之类的也没有考虑在内,如果要考虑这个的话,我想是否可以用map将id与整个原子的信息对应起来。 代码
#ifndef _PDB_H_ #define _PDB_H_ #include<iostream> #include<fstream> #include<cstdio> #include<string> #include<vector> #define atoms vector<atom> #define chains vector<chain> #define aint vector<atom>::size_type #define cint vector<chain>::size_type using namespace std; class atom{ private: short atom_id; string atom_nick; string atom_res; char atom_chain; short atom_res_id; float atom_x, atom_y, atom_z, atom_w, atom_bfactor; char atom_name; public: atom(short, string, string, char, short, float, float, float, float, float, char); atom(string); string line(); }; atom::atom( short a_id, string a_nick, string r, char c, short r_id, float a_x, float a_y, float a_z, float a_w, float b, char a_name){ atom_id = a_id; atom_nick = a_nick; atom_res = r; atom_chain = c; atom_res_id = r_id; atom_x = a_x; atom_y = a_y; atom_z = a_z; atom_w = a_w; atom_bfactor = b; atom_name = a_name; } atom::atom(string l){ atom_id = atoi(l.substr(6,5).c_str()); atom_nick = l.substr(13,3); atom_res = l.substr(17,3); atom_chain = l[21]; atom_res_id = atoi(l.substr(22,4).c_str()); atom_x = atof(l.substr(30,8).c_str()); atom_y = atof(l.substr(38,8).c_str()); atom_z = atof(l.substr(46,8).c_str()); atom_w = atof(l.substr(54,6).c_str()); atom_bfactor = atof(l.substr(60,6).c_str()); atom_name = l.size()>77 ? l[77] : ' '; } string atom::line(){ char line[255]; (void)sprintf( line, "ATOM %5u %-3s %-3s %c%4u %8.3f%8.3f%8.3f%6.2f%6.2f %c", atom_id, atom_nick.c_str(), atom_res.c_str(), atom_chain, atom_res_id, atom_x, atom_y, atom_z, atom_w, atom_bfactor, atom_name); return string(line); } //=============================================== class chain{ private: atoms chain_atms; char chain_label; public: chain(char); void addAtom(atom); void saveToFile(string); aint size(); char label(); atom operator[](aint); }; chain::chain(char l){ chain_label = l; } aint chain::size(){ return chain_atms.size(); } atom chain::operator[](aint i){ if(i>=0 and i<chain_atms.size()) return chain_atms[i]; } char chain::label(){ return chain_label; } void chain::addAtom(atom a){ chain_atms.push_back(a); return; } void chain::saveToFile(string f){ ofstream in(f.c_str()); for(cint i=0; i<chain_atms.size(); i++){ in << chain_atms[i].line() << endl; } in << "TER" << endl; in.close(); return; } //=============================================== class pdb{ private: chains pdb_chns; public: pdb(string); cint size(); chain operator[](cint); }; cint pdb::size(){ return pdb_chns.size(); } chain pdb::operator[](cint i){ if(i>=0 and i<pdb_chns.size()) return pdb_chns[i]; } pdb::pdb(string pdbfile){ string l; char flag, chain_label; ifstream out1(pdbfile.c_str()); while(getline(out1, l)){ //get the chain labels first if(l.substr(0,4) == "ATOM"){ chain_label = l[21]; if(flag != chain_label){ chain chn(chain_label); pdb_chns.push_back(chn); flag = chain_label; } } } out1.close(); ifstream out2(pdbfile.c_str()); while(getline(out2, l)){ if(l.substr(0,4) == "ATOM"){ atom atm(l); chain_label = l[21]; for(cint i=0; i<pdb_chns.size(); i++){ if(chain_label == pdb_chns[i].label()) pdb_chns[i].addAtom(atm); } } } out2.close(); } #endif
首先希望大家不要把我当火星人 ^_^!
类外函数是不能直接调用类的成员变量和成员函数的, 以前根本没有意识到这样的问题
是这样的:
<?php class varhead{ var title; function varhead(title='welcome'){ $this->title=title; } function setTitle(title='welcome'){ $this->title=title; } } $varhead=new varhead(); //我先定义了这样一个类, 是用来设置网页的各种头部信息的. //并且将它实例化 function isHome(){ if($varhead->title=='welcome')echo 'HomePage'; } //这是一个类外函数, 我想调类varhead的成员变量title的值. //但是没想到, 在函数isHome中怎么也得不到$varhead->title的值. //我开始意识到, 在类外函数中, 可能不能直接调用类的成员变量 //我试过这样, 但仍然不行: /* $t=$varhead->title; function isHome(){ if($t=='welcome')echo 'HomePage'; } */ ?>
后来我在百度上找到一种解决办法, 就是在类外的函数中重新实例化一个类对象, 然后而进行调用.
function isHome(){ $varhead1=new varhead(); if($varhead1->title=='welcome')echo 'HomePage'; }
这样是可以的, 可以得到$varhead1->title的值.
但是新的问题又出现了, 这个实例化的对象$varhead1和我原来实例化的对象$varhead是两个不同的对象, 也就是说,如果我先设置了title.
$varhead->setTitle("products");
这样对函数中的对象$varhead1将不会有任何的影响, 而$varhead1->title的值还将会是默认值’welcome’, 仍然判断不出该页是否首页.
后来再想到WP的一个插件CountPosts, 由于我改过这个插件, 在里面加了留言数,评论数以及文章的点击数, 发现这个插件里面的函数可以直接使用WP实例化的数据库类$wpdb, 但它每个函数前面都将这个对象声明为了全局变量.
于是我也试试,发现这样才是解决问题的根本途径:
function isHome(){ global $varhead; if($varhead->title=='welcome')echo 'HomePage'; }
这样问题就得到了完美的解决.
也就是说要想从类外函数调用类的成员变量和成员函数就必须在类外的函数中global一下类(PS:我不知道这个操作叫什么, 什么不是声明吧),才能调用类的成员变量和函数.

Recent Comments