X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fsys-file-writer.c;h=dda351b9572ef9b77c27045c67077b9193eaa31b;hb=7a2039fb1ebfd48013ab259b28091e74e7f50588;hp=11ca1ef9fe032f398054dd3348ec96c6bb333f13;hpb=c489ad9041918ca8c80dadceade988daab1d25f8;p=pspp-builds.git diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index 11ca1ef9..dda351b9 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -42,6 +42,7 @@ #include "value-labels.h" #include "variable.h" #include +#include #include "gettext.h" #define _(msgid) gettext (msgid) @@ -61,6 +62,7 @@ struct sfm_writer int compress; /* 1=compressed, 0=not compressed. */ int case_cnt; /* Number of cases written so far. */ size_t flt64_cnt; /* Number of flt64 elements in case. */ + bool has_vls; /* Does the dict have very long strings? */ /* Compression buffering. */ flt64 *buf; /* Buffered data. */ @@ -197,6 +199,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, w->compress = opts.compress; w->case_cnt = 0; w->flt64_cnt = 0; + w->has_vls = false; w->buf = w->end = w->ptr = NULL; w->x = w->y = NULL; @@ -211,8 +214,8 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, sv->width = dv->width; /* spss compatibility nonsense */ if ( dv->width > MAX_LONG_STRING ) - sv->width = (dv->width / MAX_LONG_STRING) * (MAX_LONG_STRING + 1) - + (dv->width % MAX_LONG_STRING) ; + w->has_vls = true; + sv->fv = dv->fv; sv->flt64_cnt = var_flt64_cnt (dv); } @@ -683,7 +686,7 @@ write_vls_length_table (struct sfm_writer *w, struct string vls_length_map; - ds_init (&vls_length_map, 12 * dict_get_var_cnt (dict)); + ds_init (&vls_length_map); vls_hdr.rec_type = 7; vls_hdr.subtype = 14; @@ -729,7 +732,7 @@ write_longvar_table (struct sfm_writer *w, const struct dictionary *dict) struct string long_name_map; size_t i; - ds_init (&long_name_map, 10 * dict_get_var_cnt (dict)); + ds_init (&long_name_map); for (i = 0; i < dict_get_var_cnt (dict); i++) { struct variable *v = dict_get_var (dict, i); @@ -870,7 +873,7 @@ sfm_write_case (struct sfm_writer *w, const struct ccase *c) w->case_cnt++; if (!w->needs_translation && !w->compress - && sizeof (flt64) == sizeof (union value)) + && sizeof (flt64) == sizeof (union value) && ! w->has_vls ) { /* Fast path: external and internal representations are the same and the dictionary is properly ordered. Write @@ -898,14 +901,23 @@ sfm_write_case (struct sfm_writer *w, const struct ccase *c) memset(bounce_cur, ' ', v->flt64_cnt * sizeof (flt64)); if (v->width == 0) - *bounce_cur = case_num (c, v->fv); - else { - buf_copy_rpad((char*)bounce_cur, v->flt64_cnt * sizeof (flt64), - case_data(c, v->fv)->s, - v->width); + *bounce_cur = case_num (c, v->fv); + bounce_cur += v->flt64_cnt; } - bounce_cur += v->flt64_cnt; + else + { int ofs = 0; + while (ofs < v->width) + { + int chunk = MIN (MAX_LONG_STRING, v->width - ofs); + int nv = DIV_RND_UP (chunk, sizeof (flt64)); + buf_copy_rpad ((char *) bounce_cur, nv * sizeof (flt64), + case_data (c, v->fv)->s + ofs, chunk); + bounce_cur += nv; + ofs += chunk; + } + } + } if (!w->compress)