X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fsys-file-writer.c;h=517cf416607419c45612be23df38da0386963683;hb=19d0debdc5b72e1bb6c79956403a4d3bc054f300;hp=2639c3587aa19011b8d7671990cf2a3806d46ff5;hpb=b74d09af5e07f954c18e7cdb8aca3af47fa10208;p=pspp-builds.git diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index 2639c358..517cf416 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -1,5 +1,5 @@ /* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc. Written by Ben Pfaff . This program is free software; you can redistribute it and/or @@ -18,31 +18,35 @@ 02110-1301, USA. */ #include + #include "sys-file-writer.h" #include "sfm-private.h" -#include -#include + #include #include #include +#include #include #include #include + #include -#include "case.h" -#include "dictionary.h" -#include -#include "file-handle-def.h" #include #include +#include #include -#include "settings.h" -#include "stat-macros.h" #include +#include + +#include "case.h" +#include "dictionary.h" +#include "file-handle-def.h" +#include "settings.h" #include "value-labels.h" #include "variable.h" -#include -#include + +#include "stat-macros.h" +#include "minmax.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -295,9 +299,9 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, { struct { - int32_t rec_type P; - int32_t filler P; - } + int32_t rec_type ; + int32_t filler ; + } ATTRIBUTE((packed)) rec_999; rec_999.rec_type = 999; @@ -372,7 +376,7 @@ write_header (struct sfm_writer *w, const struct dictionary *d) if (dict_get_weight (d) != NULL) { - struct variable *weight_var; + const struct variable *weight_var; int recalc_weight_idx = 1; int i; @@ -437,8 +441,8 @@ write_header (struct sfm_writer *w, const struct dictionary *d) static inline void write_format_spec (const struct fmt_spec *src, int32_t *dest) { - assert(check_output_specifier(src, true)); - *dest = (formats[src->type].spss << 16) | (src->w << 8) | src->d; + assert (fmt_check_output (src)); + *dest = (fmt_to_io (src->type) << 16) | (src->w << 8) | src->d; } /* Write the variable record(s) for primary variable P and secondary @@ -454,7 +458,7 @@ write_variable (struct sfm_writer *w, const struct variable *v) int nm; /* Number of missing values, possibly negative. */ sv.rec_type = 2; - sv.type = min(v->width, MAX_LONG_STRING); + sv.type = MIN(v->width, MAX_LONG_STRING); sv.has_var_label = (v->label != NULL); mv_copy (&mv, &v->miss); @@ -489,14 +493,14 @@ write_variable (struct sfm_writer *w, const struct variable *v) { struct label { - int32_t label_len P; - char label[255] P; - } + int32_t label_len ; + char label[255] ; + } ATTRIBUTE((packed)) l; int ext_len; - l.label_len = min (strlen (v->label), 255); + l.label_len = MIN (strlen (v->label), 255); ext_len = ROUND_UP (l.label_len, sizeof l.label_len); memcpy (l.label, v->label, l.label_len); memset (&l.label[l.label_len], ' ', ext_len - l.label_len); @@ -519,7 +523,7 @@ write_variable (struct sfm_writer *w, const struct variable *v) memset (&sv.write, 0, sizeof sv.write); memset (&sv.name, 0, sizeof sv.name); - pad_count = DIV_RND_UP (min(v->width, MAX_LONG_STRING), + pad_count = DIV_RND_UP (MIN(v->width, MAX_LONG_STRING), (int) sizeof (flt64)) - 1; for (i = 0; i < pad_count; i++) buf_write (w, &sv, sizeof sv); @@ -533,17 +537,17 @@ write_value_labels (struct sfm_writer *w, struct variable *v, int idx) { struct value_label_rec { - int32_t rec_type P; - int32_t n_labels P; - flt64 labels[1] P; - }; + int32_t rec_type ; + int32_t n_labels ; + flt64 labels[1] ; + } ATTRIBUTE((packed)); struct var_idx_rec { - int32_t rec_type P; - int32_t n_vars P; - int32_t vars[1] P; - }; + int32_t rec_type ; + int32_t n_vars ; + int32_t vars[1] ; + } ATTRIBUTE((packed)); struct val_labs_iterator *i; struct value_label_rec *vlr; @@ -594,11 +598,10 @@ static void write_documents (struct sfm_writer *w, const struct dictionary *d) { struct - { - int32_t rec_type P; /* Always 6. */ - int32_t n_lines P; /* Number of lines of documents. */ - } - rec_6; + { + int32_t rec_type ; /* Always 6. */ + int32_t n_lines ; /* Number of lines of documents. */ + } ATTRIBUTE((packed)) rec_6; const char *documents; size_t n_lines; @@ -621,11 +624,11 @@ write_variable_display_parameters (struct sfm_writer *w, struct { - int32_t rec_type P; - int32_t subtype P; - int32_t elem_size P; - int32_t n_elem P; - } vdp_hdr; + int32_t rec_type ; + int32_t subtype ; + int32_t elem_size ; + int32_t n_elem ; + } ATTRIBUTE((packed)) vdp_hdr; vdp_hdr.rec_type = 7; vdp_hdr.subtype = 11; @@ -639,11 +642,10 @@ write_variable_display_parameters (struct sfm_writer *w, struct variable *v; struct { - int32_t measure P; - int32_t width P; - int32_t align P; - } - params; + int32_t measure ; + int32_t width ; + int32_t align ; + } ATTRIBUTE((packed)) params; v = dict_get_var(dict, i); @@ -676,13 +678,12 @@ write_vls_length_table (struct sfm_writer *w, { int i; struct - { - int32_t rec_type P; - int32_t subtype P; - int32_t elem_size P; - int32_t n_elem P; - } - vls_hdr; + { + int32_t rec_type ; + int32_t subtype ; + int32_t elem_size ; + int32_t n_elem ; + } ATTRIBUTE((packed)) vls_hdr; struct string vls_length_map; @@ -722,12 +723,11 @@ write_longvar_table (struct sfm_writer *w, const struct dictionary *dict) { struct { - int32_t rec_type P; - int32_t subtype P; - int32_t elem_size P; - int32_t n_elem P; - } - lv_hdr; + int32_t rec_type ; + int32_t subtype ; + int32_t elem_size ; + int32_t n_elem ; + } ATTRIBUTE((packed)) lv_hdr; struct string long_name_map; size_t i; @@ -759,18 +759,17 @@ write_rec_7_34 (struct sfm_writer *w) { struct { - int32_t rec_type_3 P; - int32_t subtype_3 P; - int32_t data_type_3 P; - int32_t n_elem_3 P; - int32_t elem_3[8] P; - int32_t rec_type_4 P; - int32_t subtype_4 P; - int32_t data_type_4 P; - int32_t n_elem_4 P; - flt64 elem_4[3] P; - } - rec_7; + int32_t rec_type_3 ; + int32_t subtype_3 ; + int32_t data_type_3 ; + int32_t n_elem_3 ; + int32_t elem_3[8] ; + int32_t rec_type_4 ; + int32_t subtype_4 ; + int32_t data_type_4 ; + int32_t n_elem_4 ; + flt64 elem_4[3] ; + } ATTRIBUTE((packed)) rec_7; /* Components of the version number, from major to minor. */ int version_component[3]; @@ -840,7 +839,7 @@ buf_write (struct sfm_writer *w, const void *buf, size_t nbytes) static char * append_string_max (char *dest, const char *src, const char *end) { - int nbytes = min (end - dest, (int) strlen (src)); + int nbytes = MIN (end - dest, (int) strlen (src)); memcpy (dest, src, nbytes); return dest + nbytes; }