1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "sys-file-writer.h"
22 #include "sfm-private.h"
23 #include <libpspp/message.h>
31 #include <libpspp/alloc.h>
33 #include "dictionary.h"
34 #include <libpspp/message.h>
35 #include "file-handle-def.h"
36 #include <libpspp/hash.h>
37 #include <libpspp/magic.h>
38 #include <libpspp/misc.h>
40 #include "stat-macros.h"
41 #include <libpspp/str.h>
42 #include "value-labels.h"
44 #include <libpspp/version.h>
47 #define _(msgid) gettext (msgid)
49 /* Compression bias used by PSPP. Values between (1 -
50 COMPRESSION_BIAS) and (251 - COMPRESSION_BIAS) inclusive can be
52 #define COMPRESSION_BIAS 100
54 /* System file writer. */
57 struct file_handle *fh; /* File handle. */
58 FILE *file; /* File stream. */
60 int needs_translation; /* 0=use fast path, 1=translation needed. */
61 int compress; /* 1=compressed, 0=not compressed. */
62 int case_cnt; /* Number of cases written so far. */
63 size_t flt64_cnt; /* Number of flt64 elements in case. */
65 /* Compression buffering. */
66 flt64 *buf; /* Buffered data. */
67 flt64 *end; /* Buffer end. */
68 flt64 *ptr; /* Current location in buffer. */
69 unsigned char *x; /* Location in current instruction octet. */
70 unsigned char *y; /* End of instruction octet. */
73 struct sfm_var *vars; /* Variables. */
74 size_t var_cnt; /* Number of variables. */
75 size_t var_cnt_vls; /* Number of variables including
76 very long string components. */
79 /* A variable in a system file. */
82 int width; /* 0=numeric, otherwise string width. */
83 int fv; /* Index into case. */
84 size_t flt64_cnt; /* Number of flt64 elements. */
87 static char *append_string_max (char *, const char *, const char *);
88 static void write_header (struct sfm_writer *, const struct dictionary *);
89 static void buf_write (struct sfm_writer *, const void *, size_t);
90 static void write_variable (struct sfm_writer *, const struct variable *);
91 static void write_value_labels (struct sfm_writer *,
92 struct variable *, int idx);
93 static void write_rec_7_34 (struct sfm_writer *);
95 static void write_longvar_table (struct sfm_writer *w,
96 const struct dictionary *dict);
98 static void write_vls_length_table (struct sfm_writer *w,
99 const struct dictionary *dict);
102 static void write_variable_display_parameters (struct sfm_writer *w,
103 const struct dictionary *dict);
105 static void write_documents (struct sfm_writer *, const struct dictionary *);
106 static int does_dict_need_translation (const struct dictionary *);
109 var_flt64_cnt (const struct variable *v)
111 assert(sizeof(flt64) == MAX_SHORT_STRING);
112 return width_to_bytes(v->width) / MAX_SHORT_STRING ;
116 var_flt64_cnt_nom (const struct variable *v)
118 return v->type == NUMERIC ? 1 : DIV_RND_UP (v->width, sizeof (flt64));
122 /* Returns default options for writing a system file. */
123 struct sfm_write_options
124 sfm_writer_default_options (void)
126 struct sfm_write_options opts;
127 opts.create_writeable = true;
128 opts.compress = get_scompression ();
134 /* Return a short variable name to be used as the continuation of the
135 variable with the short name SN.
137 FIXME: Need to resolve clashes somehow.
141 cont_var_name(const char *sn, int idx)
143 static char s[SHORT_NAME_LEN + 1];
145 char abb[SHORT_NAME_LEN + 1 - 3]= {0};
147 strncpy(abb, sn, SHORT_NAME_LEN - 3);
149 snprintf(s, SHORT_NAME_LEN + 1, "%s%03d", abb, idx);
155 /* Opens the system file designated by file handle FH for writing
156 cases from dictionary D according to the given OPTS. If
157 COMPRESS is nonzero, the system file will be compressed.
159 No reference to D is retained, so it may be modified or
160 destroyed at will after this function returns. D is not
161 modified by this function, except to assign short names. */
163 sfm_open_writer (struct file_handle *fh, struct dictionary *d,
164 struct sfm_write_options opts)
166 struct sfm_writer *w = NULL;
173 if (opts.version != 2 && opts.version != 3)
175 msg (ME, _("Unknown system file version %d. Treating as version %d."),
181 mode = S_IRUSR | S_IRGRP | S_IROTH;
182 if (opts.create_writeable)
183 mode |= S_IWUSR | S_IWGRP | S_IWOTH;
184 fd = open (fh_get_file_name (fh), O_WRONLY | O_CREAT | O_TRUNC, mode);
188 /* Open file handle. */
189 if (!fh_open (fh, FH_REF_FILE, "system file", "we"))
192 /* Create and initialize writer. */
193 w = xmalloc (sizeof *w);
195 w->file = fdopen (fd, "w");
197 w->needs_translation = does_dict_need_translation (d);
198 w->compress = opts.compress;
202 w->buf = w->end = w->ptr = NULL;
205 w->var_cnt = dict_get_var_cnt (d);
206 w->var_cnt_vls = w->var_cnt;
207 w->vars = xnmalloc (w->var_cnt, sizeof *w->vars);
208 for (i = 0; i < w->var_cnt; i++)
210 const struct variable *dv = dict_get_var (d, i);
211 struct sfm_var *sv = &w->vars[i];
212 sv->width = dv->width;
213 /* spss compatibility nonsense */
214 if ( dv->width > MAX_LONG_STRING )
215 sv->width = (dv->width / MAX_LONG_STRING) * (MAX_LONG_STRING + 1)
216 + (dv->width % MAX_LONG_STRING) ;
218 sv->flt64_cnt = var_flt64_cnt (dv);
221 /* Check that file create succeeded. */
228 /* Write the file header. */
231 /* Write basic variable info. */
232 dict_assign_short_names (d);
233 for (i = 0; i < dict_get_var_cnt (d); i++)
236 const struct variable *v = dict_get_var(d, i);
237 int wcount = v->width;
240 struct variable var_cont = *v;
241 if ( v->type == ALPHA)
245 mv_init(&var_cont.miss, 0);
246 strcpy(var_cont.short_name,
247 cont_var_name(v->short_name, count));
248 var_cont.label = NULL;
252 if ( wcount > MAX_LONG_STRING )
254 var_cont.width = MAX_LONG_STRING;
255 wcount -= EFFECTIVE_LONG_STRING_LENGTH;
259 var_cont.width = wcount;
260 wcount -= var_cont.width;
263 var_cont.write.w = var_cont.width;
264 var_cont.print.w = var_cont.width;
267 write_variable (w, &var_cont);
271 /* Write out value labels. */
272 for (idx = i = 0; i < dict_get_var_cnt (d); i++)
274 struct variable *v = dict_get_var (d, i);
276 write_value_labels (w, v, idx);
277 idx += var_flt64_cnt (v);
280 if (dict_get_documents (d) != NULL)
281 write_documents (w, d);
285 write_variable_display_parameters (w, d);
287 if (opts.version >= 3)
288 write_longvar_table (w, d);
290 write_vls_length_table(w, d);
292 /* Write end-of-headers record. */
301 rec_999.rec_type = 999;
304 buf_write (w, &rec_999, sizeof rec_999);
309 w->buf = xnmalloc (128, sizeof *w->buf);
311 w->end = &w->buf[128];
312 w->x = (unsigned char *) w->ptr++;
313 w->y = (unsigned char *) w->ptr;
316 if (sfm_write_error (w))
322 sfm_close_writer (w);
326 msg (ME, _("Error opening \"%s\" for writing as a system file: %s."),
327 fh_get_file_name (fh), strerror (errno));
332 does_dict_need_translation (const struct dictionary *d)
338 for (i = 0; i < dict_get_var_cnt (d); i++)
340 struct variable *v = dict_get_var (d, i);
341 if (v->fv != case_idx)
348 /* Returns value of X truncated to two least-significant digits. */
359 /* Write the sysfile_header header to system file W. */
361 write_header (struct sfm_writer *w, const struct dictionary *d)
363 struct sysfile_header hdr;
369 memcpy (hdr.rec_type, "$FL2", 4);
371 p = stpcpy (hdr.prod_name, "@(#) SPSS DATA FILE ");
372 p = append_string_max (p, version, &hdr.prod_name[60]);
373 p = append_string_max (p, " - ", &hdr.prod_name[60]);
374 p = append_string_max (p, host_system, &hdr.prod_name[60]);
375 memset (p, ' ', &hdr.prod_name[60] - p);
380 for (i = 0; i < dict_get_var_cnt (d); i++)
382 w->flt64_cnt += var_flt64_cnt (dict_get_var (d, i));
384 hdr.nominal_case_size = w->flt64_cnt;
386 hdr.compress = w->compress;
388 if (dict_get_weight (d) != NULL)
390 struct variable *weight_var;
391 int recalc_weight_idx = 1;
394 weight_var = dict_get_weight (d);
397 struct variable *v = dict_get_var (d, i);
400 recalc_weight_idx += var_flt64_cnt (v);
402 hdr.weight_idx = recalc_weight_idx;
408 hdr.bias = COMPRESSION_BIAS;
410 if (time (&t) == (time_t) -1)
412 memcpy (hdr.creation_date, "01 Jan 70", 9);
413 memcpy (hdr.creation_time, "00:00:00", 8);
417 static const char *month_name[12] =
419 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
420 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
422 struct tm *tmp = localtime (&t);
423 int day = rerange (tmp->tm_mday);
424 int mon = rerange (tmp->tm_mon + 1);
425 int year = rerange (tmp->tm_year);
426 int hour = rerange (tmp->tm_hour + 1);
427 int min = rerange (tmp->tm_min + 1);
428 int sec = rerange (tmp->tm_sec + 1);
431 sprintf (buf, "%02d %s %02d", day, month_name[mon - 1], year);
432 memcpy (hdr.creation_date, buf, sizeof hdr.creation_date);
433 sprintf (buf, "%02d:%02d:%02d", hour - 1, min - 1, sec - 1);
434 memcpy (hdr.creation_time, buf, sizeof hdr.creation_time);
438 const char *label = dict_get_label (d);
442 buf_copy_str_rpad (hdr.file_label, sizeof hdr.file_label, label);
445 memset (hdr.padding, 0, sizeof hdr.padding);
447 buf_write (w, &hdr, sizeof hdr);
450 /* Translates format spec from internal form in SRC to system file
453 write_format_spec (const struct fmt_spec *src, int32_t *dest)
455 assert(check_output_specifier(src, true));
456 *dest = (formats[src->type].spss << 16) | (src->w << 8) | src->d;
459 /* Write the variable record(s) for primary variable P and secondary
460 variable S to system file W. */
462 write_variable (struct sfm_writer *w, const struct variable *v)
464 struct sysfile_variable sv;
466 /* Missing values. */
467 struct missing_values mv;
468 flt64 m[3]; /* Missing value values. */
469 int nm; /* Number of missing values, possibly negative. */
472 sv.type = min(v->width, MAX_LONG_STRING);
473 sv.has_var_label = (v->label != NULL);
475 mv_copy (&mv, &v->miss);
477 if (mv_has_range (&mv))
480 mv_pop_range (&mv, &x, &y);
481 m[nm++] = x == LOWEST ? second_lowest_flt64 : x;
482 m[nm++] = y == HIGHEST ? FLT64_MAX : y;
484 while (mv_has_value (&mv))
487 mv_pop_value (&mv, &value);
488 if (v->type == NUMERIC)
491 buf_copy_rpad ((char *) &m[nm], sizeof m[nm], value.s, v->width);
494 if (mv_has_range (&v->miss))
497 sv.n_missing_values = nm;
498 write_format_spec (&v->print, &sv.print);
499 write_format_spec (&v->write, &sv.write);
500 buf_copy_str_rpad (sv.name, sizeof sv.name, v->short_name);
501 buf_write (w, &sv, sizeof sv);
514 l.label_len = min (strlen (v->label), 255);
515 ext_len = ROUND_UP (l.label_len, sizeof l.label_len);
516 memcpy (l.label, v->label, l.label_len);
517 memset (&l.label[l.label_len], ' ', ext_len - l.label_len);
519 buf_write (w, &l, offsetof (struct label, label) + ext_len);
523 buf_write (w, m, sizeof *m * abs (nm));
525 if (v->type == ALPHA && v->width > (int) sizeof (flt64))
531 sv.has_var_label = 0;
532 sv.n_missing_values = 0;
533 memset (&sv.print, 0, sizeof sv.print);
534 memset (&sv.write, 0, sizeof sv.write);
535 memset (&sv.name, 0, sizeof sv.name);
537 pad_count = DIV_RND_UP (min(v->width, MAX_LONG_STRING),
538 (int) sizeof (flt64)) - 1;
539 for (i = 0; i < pad_count; i++)
540 buf_write (w, &sv, sizeof sv);
544 /* Writes the value labels for variable V having system file
545 variable index IDX to system file W. */
547 write_value_labels (struct sfm_writer *w, struct variable *v, int idx)
549 struct value_label_rec
563 struct val_labs_iterator *i;
564 struct value_label_rec *vlr;
565 struct var_idx_rec vir;
570 if (!val_labs_count (v->val_labs))
573 /* Pass 1: Count bytes. */
574 vlr_size = (sizeof (struct value_label_rec)
575 + sizeof (flt64) * (val_labs_count (v->val_labs) - 1));
576 for (vl = val_labs_first (v->val_labs, &i); vl != NULL;
577 vl = val_labs_next (v->val_labs, &i))
578 vlr_size += ROUND_UP (strlen (vl->label) + 1, sizeof (flt64));
580 /* Pass 2: Copy bytes. */
581 vlr = xmalloc (vlr_size);
583 vlr->n_labels = val_labs_count (v->val_labs);
585 for (vl = val_labs_first_sorted (v->val_labs, &i); vl != NULL;
586 vl = val_labs_next (v->val_labs, &i))
588 size_t len = strlen (vl->label);
590 *loc++ = vl->value.f;
591 *(unsigned char *) loc = len;
592 memcpy (&((char *) loc)[1], vl->label, len);
593 memset (&((char *) loc)[1 + len], ' ',
594 REM_RND_UP (len + 1, sizeof (flt64)));
595 loc += DIV_RND_UP (len + 1, sizeof (flt64));
598 buf_write (w, vlr, vlr_size);
603 vir.vars[0] = idx + 1;
604 buf_write (w, &vir, sizeof vir);
607 /* Writes record type 6, document record. */
609 write_documents (struct sfm_writer *w, const struct dictionary *d)
613 int32_t rec_type P; /* Always 6. */
614 int32_t n_lines P; /* Number of lines of documents. */
618 const char *documents;
621 documents = dict_get_documents (d);
622 n_lines = strlen (documents) / 80;
625 rec_6.n_lines = n_lines;
626 buf_write (w, &rec_6, sizeof rec_6);
627 buf_write (w, documents, 80 * n_lines);
630 /* Write the alignment, width and scale values */
632 write_variable_display_parameters (struct sfm_writer *w,
633 const struct dictionary *dict)
645 vdp_hdr.rec_type = 7;
646 vdp_hdr.subtype = 11;
647 vdp_hdr.elem_size = 4;
648 vdp_hdr.n_elem = w->var_cnt_vls * 3;
650 buf_write (w, &vdp_hdr, sizeof vdp_hdr);
652 for ( i = 0 ; i < w->var_cnt ; ++i )
663 v = dict_get_var(dict, i);
665 params.measure = v->measure;
666 params.width = v->display_width;
667 params.align = v->alignment;
669 buf_write (w, ¶ms, sizeof(params));
671 if ( v->width > MAX_LONG_STRING )
673 int wcount = v->width - EFFECTIVE_LONG_STRING_LENGTH ;
677 params.width = wcount > MAX_LONG_STRING ? 32 : wcount;
679 buf_write (w, ¶ms, sizeof(params));
681 wcount -= EFFECTIVE_LONG_STRING_LENGTH ;
687 /* Writes the table of lengths for Very Long String Variables */
689 write_vls_length_table (struct sfm_writer *w,
690 const struct dictionary *dict)
702 struct string vls_length_map;
704 ds_init (&vls_length_map, 12 * dict_get_var_cnt (dict));
706 vls_hdr.rec_type = 7;
707 vls_hdr.subtype = 14;
708 vls_hdr.elem_size = 1;
711 for (i = 0; i < dict_get_var_cnt (dict); ++i)
713 const struct variable *v = dict_get_var (dict, i);
715 if ( v->width <= MAX_LONG_STRING )
718 ds_printf (&vls_length_map, "%s=%05d", v->short_name, v->width);
719 ds_putc (&vls_length_map, '\0');
720 ds_putc (&vls_length_map, '\t');
723 vls_hdr.n_elem = ds_length (&vls_length_map);
725 if ( vls_hdr.n_elem > 0 )
727 buf_write (w, &vls_hdr, sizeof vls_hdr);
728 buf_write (w, ds_data (&vls_length_map), ds_length (&vls_length_map));
731 ds_destroy (&vls_length_map);
734 /* Writes the long variable name table */
736 write_longvar_table (struct sfm_writer *w, const struct dictionary *dict)
747 struct string long_name_map;
750 ds_init (&long_name_map, 10 * dict_get_var_cnt (dict));
751 for (i = 0; i < dict_get_var_cnt (dict); i++)
753 struct variable *v = dict_get_var (dict, i);
756 ds_putc (&long_name_map, '\t');
757 ds_printf (&long_name_map, "%s=%s", v->short_name, v->name);
762 lv_hdr.elem_size = 1;
763 lv_hdr.n_elem = ds_length (&long_name_map);
765 buf_write (w, &lv_hdr, sizeof lv_hdr);
766 buf_write (w, ds_data (&long_name_map), ds_length (&long_name_map));
768 ds_destroy (&long_name_map);
771 /* Writes record type 7, subtypes 3 and 4. */
773 write_rec_7_34 (struct sfm_writer *w)
777 int32_t rec_type_3 P;
779 int32_t data_type_3 P;
782 int32_t rec_type_4 P;
784 int32_t data_type_4 P;
790 /* Components of the version number, from major to minor. */
791 int version_component[3];
793 /* Used to step through the version string. */
796 /* Parses the version string, which is assumed to be of the form
797 #.#x, where each # is a string of digits, and x is a single
799 version_component[0] = strtol (bare_version, &p, 10);
802 version_component[1] = strtol (bare_version, &p, 10);
803 version_component[2] = (isalpha ((unsigned char) *p)
804 ? tolower ((unsigned char) *p) - 'a' : 0);
806 rec_7.rec_type_3 = 7;
808 rec_7.data_type_3 = sizeof (int32_t);
810 rec_7.elem_3[0] = version_component[0];
811 rec_7.elem_3[1] = version_component[1];
812 rec_7.elem_3[2] = version_component[2];
813 rec_7.elem_3[3] = -1;
815 /* PORTME: 1=IEEE754, 2=IBM 370, 3=DEC VAX E. */
822 /* PORTME: 1=big-endian, 2=little-endian. */
829 /* PORTME: 1=EBCDIC, 2=7-bit ASCII, 3=8-bit ASCII, 4=DEC Kanji. */
832 rec_7.rec_type_4 = 7;
834 rec_7.data_type_4 = sizeof (flt64);
836 rec_7.elem_4[0] = -FLT64_MAX;
837 rec_7.elem_4[1] = FLT64_MAX;
838 rec_7.elem_4[2] = second_lowest_flt64;
840 buf_write (w, &rec_7, sizeof rec_7);
843 /* Write NBYTES starting at BUF to the system file represented by
846 buf_write (struct sfm_writer *w, const void *buf, size_t nbytes)
848 assert (buf != NULL);
849 fwrite (buf, nbytes, 1, w->file);
852 /* Copies string DEST to SRC with the proviso that DEST does not reach
853 byte END; no null terminator is copied. Returns a pointer to the
854 byte after the last byte copied. */
856 append_string_max (char *dest, const char *src, const char *end)
858 int nbytes = min (end - dest, (int) strlen (src));
859 memcpy (dest, src, nbytes);
860 return dest + nbytes;
863 /* Makes certain that the compression buffer of H has room for another
864 element. If there's not room, pads out the current instruction
865 octet with zero and dumps out the buffer. */
867 ensure_buf_space (struct sfm_writer *w)
869 if (w->ptr >= w->end)
871 memset (w->x, 0, w->y - w->x);
874 buf_write (w, w->buf, sizeof *w->buf * 128);
878 static void write_compressed_data (struct sfm_writer *w, const flt64 *elem);
880 /* Writes case C to system file W.
881 Returns 1 if successful, 0 if an I/O error occurred. */
883 sfm_write_case (struct sfm_writer *w, const struct ccase *c)
885 if (ferror (w->file))
890 if (!w->needs_translation && !w->compress
891 && sizeof (flt64) == sizeof (union value))
893 /* Fast path: external and internal representations are the
894 same and the dictionary is properly ordered. Write
896 buf_write (w, case_data_all (c), sizeof (union value) * w->flt64_cnt);
900 /* Slow path: internal and external representations differ.
901 Write into a bounce buffer, then write to W. */
908 bounce_size = sizeof *bounce * w->flt64_cnt;
909 bounce = bounce_cur = local_alloc (bounce_size);
910 bounce_end = bounce + bounce_size;
912 for (i = 0; i < w->var_cnt; i++)
914 struct sfm_var *v = &w->vars[i];
916 memset(bounce_cur, ' ', v->flt64_cnt * sizeof (flt64));
919 *bounce_cur = case_num (c, v->fv);
922 buf_copy_rpad((char*)bounce_cur, v->flt64_cnt * sizeof (flt64),
923 case_data(c, v->fv)->s,
926 bounce_cur += v->flt64_cnt;
930 buf_write (w, bounce, bounce_size);
932 write_compressed_data (w, bounce);
937 return !sfm_write_error (w);
941 put_instruction (struct sfm_writer *w, unsigned char instruction)
945 ensure_buf_space (w);
946 w->x = (unsigned char *) w->ptr++;
947 w->y = (unsigned char *) w->ptr;
949 *w->x++ = instruction;
953 put_element (struct sfm_writer *w, const flt64 *elem)
955 ensure_buf_space (w);
956 memcpy (w->ptr++, elem, sizeof *elem);
960 write_compressed_data (struct sfm_writer *w, const flt64 *elem)
964 for (i = 0; i < w->var_cnt; i++)
966 struct sfm_var *v = &w->vars[i];
970 if (*elem == -FLT64_MAX)
971 put_instruction (w, 255);
972 else if (*elem >= 1 - COMPRESSION_BIAS
973 && *elem <= 251 - COMPRESSION_BIAS
974 && *elem == (int) *elem)
975 put_instruction (w, (int) *elem + COMPRESSION_BIAS);
978 put_instruction (w, 253);
979 put_element (w, elem);
987 for (j = 0; j < v->flt64_cnt; j++, elem++)
989 if (!memcmp (elem, " ", sizeof (flt64)))
990 put_instruction (w, 254);
993 put_instruction (w, 253);
994 put_element (w, elem);
1001 /* Returns true if an I/O error has occurred on WRITER, false otherwise. */
1003 sfm_write_error (const struct sfm_writer *writer)
1005 return ferror (writer->file);
1008 /* Closes a system file after we're done with it.
1009 Returns true if successful, false if an I/O error occurred. */
1011 sfm_close_writer (struct sfm_writer *w)
1019 if (w->file != NULL)
1022 if (w->buf != NULL && w->ptr > w->buf)
1024 memset (w->x, 0, w->y - w->x);
1025 buf_write (w, w->buf, (w->ptr - w->buf) * sizeof *w->buf);
1029 ok = !sfm_write_error (w);
1031 /* Seek back to the beginning and update the number of cases.
1032 This is just a courtesy to later readers, so there's no need
1033 to check return values or report errors. */
1034 if (ok && !fseek (w->file, offsetof (struct sysfile_header, case_cnt),
1037 int32_t case_cnt = w->case_cnt;
1038 fwrite (&case_cnt, sizeof case_cnt, 1, w->file);
1042 if (fclose (w->file) == EOF)
1046 msg (ME, _("An I/O error occurred writing system file \"%s\"."),
1047 fh_get_file_name (w->fh));
1050 fh_close (w->fh, "system file", "we");