X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdata-io%2Fdata-writer.c;h=5f87d0060ac589a27c0713ba8cfc38ca91329642;hb=80788c833f111c2e9aef3e25bdb44d6a56423313;hp=5270db0e8119f86236ba5e64e68a510b8cf6840c;hpb=546590abfc8b8f2d2b54bbceb6a4f29b7cd7d6c4;p=pspp diff --git a/src/language/data-io/data-writer.c b/src/language/data-io/data-writer.c index 5270db0e81..5f87d0060a 100644 --- a/src/language/data-io/data-writer.c +++ b/src/language/data-io/data-writer.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-2004, 2006, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 1997-2004, 2006, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -49,8 +49,10 @@ struct dfm_writer FILE *file; /* Associated file. */ struct replace_file *rf; /* Atomic file replacement support. */ char *encoding; /* Encoding. */ + enum fh_line_ends line_ends; /* Line ends for text files. */ int unit; /* Unit width, in bytes. */ + char cr[MAX_UNIT]; /* \r in encoding, 'unit' bytes long. */ char lf[MAX_UNIT]; /* \n in encoding, 'unit' bytes long. */ char spaces[32]; /* 32 bytes worth of ' ' in encoding. */ }; @@ -93,7 +95,9 @@ dfm_open_writer (struct file_handle *fh, const char *encoding) w->rf = replace_file_start (fh_get_file_name (w->fh), "wb", 0666, &w->file, NULL); w->encoding = xstrdup (encoding); + w->line_ends = fh_get_line_ends (fh); w->unit = ei.unit; + memcpy (w->cr, ei.cr, sizeof w->cr); memcpy (w->lf, ei.lf, sizeof w->lf); for (ofs = 0; ofs + ei.unit <= sizeof w->spaces; ofs += ei.unit) memcpy (&w->spaces[ofs], ei.space, ei.unit); @@ -134,6 +138,8 @@ dfm_put_record (struct dfm_writer *w, const char *rec, size_t len) { case FH_MODE_TEXT: fwrite (rec, len, 1, w->file); + if (w->line_ends == FH_END_CRLF) + fwrite (w->cr, w->unit, 1, w->file); fwrite (w->lf, w->unit, 1, w->file); break;