Page 1 of 1

sc readfile, writefile and text - unreadable outputs

Posted: 20 Apr 2012 22:46
by neutrox
I am seeing some discrepancies on sc readfile/writefile and sc text but it may be just me:

if <curitem> is the result of sc readurl saved as .txt,

Code: Select all

$a = readfile("<curitem>"); writefile("new.txt", $a);
gives different result from
text readfile("<curitem>");

TU for sc writefile won't do a difference here.

IOW when I pick sc text I have a read-able output, OTOH if I open a file created by sc readurl, sc readfile and writefile I just have a mess of words with no meaningful spacing at all.

Re: sc readfile, writefile and text - unreadable outputs

Posted: 26 Apr 2012 00:41
by neutrox
Guys, I badly need help on this.

The problem seems to be the lack of support of custom line feeds which are present on the sc text command so my suggestion is giving sc writefile the same ability. Sometimes it is great to have the original text formatting but in the case I explained in my previous post it is just too bad not being possible to convert documents to a different line feed.

Re: sc readfile, writefile and text - unreadable outputs

Posted: 28 Apr 2012 21:28
by neutrox

Code: Select all

writefile("d:\Downloads\Stuff\Offline\new.txt", readfile("d:\Downloads\Stuff\Offline\Offline Page.txt", t, , 65000), o, ); run "d:\Downloads\Stuff\Offline\new.txt";
I tried several encodings as attempts based on this page and xy documentation: http://msdn.microsoft.com/en-us/library ... epage.aspx

If I open the Offline Page.txt, select all, copy & paste it elsewhere other than notepad (wordpad, for instance), I get the desired spacing. As said, a simple text readfile(<curitem>); will do. But I need to fix those documents so they are eyes-friendly!

Re: sc readfile, writefile and text - unreadable outputs

Posted: 30 Apr 2012 07:17
by admin
I don't think your description of the problem is complete enough for me to reproduce it. Please give me a copy-and-paste script that will create the error before my eyes.

Re: sc readfile, writefile and text - unreadable outputs

Posted: 30 Apr 2012 13:53
by neutrox

Code: Select all

writefile("ReadURL Test.text", readurl("http://www.youtube.com/watch?v=rte3kfzNXPg"));
then use this

Code: Select all

text readfile("ReadURL Test.text");
now open it with standard notepad:

Code: Select all

openwith notepad, "ReadURL Test.text";
What was a perfectly readable text-and-code now is just a heavy block of words due to lack of line feeds.

The problem is:
how to force sc writefile to write the necessary line feeds* info so the saved document
will store spacing in a format notepad will interpret line feeds like sc text does?

Because if I copy the output from sc text window into a new notepad document, then
notepad will correctly open it afterwards.
_________
*or sc readurl to correctly feed sc writefile, I don't know. But it does somehow, the line feeds are stored as sc text correctly interprets them. :roll:

Re: sc readfile, writefile and text - unreadable outputs

Posted: 30 Apr 2012 14:39
by admin
Yawn. It's a UNIX file and XY says so in its preview Tab. Notepad is too stupid to handle UNIX. That's all.

Re: sc readfile, writefile and text - unreadable outputs

Posted: 30 Apr 2012 18:04
by PeterH
I think "unix" is only LF (x'0a') for new lines?

Then you could change all LF to CRLF (x'0a' to x'0d0a').

Some editors (and other programs) understand both, some don't ...

Re: sc readfile, writefile and text - unreadable outputs

Posted: 30 Apr 2012 18:59
by neutrox
It seems that XYplorer won't allow use of "<cr>" and/or "<lf>" for search and replacement.

The following won't do it as well:

Code: Select all

[code]$base = readfile("<curitem>"); $lf =  chr(13).chr(10).chr(32).chr(32); replace $base, $base, "$lf", "<crlf>"; writefile("Text Fix.txt", $base);
[/code]

Code: Select all

[code]$base = readfile("<curitem>"); $lf =  chr(13).chr(10).chr(32); replace $base, $base, "$lf", "<crlf>"; writefile("Text Fix.txt", $base);
[/code]

