[GRASS-dev] [GRASS GIS] #3155: inconsistent newlines handling on Windows

GRASS GIS trac at osgeo.org
Sun Nov 13 15:53:25 PST 2016


#3155: inconsistent newlines handling on Windows
--------------------------+-------------------------
  Reporter:  annakrat     |      Owner:  grass-dev@…
      Type:  defect       |     Status:  new
  Priority:  normal       |  Milestone:  7.2.1
 Component:  LibVector    |    Version:  svn-trunk
Resolution:               |   Keywords:  newline
       CPU:  Unspecified  |   Platform:  MSWindows 8
--------------------------+-------------------------

Comment (by wenzeslaus):

 It actually sounds more like http://stackoverflow.com/questions/11497376
 /new-line-python, specifically Nate C-K's comment to Charlie Martin's
 answer, except that `fprintf(ascii, "%s", HOST_NEWLINE);` is in C.

 It seems that HOST_NEWLINE being `\r\n` on Windows is passed to
 `fprintf()` which seems to automatically replace `\n` by `\r\n` resulting
 in `\r\n\n` in the file (which is what is not possible to parse later in
 Python).

 [http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf ISO/IEC
 9899:TC3] says:
 > 5.2.2  Character display semantics
 >
 > Alphabetic escape sequences representing nongraphic characters in the
 execution character set are > intended to produce actions on display de
 vices as follows:
 > * ...
 > * \n (new line) Moves the active position to the initial position of the
 next line.
 > * \r (carriage return) Moves the active position to the initial position
 of the current line.
 > * ...

 [https://en.wikipedia.org/wiki/Newline#In_programming_languages Wikipedia]
 says:
 > The C standard only guarantees two things:
 > * Each of these escape sequences maps to a unique implementation-defined
 number that can be stored in a single char value.
 > * When writing a file in text mode, '\n' is transparently translated to
 the native newline sequence used by the system, which may be longer than
 one character. When reading in text mode, the native newline sequence is
 translated back to '\n'. In binary mode, no translation is performed, and
 the internal representation produced by '\n' is output directly.

 The behavior fits what these two resources say, so it seems that
 `HOST_NEWLINE` can be changed to always mean `\n` and/or not used at all.

 `HOST_NEWLINE` seems to be used only in `lib/vector/Vlib/ascii.c`,
 `i.cluster`, and `v.out.ascii`.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3155#comment:3>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list