X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fsys-file-writer.c;h=b1cb7c22c0dcd5e7a1343041b66d75fcac28cd36;hb=9ade26c8349b4434008c46cf09bc7473ec743972;hp=efefa8fb7e7e17754c1ff0589337fb52f07e4b60;hpb=d8493b3b0617cc447446a70b031a69079bc19002;p=pspp-builds.git diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index efefa8fb..b1cb7c22 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011 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 @@ -47,6 +47,7 @@ #include "libpspp/message.h" #include "libpspp/misc.h" #include "libpspp/str.h" +#include "libpspp/string-array.h" #include "libpspp/version.h" #include "gl/xmemdup0.h" @@ -238,7 +239,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, idx += sfm_width_to_octs (var_get_width (v)); } - if (dict_get_documents (d) != NULL) + if (dict_get_document_line_cnt (d) > 0) write_documents (w, d); write_integer_info_record (w); @@ -552,11 +553,22 @@ write_value_labels (struct sfm_writer *w, struct variable *v, int idx) static void write_documents (struct sfm_writer *w, const struct dictionary *d) { - size_t line_cnt = dict_get_document_line_cnt (d); + const struct string_array *docs = dict_get_documents (d); + const char *enc = dict_get_encoding (d); + size_t i; write_int (w, 6); /* Record type. */ - write_int (w, line_cnt); - write_bytes (w, dict_get_documents (d), line_cnt * DOC_LINE_LENGTH); + write_int (w, docs->n); + for (i = 0; i < docs->n; i++) + { + char *s = recode_string (enc, "UTF-8", docs->strings[i], -1); + size_t s_len = strlen (s); + size_t write_len = MIN (s_len, DOC_LINE_LENGTH); + + write_bytes (w, s, write_len); + write_spaces (w, DOC_LINE_LENGTH - write_len); + free (s); + } } static void @@ -679,7 +691,7 @@ write_mrsets (struct sfm_writer *w, const struct dictionary *dict, ds_put_format (&s, " %s", var_get_short_name (mrset->vars[j], 0)); ds_put_byte (&s, '\n'); } - write_attribute_record (w, &s, 7); + write_attribute_record (w, &s, pre_v14 ? 7 : 19); ds_destroy (&s); }