projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix TEMPORARY bug and add regression test.
[pspp-builds.git]
/
src
/
sfm-write.c
diff --git
a/src/sfm-write.c
b/src/sfm-write.c
index b96a0733f6d8e5858467d9bca281089db5b827df..fd500f45c00b42062240d2eeb7bdf24813e083b7 100644
(file)
--- a/
src/sfm-write.c
+++ b/
src/sfm-write.c
@@
-17,24
+17,9
@@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
-/* AIX requires this to be the first thing in the file. */
#include <config.h>
#include <config.h>
-#if __GNUC__
-#define alloca __builtin_alloca
-#else
-#if HAVE_ALLOCA_H
-#include <alloca.h>
-#else
-#ifdef _AIX
-#pragma alloca
-#else
-#ifndef alloca /* predefined by HP cc +Olibcalls */
-char *alloca ();
-#endif
-#endif
-#endif
-#endif
-
+#include "sfm.h"
+#include "sfmP.h"
#include <assert.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include <stdlib.h>
#include <ctype.h>
@@
-44,15
+29,12
@@
char *alloca ();
#include <unistd.h> /* Required by SunOS4. */
#endif
#include "alloc.h"
#include <unistd.h> /* Required by SunOS4. */
#endif
#include "alloc.h"
-#include "approx.h"
#include "error.h"
#include "file-handle.h"
#include "getline.h"
#include "hash.h"
#include "magic.h"
#include "misc.h"
#include "error.h"
#include "file-handle.h"
#include "getline.h"
#include "hash.h"
#include "magic.h"
#include "misc.h"
-#include "sfm.h"
-#include "sfmP.h"
#include "str.h"
#include "value-labels.h"
#include "var.h"
#include "str.h"
#include "value-labels.h"
#include "var.h"
@@
-143,13
+125,13
@@
sfm_write_dictionary (struct sfm_write_info *inf)
goto lossage;
/* Write basic variable info. */
goto lossage;
/* Write basic variable info. */
- for (i = 0; i < d
->nvar
; i++)
- write_variable (inf, d
->var[i]
);
+ for (i = 0; i < d
ict_get_var_cnt (d)
; i++)
+ write_variable (inf, d
ict_get_var (d, i)
);
/* Write out value labels. */
/* Write out value labels. */
- for (index = i = 0; i < d
->nvar
; i++)
+ for (index = i = 0; i < d
ict_get_var_cnt (d)
; i++)
{
{
- struct variable *v = d
->var[i]
;
+ struct variable *v = d
ict_get_var (d, i)
;
if (!write_value_labels (inf, v, index))
goto lossage;
if (!write_value_labels (inf, v, index))
goto lossage;
@@
-157,7
+139,7
@@
sfm_write_dictionary (struct sfm_write_info *inf)
: DIV_RND_UP (v->width, sizeof (flt64)));
}
: DIV_RND_UP (v->width, sizeof (flt64)));
}
- if (d
->documents
!= NULL && !write_documents (inf))
+ if (d
ict_get_documents (d)
!= NULL && !write_documents (inf))
goto lossage;
if (!write_rec_7_34 (inf))
goto lossage;
goto lossage;
if (!write_rec_7_34 (inf))
goto lossage;
@@
-227,18
+209,18
@@
write_header (struct sfm_write_info *inf)
hdr.layout_code = 2;
hdr.case_size = 0;
hdr.layout_code = 2;
hdr.case_size = 0;
- for (i = 0; i < d
->nvar
; i++)
+ for (i = 0; i < d
ict_get_var_cnt (d)
; i++)
{
{
- struct variable *v = d
->var[i]
;
+ struct variable *v = d
ict_get_var (d, i)
;
hdr.case_size += (v->type == NUMERIC ? 1
: DIV_RND_UP (v->width, sizeof (flt64)));
}
inf->case_size = hdr.case_size;
p = ext->elem_type = xmalloc (inf->case_size);
hdr.case_size += (v->type == NUMERIC ? 1
: DIV_RND_UP (v->width, sizeof (flt64)));
}
inf->case_size = hdr.case_size;
p = ext->elem_type = xmalloc (inf->case_size);
- for (i = 0; i < d
->nvar
; i++)
+ for (i = 0; i < d
ict_get_var_cnt (d)
; i++)
{
{
- struct variable *v = d
->var[i]
;
+ struct variable *v = d
ict_get_var (d, i)
;
int count = (v->type == NUMERIC ? 1
: DIV_RND_UP (v->width, sizeof (flt64)));
while (count--)
int count = (v->type == NUMERIC ? 1
: DIV_RND_UP (v->width, sizeof (flt64)));
while (count--)
@@
-247,14
+229,18
@@
write_header (struct sfm_write_info *inf)
hdr.compressed = inf->compress;
hdr.compressed = inf->compress;
- update_weighting (d);
- if (d->weight_index != -1)
+ if (dict_get_weight (d) != NULL)
{
{
+ struct variable *weight_var;
int recalc_weight_index = 1;
int recalc_weight_index = 1;
+ int i;
- for (i = 0; i < d->weight_index; i++)
- {
- struct variable *v = d->var[i];
+ weight_var = dict_get_weight (d);
+ for (i = 0; ; i++)
+ {
+ struct variable *v = dict_get_var (d, i);
+ if (v == weight_var)
+ break;
recalc_weight_index += (v->type == NUMERIC ? 1
: DIV_RND_UP (v->width, sizeof (flt64)));
}
recalc_weight_index += (v->type == NUMERIC ? 1
: DIV_RND_UP (v->width, sizeof (flt64)));
}
@@
-292,9
+278,15
@@
write_header (struct sfm_write_info *inf)
sprintf (buf, "%02d:%02d:%02d", hour - 1, min - 1, sec - 1);
memcpy (hdr.creation_time, buf, sizeof hdr.creation_time);
}
sprintf (buf, "%02d:%02d:%02d", hour - 1, min - 1, sec - 1);
memcpy (hdr.creation_time, buf, sizeof hdr.creation_time);
}
+
+ {
+ const char *label = dict_get_label (d);
+ if (label == NULL)
+ label = "";
- st_bare_pad_copy (hdr.file_label, d->label ? d->label : "",
- sizeof hdr.file_label);
+ st_bare_pad_copy (hdr.file_label, label, sizeof hdr.file_label);
+ }
+
memset (hdr.padding, 0, sizeof hdr.padding);
if (!bufwrite (inf->h, &hdr, sizeof hdr))
memset (hdr.padding, 0, sizeof hdr.padding);
if (!bufwrite (inf->h, &hdr, sizeof hdr))
@@
-508,11
+500,17
@@
write_documents (struct sfm_write_info * inf)
}
rec_6;
}
rec_6;
+ const char *documents;
+ size_t n_lines;
+
+ documents = dict_get_documents (d);
+ n_lines = strlen (documents) / 80;
+
rec_6.rec_type = 6;
rec_6.rec_type = 6;
- rec_6.n_lines =
d->n_document
s;
+ rec_6.n_lines =
n_line
s;
if (!bufwrite (inf->h, &rec_6, sizeof rec_6))
return 0;
if (!bufwrite (inf->h, &rec_6, sizeof rec_6))
return 0;
- if (!bufwrite (inf->h, d
->documents, 80 * d->n_document
s))
+ if (!bufwrite (inf->h, d
ocuments, 80 * n_line
s))
return 0;
return 1;
return 0;
return 1;
@@
-677,13
+675,13
@@
sfm_write_case (struct file_handle * h, const flt64 *elem, int n_elem)
*ext->x++ = 255;
continue;
}
*ext->x++ = 255;
continue;
}
- else
+ else
if (*elem > INT_MIN && *elem < INT_MAX)
{
{
- int value = *elem
< 0 ? *elem - EPSILON : *elem + EPSILON
;
+ int value = *elem;
if (value >= 1 - COMPRESSION_BIAS
&& value <= 251 - COMPRESSION_BIAS
if (value >= 1 - COMPRESSION_BIAS
&& value <= 251 - COMPRESSION_BIAS
- &&
approx_eq (value, *elem)
)
+ &&
value == *elem
)
{
*ext->x++ = value + COMPRESSION_BIAS;
continue;
{
*ext->x++ = value + COMPRESSION_BIAS;
continue;