SC break problem

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Muroph
Posts: 561
Joined: 21 Aug 2007 16:13

SC break problem

Post by Muroph »

i'm having trouble with one of my scripts.
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's supposed to loop through the selected files checking and/or replacing some invalid characters (for my ebook reader).
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?
My shared scripts:
TeraCopy Integration, Tag Manager, Comments Menu, Text Replacer, Image and Media Tools, Checksum Calculator, Video Calculator
only 5 URLs are allowed on the sig...

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: SC break problem

Post by jacky »

hmm... looks like a bug, when while is inside a if :

Code: Select all

  if (1)
  {
   while (1)
   {
     break;
   }
   msg 'foo'; // never gets executed
  }
Proud XYplorer Fanatic

admin
Site Admin
Posts: 66351
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: SC break problem

Post by admin »

Indeed! Fixed.

Post Reply