digitalmars.D.learn - Doubled newlines
- bearophile (21/21) Jul 31 2010 I think there is a bug here, but can you please try it a bit?
- Andrej Mitrovic (11/44) Jul 31 2010 I'm getting normal newlines here (XP):
- Andrej Mitrovic (2/53) Jul 31 2010
- Jonathan M Davis (12/15) Jul 31 2010 Prior to Macs becoming Unix based, they used '\r' for the end-of-line ch...
- Steven Schveighoffer (28/47) Aug 02 2010 CR means carriage return. This is for old-style line printers. When yo...
- Andrej Mitrovic (2/67) Aug 02 2010
- bearophile (7/10) Aug 01 2010 Thank you for your test. Then maybe it's a problem that comes out on Win...
- div0 (4/8) Aug 01 2010 Yeah there is.
- div0 (2/13) Aug 01 2010 That's on XP btw
- Jonathan M Davis (7/13) Aug 01 2010 Oh, I don't disagree. I'm just pointing out the situation with the vario...
- Steven Schveighoffer (8/27) Aug 02 2010 Copy-pasting the source from an editor to the newsgroup window may not
- dcoder (16/37) Aug 03 2010 By the way, your code works correctly on my computer. I ran the program...
I think there is a bug here, but can you please try it a bit? The name of this program is "test.d", so it loads its souce code: import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } On windows the output is: import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } So it shows extra newlines (on Windows newlines are two chars). On Windows a similar Python program doesn't show the doubled newlines: s = open("test.d").read() print s Bye, bearophile
Jul 31 2010
I'm getting normal newlines here (XP): C:\output>test.exe import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } The text used CR+LF newlines. I also tried them using LF newlines, which worked fine. But I've then tried with CR and that gives out weird output like so: } write(s);= readText("test.d"); bearophile Wrote:I think there is a bug here, but can you please try it a bit? The name of this program is "test.d", so it loads its souce code: import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } On windows the output is: import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } So it shows extra newlines (on Windows newlines are two chars). On Windows a similar Python program doesn't show the doubled newlines: s = open("test.d").read() print s Bye, bearophile
Jul 31 2010
Oh and I'm getting the same issue in Python when using CR only. I don't know why I have the CR option in the text editor if it doesn't work properly. I guess CR is used on the Macs maybe..? Andrej Mitrovic Wrote:I'm getting normal newlines here (XP): C:\output>test.exe import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } The text used CR+LF newlines. I also tried them using LF newlines, which worked fine. But I've then tried with CR and that gives out weird output like so: } write(s);= readText("test.d"); bearophile Wrote:I think there is a bug here, but can you please try it a bit? The name of this program is "test.d", so it loads its souce code: import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } On windows the output is: import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } So it shows extra newlines (on Windows newlines are two chars). On Windows a similar Python program doesn't show the doubled newlines: s = open("test.d").read() print s Bye, bearophile
Jul 31 2010
On Saturday 31 July 2010 20:10:05 Andrej Mitrovic wrote:Oh and I'm getting the same issue in Python when using CR only. I don't know why I have the CR option in the text editor if it doesn't work properly. I guess CR is used on the Macs maybe..?Prior to Macs becoming Unix based, they used '\r' for the end-of-line character. Once they became Unix based, they did what Unix does and used '\n'. So, at this point, you really only have to worry about '\n' vs '\r\n' with Windows being the only odd man out. The funny thing is that _technically_ speaking, Windows is right: a newline drops down a line, and carriage return goes to the beginning of a line, so both are necessary. But since we don't use typewriters anymore or use consoles in that way, combing them into one character like C did is better, and that's what most everything does. So, while Wnidows is arguably more correct, it causes problems and is arguably inferior. - Jonathan M Davis
Jul 31 2010
On Sat, 31 Jul 2010 23:10:05 -0400, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:Oh and I'm getting the same issue in Python when using CR only. I don't know why I have the CR option in the text editor if it doesn't work properly. I guess CR is used on the Macs maybe..? Andrej Mitrovic Wrote:CR means carriage return. This is for old-style line printers. When you sent a CR, it means, literally, move the carriage back to the front of the line. When you sent a LF (line feed), it means, feed the paper another line. If you printed a file to such a printer with just line feeds, you would see: import std.file: readText; import std.stdio: write; void main() { ... If you printed the file with just CRs, you would see all the lines super-imposed over eachother, because the paper is never moved, just the carriage is returned. This is the effect you are seeing, each line is super-imposed over the other. However, on a terminal, you don't see the residual letters from previously printed lines, they are completely overwritten. Essentially, if you put in a sleep between printing each line, what you'd see is this: import std.file: readText; .. pause .. import std.stdio: write;t; .. pause .. void main() {dio: write;t; .... Hope this helps ;) -SteveI'm getting normal newlines here (XP): C:\output>test.exe import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } The text used CR+LF newlines. I also tried them using LF newlines, which worked fine. But I've then tried with CR and that gives out weird output like so: } write(s);= readText("test.d");
Aug 02 2010
It makes sense now. Thanks. :) Steven Schveighoffer Wrote:On Sat, 31 Jul 2010 23:10:05 -0400, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:Oh and I'm getting the same issue in Python when using CR only. I don't know why I have the CR option in the text editor if it doesn't work properly. I guess CR is used on the Macs maybe..? Andrej Mitrovic Wrote:CR means carriage return. This is for old-style line printers. When you sent a CR, it means, literally, move the carriage back to the front of the line. When you sent a LF (line feed), it means, feed the paper another line. If you printed a file to such a printer with just line feeds, you would see: import std.file: readText; import std.stdio: write; void main() { ... If you printed the file with just CRs, you would see all the lines super-imposed over eachother, because the paper is never moved, just the carriage is returned. This is the effect you are seeing, each line is super-imposed over the other. However, on a terminal, you don't see the residual letters from previously printed lines, they are completely overwritten. Essentially, if you put in a sleep between printing each line, what you'd see is this: import std.file: readText; .. pause .. import std.stdio: write;t; .. pause .. void main() {dio: write;t; .... Hope this helps ;) -SteveI'm getting normal newlines here (XP): C:\output>test.exe import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } The text used CR+LF newlines. I also tried them using LF newlines, which worked fine. But I've then tried with CR and that gives out weird output like so: } write(s);= readText("test.d");
Aug 02 2010
Andrej Mitrovic:I'm getting normal newlines here (XP):Thank you for your test. Then maybe it's a problem that comes out on Windows Vista only, I don't know. --------------------- Jonathan M Davis:So, while Wnidows is arguably more correct, it causes problems and is arguably inferior.The point is that probably there is a newline-related bug somewhere in Phobos and I'd like to find it. Bye, bearophile
Aug 01 2010
On 01/08/2010 13:12, bearophile wrote:Andrej Mitrovic: The point is that probably there is a newline-related bug somewhere in Phobos and I'd like to find it. Bye, bearophileYeah there is. I get doubled new lines as well when passing a handle opened with fopen to a CFile thingy.
Aug 01 2010
On 01/08/2010 18:22, div0 wrote:On 01/08/2010 13:12, bearophile wrote:That's on XP btwAndrej Mitrovic: The point is that probably there is a newline-related bug somewhere in Phobos and I'd like to find it. Bye, bearophileYeah there is. I get doubled new lines as well when passing a handle opened with fopen to a CFile thingy.
Aug 01 2010
On Sunday 01 August 2010 05:12:04 bearophile wrote:Jonathan M Davis:Oh, I don't disagree. I'm just pointing out the situation with the various end- of-line characters on the various OSes. It sounds like the two character solution of Windows might be messing things up somewhere, but I was just pointing out the character situation. However, the error does indeed need to be found and fiixed. - Jonathan M DavisSo, while Wnidows is arguably more correct, it causes problems and is arguably inferior.The point is that probably there is a newline-related bug somewhere in Phobos and I'd like to find it.
Aug 01 2010
On Sat, 31 Jul 2010 21:15:21 -0400, bearophile <bearophileHUGS lycos.com> wrote:I think there is a bug here, but can you please try it a bit? The name of this program is "test.d", so it loads its souce code: import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } On windows the output is: import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } So it shows extra newlines (on Windows newlines are two chars). On Windows a similar Python program doesn't show the doubled newlines: s = open("test.d").read() print sCopy-pasting the source from an editor to the newsgroup window may not allow others to see the problem, since it may have to do with non-visible characters. Attach the file directly to a news post, then maybe we can repeat it easier. -Steve
Aug 02 2010
== Quote from bearophile (bearophileHUGS lycos.com)'s articleI think there is a bug here, but can you please try it a bit? The name of this program is "test.d", so it loads its souce code: import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } On windows the output is: import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } So it shows extra newlines (on Windows newlines are two chars). On Windows a similar Python program doesn't show the doubled newlines: s = open("test.d").read() print s Bye, bearophileBy the way, your code works correctly on my computer. I ran the program in cygwin using a bash shell under Windows XP. What doesn't work correctly in this setup is writef() followed by user input. I need to add stdout.flush() after writef. So go figure... $ dmd --help Digital Mars D Compiler v2.047 Copyright (c) 1999-2010 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/2.0/index.html $ ./readlines.exe import std.file: readText; import std.stdio: write; void main() { string s = readText( "readlines.d"); write(s); }
Aug 03 2010