Skip to content
⌘ NSIS Forum Archive

newline in !appendfile

6 posts

aerDNA#

newline in !appendfile

I just noticed that when used with !appendfile, $\n wil produce CR+LF in 2.46 but only LF in 3.0b1. I'm a bit tired so maybe I missed it but I don't see this change documented. It can be a problem when writing code that's supposed to be backwards compatible because using $\r$\n will produce CR+CR+LF in v2 (although this is probably not a problem for most practical purposes).
Anders#
MakeNSIS should be able to parse a file without having to worry about the newline type. Batch files also seem to be able to handle a plain \n.

2.46 just writes \n using fprintf, what happens after that depends on the compiler used to build makensis and the operating system it is running on. The POSIX build will just write a \n while the Microsoft CRT converts \n to \r\n internally.

3.x bypasses the CRT and always writes raw bytes. I supposed it would be possible to add a switch that writes the platform native newline automatically.
aerDNA#
Originally Posted by Anders View Post
Batch files also seem to be able to handle a plain \n.
True, it looks like a giant sausage to human eye but works just fine and \r\r\n doesn't bother CMD either. That's why I think it's not much of a real world issue. When it matters, one can always detect NSIS version and use the appropriate newline format, although I wouldn't know how to account for POSIX build.
Anders#
Originally Posted by aerDNA View Post
When it matters, one can always detect NSIS version and use the appropriate newline format, although I wouldn't know how to account for POSIX build.
NSIS_WIN32_MAKENSIS is not defined
aerDNA#
Ah, great. So something like this should cover all cases:
!searchparse '${NSIS_VERSION}' 'v' 'NSIS_VERSION_MAJOR' '.'
!if ${NSIS_VERSION_MAJOR} > 2
   !define NEWLINE "$\r$\n"
!else
   !ifdef NSIS_WIN32_MAKENSIS
      !define NEWLINE "$\n"
   !else
      !define NEWLINE "$\r$\n"
   !endif
!endif