Code: Select all

$base = readfile("<curitem>"); $lf =  chr(13).chr(10); replace $base, $base, "$lf", "<crlf>"; writefile("Text Fix.txt", $base);

Code: Select all

$base = readfile("<curitem>"); $lf =  chr(13); replace $base, $base, "$lf", "<crlf>"; writefile("Text Fix.txt", $base);
So how could I change those, PeterH?

Re: sc readfile, writefile and text - unreadable outputs

Posted: 30 Apr 2012 21:55
by Stefan
neutrox wrote:It seems that XYplorer won't allow use of "<cr>" and/or "<lf>" for search and replacement.
e.g.

Code: Select all

//$name = "<curname>";
     
   $data = readfile("<curitem>");
   ////match "\n" but not if there is an "\r" before:
   $data = regexreplace($data, "([^\r])\n", "$1<crlf>");
   text $data;
      
   //writefile($name . "_Win32.txt", $data);

Re: sc readfile, writefile and text - unreadable outputs

Posted: 30 Apr 2012 21:58
by highend

Code: Select all

	$base = readfile("<curitem>");
	$base = regexreplace($base, "\n", "<crlf>");
	writefile("Text Fix.txt", $base);

Re: sc readfile, writefile and text - unreadable outputs

Posted: 30 Apr 2012 22:32
by Stefan
highend wrote:

Code: Select all

	$base = readfile("<curitem>");
	$base = regexreplace($base, "\n", "<crlf>");
	writefile("Text Fix.txt", $base);
That will not only replace \n to \r\n
but also replace \r\n to \r\r\n
in files with mixed LE
or for files with windows LE only, processed by accident.

Re: sc readfile, writefile and text - unreadable outputs

Posted: 30 Apr 2012 22:43
by PeterH
neutrox wrote:So how could I change those, PeterH?
Hey: nobody looked what you did wrong?

So: *what* did you try to replace???
I said x'0a', that's decimal 10, isn't it?

:arrow: I don't understand the idea of your first 3 examples.
But if, in the last version, you replace chr(13) with chr(10), you would be lucky.

(And if your scripts would have a better form people reading them would be more happy :roll: )

Re: sc readfile, writefile and text - unreadable outputs

Posted: 03 May 2012 02:31
by neutrox
PeterH wrote: :arrow: I don't understand the idea of your first 3 examples.
But if, in the last version, you replace chr(13) with chr(10), you would be lucky.

(And if your scripts would have a better form people reading them would be more happy :roll: )
Those were attempts to get the replacement done.

I'll keep the readability on the back of my mind, sorry...... :oops:

Stefan, I understand your worry but highend's solution did he job.

For a reason I can't tell your script eliminates the closing ">" on several lines, thus damaging the original code.

Re: sc readfile, writefile and text - unreadable outputs

Posted: 03 May 2012 10:07
by PeterH
neutrox wrote:
PeterH wrote: :arrow: I don't understand the idea of your first 3 examples.
But if, in the last version, you replace chr(13) with chr(10), you would be lucky.

(And if your scripts would have a better form people reading them would be more happy :roll: )
Those were attempts to get the replacement done.
Still I don't understand the idea...

If chr(13) isn't found, anything concatenated with chr(13) will not be found at all, isn't it?
(Imagine words: if a text doesn't contain "to" it will surely not contain "today"...)

So I'm afraid there is some problem in your understanding of replace()?
( :D note my writing of the function replace() :biggrin: )

Re: sc readfile, writefile and text - unreadable outputs

Posted: 03 May 2012 11:03
by Stefan
neutrox wrote:Stefan, I understand your worry but highend's solution did he job.
Right, it works for any line ender, "\n" and even "\r\n" or both mixed inside an file.
But the point is it should not work if you have already windows line enders "\r\n" because you get "\r\r\n" then.

For a reason I can't tell your script eliminates the closing ">" on several lines,
Oh silly me :cry: Of course :lol: it's wrong, i see now.
I have modified now my expression above. Sorry.