Jump to content
  • Advertisement
Sign in to follow this  
roos

Endlines not consistent between text editors

This topic is 4890 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, This really gets to me... Sometimes I open a text file in one text editor and all the text appears on one line without any endlines. Or sometimes I open it and there's an extra blank line between every actual line of code. This might have to do with the fact that the piece of code I'm trying to edit was written by someone who uses Linux and I use windows (VC++). So, other than forcing to make everyone use the same text editor, is there any way to solve this problem? Perhaps visual studio has some option hidden away somewhere to correctly read endlines in files that were created in Linux? Thanks roos

Share this post


Link to post
Share on other sites
Advertisement
Sounds like you have some newline transition problems. Personally I've never had problems with MSVC opening the files properly. However, sometimes you can get around the problem with using Wordpad to open and then save the file.

How are you sharing the source? One way to avoid this kind of thing is to use FTP in A mode to transfer files since it should adjust the newline conventions to be the same as the clients.

Share this post


Link to post
Share on other sites
Thanks for replying SiCrane... Yeah, I thought about just opening the file up in WordPad and then re-saving it. Though that would fix the problem for me, are you sure that wouldn't cause the endlines to be messed up for the other coders when they open it in vi or emacs or whatever? Right now I'm the only guy on the team using Windows so I'd hate to screw everything up for the rest of the dev team as the first thing I do after they accepted me to their team, lol.

As for sharing the source, we're using CVS provided by SourceForge. I just did a checkout using TortoiseCVS.

Thanks,
roos

Share this post


Link to post
Share on other sites
Quote:

This really gets to me... Sometimes I open a text file in one text editor and all the text appears on one line without any endlines. Or sometimes I open it and there's an extra blank line between every actual line of code.


This happens because of a difference in the way in which linux and windows represent newlines. On linux, \n (line feed) is sufficient to indicate a newline whereas on windows \r\n is used (carriage return followed by line feed). I believe dos/windows uses \r\n because of the way early printers worked. Pre OS X used \r (carriage return) as the newline.

In your case, a single line file would indicate that the file was written with a *nix text editor and therefore contains \n instead of \r\n. May I suggest that it also indicates that the text editor is somewhat primitive(notepad perhaps?). Any half-decent windows text editor will interpret \n or \r properly. The double spacing probably happens because the text editor believes the text file was created in *nix and therefore interprets \r\n as two new lines.

To complicate matters further, network standards use \r\n as a newline. This can sometimes cause problems for *nix users who don't realise it.


Unfortunately, I can't help with your VC++ query. I imagine it will have such a an option though.

Quote:

... are you sure that wouldn't cause the endlines to be messed up for the other coders when they open it in vi or emacs or whateve

In my experiance Vim under linux will correctly recognise a windows text file and interpret the \r\n as a single space. Like SiCrane mentioned, I often use ftp or ssh to transfer files between linux and windows so \n may get converted to \r\n automatically.

Share this post


Link to post
Share on other sites
Don't know about Visual Studio, but most Java IDEs will have an option to set the newline convention to any of the three options.

shmoove

Share this post


Link to post
Share on other sites
In case you can't get it to work, there's a couple of programs to convert with. Google for dos2unix and unix2dos.

Share this post


Link to post
Share on other sites
You don't even need to open the file in Wordpad - just copy-paste it in, then copy-paste it back out again into the original editor. As a result, I can now type Ctrl+A Ctrl+C Win+R write Enter Ctrl+V Ctrl+A Ctrl+C Alt+F4 N Ctrl+V very fast. [wink]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!