@@ -280,19 +280,31 @@ REBINT Mode_Syms[] = {
280
280
***********************************************************************/
281
281
{
282
282
REBSER * ser ;
283
+ REBOOL lines = (args & AM_WRITE_LINES ) != 0 ;
284
+ REBINT n = 0 ;
283
285
284
286
if (IS_BLOCK (data )) {
285
287
// Form the values of the block
286
288
// !! Could be made more efficient if we broke the FORM
287
289
// into 32K chunks for writing.
288
290
REB_MOLD mo = {0 };
289
291
Reset_Mold (& mo );
290
- if (args & AM_WRITE_LINES ) {
291
- mo .opts = 1 << MOPT_LINES ;
292
- }
292
+ if (lines ) mo .opts = 1 << MOPT_LINES ;
293
293
Mold_Value (& mo , data , 0 );
294
294
Set_String (data , mo .series ); // fall into next section
295
295
len = SERIES_TAIL (mo .series );
296
+ } else if (lines ) {
297
+ // if there was: WRITE/LINES "string"
298
+ // append temporary CRLF on Windows or LF on Posix
299
+ // @@ https://github.com/rebol/rebol-issues/issues/2102
300
+ #ifdef TO_WINDOWS
301
+ Append_Bytes_Len (VAL_SERIES (data ), "\r\n" , 2 );
302
+ n = 2 ;
303
+ #else
304
+ Append_Byte (VAL_SERIES (data ), '\n' );
305
+ n = 1 ;
306
+ #endif
307
+ len += n ;
296
308
}
297
309
298
310
// Auto convert string to UTF-8
@@ -306,6 +318,13 @@ REBINT Mode_Syms[] = {
306
318
}
307
319
file -> length = len ;
308
320
OS_DO_DEVICE (file , RDC_WRITE );
321
+
322
+ if (n > 0 ) {
323
+ // remove the temporary added newline from the series
324
+ len -= n ;
325
+ SET_STR_END (VAL_SERIES (data ), len );
326
+ VAL_SERIES (data )-> tail = len ;
327
+ }
309
328
}
310
329
311
330
0 commit comments