the cause could be either a bug or just my incompetence.
this is the script (no time to add comments, sorry):
Code: Select all
"Check files : check"
global $check,$fix;
$check=1;
$fix=0;
sub _check;
"Fix (Unicode) : utf16"
global $enc,$check,$fix;
$enc=tu;
$check=0;
$fix=1;
sub _check;
"Fix (ASCII) : ascii"
global $enc,$check,$fix;
$enc=ta;
$check=0;
$fix=1;
sub _check;
"Check and fix (Unicode) : cnfutf16"
global $enc,$check,$fix;
$enc=tu;
$check=1;
$fix=1;
sub _check;
"Check and fix (ASCII) : cnfascii"
global $enc,$check,$fix;
$enc=ta;
$check=1;
$fix=1;
sub _check;
"_check"
global $check,$fix,$filelist,$total,$charlist,$replist;
$total=getinfo(countselected);
end ($total<1);
$charlist="─|-|–|–|—|ー|á|à|â|ã|ä|é|è|ë|ê|í|ì|ï|ō|ó|ò|ö|õ|ô|ú|ù|ü|’|‘|“|”|…|!| |『|』|~|↓|ç|";
$replist="-|-|-|-|--|--|a|a|a|a|a|e|e|e|e|i|i|i|o|o|o|o|o|o|u|u|u|'|'|""|""|...|!| |[|]|~||$|";
$filelist = getinfo("SelectedItemsPathNames",<crlf>);
if($check==1){
$invlist="";
$invtotal=0;
$count=1;
while($count<=$total){ //outer file loop
$file=gettoken($filelist,$count,<crlf>);
$data=readfile($file);
$count2=1;
$invalid=0;
while(1){ //inner char loop
$char=gettoken($charlist,$count2,"|");
if("$char"==""){break;} //when it reaches the end of the list it jumps from here......
if(strpos($data,$char,,1)>-1){$invalid=1;}
$count2++;}
if($invalid==1){
$invlist=$invlist.$file.<crlf>;
$invtotal++;}
status "Checked $count of $total files",,progress;
$count++;}
if($fix==1){ //......to here
if($invtotal>0){
$filelist=input("$invtotal files contain invalid characters<crlf>Select which files you want to fix",,$invlist);
$total=$invtotal;
sub _fix;}
else{msg "No invalid chars found",,ready;}}
else{
if($invtotal>0){text $invlist,,,"$invtotal files contain invalid characters";}
else{msg "No invalid chars found",,ready;}}}
elseif($fix==1){sub _fix;}
"_fix"
global $filelist,$enc,$total,$charlist,$replist;
$count=1;
while($count<=$total){
$file=gettoken($filelist,$count,<crlf>);
$data=readfile($file);
$count2=1;
while(1){
$char=gettoken($charlist,$count2,"|");
if("$char"==""){break;}
$rep=gettoken($replist,$count2,"|");
$data=replace($data,$char,$rep);
$count2++;}
writefile($file,$data,o,$enc);
status "Fixed $count of $total files",,progress;
$count++;}
status "Done! ($total files fixed)",,ready;}it uses 2 while loops on the "check" script, one for the files and another (inside the first) for the char list.
when the the inner char loop reaches the end of the char list it hits a break command that should stop this loop and continue the file loop.
however, the break command actually end both loops, and the script does not work properly.
i re-checked the whole script many times and i still don't know what's wrong with it.
however, i couldn't reproduce this behaviour on a similar script.
so, did i miss something obvious or it's really a bug?
XYplorer Beta Club